Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .ci/scripts/collect_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions .ci/scripts/validate_commit_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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))
Expand All @@ -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.")
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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))
Expand All @@ -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.")
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
34 changes: 16 additions & 18 deletions pulp-glue/src/pulp_glue/common/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"):
Expand All @@ -1468,7 +1466,7 @@ class PulpPublicationContext(PulpEntityContext):
ID_PREFIX = "publications"
HREF_PATTERN = r"publications/(?P<plugin>[\w\-_]+)/(?P<resource_type>[\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"):
Expand Down Expand Up @@ -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"):
Expand Down Expand Up @@ -1584,9 +1582,9 @@ class PulpRepositoryContext(PulpEntityContext):
HREF_PATTERN = r"repositories/(?P<plugin>[\w\-_]+)/(?P<resource_type>[\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"):
Expand Down Expand Up @@ -1711,7 +1709,7 @@ class PulpContentContext(PulpEntityContext):
ID_PREFIX = "content"
HREF_PATTERN = r"content/(?P<plugin>[\w\-_]+)/(?P<resource_type>[\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"):
Expand Down Expand Up @@ -1828,7 +1826,7 @@ class PulpACSContext(PulpEntityContext):
HREF_PATTERN = r"acs/(?P<plugin>[\w\-_]+)/(?P<resource_type>[\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"):
Expand All @@ -1853,7 +1851,7 @@ class PulpContentGuardContext(PulpEntityContext):
HREF_PATTERN = r"contentguards/(?P<plugin>[\w\-_]+)/(?P<resource_type>[\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"):
Expand Down
5 changes: 2 additions & 3 deletions pulp-glue/src/pulp_glue/common/i18n.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
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.
Expand Down
14 changes: 6 additions & 8 deletions pulp-glue/src/pulp_glue/common/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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."))
Expand Down
2 changes: 1 addition & 1 deletion pulp-glue/src/pulp_glue/common/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions pulp-glue/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 1 addition & 3 deletions pulp-glue/tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/pulp_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 4 additions & 6 deletions src/pulp_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <header-name>:<value> \n{failed_headers}")

Expand Down Expand Up @@ -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
Expand Down
Loading
Loading