From b530dd216d1c6a7c5096f748c64fb9ecc24b9caf Mon Sep 17 00:00:00 2001 From: Alexander Saprykin Date: Thu, 24 Oct 2024 16:51:23 +0200 Subject: [PATCH] Enable flake8-builtins plugin for ruff (#2333) --- .../management/commands/dump-auth-config.py | 2 +- .../integration/api/test_artifact_download.py | 8 +++---- .../integration/api/test_artifact_upload.py | 2 +- .../api/test_galaxy_stage_ansible.py | 4 ++-- .../api/test_upload_to_custom_repos.py | 4 ++-- .../tests/integration/utils/collections.py | 8 ++++++- galaxy_ng/tests/integration/utils/tools.py | 22 +++++++++---------- pyproject.toml | 5 +++++ 8 files changed, 33 insertions(+), 22 deletions(-) diff --git a/galaxy_ng/app/management/commands/dump-auth-config.py b/galaxy_ng/app/management/commands/dump-auth-config.py index 2adf93e0a9..99491a1c40 100644 --- a/galaxy_ng/app/management/commands/dump-auth-config.py +++ b/galaxy_ng/app/management/commands/dump-auth-config.py @@ -83,7 +83,7 @@ def post_config_ldap(self): return post_config - def format_config_data(self, type, keys, prefix): + def format_config_data(self, type, keys, prefix): # noqa: A002 config = { "type": f"galaxy.authentication.authenticator_plugins.{type}", "enabled": self.is_enabled(keys), diff --git a/galaxy_ng/tests/integration/api/test_artifact_download.py b/galaxy_ng/tests/integration/api/test_artifact_download.py index 0c18b47873..85d41f5e34 100644 --- a/galaxy_ng/tests/integration/api/test_artifact_download.py +++ b/galaxy_ng/tests/integration/api/test_artifact_download.py @@ -41,9 +41,9 @@ def test_download_artifact(ansible_config, galaxy_client): hub_4_5 = is_hub_4_5(ansible_config) set_certification(ansible_config(), gc, artifact, hub_4_5=hub_4_5) - with tempfile.TemporaryDirectory() as dir: + with tempfile.TemporaryDirectory() as dir_: filename = f"{namespace}-{name}-{version}.tar.gz" - tarball_path = f"{dir}/{filename}" + tarball_path = f"{dir_}/{filename}" url = (f"{gc.galaxy_root}v3/plugin/ansible/content/" f"published/collections/artifacts/{filename}") @@ -94,9 +94,9 @@ def test_download_artifact_validated(ansible_config, galaxy_client): assert resp["state"] == "completed" set_certification(ansible_config(), gc, artifact, level="validated") - with tempfile.TemporaryDirectory() as dir: + with tempfile.TemporaryDirectory() as dir_: filename = f"{artifact.namespace}-{artifact.name}-{artifact.version}.tar.gz" - tarball_path = f"{dir}/{filename}" + tarball_path = f"{dir_}/{filename}" url = (f"{gc.galaxy_root}v3/plugin/ansible/content/" f"validated/collections/artifacts/{filename}") diff --git a/galaxy_ng/tests/integration/api/test_artifact_upload.py b/galaxy_ng/tests/integration/api/test_artifact_upload.py index 90d214c230..0e0c0def2d 100644 --- a/galaxy_ng/tests/integration/api/test_artifact_upload.py +++ b/galaxy_ng/tests/integration/api/test_artifact_upload.py @@ -29,7 +29,7 @@ class ErrorTestMode: """Represents a test scenario for publishing a collection.""" - def __init__(self, name, file, status, resp, no_filename=False, hash=True): + def __init__(self, name, file, status, resp, no_filename=False, hash=True): # noqa: A002 """Configure the test scenario. :param name: Name for use in the test ID. diff --git a/galaxy_ng/tests/integration/api/test_galaxy_stage_ansible.py b/galaxy_ng/tests/integration/api/test_galaxy_stage_ansible.py index f1fcde6a41..64da9b0c77 100644 --- a/galaxy_ng/tests/integration/api/test_galaxy_stage_ansible.py +++ b/galaxy_ng/tests/integration/api/test_galaxy_stage_ansible.py @@ -175,10 +175,10 @@ def test_social_download_artifact(gh_user_1, generate_test_artifact): resp = wait_for_task(gh_user_1, resp) assert resp["state"] == "completed" - with tempfile.TemporaryDirectory() as dir: + with tempfile.TemporaryDirectory() as dir_: filename = f"{expected_ns}-{generate_test_artifact.name}-" \ f"{generate_test_artifact.version}.tar.gz" - tarball_path = f"{dir}/{filename}" + tarball_path = f"{dir_}/{filename}" url = f"{gh_user_1.galaxy_root}v3/plugin/" \ f"ansible/content/published/collections/artifacts/{filename}" diff --git a/galaxy_ng/tests/integration/api/test_upload_to_custom_repos.py b/galaxy_ng/tests/integration/api/test_upload_to_custom_repos.py index 0f921817e8..a74edc3214 100644 --- a/galaxy_ng/tests/integration/api/test_upload_to_custom_repos.py +++ b/galaxy_ng/tests/integration/api/test_upload_to_custom_repos.py @@ -40,13 +40,13 @@ def _upload_test_common(config, client, artifact, base_path, dest_base_path=None assert collection_resp["name"] == artifact.name # test download - with tempfile.TemporaryDirectory() as dir: + with tempfile.TemporaryDirectory() as dir_: if gc: api_root = gc.galaxy_root else: api_root = config["url"] filename = f"{artifact.namespace}-{artifact.name}-{artifact.version}.tar.gz" - tarball_path = f"{dir}/{filename}" + tarball_path = f"{dir_}/{filename}" url = ( f"{api_root}v3/plugin/ansible/content/" f"{dest_base_path}/collections/artifacts/{filename}" diff --git a/galaxy_ng/tests/integration/utils/collections.py b/galaxy_ng/tests/integration/utils/collections.py index 2c2a105fd2..9626333d55 100644 --- a/galaxy_ng/tests/integration/utils/collections.py +++ b/galaxy_ng/tests/integration/utils/collections.py @@ -234,7 +234,13 @@ def build_collection( def upload_artifact( - config, client, artifact, hash=True, no_filename=False, no_file=False, use_distribution=False + config, + client, + artifact, + hash=True, # noqa: A002 + no_filename=False, + no_file=False, + use_distribution=False ): """ Publishes a collection to a Galaxy server and returns the import task URI. diff --git a/galaxy_ng/tests/integration/utils/tools.py b/galaxy_ng/tests/integration/utils/tools.py index 53860c7d87..35dd63f080 100644 --- a/galaxy_ng/tests/integration/utils/tools.py +++ b/galaxy_ng/tests/integration/utils/tools.py @@ -31,21 +31,21 @@ def random_name(prefix: str, *, length: int = 8, sep: str = '-'): def iterate_all(api_client, url, gc=None): """Iterate through all of the items on every page in a paginated list view.""" - next = url + next_ = url key = "data" - while next is not None: + while next_ is not None: if gc: - r = gc.get(next) + r = gc.get(next_) else: - r = api_client(next) + r = api_client(next_) # pulp uses "results" if "data" not in r: key = "results" yield from r[key] if "next" in r: - next = r["next"] + next_ = r["next"] else: - next = r["links"]["next"] + next_ = r["links"]["next"] def generate_random_artifact_version(): @@ -59,15 +59,15 @@ def gen_string(size=10, chars=string.ascii_lowercase): def iterate_all_gk(gc_admin, url): """Iterate through all of the items on every page in a paginated list view.""" - next = url + next_ = url key = "data" - while next is not None: - r = gc_admin.get(next) + while next_ is not None: + r = gc_admin.get(next_) # pulp uses "results" if "data" not in r: key = "results" yield from r[key] if "next" in r: - next = r["next"] + next_ = r["next"] else: - next = r["links"]["next"] + next_ = r["links"]["next"] diff --git a/pyproject.toml b/pyproject.toml index 2651976e3b..c179f8b688 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -105,6 +105,8 @@ select = [ "E", # pycodestyle warnings "W", + # flake8-builtins + "A", # flake8-bugbear "B", # flake8-comprehensions @@ -153,3 +155,6 @@ extend-ignore = [ # Ignore "E501 Line too long" in migrations, since most of the warnings # are due to autogenerated code. "galaxy_ng/app/migrations/*" = ["E501"] + +[tool.ruff.lint.flake8-builtins] +builtins-ignorelist = ["id"]