diff --git a/lib/galaxy/datatypes/sequence.py b/lib/galaxy/datatypes/sequence.py index 5fe01c38f9fc..89746eec5c3e 100644 --- a/lib/galaxy/datatypes/sequence.py +++ b/lib/galaxy/datatypes/sequence.py @@ -175,7 +175,7 @@ def do_slow_split(cls, input_datasets, subdir_generator_function, split_params): def do_fast_split(cls, input_datasets, toc_file_datasets, subdir_generator_function, split_params): data = json.load(open(toc_file_datasets[0].file_name)) sections = data["sections"] - total_sequences = int(0) + total_sequences = 0 for section in sections: total_sequences += int(section["sequences"]) sequences_per_file = cls.get_sequences_per_file(total_sequences, split_params) @@ -247,7 +247,7 @@ def get_split_commands_with_toc( sections = toc_file["sections"] result = [] - current_sequence = int(0) + current_sequence = 0 i = 0 # skip to the section that contains my starting sequence while i < len(sections) and start_sequence >= current_sequence + int(sections[i]["sequences"]): diff --git a/lib/galaxy/dependencies/pinned-lint-requirements.txt b/lib/galaxy/dependencies/pinned-lint-requirements.txt index 0685b383b397..4349574508b8 100644 --- a/lib/galaxy/dependencies/pinned-lint-requirements.txt +++ b/lib/galaxy/dependencies/pinned-lint-requirements.txt @@ -5,6 +5,6 @@ importlib-metadata==4.2.0 mccabe==0.7.0 pycodestyle==2.9.1 pyflakes==2.5.0 -ruff==0.0.280 +ruff==0.0.283 typing_extensions==4.7.1 zipp==3.15.0 diff --git a/lib/galaxy/managers/citations.py b/lib/galaxy/managers/citations.py index 64e8ca91754d..09a4e137cbee 100644 --- a/lib/galaxy/managers/citations.py +++ b/lib/galaxy/managers/citations.py @@ -152,12 +152,10 @@ def to_bibtex(self): log.exception("Failed to fetch bibtex for DOI %s", self.__doi) if self.raw_bibtex is DoiCitation.BIBTEX_UNSET: - return """@MISC{{{doi}, - DOI = {{{doi}}}, + return f"""@MISC{{{self.__doi}, + DOI = {{{self.__doi}}}, note = {{Failed to fetch BibTeX for DOI.}} - }}""".format( - doi=self.__doi - ) + }}""" else: return self.raw_bibtex diff --git a/lib/galaxy/managers/cloud.py b/lib/galaxy/managers/cloud.py index 671ec216989e..2a26640c9cee 100644 --- a/lib/galaxy/managers/cloud.py +++ b/lib/galaxy/managers/cloud.py @@ -86,7 +86,7 @@ def configure_provider(provider, credentials): if len(missing_credentials) > 0: raise RequestParameterMissingException( "The following required key(s) are missing from the provided " - "credentials object: {}".format(missing_credentials) + f"credentials object: {missing_credentials}" ) session_token = credentials.get("SessionToken") config = {"aws_access_key": access, "aws_secret_key": secret, "aws_session_token": session_token} @@ -107,7 +107,7 @@ def configure_provider(provider, credentials): if len(missing_credentials) > 0: raise RequestParameterMissingException( "The following required key(s) are missing from the provided " - "credentials object: {}".format(missing_credentials) + f"credentials object: {missing_credentials}" ) config = { @@ -145,7 +145,7 @@ def configure_provider(provider, credentials): if len(missing_credentials) > 0: raise RequestParameterMissingException( "The following required key(s) are missing from the provided " - "credentials object: {}".format(missing_credentials) + f"credentials object: {missing_credentials}" ) config = { "os_username": username, @@ -161,8 +161,8 @@ def configure_provider(provider, credentials): connection = CloudProviderFactory().create_provider(ProviderList.GCP, config) else: raise RequestParameterInvalidException( - "Unrecognized provider '{}'; the following are the supported " - "providers: {}.".format(provider, SUPPORTED_PROVIDERS.keys()) + f"Unrecognized provider '{provider}'; the following are the supported " + f"providers: {SUPPORTED_PROVIDERS.keys()}." ) # The authorization-assertion mechanism of Cloudbridge assumes a user has an elevated privileges, diff --git a/lib/galaxy/objectstore/pithos.py b/lib/galaxy/objectstore/pithos.py index 63b81bbc2815..6dfa71b239fb 100644 --- a/lib/galaxy/objectstore/pithos.py +++ b/lib/galaxy/objectstore/pithos.py @@ -320,10 +320,7 @@ def _size(self, obj, **kwargs) -> int: try: return os.path.getsize(self._get_cache_path(path)) except OSError as ex: - log.warning( - "Could not get size of file {path} in local cache," - "will try Pithos. Error: {err}".format(path=path, err=ex) - ) + log.warning(f"Could not get size of file {path} in local cache," f"will try Pithos. Error: {ex}") try: file = self.pithos.get_object_info(path) except ClientError as ce: @@ -406,10 +403,7 @@ def _update_from_file(self, obj, **kwargs): if kwargs.get("create"): self._create(obj, **kwargs) if not self._exists(obj, **kwargs): - raise ObjectNotFound( - "objectstore.update_from_file, object does not exist: {obj}, " - "kwargs: {kwargs}".format(obj=obj, kwargs=kwargs) - ) + raise ObjectNotFound(f"objectstore.update_from_file, object does not exist: {obj}, " f"kwargs: {kwargs}") path = self._construct_path(obj, **kwargs) cache_path = self._get_cache_path(path) diff --git a/lib/galaxy/queues.py b/lib/galaxy/queues.py index 75fd4fa5fb53..d68012beb5c7 100644 --- a/lib/galaxy/queues.py +++ b/lib/galaxy/queues.py @@ -23,8 +23,7 @@ def all_control_queues_for_declare(application_stack): """ # Get all active processes and construct queues for each process process_names = ( - "{p.server_name}@{p.hostname}".format(p=p) - for p in application_stack.app.database_heartbeat.get_active_processes() + f"{p.server_name}@{p.hostname}" for p in application_stack.app.database_heartbeat.get_active_processes() ) return [Queue(f"control.{server_name}", galaxy_exchange, routing_key="control.*") for server_name in process_names] diff --git a/lib/galaxy/tool_util/deps/brew_exts.py b/lib/galaxy/tool_util/deps/brew_exts.py index 7e8b67991678..852d7425a908 100755 --- a/lib/galaxy/tool_util/deps/brew_exts.py +++ b/lib/galaxy/tool_util/deps/brew_exts.py @@ -160,14 +160,14 @@ def __init__(self, command, stdout, stderr): self.stdout = stdout self.stderr = stderr self.message = ( - "Failed to execute command-line {}, stderr was:\n" + f"Failed to execute command-line {command}, stderr was:\n" "-------->>begin stderr<<--------\n" - "{}\n" + f"{stderr}\n" "-------->>end stderr<<--------\n" "-------->>begin stdout<<--------\n" - "{}\n" + f"{stdout}\n" "-------->>end stdout<<--------\n" - ).format(command, stderr, stdout) + ) def __str__(self): return self.message diff --git a/lib/galaxy/util/__init__.py b/lib/galaxy/util/__init__.py index 7d3df0d4ded1..680df532d56c 100644 --- a/lib/galaxy/util/__init__.py +++ b/lib/galaxy/util/__init__.py @@ -544,7 +544,7 @@ def pretty_print_time_interval(time=False, precise=False, utc=False): now = datetime.utcnow() else: now = datetime.now() - if type(time) is int: + if isinstance(time, (int, float)): diff = now - datetime.fromtimestamp(time) elif isinstance(time, datetime): diff = now - time diff --git a/lib/galaxy/util/commands.py b/lib/galaxy/util/commands.py index 679aba33f4f4..321dd71f2fad 100644 --- a/lib/galaxy/util/commands.py +++ b/lib/galaxy/util/commands.py @@ -155,14 +155,14 @@ def __init__(self, command, stdout, stderr, returncode): self.stderr = stderr self.returncode = returncode self.message = ( - "Failed to execute command-line {}, stderr was:\n" + f"Failed to execute command-line {command}, stderr was:\n" "-------->>begin stderr<<--------\n" - "{}\n" + f"{stderr}\n" "-------->>end stderr<<--------\n" "-------->>begin stdout<<--------\n" - "{}\n" + f"{stdout}\n" "-------->>end stdout<<--------\n" - ).format(command, stderr, stdout) + ) def __str__(self): """Return a verbose error message indicating the command problem.""" diff --git a/lib/galaxy/webapps/base/webapp.py b/lib/galaxy/webapps/base/webapp.py index 4e2cac6e5086..93ca937e0484 100644 --- a/lib/galaxy/webapps/base/webapp.py +++ b/lib/galaxy/webapps/base/webapp.py @@ -147,7 +147,7 @@ def build_apispec(self): methods = [] if rule.conditions: m = rule.conditions.get("method", []) - methods = type(m) is str and [m] or m + methods = [m] if isinstance(m, str) else m # Find the controller class if controller not in self.api_controllers: # Only happens when removing a controller after porting to FastAPI. diff --git a/lib/galaxy/webapps/galaxy/api/cloudauthz.py b/lib/galaxy/webapps/galaxy/api/cloudauthz.py index 36616b095afc..fb0227f1f906 100644 --- a/lib/galaxy/webapps/galaxy/api/cloudauthz.py +++ b/lib/galaxy/webapps/galaxy/api/cloudauthz.py @@ -124,8 +124,7 @@ def create(self, trans, payload, **kwargs): if not isinstance(config, dict): log.debug(msg_template.format(f"invalid config type `{type(config)}`, expect `dict`")) raise RequestParameterInvalidException( - "Invalid type for the required `config` variable; expect `dict` " - "but received `{}`.".format(type(config)) + "Invalid type for the required `config` variable; expect `dict` " f"but received `{type(config)}`." ) if authn_id: try: diff --git a/lib/galaxy/webapps/galaxy/api/library_contents.py b/lib/galaxy/webapps/galaxy/api/library_contents.py index e3c5ecce3ee1..a0e21e1ad6d6 100644 --- a/lib/galaxy/webapps/galaxy/api/library_contents.py +++ b/lib/galaxy/webapps/galaxy/api/library_contents.py @@ -371,9 +371,9 @@ def _upload_library_dataset(self, trans, folder_id: int, **kwd): trans, folder_id=folder.id, replace_dataset=replace_dataset, **kwd ) if created_outputs_dict: - if type(created_outputs_dict) == str: + if isinstance(created_outputs_dict, str): return 400, created_outputs_dict - elif type(created_outputs_dict) == tuple: + elif isinstance(created_outputs_dict, tuple): return created_outputs_dict[0], created_outputs_dict[1] return 200, created_outputs_dict else: diff --git a/lib/galaxy/webapps/galaxy/api/users.py b/lib/galaxy/webapps/galaxy/api/users.py index cd2768f5e13c..3cbbb57751c2 100644 --- a/lib/galaxy/webapps/galaxy/api/users.py +++ b/lib/galaxy/webapps/galaxy/api/users.py @@ -1087,7 +1087,7 @@ def set_toolbox_filters(self, trans, id, payload=None, **kwd): for prefixed_name in payload: if prefixed_name.startswith(filter_type): filter_selection = payload.get(prefixed_name) - if type(filter_selection) != bool: + if not isinstance(filter_selection, bool): raise exceptions.RequestParameterInvalidException( "Please specify the filter selection as boolean value." ) diff --git a/lib/galaxy/webapps/galaxy/controllers/authnz.py b/lib/galaxy/webapps/galaxy/controllers/authnz.py index 71bd0fbcf7e4..88af61d8fa11 100644 --- a/lib/galaxy/webapps/galaxy/controllers/authnz.py +++ b/lib/galaxy/webapps/galaxy/controllers/authnz.py @@ -101,9 +101,9 @@ def callback(self, trans, provider, idphint=None, **kwargs): " Error message: {}".format(provider, user, kwargs.get("error", "None")) ) return trans.show_error_message( - "Failed to handle authentication callback from {}. " + f"Failed to handle authentication callback from {provider}. " "Please try again, and if the problem persists, contact " - "the Galaxy instance admin".format(provider) + "the Galaxy instance admin" ) try: success, message, (redirect_url, user) = trans.app.authnz_manager.callback( diff --git a/lib/galaxy_test/api/test_drs.py b/lib/galaxy_test/api/test_drs.py index c221e486a03c..00921aca35fe 100644 --- a/lib/galaxy_test/api/test_drs.py +++ b/lib/galaxy_test/api/test_drs.py @@ -130,7 +130,7 @@ def test_exception_handling_schema(self): for method in HTTP_METHODS: api_url = self._url_join(f"ga4gh/drs/v1/objects/{drs_id}/access/fakeid") error_response = method(api_url) - assert type(error_response.status_code) == int + assert isinstance(error_response.status_code, int) assert error_response.status_code == 404 error_as_dict = error_response.json() assert "status_code" in error_as_dict diff --git a/scripts/api/common.py b/scripts/api/common.py index 1a99d4af6c32..1b5a09e44070 100644 --- a/scripts/api/common.py +++ b/scripts/api/common.py @@ -109,7 +109,7 @@ def display(api_key, url, return_formatted=True): print("------------------") for k, v in r.items(): print(f"{k}: {v}") - elif type(r) == str: + elif isinstance(r, str): print(r) else: print("response is unknown type: %s" % type(r)) diff --git a/test/integration/test_cli_runners.py b/test/integration/test_cli_runners.py index 3dd4ed613792..b240ebaf7cc3 100644 --- a/test/integration/test_cli_runners.py +++ b/test/integration/test_cli_runners.py @@ -43,7 +43,7 @@ def start_ssh_docker(container_name, jobs_directory, port=10022, image="agaveapi "--rm", "--privileged", # for torque "-v", - "{jobs_directory}:{jobs_directory}".format(jobs_directory=jobs_directory), + f"{jobs_directory}:{jobs_directory}", "-v", f"{ssh_keys.public_key_file}:/home/testuser/.ssh/authorized_keys", "--ulimit", diff --git a/test/unit/config/test_load_config.py b/test/unit/config/test_load_config.py index 13e4cd8754d3..7ab70339437f 100644 --- a/test/unit/config/test_load_config.py +++ b/test/unit/config/test_load_config.py @@ -47,10 +47,10 @@ def test_load_config_from_schema(mock_init): assert config.property5 is None assert config.property6 is None - assert type(config.property1) is str - assert type(config.property2) is int - assert type(config.property3) is float - assert type(config.property4) is bool + assert isinstance(config.property1, str) + assert isinstance(config.property2, int) + assert isinstance(config.property3, float) + assert isinstance(config.property4, bool) def test_update_raw_config_from_kwargs(mock_init): @@ -64,10 +64,10 @@ def test_update_raw_config_from_kwargs(mock_init): assert config._raw_config["property5"] is None # no change assert config._raw_config["property6"] is None # no change - assert type(config._raw_config["property1"]) is str - assert type(config._raw_config["property2"]) is int - assert type(config._raw_config["property3"]) is float - assert type(config._raw_config["property4"]) is bool + assert isinstance(config._raw_config["property1"], str) + assert isinstance(config._raw_config["property2"], int) + assert isinstance(config._raw_config["property3"], float) + assert isinstance(config._raw_config["property4"], bool) def test_update_raw_config_from_string_kwargs(mock_init): @@ -80,10 +80,10 @@ def test_update_raw_config_from_string_kwargs(mock_init): assert config._raw_config["property3"] == 2.0 # updated assert config._raw_config["property4"] is False # updated - assert type(config._raw_config["property1"]) is str - assert type(config._raw_config["property2"]) is int - assert type(config._raw_config["property3"]) is float - assert type(config._raw_config["property4"]) is bool + assert isinstance(config._raw_config["property1"], str) + assert isinstance(config._raw_config["property2"], int) + assert isinstance(config._raw_config["property3"], float) + assert isinstance(config._raw_config["property4"], bool) def test_update_raw_config_from_kwargs_with_none(mock_init): @@ -111,7 +111,7 @@ def test_update_raw_config_from_kwargs_falsy_not_none(mock_init): config = BaseAppConfiguration(property1=0) assert config._raw_config["property1"] == "0" # updated - assert type(config._raw_config["property1"]) is str # and converted to str + assert isinstance(config._raw_config["property1"], str) # and converted to str def test_unset_renamed_option_set_by_old_option(mock_init, monkeypatch): diff --git a/test/unit/config/test_schema.py b/test/unit/config/test_schema.py index 1b6b11b4c86a..820f74300e25 100644 --- a/test/unit/config/test_schema.py +++ b/test/unit/config/test_schema.py @@ -60,10 +60,10 @@ def mock_init(self, stream): assert schema.defaults["property5"] is None assert schema.defaults["property6"] is None - assert type(schema.defaults["property1"]) is str - assert type(schema.defaults["property2"]) is int - assert type(schema.defaults["property3"]) is float - assert type(schema.defaults["property4"]) is bool + assert isinstance(schema.defaults["property1"], str) + assert isinstance(schema.defaults["property2"], int) + assert isinstance(schema.defaults["property3"], float) + assert isinstance(schema.defaults["property4"], bool) assert len(schema.reloadable_options) == 2 assert "property2" in schema.reloadable_options