diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 56c8a0df2..077b80f80 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -41,3 +41,9 @@ repos: rev: 0.13.0 hooks: - id: check-github-workflows + + - repo: https://github.com/asottile/pyupgrade + rev: v2.31.0 + hooks: + - id: pyupgrade + args: [--py37-plus] diff --git a/aiidalab_widgets_base/codes.py b/aiidalab_widgets_base/codes.py index 37959ca57..5a89231a5 100644 --- a/aiidalab_widgets_base/codes.py +++ b/aiidalab_widgets_base/codes.py @@ -254,7 +254,7 @@ def __init__(self, path_to_root="../", **kwargs): btn_setup_code, self._setup_code_out, ] - super(AiiDACodeSetup, self).__init__(children, **kwargs) + super().__init__(children, **kwargs) @validate("input_plugin") def _validate_input_plugin(self, proposal): diff --git a/aiidalab_widgets_base/computational_resources.py b/aiidalab_widgets_base/computational_resources.py index 05b051198..87fb286f0 100644 --- a/aiidalab_widgets_base/computational_resources.py +++ b/aiidalab_widgets_base/computational_resources.py @@ -853,10 +853,8 @@ def __init__(self, path_to_root="../", **kwargs): # Code plugin. self.input_plugin = ipw.Dropdown( options=sorted( - [ - (ep.name, ep) - for ep in plugins.entry_point.get_entry_points("aiida.calculations") - ] + (ep.name, ep) + for ep in plugins.entry_point.get_entry_points("aiida.calculations") ), description="Code plugin:", layout=LAYOUT, diff --git a/aiidalab_widgets_base/computers.py b/aiidalab_widgets_base/computers.py index 52e71d93d..986f011a5 100644 --- a/aiidalab_widgets_base/computers.py +++ b/aiidalab_widgets_base/computers.py @@ -171,7 +171,7 @@ def __init__(self, **kwargs): btn_setup_ssh, self._setup_ssh_out, ] - super(SshComputerSetup, self).__init__(children, **kwargs) + super().__init__(children, **kwargs) @staticmethod def _ssh_keygen(): @@ -297,8 +297,8 @@ def _send_pubkey(hostname, username, password, proxycmd=""): from pexpect import TIMEOUT timeout = 10 - print("Sending public key to {}... ".format(hostname), end="") - str_ssh = "ssh-copy-id {}@{}".format(username, hostname) + print(f"Sending public key to {hostname}... ", end="") + str_ssh = f"ssh-copy-id {username}@{hostname}" if proxycmd: str_ssh += ' -o "ProxyCommand ssh -q -Y ' + proxycmd + ' netcat %h %p\n"' child = pexpect.spawn(str_ssh) @@ -314,7 +314,7 @@ def _send_pubkey(hostname, username, password, proxycmd=""): timeout=timeout, ) # final except TIMEOUT: - print("Exceeded {} s timeout".format(timeout)) + print(f"Exceeded {timeout} s timeout") return False possible_output = { @@ -736,11 +736,11 @@ def __init__(self, **kwargs): ipw.HBox([btn_setup_comp, btn_test]), ipw.HBox([self._setup_comp_out, self._test_out]), ] - super(AiidaComputerSetup, self).__init__(children, **kwargs) + super().__init__(children, **kwargs) def _configure_computer(self): """Create AuthInfo.""" - print("Configuring '{}'".format(self.label)) + print(f"Configuring '{self.label}'") sshcfg = parse_sshconfig(self.hostname) authparams = { "compress": True, diff --git a/aiidalab_widgets_base/databases.py b/aiidalab_widgets_base/databases.py index 66faa6433..f2b9331d9 100644 --- a/aiidalab_widgets_base/databases.py +++ b/aiidalab_widgets_base/databases.py @@ -66,7 +66,7 @@ def __init__(self, title="", **kwargs): self.query_message, ipw.HBox([self.drop_structure, self.link]), ] - super(CodQueryWidget, self).__init__(children=children, **kwargs) + super().__init__(children=children, **kwargs) @staticmethod def _query(idn=None, formula=None): @@ -106,7 +106,7 @@ def _on_click_query(self, change): # pylint: disable=unused-argument ) structures.append(entry_add) - self.query_message.value += "{} structures found".format(len(structures) - 1) + self.query_message.value += f"{len(structures) - 1} structures found" self.drop_structure.options = structures def _on_select_structure(self, change): @@ -462,10 +462,10 @@ def _reset(self, _=None): def clean_up_database(self, database, plugin): for domain in list(database.keys()): - for computer in list(database[domain].keys() - set(["default"])): + for computer in list(database[domain].keys() - {"default"}): for code in list( database[domain][computer].keys() - - set(["computer-configure", "computer-setup"]) + - {"computer-configure", "computer-setup"} ): if plugin != database[domain][computer][code]["input_plugin"]: del database[domain][computer][code] @@ -473,18 +473,18 @@ def clean_up_database(self, database, plugin): if ( len( database[domain][computer].keys() - - set(["computer-configure", "computer-setup"]) + - {"computer-configure", "computer-setup"} ) == 0 ): del database[domain][computer] # If no computers remained - remove the domain. - if len(database[domain].keys() - set(["default"])) == 0: + if len(database[domain].keys() - {"default"}) == 0: del database[domain] # Making sure the 'default' key still points to an existing computer. elif database[domain]["default"] not in database[domain]: database[domain]["default"] = sorted( - database[domain].keys() - set(["default"]) + database[domain].keys() - {"default"} )[0] return database diff --git a/aiidalab_widgets_base/elns.py b/aiidalab_widgets_base/elns.py index 6fad47d64..6565f6bea 100644 --- a/aiidalab_widgets_base/elns.py +++ b/aiidalab_widgets_base/elns.py @@ -19,7 +19,7 @@ def connect_to_eln(eln_instance=None, **kwargs): # assuming that the connection can only be established to the ELNs # with the stored configuration. try: - with open(ELN_CONFIG, "r") as file: + with open(ELN_CONFIG) as file: config = json.load(file) except (FileNotFoundError, json.JSONDecodeError, KeyError): return ( @@ -235,7 +235,7 @@ def write_to_config(self, config): def get_config(self): try: - with open(ELN_CONFIG, "r") as file: + with open(ELN_CONFIG) as file: return json.load(file) except (FileNotFoundError, json.JSONDecodeError, KeyError): return {} diff --git a/aiidalab_widgets_base/export.py b/aiidalab_widgets_base/export.py index 16e1b87b5..69a849fef 100644 --- a/aiidalab_widgets_base/export.py +++ b/aiidalab_widgets_base/export.py @@ -11,11 +11,11 @@ class ExportButtonWidget(Button): def __init__(self, process, **kwargs): self.process = process if "description" not in kwargs: - kwargs["description"] = "Export workflow ({})".format(self.process.id) + kwargs["description"] = f"Export workflow ({self.process.id})" if "layout" not in kwargs: kwargs["layout"] = {} kwargs["layout"]["width"] = "initial" - super(ExportButtonWidget, self).__init__(**kwargs) + super().__init__(**kwargs) self.on_click(self.export_aiida_subgraph) def export_aiida_subgraph(self, change=None): # pylint: disable=unused-argument @@ -42,7 +42,7 @@ def export_aiida_subgraph(self, change=None): # pylint: disable=unused-argument link.click(); document.body.removeChild(link); """.format( - payload=payload, filename="export_{}.aiida".format(self.process.id) + payload=payload, filename=f"export_{self.process.id}.aiida" ) ) display(javas) diff --git a/aiidalab_widgets_base/process.py b/aiidalab_widgets_base/process.py index ab4410a4f..62f8d30f5 100644 --- a/aiidalab_widgets_base/process.py +++ b/aiidalab_widgets_base/process.py @@ -210,7 +210,7 @@ def show_selected_input(self, change=None): clear_output() if change["new"]: selected_input = self.process.inputs[change["new"]] - self.info.value = "PK: {}".format(selected_input.id) + self.info.value = f"PK: {selected_input.id}" display(viewer(selected_input)) @@ -247,7 +247,7 @@ def show_selected_output(self, change=None): clear_output() if change["new"]: selected_output = self.process.outputs[change["new"]] - self.info.value = "PK: {}".format(selected_output.id) + self.info.value = f"PK: {selected_output.id}" display(viewer(selected_output)) @@ -278,7 +278,7 @@ def __init__( self.followers.append( ipw.VBox( [ - ipw.HTML("