diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8e5b1995..401048c5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,49 +12,24 @@ repos: - id: trailing-whitespace exclude: miscellaneous/structures + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.2.2 + hooks: + - id: ruff-format + exclude: ^docs/.* + - id: ruff + args: [--fix, --exit-non-zero-on-fix, --show-fixes] + - repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt rev: 0.2.3 hooks: - id: yamlfmt - - repo: https://github.com/psf/black - rev: 23.12.1 - hooks: - - id: black - language_version: python3 # Should be a command that runs python3.6+ - - - repo: https://github.com/PyCQA/flake8 - rev: 6.1.0 - hooks: - - id: flake8 - args: [--count, --show-source, --statistics] - additional_dependencies: - - flake8-bugbear==23.2.13 - - flake8-builtins==2.1.0 - - flake8-comprehensions==3.10.1 - - flake8-debugger==4.1.2 - - flake8-logging-format==0.9.0 - - pep8-naming==0.13.3 - - pyflakes==3.1.0 - - tryceratops==1.1.0 - - - repo: https://github.com/pycqa/isort - rev: 5.13.2 - hooks: - - id: isort - args: [--profile, black, --filter-files] - - repo: https://github.com/sirosen/check-jsonschema rev: 0.27.3 hooks: - id: check-github-workflows - - repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 - hooks: - - id: pyupgrade - args: [--py39-plus] - - repo: https://github.com/kynan/nbstripout rev: 0.6.1 hooks: diff --git a/aiidalab_widgets_base/bug_report.py b/aiidalab_widgets_base/bug_report.py index 5a494481..9ffe4a67 100644 --- a/aiidalab_widgets_base/bug_report.py +++ b/aiidalab_widgets_base/bug_report.py @@ -28,6 +28,7 @@ def find_installed_packages(python_bin: str | None = None) -> dict[str, str]: [python_bin, "-m", "pip", "list", "--format=json"], encoding="utf-8", capture_output=True, + check=True, ).stdout return {package["name"]: package["version"] for package in json.loads(output)} @@ -160,7 +161,7 @@ def install_create_github_issue_exception_handler(output, url, labels=None): display(welcome_message, app_with_work_chain_selector, footer) """ - global _ORIGINAL_EXCEPTION_HANDLER + global _ORIGINAL_EXCEPTION_HANDLER # noqa if labels is None: labels = [] diff --git a/aiidalab_widgets_base/computational_resources.py b/aiidalab_widgets_base/computational_resources.py index 61db1274..937607f4 100644 --- a/aiidalab_widgets_base/computational_resources.py +++ b/aiidalab_widgets_base/computational_resources.py @@ -376,7 +376,7 @@ def _ssh_keygen(self): "", ] if not fpath.exists(): - subprocess.run(keygen_cmd, capture_output=True) + subprocess.run(keygen_cmd, capture_output=True, check=True) def _can_login(self): """Check if it is possible to login into the remote host.""" @@ -1028,6 +1028,7 @@ def test(self, _=None): process_result = subprocess.run( ["verdi", "computer", "test", "--print-traceback", self.label.value], capture_output=True, + check=False, ) if process_result.returncode == 0: @@ -1602,7 +1603,7 @@ def __init__( enable_detailed_setup=True, ): if not any((enable_detailed_setup, enable_quick_setup)): - raise ValueError( # noqa + raise ValueError( "At least one of `enable_quick_setup` and `enable_detailed_setup` should be True." ) diff --git a/aiidalab_widgets_base/databases.py b/aiidalab_widgets_base/databases.py index c3b57a5b..48d39ccd 100644 --- a/aiidalab_widgets_base/databases.py +++ b/aiidalab_widgets_base/databases.py @@ -152,8 +152,8 @@ class :class:`aiidalab_widgets_base.structures.StructureManagerWidget`. def __init__( self, - embedded: bool = True, - title: str = None, + embedded=True, + title=None, **kwargs, ) -> None: try: diff --git a/aiidalab_widgets_base/elns.py b/aiidalab_widgets_base/elns.py index 64e27f23..b14977a9 100644 --- a/aiidalab_widgets_base/elns.py +++ b/aiidalab_widgets_base/elns.py @@ -249,9 +249,7 @@ def update_list_of_elns(self): self.write_to_config(config) default_eln = None - self.eln_instance.options = [("Setup new ELN", {})] + [ - (k, v) for k, v in config.items() - ] + self.eln_instance.options = [("Setup new ELN", {}), *list(config.items())] if default_eln: self.eln_instance.label = default_eln diff --git a/aiidalab_widgets_base/export.py b/aiidalab_widgets_base/export.py index 9b34304b..bdd4a106 100644 --- a/aiidalab_widgets_base/export.py +++ b/aiidalab_widgets_base/export.py @@ -40,8 +40,6 @@ def export_aiida_subgraph(self, change=None): # pylint: disable=unused-argument document.body.appendChild(link); link.click(); document.body.removeChild(link); - """.format( - payload=payload, filename=f"export_{self.process.id}.aiida" - ) + """.format(payload=payload, filename=f"export_{self.process.id}.aiida") ) display(javas) diff --git a/aiidalab_widgets_base/misc.py b/aiidalab_widgets_base/misc.py index 6afbf00a..fb7e79b7 100644 --- a/aiidalab_widgets_base/misc.py +++ b/aiidalab_widgets_base/misc.py @@ -20,7 +20,7 @@ def copy_to_clipboard(self, change=None): # pylint:disable=unused-argument from IPython.display import Javascript, display javas = Javascript( - """ + f""" function copyStringToClipboard (str) {{ // Create new element var el = document.createElement('textarea'); @@ -37,10 +37,8 @@ def copy_to_clipboard(self, change=None): # pylint:disable=unused-argument // Remove temporary element document.body.removeChild(el); }} - copyStringToClipboard("{selection}"); - """.format( - selection=self.value - ) + copyStringToClipboard("{self.value}"); + """ ) # For the moment works for Chrome, but doesn't work for Firefox. if self.value: # If no value provided - do nothing. display(javas) diff --git a/aiidalab_widgets_base/process.py b/aiidalab_widgets_base/process.py index 8839ddba..bf75cc67 100644 --- a/aiidalab_widgets_base/process.py +++ b/aiidalab_widgets_base/process.py @@ -156,10 +156,10 @@ def __init__(self, process=None, **kwargs): self.info = ipw.HTML() self.flat_mapping = self.generate_flat_mapping(process=process) or {} - inputs_list = [(key, value) for key, value in self.flat_mapping.items()] + inputs_list = list(self.flat_mapping.items()) self._inputs = ipw.Dropdown( - options=[("Select input", "")] + inputs_list, + options=[("Select input", ""), *inputs_list], description="Select input:", style={"description_width": "initial"}, disabled=False, @@ -230,7 +230,7 @@ def __init__(self, process=None, **kwargs): else [] ) outputs = ipw.Dropdown( - options=[("Select output", "")] + outputs_list, + options=[("Select output", ""), *outputs_list], label="Select output", description="Select outputs:", style={"description_width": "initial"}, @@ -285,7 +285,7 @@ def __init__( ) ) self.output = ipw.HTML() - super().__init__(children=[self.output] + self.followers, **kwargs) + super().__init__(children=[self.output, *self.followers], **kwargs) self.update() def update(self): diff --git a/aiidalab_widgets_base/structures.py b/aiidalab_widgets_base/structures.py index c3f4ecea..fc2d80f9 100644 --- a/aiidalab_widgets_base/structures.py +++ b/aiidalab_widgets_base/structures.py @@ -118,8 +118,11 @@ def __init__( self._structure_importers(importers), self.viewer, ipw.HBox( - store_and_description - + [self.structure_label, self.structure_description] + [ + *store_and_description, + self.structure_label, + self.structure_description, + ] ), ] @@ -131,7 +134,7 @@ def __init__( accordion.set_title(0, "Edit Structure") children += [accordion] - super().__init__(children=children + [self.output], **kwargs) + super().__init__(children=[*children, self.output], **kwargs) def _structure_importers(self, importers): """Preparing structure importers.""" @@ -217,7 +220,7 @@ def store_structure(self, _=None): ): # Make a link between self.input_structure and self.structure_node @engine.calcfunction - def user_modifications(source_structure): + def user_modifications(_source_structure): return self.structure_node structure_node = user_modifications(self.input_structure) @@ -469,7 +472,7 @@ class StructureExamplesWidget(ipw.VBox): def __init__(self, examples, title="", **kwargs): self.title = title - self.on_structure_selection = lambda structure_ase, name: None + self.on_structure_selection = lambda _structure_ase, _name: None self._select_structure = ipw.Dropdown( options=self.get_example_structures(examples) ) @@ -483,7 +486,7 @@ def get_example_structures(examples): raise TypeError( f"parameter examples should be of type list, {type(examples)} given" ) - return [("Select structure", False)] + examples + return [("Select structure", False), *examples] def _on_select_structure(self, change=None): """When structure is selected.""" @@ -687,7 +690,7 @@ class SmilesWidget(ipw.VBox): def __init__(self, title=""): self.title = title - try: # noqa: TC101 + try: from rdkit import Chem # noqa: F401 from rdkit.Chem import AllChem # noqa: F401 except ImportError: @@ -1065,13 +1068,11 @@ def _apply_cell_transformation(self, _=None, atoms=None): try: atoms = make_supercell(atoms, mat) except Exception as e: - self._status_message.message = """ + self._status_message.message = f"""