From f17e840b85e464a172507992a3d922c646f249a9 Mon Sep 17 00:00:00 2001 From: Matthias Dellweg Date: Thu, 23 Apr 2026 14:20:21 +0200 Subject: [PATCH 1/2] Apply ruff UP and FURB fixes --- .ci/scripts/collect_changes.py | 5 +- .ci/scripts/validate_commit_message.py | 6 +- .../.ci/scripts/collect_changes.py | 5 +- .../.ci/scripts/validate_commit_message.py | 6 +- pulp-glue/src/pulp_glue/common/context.py | 34 +++++----- pulp-glue/src/pulp_glue/common/i18n.py | 4 +- pulp-glue/src/pulp_glue/common/openapi.py | 14 ++--- pulp-glue/src/pulp_glue/common/schema.py | 2 +- pulp-glue/tests/conftest.py | 4 +- pulp-glue/tests/test_schema.py | 4 +- src/pulp_cli/__init__.py | 2 +- src/pulp_cli/config.py | 10 ++- src/pulp_cli/generic.py | 30 ++++----- src/pulpcore/cli/common/acs.py | 4 +- src/pulpcore/cli/container/content.py | 2 +- src/pulpcore/cli/file/repository.py | 2 +- src/pulpcore/cli/rpm/content.py | 63 ++++++++++++------- tests/conftest.py | 3 +- tests/test_help_pages.py | 6 +- 19 files changed, 105 insertions(+), 101 deletions(-) diff --git a/.ci/scripts/collect_changes.py b/.ci/scripts/collect_changes.py index 499265cca..0bf0901ac 100755 --- a/.ci/scripts/collect_changes.py +++ b/.ci/scripts/collect_changes.py @@ -80,7 +80,7 @@ def main(): branches.sort(key=lambda ref: parse_version(ref.remote_head), reverse=True) branches = [ref.name for ref in branches] - with open(CHANGELOG_FILE, "r") as f: + with open(CHANGELOG_FILE) as f: main_changelog = f.read() preamble, main_changes = split_changelog(main_changelog) old_length = len(main_changes) @@ -105,8 +105,7 @@ def main(): print(f"{new_length - old_length} new versions have been added.") with open(CHANGELOG_FILE, "w") as fp: fp.write(preamble) - for change in main_changes: - fp.write(change[1]) + fp.writelines(change[1] for change in main_changes) repo.git.commit("-m", "Update Changelog", CHANGELOG_FILE) diff --git a/.ci/scripts/validate_commit_message.py b/.ci/scripts/validate_commit_message.py index aeea5f29f..b57fd7de4 100644 --- a/.ci/scripts/validate_commit_message.py +++ b/.ci/scripts/validate_commit_message.py @@ -33,7 +33,7 @@ if NOISSUE_MARKER in message: sys.exit("Do not add '[noissue]' in the commit message.") -if any((re.match(pattern, message) for pattern in BLOCKING_REGEX)): +if any(re.match(pattern, message) for pattern in BLOCKING_REGEX): sys.exit("This PR is not ready for consumption.") g = Github(os.environ.get("GITHUB_TOKEN")) @@ -58,7 +58,7 @@ def check_changelog(issue): sys.exit(f"Invalid extension for changelog entry '{match}'.") -print("Checking commit message for {sha}.".format(sha=sha[0:7])) +print(f"Checking commit message for {sha[0:7]}.") # validate the issue attached to the commit issue_regex = r"(?:{keywords})[\s:]+#(\d+)".format(keywords=("|").join(KEYWORDS)) @@ -72,4 +72,4 @@ def check_changelog(issue): check_status(issue) check_changelog(issue) -print("Commit message for {sha} passed.".format(sha=sha[0:7])) +print(f"Commit message for {sha[0:7]} passed.") diff --git a/cookiecutter/ci/{{ cookiecutter.__project_name }}/.ci/scripts/collect_changes.py b/cookiecutter/ci/{{ cookiecutter.__project_name }}/.ci/scripts/collect_changes.py index 499265cca..0bf0901ac 100755 --- a/cookiecutter/ci/{{ cookiecutter.__project_name }}/.ci/scripts/collect_changes.py +++ b/cookiecutter/ci/{{ cookiecutter.__project_name }}/.ci/scripts/collect_changes.py @@ -80,7 +80,7 @@ def main(): branches.sort(key=lambda ref: parse_version(ref.remote_head), reverse=True) branches = [ref.name for ref in branches] - with open(CHANGELOG_FILE, "r") as f: + with open(CHANGELOG_FILE) as f: main_changelog = f.read() preamble, main_changes = split_changelog(main_changelog) old_length = len(main_changes) @@ -105,8 +105,7 @@ def main(): print(f"{new_length - old_length} new versions have been added.") with open(CHANGELOG_FILE, "w") as fp: fp.write(preamble) - for change in main_changes: - fp.write(change[1]) + fp.writelines(change[1] for change in main_changes) repo.git.commit("-m", "Update Changelog", CHANGELOG_FILE) diff --git a/cookiecutter/ci/{{ cookiecutter.__project_name }}/.ci/scripts/validate_commit_message.py b/cookiecutter/ci/{{ cookiecutter.__project_name }}/.ci/scripts/validate_commit_message.py index 4c925f248..2118ee68c 100644 --- a/cookiecutter/ci/{{ cookiecutter.__project_name }}/.ci/scripts/validate_commit_message.py +++ b/cookiecutter/ci/{{ cookiecutter.__project_name }}/.ci/scripts/validate_commit_message.py @@ -33,7 +33,7 @@ if NOISSUE_MARKER in message: sys.exit("Do not add '[noissue]' in the commit message.") -if any((re.match(pattern, message) for pattern in BLOCKING_REGEX)): +if any(re.match(pattern, message) for pattern in BLOCKING_REGEX): sys.exit("This PR is not ready for consumption.") g = Github(os.environ.get("GITHUB_TOKEN")) @@ -58,7 +58,7 @@ def check_changelog(issue): sys.exit(f"Invalid extension for changelog entry '{match}'.") -print("Checking commit message for {sha}.".format(sha=sha[0:7])) +print(f"Checking commit message for {sha[0:7]}.") # validate the issue attached to the commit issue_regex = r"(?:{keywords})[\s:]+#(\d+)".format(keywords=("|").join(KEYWORDS)) @@ -72,4 +72,4 @@ def check_changelog(issue): check_status(issue) check_changelog(issue) -print("Commit message for {sha} passed.".format(sha=sha[0:7])) +print(f"Commit message for {sha[0:7]} passed.") diff --git a/pulp-glue/src/pulp_glue/common/context.py b/pulp-glue/src/pulp_glue/common/context.py index a3b376a15..be6f74e9c 100644 --- a/pulp-glue/src/pulp_glue/common/context.py +++ b/pulp-glue/src/pulp_glue/common/context.py @@ -425,7 +425,7 @@ def from_config(cls, config: dict[str, t.Any]) -> "t.Self": ) if "headers" in config: api_kwargs["headers"] = dict( - (header.split(":", maxsplit=1) for header in config["headers"]) + header.split(":", maxsplit=1) for header in config["headers"] ) for key in ["cert", "key", "user_agent", "cid", "dry_run"]: if key in config: @@ -843,7 +843,7 @@ class PulpEntityContext(PulpViewSetContext): PLUGIN: t.ClassVar[str] RESOURCE_TYPE: t.ClassVar[str] MODEL: t.ClassVar[str] - PRN_TYPE_REGISTRY: t.Final[dict[str, t.Type["PulpEntityContext"]]] = {} + PRN_TYPE_REGISTRY: t.Final[dict[str, type["PulpEntityContext"]]] = {} def __init_subclass__(cls, **kwargs: t.Any) -> None: super().__init_subclass__(**kwargs) @@ -1141,13 +1141,11 @@ def create( try: if getattr(self, "HREF_PATTERN", None): self.pulp_href = next( - ( - h - for h in result["created_resources"] - if re.match( - re.escape(self.pulp_ctx.api_path) + self.HREF_PATTERN, - h, - ) + h + for h in result["created_resources"] + if re.match( + re.escape(self.pulp_ctx.api_path) + self.HREF_PATTERN, + h, ) ) else: @@ -1394,7 +1392,7 @@ def capable(self, capability: str) -> bool: Whether the capability is provided for this context. """ return capability in self.CAPABILITIES and all( - (self.pulp_ctx.has_plugin(pr) for pr in self.CAPABILITIES[capability]) + self.pulp_ctx.has_plugin(pr) for pr in self.CAPABILITIES[capability] ) def needs_capability(self, capability: str) -> None: @@ -1447,7 +1445,7 @@ class PulpRemoteContext(PulpEntityContext): "sock_read_timeout", "rate_limit", } - TYPE_REGISTRY: t.Final[dict[str, t.Type["PulpRemoteContext"]]] = {} + TYPE_REGISTRY: t.Final[dict[str, type["PulpRemoteContext"]]] = {} def __init_subclass__(cls, **kwargs: t.Any) -> None: if hasattr(cls, "PLUGIN") and hasattr(cls, "RESOURCE_TYPE"): @@ -1468,7 +1466,7 @@ class PulpPublicationContext(PulpEntityContext): ID_PREFIX = "publications" HREF_PATTERN = r"publications/(?P[\w\-_]+)/(?P[\w\-_]+)/" HREF_TEMPLATE = "publications/{plugin}/{resource_type}/{pulp_id}/" - TYPE_REGISTRY: t.Final[dict[str, t.Type["PulpPublicationContext"]]] = {} + TYPE_REGISTRY: t.Final[dict[str, type["PulpPublicationContext"]]] = {} def __init_subclass__(cls, **kwargs: t.Any) -> None: if hasattr(cls, "PLUGIN") and hasattr(cls, "RESOURCE_TYPE"): @@ -1503,7 +1501,7 @@ class PulpDistributionContext(PulpEntityContext): "repository", "repository_version", } - TYPE_REGISTRY: t.Final[dict[str, t.Type["PulpDistributionContext"]]] = {} + TYPE_REGISTRY: t.Final[dict[str, type["PulpDistributionContext"]]] = {} def __init_subclass__(cls, **kwargs: t.Any) -> None: if hasattr(cls, "PLUGIN") and hasattr(cls, "RESOURCE_TYPE"): @@ -1584,9 +1582,9 @@ class PulpRepositoryContext(PulpEntityContext): HREF_PATTERN = r"repositories/(?P[\w\-_]+)/(?P[\w\-_]+)/" HREF_TEMPLATE = "repositories/{plugin}/{resource_type}/{pulp_id}/" ID_PREFIX = "repositories" - VERSION_CONTEXT: t.ClassVar[t.Type[PulpRepositoryVersionContext]] = PulpRepositoryVersionContext + VERSION_CONTEXT: t.ClassVar[type[PulpRepositoryVersionContext]] = PulpRepositoryVersionContext NULLABLES = {"description", "remote", "retain_repo_versions"} - TYPE_REGISTRY: t.Final[dict[str, t.Type["PulpRepositoryContext"]]] = {} + TYPE_REGISTRY: t.Final[dict[str, type["PulpRepositoryContext"]]] = {} def __init_subclass__(cls, **kwargs: t.Any) -> None: if hasattr(cls, "PLUGIN") and hasattr(cls, "RESOURCE_TYPE"): @@ -1711,7 +1709,7 @@ class PulpContentContext(PulpEntityContext): ID_PREFIX = "content" HREF_PATTERN = r"content/(?P[\w\-_]+)/(?P[\w\-_]+)/" HREF_TEMPLATE = "content/{plugin}/{resource_type}/{pulp_id}/" - TYPE_REGISTRY: t.Final[dict[str, t.Type["PulpContentContext"]]] = {} + TYPE_REGISTRY: t.Final[dict[str, type["PulpContentContext"]]] = {} def __init_subclass__(cls, **kwargs: t.Any) -> None: if hasattr(cls, "PLUGIN") and hasattr(cls, "RESOURCE_TYPE"): @@ -1828,7 +1826,7 @@ class PulpACSContext(PulpEntityContext): HREF_PATTERN = r"acs/(?P[\w\-_]+)/(?P[\w\-_]+)/" HREF_TEMPLATE = "acs/{plugin}/{resource_type}/{pulp_id}/" ID_PREFIX = "acs" - TYPE_REGISTRY: t.Final[dict[str, t.Type["PulpACSContext"]]] = {} + TYPE_REGISTRY: t.Final[dict[str, type["PulpACSContext"]]] = {} def __init_subclass__(cls, **kwargs: t.Any) -> None: if hasattr(cls, "PLUGIN") and hasattr(cls, "RESOURCE_TYPE"): @@ -1853,7 +1851,7 @@ class PulpContentGuardContext(PulpEntityContext): HREF_PATTERN = r"contentguards/(?P[\w\-_]+)/(?P[\w\-_]+)/" HREF_TEMPLATE = "contentguards/{plugin}/{resource_type}/{pulp_id}/" NULLABLES = {"description"} - TYPE_REGISTRY: t.Final[dict[str, t.Type["PulpContentGuardContext"]]] = {} + TYPE_REGISTRY: t.Final[dict[str, type["PulpContentGuardContext"]]] = {} def __init_subclass__(cls, **kwargs: t.Any) -> None: if hasattr(cls, "PLUGIN") and hasattr(cls, "RESOURCE_TYPE"): diff --git a/pulp-glue/src/pulp_glue/common/i18n.py b/pulp-glue/src/pulp_glue/common/i18n.py index d7098fe2f..78b69eec6 100644 --- a/pulp-glue/src/pulp_glue/common/i18n.py +++ b/pulp-glue/src/pulp_glue/common/i18n.py @@ -1,10 +1,10 @@ import gettext -from functools import lru_cache +from functools import cache from importlib.resources import files # Need to call lru_cache() before using it as a decorator for python 3.7 compatibility -@lru_cache(maxsize=None) +@cache def get_translation(name: str) -> gettext.NullTranslations: """ Return a translations object for a certain import path. diff --git a/pulp-glue/src/pulp_glue/common/openapi.py b/pulp-glue/src/pulp_glue/common/openapi.py index c489ea0ed..53aafe538 100644 --- a/pulp-glue/src/pulp_glue/common/openapi.py +++ b/pulp-glue/src/pulp_glue/common/openapi.py @@ -197,8 +197,8 @@ def cid(self) -> str | None: return self._headers.get("Correlation-Id") @cached_property - def ssl_context(self) -> t.Union[ssl.SSLContext, bool]: - _ssl_context: t.Union[ssl.SSLContext, bool] + def ssl_context(self) -> ssl.SSLContext | bool: + _ssl_context: ssl.SSLContext | bool if self._verify_ssl is False: _ssl_context = False else: @@ -390,7 +390,7 @@ def _render_request_body( candidate_content_types = [ "multipart/form-data", ] - if not any((isinstance(value, (bytes, BufferedReader)) for value in body.values())): + if not any(isinstance(value, (bytes, BufferedReader)) for value in body.values()): candidate_content_types = [ "application/json", "application/x-www-form-urlencoded", @@ -524,11 +524,9 @@ def _select_proposal( security_schemes = self._api_spec.components.security_schemes try: proposal = next( - ( - p - for p in request.security - if self._auth_provider.can_complete(p, security_schemes) - ) + p + for p in request.security + if self._auth_provider.can_complete(p, security_schemes) ) except StopIteration: raise OpenAPIError(_("No suitable auth scheme found.")) diff --git a/pulp-glue/src/pulp_glue/common/schema.py b/pulp-glue/src/pulp_glue/common/schema.py index 42b69d584..abcb613f3 100644 --- a/pulp-glue/src/pulp_glue/common/schema.py +++ b/pulp-glue/src/pulp_glue/common/schema.py @@ -45,7 +45,7 @@ def encode_param(value: t.Any) -> t.Any: def _assert_type( name: str, value: t.Any, - types: t.Type[object] | tuple[t.Type[object], ...], + types: type[object] | tuple[type[object], ...], type_name: str, ) -> None: if not isinstance(value, types): diff --git a/pulp-glue/tests/conftest.py b/pulp-glue/tests/conftest.py index 7e927f9f3..5d468daa0 100644 --- a/pulp-glue/tests/conftest.py +++ b/pulp-glue/tests/conftest.py @@ -24,7 +24,7 @@ def pulp_ctx( request: pytest.FixtureRequest, pulp_cli_settings: dict[str, dict[str, t.Any]] ) -> PulpContext: - if not any((mark.name == "live" for mark in request.node.iter_markers())): + if not any(mark.name == "live" for mark in request.node.iter_markers()): pytest.fail("This fixture can only be used in live (integration) tests.") verbose = request.config.getoption("verbose") @@ -57,7 +57,7 @@ def mock_pulp_ctx( def fake_pulp_ctx( request: pytest.FixtureRequest, pulp_cli_settings: dict[str, dict[str, t.Any]] ) -> PulpContext: - if not any((mark.name == "live" for mark in request.node.iter_markers())): + if not any(mark.name == "live" for mark in request.node.iter_markers()): pytest.fail("This fixture can only be used in live (integration) tests.") verbose = request.config.getoption("verbose") diff --git a/pulp-glue/tests/test_schema.py b/pulp-glue/tests/test_schema.py index 64070f54d..70d9ea27a 100644 --- a/pulp-glue/tests/test_schema.py +++ b/pulp-glue/tests/test_schema.py @@ -382,9 +382,7 @@ def test_validation_failed(schema: oas.Schema, value: t.Any, match: str | None) ], ) @pydantic.validate_call -def test_invalid_schema_raises( - schema: oas.Schema, value: t.Any, exc_type: t.Type[Exception] -) -> None: +def test_invalid_schema_raises(schema: oas.Schema, value: t.Any, exc_type: type[Exception]) -> None: with pytest.raises(exc_type): validate(schema, "testvar", value, COMPONENTS) diff --git a/src/pulp_cli/__init__.py b/src/pulp_cli/__init__.py index 673378aeb..b0cc63b3b 100644 --- a/src/pulp_cli/__init__.py +++ b/src/pulp_cli/__init__.py @@ -233,7 +233,7 @@ def main( api_kwargs = dict( base_url=base_url, - headers=dict((header.split(":", maxsplit=1) for header in headers)), + headers=dict(header.split(":", maxsplit=1) for header in headers), verify_ssl=verify_ssl, refresh_cache=refresh_api, dry_run=dry_run, diff --git a/src/pulp_cli/config.py b/src/pulp_cli/config.py index 953090952..fd81da527 100644 --- a/src/pulp_cli/config.py +++ b/src/pulp_cli/config.py @@ -66,7 +66,7 @@ def headers_callback( ) -> t.Iterable[str]: if value: header_regex = re.compile(HEADER_REGEX) - failed_headers = ", ".join((item for item in value if not header_regex.match(item))) + failed_headers = ", ".join(item for item in value if not header_regex.match(item)) if failed_headers: raise click.BadParameter(f"format must be : \n{failed_headers}") @@ -190,15 +190,13 @@ def validate_config(config: dict[str, t.Any], strict: bool = False) -> None: errors.append(_("'domain' must be a slug string")) if "headers" in config: if not isinstance(config["headers"], list) or not all( - ( - isinstance(header, str) and re.match(HEADER_REGEX, header) - for header in config["headers"] - ) + isinstance(header, str) and re.match(HEADER_REGEX, header) + for header in config["headers"] ): errors.append(_("'headers' must be a list of strings with a colon separator")) if "plugins" in config and not ( isinstance(config["plugins"], list) - and all((isinstance(item, str) for item in config["plugins"])) + and all(isinstance(item, str) for item in config["plugins"]) ): errors.append(_("'plugins' must be a list of strings")) unknown_settings = set(config.keys()) - SETTINGS diff --git a/src/pulp_cli/generic.py b/src/pulp_cli/generic.py index 03d95fbd1..a4f4ddfae 100644 --- a/src/pulp_cli/generic.py +++ b/src/pulp_cli/generic.py @@ -393,7 +393,7 @@ class PulpCommand(click.Command): def __init__( self, *args: t.Any, - allowed_with_contexts: tuple[t.Type[PulpEntityContext]] | None = None, + allowed_with_contexts: tuple[type[PulpEntityContext]] | None = None, needs_plugins: list[PluginRequirement] | None = None, **kwargs: t.Any, ): @@ -475,7 +475,7 @@ def list_commands(self, ctx: click.Context) -> list[str]: def pulp_command( name: str | None = None, - cls: t.Type[PulpCommand] = PulpCommand, + cls: type[PulpCommand] = PulpCommand, **kwargs: t.Any, ) -> t.Callable[[_AnyCallable], PulpCommand]: """ @@ -490,7 +490,7 @@ def pulp_command( def pulp_group( name: str | None = None, - cls: t.Type[PulpGroup] = PulpGroup, + cls: type[PulpGroup] = PulpGroup, **kwargs: t.Any, ) -> t.Callable[[_AnyCallable], PulpGroup]: """ @@ -514,7 +514,7 @@ def __init__( self, *args: t.Any, needs_plugins: list[PluginRequirement] | None = None, - allowed_with_contexts: tuple[t.Type[PulpEntityContext]] | None = None, + allowed_with_contexts: tuple[type[PulpEntityContext]] | None = None, **kwargs: t.Any, ): self.needs_plugins = needs_plugins @@ -587,7 +587,7 @@ def handle_parse_result( @lru_cache(typed=True) def lookup_callback( - attribute: str, context_class: t.Type[PulpEntityContext] = PulpEntityContext + attribute: str, context_class: type[PulpEntityContext] = PulpEntityContext ) -> t.Callable[[click.Context, click.Parameter, str | None], str | None]: def _callback(ctx: click.Context, param: click.Parameter, value: str | None) -> str | None: if value is not None: @@ -602,7 +602,7 @@ def _callback(ctx: click.Context, param: click.Parameter, value: str | None) -> def href_callback( - context_class: t.Type[PulpEntityContext] = PulpEntityContext, + context_class: type[PulpEntityContext] = PulpEntityContext, ) -> t.Callable[[click.Context, click.Parameter, str | None], str | None]: def _href_callback(ctx: click.Context, param: click.Parameter, value: str | None) -> str | None: if value is not None: @@ -719,7 +719,7 @@ def load_labels_callback( def create_content_json_callback( - context_class: t.Type[PulpContentContext] | None = None, + context_class: type[PulpContentContext] | None = None, schema: s.Schema | None = None, ) -> t.Any: @load_file_wrapper @@ -791,7 +791,7 @@ def remote_header_callback( return None header_regex = re.compile(HEADER_REGEX) failed_headers = ", ".join( - (item for item in value if not (item == "" or header_regex.match(item))) + item for item in value if not (item == "" or header_regex.match(item)) ) if failed_headers: raise click.BadParameter(f"format must be : \n{failed_headers}") @@ -812,7 +812,7 @@ def remote_header_callback( def pulp_option( *args: t.Any, - cls: t.Type[PulpOption] = PulpOption, + cls: type[PulpOption] = PulpOption, **kwargs: t.Any, ) -> t.Callable[[FC], FC]: """ @@ -854,9 +854,9 @@ def _inner(cmd: PulpCommand) -> PulpCommand: def option_group( name: str, - options: t.List[str], + options: list[str], /, - callback: t.Callable[[click.Context, t.Dict[str, t.Any]], t.Any] | None = None, + callback: t.Callable[[click.Context, dict[str, t.Any]], t.Any] | None = None, require_all: bool = True, expose_value: bool = True, ) -> t.Callable[[PulpCommand], PulpCommand]: @@ -908,7 +908,7 @@ def resource_lookup_option(*args: t.Any, **kwargs: t.Any) -> t.Callable[[FC], FC A factory to create a lookup option that will pass the lookup to the closest matching Context. """ lookup_key: str | None = kwargs.pop("lookup_key", "name") - context_class: t.Type[PulpEntityContext] = kwargs.pop("context_class") + context_class: type[PulpEntityContext] = kwargs.pop("context_class") def _option_callback( ctx: click.Context, param: click.Parameter, value: str | None @@ -993,10 +993,10 @@ def resource_option(*args: t.Any, **kwargs: t.Any) -> t.Callable[[FC], FC]: default_plugin: str | None = kwargs.pop("default_plugin", None) default_type: str | None = kwargs.pop("default_type", None) lookup_key: str = kwargs.pop("lookup_key", "name") - context_table: dict[str, t.Type[PulpEntityContext]] = kwargs.pop("context_table") + context_table: dict[str, type[PulpEntityContext]] = kwargs.pop("context_table") capabilities: list[str] | None = kwargs.pop("capabilities", None) href_pattern: str | None = kwargs.pop("href_pattern", None) - parent_resource_lookup: tuple[str, t.Type[PulpEntityContext]] | None = kwargs.pop( + parent_resource_lookup: tuple[str, type[PulpEntityContext]] | None = kwargs.pop( "parent_resource_lookup", None ) @@ -1149,7 +1149,7 @@ def type_option(*args: t.Any, **kwargs: t.Any) -> t.Callable[[FC], FC]: """ A factory for `--type` options to allow selecting the class of the `PulpEntityContext` to use. """ - choices: dict[str, t.Type[PulpEntityContext]] = kwargs.pop("choices") + choices: dict[str, type[PulpEntityContext]] = kwargs.pop("choices") assert choices and isinstance(choices, dict) type_names = list(choices.keys()) case_sensitive = kwargs.pop("case_sensitive", False) diff --git a/src/pulpcore/cli/common/acs.py b/src/pulpcore/cli/common/acs.py index 4a2db8727..7ffb4cb90 100644 --- a/src/pulpcore/cli/common/acs.py +++ b/src/pulpcore/cli/common/acs.py @@ -33,8 +33,8 @@ def acs_command( - acs_contexts: dict[str, t.Type[PulpACSContext]], - remote_context_table: dict[str, t.Type[PulpRemoteContext]], + acs_contexts: dict[str, type[PulpACSContext]], + remote_context_table: dict[str, type[PulpRemoteContext]], ) -> click.Command: default_remote_plugin, default_remote_type = list(remote_context_table.keys())[0].split(":") diff --git a/src/pulpcore/cli/container/content.py b/src/pulpcore/cli/container/content.py index b18216c63..4abe222da 100644 --- a/src/pulpcore/cli/container/content.py +++ b/src/pulpcore/cli/container/content.py @@ -25,7 +25,7 @@ _ = gettext.gettext -def _content_callback(ctx: click.Context, value: t.Dict[str, t.Any]) -> None: +def _content_callback(ctx: click.Context, value: dict[str, t.Any]) -> None: if value: entity_ctx = ctx.find_object(PulpContentContext) assert entity_ctx is not None diff --git a/src/pulpcore/cli/file/repository.py b/src/pulpcore/cli/file/repository.py index b5a8bad98..5393dab14 100644 --- a/src/pulpcore/cli/file/repository.py +++ b/src/pulpcore/cli/file/repository.py @@ -59,7 +59,7 @@ ) -def _content_callback(ctx: click.Context, value: t.Dict[str, t.Any]) -> t.Any: +def _content_callback(ctx: click.Context, value: dict[str, t.Any]) -> t.Any: if value: entity_ctx = ctx.find_object(PulpFileContentContext) assert entity_ctx is not None diff --git a/src/pulpcore/cli/rpm/content.py b/src/pulpcore/cli/rpm/content.py index cf14c8444..a9f5786f1 100644 --- a/src/pulpcore/cli/rpm/content.py +++ b/src/pulpcore/cli/rpm/content.py @@ -4,7 +4,11 @@ import click -from pulp_glue.common.context import PluginRequirement, PulpContentContext, PulpEntityContext +from pulp_glue.common.context import ( + PluginRequirement, + PulpContentContext, + PulpEntityContext, +) from pulp_glue.common.i18n import get_translation from pulp_glue.core.context import PulpArtifactContext from pulp_glue.rpm.context import ( @@ -161,7 +165,10 @@ def content() -> None: ), pulp_option("--epoch", allowed_with_contexts=(PulpRpmPackageContext,)), pulp_option( - "--epoch-in", "epoch__in", multiple=True, allowed_with_contexts=(PulpRpmPackageContext,) + "--epoch-in", + "epoch__in", + multiple=True, + allowed_with_contexts=(PulpRpmPackageContext,), ), pulp_option("--epoch-ne", "epoch__ne", allowed_with_contexts=(PulpRpmPackageContext,)), pulp_option( @@ -170,7 +177,10 @@ def content() -> None: ), pulp_option("--id", allowed_with_contexts=(PulpRpmAdvisoryContext,)), pulp_option( - "--id-in", "id__in", multiple=True, allowed_with_contexts=(PulpRpmAdvisoryContext,) + "--id-in", + "id__in", + multiple=True, + allowed_with_contexts=(PulpRpmAdvisoryContext,), ), pulp_option("--module", allowed_with_contexts=(PulpRpmModulemdDefaultsContext,)), pulp_option( @@ -249,11 +259,15 @@ def content() -> None: ), pulp_option("--status", allowed_with_contexts=(PulpRpmAdvisoryContext,)), pulp_option( - "--status-in", "status__in", multiple=True, allowed_with_contexts=(PulpRpmAdvisoryContext,) + "--status-in", + "status__in", + multiple=True, + allowed_with_contexts=(PulpRpmAdvisoryContext,), ), pulp_option("--status-ne", "status__ne", allowed_with_contexts=(PulpRpmAdvisoryContext,)), pulp_option( - "--stream", allowed_with_contexts=(PulpRpmModulemdDefaultsContext, PulpRpmModulemdContext) + "--stream", + allowed_with_contexts=(PulpRpmModulemdDefaultsContext, PulpRpmModulemdContext), ), pulp_option( "--stream-in", @@ -263,7 +277,10 @@ def content() -> None: ), pulp_option("--type", allowed_with_contexts=(PulpRpmAdvisoryContext,)), pulp_option( - "--type-in", "type__in", multiple=True, allowed_with_contexts=(PulpRpmAdvisoryContext,) + "--type-in", + "type__in", + multiple=True, + allowed_with_contexts=(PulpRpmAdvisoryContext,), ), pulp_option("--type-ne", "type__ne", allowed_with_contexts=(PulpRpmAdvisoryContext,)), pulp_option( @@ -469,10 +486,8 @@ def upload( final_version_number = _latest_version_number(final_dest_repo_ctx) if final_version_number: click.echo( - _( - "Created new version {} in {}".format( - final_version_number, final_dest_repo_ctx.entity["name"] - ) + _("Created new version {} in {}").format( + final_version_number, final_dest_repo_ctx.entity["name"] ), err=True, ) @@ -480,10 +495,14 @@ def upload( if do_publish: # Publish to generate metadata for the resulting repo-version click.echo( - _("Publishing repository {}.".format(final_dest_repo_ctx.entity["name"])), err=True + _("Publishing repository {}.").format(final_dest_repo_ctx.entity["name"]), + err=True, ) publication_ctx = PulpRpmPublicationContext(pulp_ctx) - body = {"repository": final_dest_repo_ctx.pulp_href, "version": final_version_number} + body = { + "repository": final_dest_repo_ctx.pulp_href, + "version": final_version_number, + } result = publication_ctx.create(body) elif isinstance(entity_ctx, PulpRpmAdvisoryContext): @@ -519,7 +538,7 @@ def _copy_to_final( ] copy_ctx = PulpRpmCopyContext(pulp_ctx) click.echo( - _("Creating new version of repository {}".format(final_dest_repo_ctx.entity["name"])), + _("Creating new version of repository {}").format(final_dest_repo_ctx.entity["name"]), err=True, ) result = copy_ctx.copy(config=copy_config) @@ -540,21 +559,17 @@ def _upload_rpms( # Build message based on whether we have a repository or not if dest_repo_ctx: click.echo( - _( - "About to upload {} files for {}.".format( - len(rpm_names), - dest_repo_ctx.entity["name"], - ) + _("About to upload {} files for {}.").format( + len(rpm_names), + dest_repo_ctx.entity["name"], ), err=True, ) else: click.echo( - _( - "About to upload {} files from {}.".format( - len(rpm_names), - directory, - ) + _("About to upload {} files from {}.").format( + len(rpm_names), + directory, ), err=True, ) @@ -569,7 +584,7 @@ def _upload_rpms( click.echo(_("Uploaded {}...").format(name), err=True) successful_uploads += 1 except Exception as e: - click.echo(_("Failed to upload file {} : {}".format(name, e)), err=True) + click.echo(_("Failed to upload file {} : {}").format(name, e), err=True) if not successful_uploads: raise click.ClickException(_("No successful uploads using directory {}!").format(directory)) diff --git a/tests/conftest.py b/tests/conftest.py index 788fe99c7..654095c0a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,3 @@ -import typing as t from urllib.parse import urljoin import pytest @@ -7,7 +6,7 @@ @pytest.fixture -def pulp_cli_vars(pulp_cli_vars: t.Dict[str, str]) -> t.Dict[str, str]: +def pulp_cli_vars(pulp_cli_vars: dict[str, str]) -> dict[str, str]: PULP_FIXTURES_URL = pulp_cli_vars["PULP_FIXTURES_URL"] result = {} result.update(pulp_cli_vars) diff --git a/tests/test_help_pages.py b/tests/test_help_pages.py index d204ba371..dbc4ea027 100644 --- a/tests/test_help_pages.py +++ b/tests/test_help_pages.py @@ -10,7 +10,7 @@ load_plugins() -def traverse_commands(command: click.Command, args: t.List[str]) -> t.Iterator[t.List[str]]: +def traverse_commands(command: click.Command, args: list[str]) -> t.Iterator[list[str]]: yield args if isinstance(command, click.Group): @@ -110,8 +110,8 @@ def test_help_shows_all_available_commands(no_api: None) -> None: def test_deferred_context( monkeypatch: pytest.MonkeyPatch, no_api: None, - command: t.List[str], - options: t.List[str], + command: list[str], + options: list[str], ) -> None: monkeypatch.setattr( reduce( From 7ccac28b2cb0d9711ec6451ed8bb23856ff599d8 Mon Sep 17 00:00:00 2001 From: Matthias Dellweg Date: Thu, 23 Apr 2026 14:41:51 +0200 Subject: [PATCH 2/2] Add gettext checks to linting --- .../ci/{{ cookiecutter.__project_name }}/pyproject.toml.update | 2 +- pulp-glue/src/pulp_glue/common/i18n.py | 1 - pyproject.toml | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cookiecutter/ci/{{ cookiecutter.__project_name }}/pyproject.toml.update b/cookiecutter/ci/{{ cookiecutter.__project_name }}/pyproject.toml.update index 41c7f6c56..06e64f602 100644 --- a/cookiecutter/ci/{{ cookiecutter.__project_name }}/pyproject.toml.update +++ b/cookiecutter/ci/{{ cookiecutter.__project_name }}/pyproject.toml.update @@ -165,7 +165,7 @@ extend-exclude = ["cookiecutter"] [tool.ruff.lint] # This section is managed by the cookiecutter templates. -extend-select = ["I"] +extend-select = ["I", "INT"] [tool.ruff.lint.isort] # This section is managed by the cookiecutter templates. diff --git a/pulp-glue/src/pulp_glue/common/i18n.py b/pulp-glue/src/pulp_glue/common/i18n.py index 78b69eec6..62b0705df 100644 --- a/pulp-glue/src/pulp_glue/common/i18n.py +++ b/pulp-glue/src/pulp_glue/common/i18n.py @@ -3,7 +3,6 @@ from importlib.resources import files -# Need to call lru_cache() before using it as a decorator for python 3.7 compatibility @cache def get_translation(name: str) -> gettext.NullTranslations: """ diff --git a/pyproject.toml b/pyproject.toml index eff8da16e..de7523dc1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -203,7 +203,7 @@ extend-exclude = ["cookiecutter"] [tool.ruff.lint] # This section is managed by the cookiecutter templates. -extend-select = ["I"] +extend-select = ["I", "INT"] [tool.ruff.lint.isort] # This section is managed by the cookiecutter templates.