diff --git a/.ci/gen_certs.py b/.ci/gen_certs.py index 5026efff8..e6eed981e 100644 --- a/.ci/gen_certs.py +++ b/.ci/gen_certs.py @@ -1,27 +1,30 @@ +# /// script +# requires-python = ">=3.10" +# dependencies = [ +# "trustme>=1.2.1,<1.3.0", +# ] +# /// + import argparse -import os import sys -import typing as t +from pathlib import Path import trustme -def main(argv: t.Optional[t.List[str]] = None) -> None: - if argv is None: - argv = sys.argv[1:] - +def main() -> None: parser = argparse.ArgumentParser(prog="gen_certs") parser.add_argument( "-d", "--dir", - default=os.getcwd(), + default=".", help="Directory where certificates and keys are written to. Defaults to cwd.", ) - args = parser.parse_args(argv) - cert_dir = args.dir + args = parser.parse_args(sys.argv[1:]) + cert_dir = Path(args.dir) - if not os.path.isdir(cert_dir): + if not cert_dir.is_dir(): raise ValueError(f"--dir={cert_dir} is not a directory") key_type = trustme.KeyType["ECDSA"] @@ -29,28 +32,26 @@ def main(argv: t.Optional[t.List[str]] = None) -> None: # Generate the CA certificate ca = trustme.CA(key_type=key_type) # Write the certificate the client should trust - ca_cert_path = os.path.join(cert_dir, "ca.pem") + ca_cert_path = cert_dir / "ca.pem" ca.cert_pem.write_to_path(path=ca_cert_path) # Generate the server certificate server_cert = ca.issue_cert("localhost", "127.0.0.1", "::1", key_type=key_type) # Write the certificate and private key the server should use - server_key_path = os.path.join(cert_dir, "server.key") - server_cert_path = os.path.join(cert_dir, "server.pem") + server_key_path = cert_dir / "server.key" + server_cert_path = cert_dir / "server.pem" server_cert.private_key_pem.write_to_path(path=server_key_path) - with open(server_cert_path, mode="w") as f: - f.truncate() + server_cert_path.write_text("") for blob in server_cert.cert_chain_pems: blob.write_to_path(path=server_cert_path, append=True) # Generate the client certificate client_cert = ca.issue_cert("admin@example.com", common_name="admin", key_type=key_type) # Write the certificate and private key the client should use - client_key_path = os.path.join(cert_dir, "client.key") - client_cert_path = os.path.join(cert_dir, "client.pem") + client_key_path = cert_dir / "client.key" + client_cert_path = cert_dir / "client.pem" client_cert.private_key_pem.write_to_path(path=client_key_path) - with open(client_cert_path, mode="w") as f: - f.truncate() + client_cert_path.write_text("") for blob in client_cert.cert_chain_pems: blob.write_to_path(path=client_cert_path, append=True) diff --git a/.ci/run_container.sh b/.ci/run_container.sh index b3a1c7e9b..d1a837cbe 100755 --- a/.ci/run_container.sh +++ b/.ci/run_container.sh @@ -69,6 +69,9 @@ else fi export PULP_CONTENT_ORIGIN +PULP_SECRET_KEY="$(python3 -c "import secrets; print(secrets.token_urlsafe(50))")" +export PULP_SECRET_KEY + "${CONTAINER_RUNTIME}" \ run ${RM:+--rm} \ --env S6_KEEP_ENV=1 \ @@ -79,6 +82,7 @@ export PULP_CONTENT_ORIGIN ${PULP_DOMAIN_ENABLED:+--env PULP_DOMAIN_ENABLED} \ ${PULP_ENABLED_PLUGINS:+--env PULP_ENABLED_PLUGINS} \ --env PULP_CONTENT_ORIGIN \ + --env PULP_SECRET_KEY \ --detach \ --name "pulp-ephemeral" \ --volume "${PULP_CLI_TEST_TMPDIR}/settings:/etc/pulp${SELINUX:+:Z}" \ diff --git a/.ci/scripts/calc_constraints.py b/.ci/scripts/calc_constraints.py deleted file mode 100755 index d90642511..000000000 --- a/.ci/scripts/calc_constraints.py +++ /dev/null @@ -1,112 +0,0 @@ -#!/bin/python3 - -import argparse -import fileinput -import sys - -from packaging.requirements import Requirement -from packaging.version import Version - -try: - import tomllib -except ImportError: - import tomli as tomllib - - -def split_comment(line): - split_line = line.split("#", maxsplit=1) - try: - comment = " # " + split_line[1].strip() - except IndexError: - comment = "" - return split_line[0].strip(), comment - - -def to_upper_bound(req): - try: - requirement = Requirement(req) - except ValueError: - return f"# UNPARSABLE: {req}" - else: - for spec in requirement.specifier: - if spec.operator == "~=": - return f"# NO BETTER CONSTRAINT: {req}" - if spec.operator == "<=": - operator = "==" - max_version = spec.version - return f"{requirement.name}{operator}{max_version}" - if spec.operator == "<": - operator = "~=" - version = Version(spec.version) - if version.micro != 0: - max_version = f"{version.major}.{version.minor}.{version.micro - 1}" - elif version.minor != 0: - max_version = f"{version.major}.{version.minor - 1}" - elif version.major != 0: - max_version = f"{version.major - 1}.0" - else: - return f"# NO BETTER CONSTRAINT: {req}" - return f"{requirement.name}{operator}{max_version}" - return f"# NO UPPER BOUND: {req}" - - -def to_lower_bound(req): - try: - requirement = Requirement(req) - except ValueError: - return f"# UNPARSABLE: {req}" - else: - for spec in requirement.specifier: - if spec.operator == ">=": - if requirement.name == "pulpcore": - # Currently an exception to allow for pulpcore bugfix releases. - # TODO Semver libraries should be allowed too. - operator = "~=" - else: - operator = "==" - min_version = spec.version - return f"{requirement.name}{operator}{min_version}" - return f"# NO LOWER BOUND: {req}" - - -def main(): - """Calculate constraints for the lower bound of dependencies where possible.""" - parser = argparse.ArgumentParser( - prog=sys.argv[0], - description="Calculate constraints for the lower or upper bound of dependencies where " - "possible.", - ) - parser.add_argument("-u", "--upper", action="store_true") - parser.add_argument("filename", nargs="*") - args = parser.parse_args() - - modifier = to_upper_bound if args.upper else to_lower_bound - - req_files = [filename for filename in args.filename if not filename.endswith("pyproject.toml")] - pyp_files = [filename for filename in args.filename if filename.endswith("pyproject.toml")] - if req_files: - with fileinput.input(files=req_files) as req_file: - for line in req_file: - if line.strip().startswith("#"): - # Shortcut comment only lines - print(line.strip()) - else: - req, comment = split_comment(line) - new_req = modifier(req) - print(new_req + comment) - for filename in pyp_files: - with open(filename, "rb") as fp: - pyproject = tomllib.load(fp) - for req in pyproject["project"]["dependencies"]: - new_req = modifier(req) - print(new_req) - optional_dependencies = pyproject["project"].get("optional-dependencies") - if optional_dependencies: - for opt in optional_dependencies.values(): - for req in opt: - new_req = modifier(req) - print(new_req) - - -if __name__ == "__main__": - main() diff --git a/.ci/scripts/check_changelog_snippets.py b/.ci/scripts/check_changelog_snippets.py new file mode 100755 index 000000000..0fd9f8a53 --- /dev/null +++ b/.ci/scripts/check_changelog_snippets.py @@ -0,0 +1,36 @@ +#!/bin/env python3 +# /// script +# requires-python = ">=3.11" +# dependencies = [ +# ] +# /// +import re +import sys +from pathlib import Path + +import tomllib + +EXCEPTIONS = [ + ".TEMPLATE.md", + ".gitkeep", + "pulp-glue", +] + + +def snippet_valid(path: Path, changelog_exts: list[str]) -> bool: + return (path.name in EXCEPTIONS) or ( + path.suffix in changelog_exts + and (path.stem.startswith("+") or re.fullmatch(r"\d*", path.stem)) + ) + + +if __name__ == "__main__": + with Path("pyproject.toml").open("rb") as fp: + pyproject_toml = tomllib.load(fp) + changelog_exts = [ + f".{item['directory']}" for item in pyproject_toml["tool"]["towncrier"]["type"] + ] + matches = Path("CHANGES").rglob("*") + invalid_snippets = ", ".join(f"'{s}'" for s in matches if not snippet_valid(s, changelog_exts)) + if invalid_snippets: + sys.exit(f"LINT: Invalid changelog entries: {invalid_snippets}.") diff --git a/.ci/scripts/check_click_for_mypy.py b/.ci/scripts/check_click_for_mypy.py index 408a7c6af..d4b1aea7f 100755 --- a/.ci/scripts/check_click_for_mypy.py +++ b/.ci/scripts/check_click_for_mypy.py @@ -1,5 +1,11 @@ #!/bin/env python3 - +# /// script +# requires-python = ">=3.11" +# dependencies = [ +# "packaging>=25.0,<25.1", +# ] +# /// +import sys from importlib import metadata from packaging.version import Version @@ -9,4 +15,4 @@ if click_version < Version("8.1.1"): print("🚧 Linting with mypy is currently only supported with click>=8.1.1. 🚧") print("🔧 Please run `pip install click>=8.1.1` first. 🔨") - exit(1) + sys.exit(1) diff --git a/.ci/scripts/collect_changes.py b/.ci/scripts/collect_changes.py index e6cb0da7a..9ed2b481a 100755 --- a/.ci/scripts/collect_changes.py +++ b/.ci/scripts/collect_changes.py @@ -1,15 +1,24 @@ #!/bin/env python3 +# /// script +# requires-python = ">=3.13" +# dependencies = [ +# "gitpython>=3.1.46,<3.2.0", +# "packaging>=25.0,<25.1", +# ] +# /// import itertools -import os import re -import tomllib +import typing as t +from pathlib import Path +import tomllib from git import GitCommandError, Repo +from packaging.version import Version from packaging.version import parse as parse_version # Read Towncrier settings -with open("pyproject.toml", "rb") as fp: +with Path("pyproject.toml").open("rb") as fp: tc_settings = tomllib.load(fp)["tool"]["towncrier"] CHANGELOG_FILE = tc_settings.get("filename", "NEWS.rst") @@ -44,7 +53,7 @@ ) -def get_changelog(repo, branch): +def get_changelog(repo: Repo, branch: str) -> str: branch_tc_settings = tomllib.loads(repo.git.show(f"{branch}:pyproject.toml"))["tool"][ "towncrier" ] @@ -52,7 +61,7 @@ def get_changelog(repo, branch): return repo.git.show(f"{branch}:{branch_changelog_file}") + "\n" -def _tokenize_changes(splits): +def _tokenize_changes(splits: list[str]) -> t.Iterator[list[Version | str]]: assert len(splits) % 3 == 0 for i in range(len(splits) // 3): title = splits[3 * i] @@ -60,21 +69,20 @@ def _tokenize_changes(splits): yield [version, title + splits[3 * i + 2]] -def split_changelog(changelog): +def split_changelog(changelog: str) -> tuple[str, list[list[Version | str]]]: preamble, rest = changelog.split(START_STRING, maxsplit=1) split_rest = re.split(TITLE_REGEX, rest) return preamble + START_STRING + split_rest[0], list(_tokenize_changes(split_rest[1:])) -def main(): - repo = Repo(os.getcwd()) +def main() -> None: + repo = Repo(Path.cwd()) remote = repo.remotes[0] branches = [ref for ref in remote.refs if re.match(r"^([0-9]+)\.([0-9]+)$", ref.remote_head)] 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: - main_changelog = f.read() + main_changelog = Path(CHANGELOG_FILE).read_text() preamble, main_changes = split_changelog(main_changelog) old_length = len(main_changes) @@ -85,7 +93,7 @@ def main(): except GitCommandError: print("No changelog found on this branch.") continue - dummy, changes = split_changelog(changelog) + _dummy, changes = split_changelog(changelog) new_changes = sorted(main_changes + changes, key=lambda x: x[0], reverse=True) # Now remove duplicates (retain the first one) main_changes = [new_changes[0]] @@ -96,10 +104,9 @@ def main(): new_length = len(main_changes) if old_length < new_length: print(f"{new_length - old_length} new versions have been added.") - with open(CHANGELOG_FILE, "w") as fp: + with Path(CHANGELOG_FILE).open("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/pr_labels.py b/.ci/scripts/pr_labels.py index 9d637b6b2..214481563 100755 --- a/.ci/scripts/pr_labels.py +++ b/.ci/scripts/pr_labels.py @@ -1,19 +1,25 @@ #!/bin/env python3 +# /// script +# requires-python = ">=3.11" +# dependencies = [ +# "gitpython>=3.1.46,<3.2.0", +# ] +# /// # This script is running with elevated privileges from the main branch against pull requests. import re import sys -import tomllib from pathlib import Path +import tomllib from git import Repo -def main(): +def main() -> None: assert len(sys.argv) == 3 - with open("pyproject.toml", "rb") as fp: + with Path("pyproject.toml").open("rb") as fp: PYPROJECT_TOML = tomllib.load(fp) BLOCKING_REGEX = re.compile(r"DRAFT|WIP|NO\s*MERGE|DO\s*NOT\s*MERGE|EXPERIMENT") ISSUE_REGEX = re.compile(r"(?:fixes|closes)[\s:]+#(\d+)") diff --git a/.ci/scripts/release.sh b/.ci/scripts/release.sh index a9c3644a9..41d26774f 100755 --- a/.ci/scripts/release.sh +++ b/.ci/scripts/release.sh @@ -23,4 +23,4 @@ towncrier build --yes --version "${NEW_VERSION}" bump-my-version bump release --commit --message "Release {new_version}" --tag --tag-name "{new_version}" --tag-message "Release {new_version}" --allow-dirty bump-my-version bump patch --commit -git push origin "${BRANCH}" "${NEW_VERSION}" +git push --atomic origin "${BRANCH}" "${NEW_VERSION}" diff --git a/.ci/scripts/validate_commit_message.py b/.ci/scripts/validate_commit_message.py index a067e66a2..3f30e318a 100644 --- a/.ci/scripts/validate_commit_message.py +++ b/.ci/scripts/validate_commit_message.py @@ -1,13 +1,19 @@ +# /// script +# requires-python = ">=3.11" +# dependencies = [ +# "pygithub>=2.8.1,<3.0.0", +# ] +# /// + import os import re import subprocess import sys -import tomllib from pathlib import Path -from github import Github +import tomllib -with open("pyproject.toml", "rb") as fp: +with Path("pyproject.toml").open("rb") as fp: PYPROJECT_TOML = tomllib.load(fp) KEYWORDS = ["fixes", "closes"] BLOCKING_REGEX = [ @@ -26,14 +32,16 @@ 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")) -repo = g.get_repo("pulp/pulp-cli") +def check_status(issue: str) -> None: + from github import Github + + g = Github(os.environ.get("GITHUB_TOKEN")) + repo = g.get_repo("pulp/pulp-cli") -def check_status(issue): gi = repo.get_issue(int(issue)) if gi.pull_request: sys.exit(f"Error: issue #{issue} is a pull request.") @@ -41,7 +49,7 @@ def check_status(issue): sys.exit(f"Error: issue #{issue} is closed.") -def check_changelog(issue): +def check_changelog(issue: str) -> None: matches = list(Path("CHANGES").rglob(f"{issue}.*")) if len(matches) < 1: @@ -51,10 +59,12 @@ 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)) +issue_regex = r"(?:{keywords})[\s:]+#(\d+)".format( + keywords=("|").join(re.escape(k) for k in KEYWORDS) +) issues = re.findall(issue_regex, message, re.IGNORECASE) cherry_pick_regex = r"^\s*\(cherry picked from commit [0-9a-f]*\)\s*$" cherry_pick = re.search(cherry_pick_regex, message, re.MULTILINE) @@ -62,7 +72,7 @@ def check_changelog(issue): if issues: for issue in issues: if not cherry_pick: - check_status(issue) check_changelog(issue) + check_status(issue) -print("Commit message for {sha} passed.".format(sha=sha[0:7])) +print(f"Commit message for {sha[0:7]} passed.") diff --git a/.ci/settings/settings.py b/.ci/settings/settings.py index ed037be22..362d83f73 100644 --- a/.ci/settings/settings.py +++ b/.ci/settings/settings.py @@ -3,6 +3,7 @@ ALLOWED_EXPORT_PATHS = ["/tmp"] ANALYTICS = False ALLOWED_CONTENT_CHECKSUMS = ["sha1", "sha256", "sha512"] +TASK_DIAGNOSTICS = ["memory"] if os.environ.get("PULP_HTTPS", "false").lower() == "true": AUTHENTICATION_BACKENDS = "@merge django.contrib.auth.backends.RemoteUserBackend" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 08389fbd6..0bc4872ba 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,35 +4,38 @@ name: "Build" on: workflow_call: +defaults: + run: + working-directory: "pulp-cli" + jobs: build: runs-on: "ubuntu-latest" steps: - - uses: "actions/checkout@v5" - - uses: "actions/cache@v4" + - name: "Checkout" + uses: "actions/checkout@v6" with: - path: "~/.cache/pip" - key: "${{ runner.os }}-pip-${{ hashFiles('**/*requirements.txt', '**/*constraints.lock', '**/setup.py', '**/pyproject.toml') }}" - restore-keys: | - ${{ runner.os }}-pip- - + path: "pulp-cli" - name: "Set up Python" - uses: "actions/setup-python@v5" + uses: "actions/setup-python@v6" with: python-version: "3.14" - - name: "Install python dependencies" - run: | - pip install build setuptools wheel + allow-prereleases: true + - name: "Install uv" + uses: "astral-sh/setup-uv@v7" + with: + enable-cache: true - name: "Build wheels" run: | make build + touch ../.root - name: "Upload wheels" - uses: "actions/upload-artifact@v4" + uses: "actions/upload-artifact@v6" with: name: "pulp_cli_packages" path: | - pulp-glue/dist/ - dist/ + .root + pulp-cli/dist/ if-no-files-found: "error" retention-days: 5 ... diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index b1dacdfce..129485d1e 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -2,11 +2,12 @@ name: "CodeQL" on: - push: - branches: - - "main" workflow_call: +defaults: + run: + working-directory: "pulp-cli" + jobs: analyze: name: "Analyze" @@ -17,15 +18,17 @@ jobs: security-events: "write" steps: - - name: "Checkout repository" - uses: "actions/checkout@v5" + - name: "Checkout" + uses: "actions/checkout@v6" + with: + path: "pulp-cli" - name: "Initialize CodeQL" - uses: "github/codeql-action/init@v3" + uses: "github/codeql-action/init@v4" with: languages: "python" - name: "Perform CodeQL Analysis" - uses: "github/codeql-action/analyze@v3" + uses: "github/codeql-action/analyze@v4" with: category: "/language:python" ... diff --git a/.github/workflows/collect_changes.yml b/.github/workflows/collect_changes.yml index ebe429afe..7f8571ce9 100644 --- a/.github/workflows/collect_changes.yml +++ b/.github/workflows/collect_changes.yml @@ -4,39 +4,52 @@ on: workflow_call: workflow_dispatch: +defaults: + run: + working-directory: "pulp-cli" + jobs: collect-changes: + permissions: + contents: "write" + pull-requests: "write" runs-on: "ubuntu-latest" steps: - - uses: "actions/checkout@v5" + - name: "Checkout" + uses: "actions/checkout@v6" with: - ref: "main" + path: "pulp-cli" fetch-depth: 0 - - uses: "actions/setup-python@v5" + - name: "Set up Python" + uses: "actions/setup-python@v6" + with: + python-version: "3.14" + allow-prereleases: true + - name: "Install uv" + uses: "astral-sh/setup-uv@v7" with: - python-version: "3.x" + enable-cache: true - name: "Setup git" run: | git config user.name pulpbot git config user.email pulp-infra@redhat.com - name: "Collect changes" run: | - pip install GitPython packaging - python3 .ci/scripts/collect_changes.py + uv run --script .ci/scripts/collect_changes.py - name: "Create Pull Request" - uses: "peter-evans/create-pull-request@v7" + uses: "peter-evans/create-pull-request@v8" id: "create_pr" with: - token: "${{ secrets.RELEASE_TOKEN }}" title: "Update Changelog" body: "" branch: "update_changes" delete-branch: true + path: "pulp-cli" - name: "Mark PR automerge" run: | gh pr merge --rebase --auto "${{ steps.create_pr.outputs.pull-request-number }}" if: "steps.create_pr.outputs.pull-request-number" env: - GH_TOKEN: "${{ secrets.RELEASE_TOKEN }}" + GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}" continue-on-error: true ... diff --git a/.github/workflows/cookiecutter.yml b/.github/workflows/cookiecutter.yml index ee59331f3..42cd33d54 100644 --- a/.github/workflows/cookiecutter.yml +++ b/.github/workflows/cookiecutter.yml @@ -11,50 +11,57 @@ defaults: jobs: update-ci: + permissions: + contents: "write" + pull-requests: "write" runs-on: "ubuntu-latest" steps: - - uses: "actions/checkout@v5" + - uses: "actions/checkout@v6" with: repository: "pulp/pulp-cli" - path: "pulp-cli" - - uses: "actions/checkout@v5" + ref: "main" + path: "pulp-cli_cc" + - name: "Checkout" + uses: "actions/checkout@v6" with: - token: "${{ secrets.RELEASE_TOKEN }}" path: "pulp-cli" + token: "${{ secrets.RELEASE_TOKEN }}" - name: "Set up Python" - uses: "actions/setup-python@v5" + uses: "actions/setup-python@v6" + with: + python-version: "3.14" + allow-prereleases: true + - name: "Install uv" + uses: "astral-sh/setup-uv@v7" with: - python-version: "3.x" + enable-cache: true - name: "Setup git" run: | git config user.name pulpbot git config user.email pulp-infra@redhat.com - - name: "Install python dependencies" - run: | - pip install cookiecutter tomlkit - name: "Apply cookiecutter templates" run: | - ../pulp-cli/cookiecutter/apply_templates.py + uv run ../pulp-cli_cc/cookiecutter/apply_templates.py if [ "$(git status --porcelain)" ] then git add . git commit -m "Update cookiecutter" fi - name: "Create Pull Request" - uses: "peter-evans/create-pull-request@v7" + uses: "peter-evans/create-pull-request@v8" id: "create_pr" with: - token: "${{ secrets.RELEASE_TOKEN }}" title: "Update cookiecutter" body: "" branch: "update_cookiecutter" delete-branch: true path: "pulp-cli" + token: "${{ secrets.RELEASE_TOKEN }}" - name: "Mark PR automerge" run: | gh pr merge --rebase --auto "${{ steps.create_pr.outputs.pull-request-number }}" if: "steps.create_pr.outputs.pull-request-number" env: - GH_TOKEN: "${{ secrets.RELEASE_TOKEN }}" + GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}" continue-on-error: true ... diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 2bc6eb751..e21a5df2d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -4,6 +4,10 @@ name: "Lint" on: workflow_call: +defaults: + run: + working-directory: "pulp-cli" + jobs: lint: runs-on: "ubuntu-latest" @@ -14,25 +18,19 @@ jobs: - "3.11" - "3.14" steps: - - uses: "actions/checkout@v5" - - uses: "actions/cache@v4" - with: - path: "~/.cache/pip" - key: "${{ runner.os }}-pip-${{ hashFiles('**/*requirements.txt', '**/*constraints.lock', '**/setup.py', '**/pyproject.toml') }}" - restore-keys: | - ${{ runner.os }}-pip- - - - name: "Download wheels" - uses: "actions/download-artifact@v5" + - name: "Checkout" + uses: "actions/checkout@v6" with: - name: "pulp_cli_packages" + path: "pulp-cli" - name: "Set up Python" - uses: "actions/setup-python@v5" + uses: "actions/setup-python@v6" with: python-version: "${{ matrix.python }}" - - name: "Install python dependencies" - run: | - pip install dist/pulp_cli-*.whl pulp-glue/dist/pulp_glue-*.whl -r lint_requirements.txt + allow-prereleases: true + - name: "Install uv" + uses: "astral-sh/setup-uv@v7" + with: + enable-cache: true - name: "Lint code" run: | make lint diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index cf39225a1..8ec5b2609 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -1,5 +1,5 @@ --- -name: "pulp-cli Nightly" +name: "Nightly" on: schedule: @@ -14,8 +14,14 @@ jobs: - "build" uses: "./.github/workflows/test.yml" codeql: + permissions: + actions: "read" + contents: "read" + security-events: "write" uses: "./.github/workflows/codeql.yml" collect_changes: + permissions: + contents: "write" + pull-requests: "write" uses: "./.github/workflows/collect_changes.yml" - secrets: "inherit" ... diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 9f0d630cd..209eb8f55 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1,5 +1,5 @@ --- -name: "pulp-cli CI" +name: "Pull Request" on: pull_request: @@ -9,15 +9,15 @@ concurrency: cancel-in-progress: true jobs: - build: - uses: "./.github/workflows/build.yml" lint: - needs: - - "build" uses: "./.github/workflows/lint.yml" - test: + build: needs: - "lint" + uses: "./.github/workflows/build.yml" + test: + needs: + - "build" uses: "./.github/workflows/test.yml" docs: needs: @@ -29,20 +29,28 @@ jobs: codeql: needs: - "lint" + permissions: + actions: "read" + contents: "read" + security-events: "write" uses: "./.github/workflows/codeql.yml" check-commits: runs-on: "ubuntu-latest" steps: - - uses: "actions/checkout@v5" + - name: "Checkout" + uses: "actions/checkout@v6" with: + path: "pulp-cli" fetch-depth: 0 - name: "Set up Python" - uses: "actions/setup-python@v5" + uses: "actions/setup-python@v6" with: - python-version: "3.x" - - name: "Install python dependencies" - run: | - pip install toml pygithub + python-version: "3.14" + allow-prereleases: true + - name: "Install uv" + uses: "astral-sh/setup-uv@v7" + with: + enable-cache: true - name: "Check commit message" env: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" @@ -50,13 +58,14 @@ jobs: run: | for SHA in $(curl -H "Authorization: token $GITHUB_TOKEN" "$GITHUB_CONTEXT" | jq -r '.[].sha') do - python .ci/scripts/validate_commit_message.py "$SHA" + uv run -q .ci/scripts/validate_commit_message.py "$SHA" VALUE=$? if [ "$VALUE" -gt 0 ]; then exit "$VALUE" fi done shell: "bash" + working-directory: "pulp-cli" ready-to-ship: # This is a dummy dependent task to have a single entry for the branch protection rules. runs-on: "ubuntu-latest" diff --git a/.github/workflows/pr_checks.yml b/.github/workflows/pr_checks.yml index ec590e501..f2d8d1c63 100644 --- a/.github/workflows/pr_checks.yml +++ b/.github/workflows/pr_checks.yml @@ -1,5 +1,5 @@ --- -name: "Pulp CLI PR static checks" +name: "PR static checks" on: pull_request_target: types: ["opened", "synchronize", "reopened"] @@ -12,26 +12,37 @@ concurrency: group: "${{ github.event.pull_request.number }}-${{ github.workflow }}" cancel-in-progress: true +defaults: + run: + working-directory: "pulp-cli" + jobs: apply_labels: - runs-on: "ubuntu-latest" - name: "Label PR" permissions: pull-requests: "write" + runs-on: "ubuntu-latest" + name: "Label PR" steps: - - uses: "actions/checkout@v5" + - name: "Checkout" + uses: "actions/checkout@v6" with: + path: "pulp-cli" fetch-depth: 0 - - uses: "actions/setup-python@v5" + - name: "Set up Python" + uses: "actions/setup-python@v6" + with: + python-version: "3.14" + allow-prereleases: true + - name: "Install uv" + uses: "astral-sh/setup-uv@v7" with: - python-version: "3.x" + enable-cache: true - name: "Determine PR labels" run: | - pip install GitPython==3.1.42 git fetch origin ${{ github.event.pull_request.head.sha }} - python .ci/scripts/pr_labels.py "origin/${{ github.base_ref }}" "${{ github.event.pull_request.head.sha }}" >> "$GITHUB_ENV" - - uses: "actions/github-script@v7" - name: "Apply PR Labels" + uv run -q .ci/scripts/pr_labels.py "origin/${{ github.base_ref }}" "${{ github.event.pull_request.head.sha }}" >> "$GITHUB_ENV" + - name: "Apply PR Labels" + uses: "actions/github-script@v8" with: script: | const { ADD_LABELS, REMOVE_LABELS } = process.env; diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 47839fec6..341236753 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,11 +1,15 @@ --- -name: "pulp-cli Publish" +name: "Publish" on: push: tags: - "[0-9]+.[0-9]+.[0-9]+" +defaults: + run: + working-directory: "pulp-cli" + jobs: build: uses: "./.github/workflows/build.yml" @@ -13,27 +17,20 @@ jobs: name: "Publish to PyPI" needs: "build" runs-on: "ubuntu-latest" + environment: + name: "pypi" + permissions: + id-token: "write" steps: - - uses: "actions/checkout@v5" - name: "Download wheels" - uses: "actions/download-artifact@v5" + uses: "actions/download-artifact@v8" with: name: "pulp_cli_packages" - - name: "Set up Python" - uses: "actions/setup-python@v5" + - name: "Install uv" + uses: "astral-sh/setup-uv@v7" with: - python-version: "3.x" - - name: "Install dependencies" - run: | - python -m pip install --upgrade pip - pip install twine - - name: "Build and publish" - env: - TWINE_USERNAME: "__token__" - TWINE_PASSWORD: "${{ secrets.PYPI_API_TOKEN }}" + enable-cache: false + - name: "Publish" run: | - cd pulp-glue - twine upload dist/* - cd .. - twine upload dist/* + uv publish ... diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 751f35aef..7d54bb2e1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,30 +1,39 @@ --- -name: "pulp-cli Release" +name: "Tag Release" on: workflow_dispatch: +defaults: + run: + working-directory: "pulp-cli" + jobs: release: name: "Release" + permissions: + contents: "write" runs-on: "ubuntu-latest" steps: - - uses: "actions/checkout@v5" + - name: "Checkout" + uses: "actions/checkout@v6" with: + path: "pulp-cli" token: "${{ secrets.RELEASE_TOKEN }}" - name: "Set up Python" - uses: "actions/setup-python@v5" + uses: "actions/setup-python@v6" with: - python-version: "3.x" - - name: "Install dependencies" - run: | - python -m pip install --upgrade pip - pip install bump-my-version~=0.20.0 towncrier~=23.11.0 + python-version: "3.14" + allow-prereleases: true + - name: "Install uv" + uses: "astral-sh/setup-uv@v7" + with: + enable-cache: true - name: "Setup git" run: | git config user.name pulpbot git config user.email pulp-infra@redhat.com - name: "Release" run: | - .ci/scripts/release.sh + uv run --with bump-my-version~=0.20.0 --with towncrier~=23.11.0 .ci/scripts/release.sh ... diff --git a/.github/workflows/release_branch.yml b/.github/workflows/release_branch.yml index aedcbf4c8..f84af1c36 100644 --- a/.github/workflows/release_branch.yml +++ b/.github/workflows/release_branch.yml @@ -3,45 +3,57 @@ name: "Create Release Branch" on: workflow_dispatch: +defaults: + run: + working-directory: "pulp-cli" + jobs: create-release-branch: + permissions: + contents: "write" + issues: "write" + pull-requests: "write" runs-on: "ubuntu-latest" steps: - - uses: "actions/checkout@v5" + - name: "Checkout" + uses: "actions/checkout@v6" with: + path: "pulp-cli" token: "${{ secrets.RELEASE_TOKEN }}" - name: "Set up Python" - uses: "actions/setup-python@v5" + uses: "actions/setup-python@v6" + with: + python-version: "3.14" + allow-prereleases: true + - name: "Install uv" + uses: "astral-sh/setup-uv@v7" with: - python-version: "3.x" + enable-cache: true - name: "Setup git" run: | git config user.name pulpbot git config user.email pulp-infra@redhat.com - - name: "Install python dependencies" - run: | - pip install bump-my-version~=0.20.0 - name: "Create Release Branch" run: | - .ci/scripts/create_release_branch.sh + uv run --with bump-my-version~=0.20.0 .ci/scripts/create_release_branch.sh - name: "Create Pull Request" - uses: "peter-evans/create-pull-request@v7" + uses: "peter-evans/create-pull-request@v8" id: "create_pr" with: - token: "${{ secrets.RELEASE_TOKEN }}" title: "Bump dev-version" body: "" branch: "bump_version" delete-branch: true + path: "pulp-cli" - name: "Mark PR automerge" run: | gh pr merge --rebase --auto "${{ steps.create_pr.outputs.pull-request-number }}" if: "steps.create_pr.outputs.pull-request-number" env: - GH_TOKEN: "${{ secrets.RELEASE_TOKEN }}" + GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}" continue-on-error: true - name: "Add Backport Label for new Branch" - uses: "actions/github-script@v7" + uses: "actions/github-script@v8" with: script: | const { NEW_BRANCH } = process.env; diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5dcc4e764..be0026acf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,6 +4,10 @@ name: "Test" on: workflow_call: +defaults: + run: + working-directory: "pulp-cli" + env: COLORTERM: "yes" TERM: "xterm-256color" @@ -14,28 +18,26 @@ jobs: unittest: runs-on: "ubuntu-latest" steps: - - uses: "actions/checkout@v5" - - uses: "actions/cache@v4" + - name: "Checkout" + uses: "actions/checkout@v6" with: - path: "~/.cache/pip" - key: "${{ runner.os }}-pip-${{ hashFiles('**/*requirements.txt', '**/*constraints.lock', '**/setup.py', '**/pyproject.toml') }}" - restore-keys: | - ${{ runner.os }}-pip- - + path: "pulp-cli" - name: "Download wheels" - uses: "actions/download-artifact@v5" + uses: "actions/download-artifact@v8" with: name: "pulp_cli_packages" - name: "Set up Python" - uses: "actions/setup-python@v5" + uses: "actions/setup-python@v6" with: python-version: "3.14" - - name: "Install Python Test Dependencies" - run: | - pip install dist/pulp_cli-*.whl pulp-glue/dist/pulp_glue-*.whl -r test_requirements.txt + allow-prereleases: true + - name: "Install uv" + uses: "astral-sh/setup-uv@v7" + with: + enable-cache: true - name: "Run tests" run: | - make unittest + uv run --isolated --with dist/pulp_glue*.whl --with dist/pulp_cli*.whl --only-group test make _unittest test: runs-on: "ubuntu-24.04" needs: @@ -73,35 +75,23 @@ jobs: pulp_api_root: "/relocated/djnd/" python: "3.9" steps: - - uses: "actions/checkout@v5" - - uses: "actions/cache@v4" + - name: "Checkout" + uses: "actions/checkout@v6" with: - path: "~/.cache/pip" - key: "${{ runner.os }}-pip-${{ hashFiles('**/*requirements.txt', '**/*constraints.lock', '**/setup.py', '**/pyproject.toml') }}" - restore-keys: | - ${{ runner.os }}-pip- - + path: "pulp-cli" - name: "Download wheels" - uses: "actions/download-artifact@v5" + uses: "actions/download-artifact@v8" with: name: "pulp_cli_packages" - name: "Set up Python" - uses: "actions/setup-python@v5" + uses: "actions/setup-python@v6" with: python-version: "${{ matrix.python }}" allow-prereleases: true - - name: "Install Python Test Dependencies" - run: | - if [ "${{matrix.lower_bounds}}" ] - then - pip install dist/pulp_cli-*.whl pulp-glue/dist/pulp_glue-*.whl -r test_requirements.txt -c lower_bounds_constraints.lock - elif [ "${{matrix.upper_bounds}}" ] - then - .ci/scripts/calc_constraints.py pyproject.toml pulp-glue/pyproject.toml --upper > upper_bounds_constraints.lock - pip install dist/pulp_cli-*.whl pulp-glue/dist/pulp_glue-*.whl -r test_requirements.txt -c upper_bounds_constraints.lock - else - pip install dist/pulp_cli-*.whl pulp-glue/dist/pulp_glue-*.whl -r test_requirements.txt - fi + - name: "Install uv" + uses: "astral-sh/setup-uv@v7" + with: + enable-cache: true - name: "Run tests" env: CONTAINER_RUNTIME: "${{ matrix.container_runtime }}" @@ -115,5 +105,15 @@ jobs: PULP_ENABLED_PLUGINS: "${{ matrix.pulp_enabled_plugins }}" OAS_VERSION: "${{ matrix.oas_version }}" run: | - .ci/run_container.sh make livetest + if [ "${{matrix.lower_bounds}}" ] + then + RESOLUTION=("--resolution" "lowest-direct") + elif [ "${{matrix.upper_bounds}}" ] + then + RESOLUTION=("--resolution" "highest") + else + RESOLUTION=() + fi + + uv run "${RESOLUTION[@]}" --isolated --with dist/pulp_glue*.whl --with dist/pulp_cli*.whl --only-group test .ci/run_container.sh make _livetest ... diff --git a/.gitignore b/.gitignore index ed761f6a8..4e13d3475 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,11 @@ *.egg-info __pycache__/ build/ -tests/cli.toml -GPG-PRIVATE-KEY-fixture-signing site/ dist/ *.po~ +uv.lock + +tests/cli.toml +GPG-PRIVATE-KEY-fixture-signing +.root diff --git a/Makefile b/Makefile index ddd4fa460..68f61ad57 100644 --- a/Makefile +++ b/Makefile @@ -1,57 +1,106 @@ +# This file is managed by the cookiecutter templates. +# Do not edit manually LANGUAGES=de -GLUE_PLUGINS=$(notdir $(wildcard pulp-glue/pulp_glue/*)) -CLI_PLUGINS=$(notdir $(wildcard pulpcore/cli/*)) +GLUE_PLUGINS=$(notdir $(wildcard pulp-glue/src/pulp_glue/*)) +CLI_PLUGINS=$(notdir $(wildcard src/pulpcore/cli/*)) +.PHONY: info info: @echo Pulp glue @echo plugins: $(GLUE_PLUGINS) @echo Pulp CLI @echo plugins: $(CLI_PLUGINS) +.PHONY: build build: - cd pulp-glue; pyproject-build -n - pyproject-build -n + uv build --all -black: format +.PHONY: _format +_format: + ruff format + ruff check --select I --fix +.PHONY: format format: - isort . - cd pulp-glue; isort . - black . + uv run --isolated --group lint $(MAKE) _format -lint: +.PHONY: _autofix +_autofix: + ruff check --fix + +.PHONY: autofix +autofix: + uv run --isolated --group lint $(MAKE) _autofix + +.PHONY: _lint +_lint: find tests .ci -name '*.sh' -print0 | xargs -0 shellcheck -x - isort -c --diff . - cd pulp-glue; isort -c --diff . - black --diff --check . - flake8 + ruff format --check --diff + ruff check --output-format concise + .ci/scripts/check_changelog_snippets.py .ci/scripts/check_click_for_mypy.py - MYPYPATH=pulp-glue mypy + mypy cd pulp-glue; mypy @echo "🙊 Code 🙈 LGTM 🙉 !" +.PHONY: lint +lint: + uv run --isolated --group lint $(MAKE) _lint + tests/cli.toml: cp $@.example $@ @echo "In order to configure the tests to talk to your test server, you might need to edit $@ ." -test: | tests/cli.toml - python3 -m pytest -v tests pulp-glue/tests cookiecutter/pulp_filter_extension.py +.PHONY: _test +_test: | tests/cli.toml + pytest -v tests pulp-glue/tests + +.PHONY: test +test: + uv run $(MAKE) _test + +PYTEST_MARK ?= live -livetest: | tests/cli.toml - python3 -m pytest -v tests pulp-glue/tests -m live +.PHONY: _livetest +_livetest: | tests/cli.toml + pytest -v tests pulp-glue/tests -m "$(PYTEST_MARK)" +.PHONY: livetest +livetest: + uv run $(MAKE) _livetest + +.PHONY: _paralleltest +_paralleltest: | tests/cli.toml + pytest -v tests pulp-glue/tests -m "$(PYTEST_MARK)" -n 8 + +.PHONY: paralleltest +paralleltest: + uv run $(MAKE) _paralleltest + +.PHONY: _unittest +_unittest: + pytest -v tests pulp-glue/tests -m "not live" + +.PHONY: unittest unittest: - python3 -m pytest -v tests pulp-glue/tests cookiecutter/pulp_filter_extension.py -m "not live" + uv run $(MAKE) _unittest + +.PHONY: _unittest_glue +_unittest_glue: + pytest -v pulp-glue/tests -m "not live" +.PHONY: unittest_glue unittest_glue: - python3 -m pytest -v pulp-glue/tests -m "not live" + uv run $(MAKE) _unittest_glue +.PHONY: docs docs: - pulp-docs build + uv run --only-group docs pulp-docs build --draft --no-blog +.PHONY: servedocs servedocs: - pulp-docs serve -w CHANGES.md -w pulp-glue/pulp_glue -w pulp_cli/generic.py + uv run --only-group docs pulp-docs serve --draft --no-blog -w CHANGES.md -w src -w pulp-glue/src pulp-glue/pulp_glue/%/locale/messages.pot: pulp-glue/pulp_glue/%/*.py xgettext -d $* -o $@ pulp-glue/pulp_glue/$*/*.py @@ -61,6 +110,7 @@ pulpcore/cli/%/locale/messages.pot: pulpcore/cli/%/*.py xgettext -d $* -o $@ pulpcore/cli/$*/*.py sed -i 's/charset=CHARSET/charset=UTF-8/g' $@ +.PHONY: extract_messages extract_messages: $(foreach GLUE_PLUGIN,$(GLUE_PLUGINS),pulp-glue/pulp_glue/$(GLUE_PLUGIN)/locale/messages.pot) $(foreach CLI_PLUGIN,$(CLI_PLUGINS),pulpcore/cli/$(CLI_PLUGIN)/locale/messages.pot) $(foreach LANGUAGE,$(LANGUAGES),pulp-glue/pulp_glue/%/locale/$(LANGUAGE)/LC_MESSAGES/messages.po): pulp-glue/pulp_glue/%/locale/messages.pot @@ -76,6 +126,7 @@ $(foreach LANGUAGE,$(LANGUAGES),pulpcore/cli/%/locale/$(LANGUAGE)/LC_MESSAGES/me %.mo: %.po msgfmt -o $@ $< +.PHONY: compile_messages compile_messages: $(foreach LANGUAGE,$(LANGUAGES),$(foreach GLUE_PLUGIN,$(GLUE_PLUGINS),pulp-glue/pulp_glue/$(GLUE_PLUGIN)/locale/$(LANGUAGE)/LC_MESSAGES/messages.mo)) $(foreach LANGUAGE,$(LANGUAGES),$(foreach CLI_PLUGIN,$(CLI_PLUGINS),pulpcore/cli/$(CLI_PLUGIN)/locale/$(LANGUAGE)/LC_MESSAGES/messages.mo)) -.PHONY: build info black lint test docs servedocs + .PRECIOUS: $(foreach LANGUAGE,$(LANGUAGES),$(foreach GLUE_PLUGIN,$(GLUE_PLUGINS),pulp-glue/pulp_glue/$(GLUE_PLUGIN)/locale/$(LANGUAGE)/LC_MESSAGES/messages.po)) $(foreach LANGUAGE,$(LANGUAGES),$(foreach CLI_PLUGIN,$(CLI_PLUGINS),pulpcore/cli/$(CLI_PLUGIN)/locale/$(LANGUAGE)/LC_MESSAGES/messages.po)) diff --git a/cookiecutter/apply_templates.py b/cookiecutter/apply_templates.py index e72ce3a0b..e4fbd2802 100755 --- a/cookiecutter/apply_templates.py +++ b/cookiecutter/apply_templates.py @@ -3,12 +3,11 @@ # This script requires click, cookiecutter, tomlkit and pyyaml import os -import tomllib from pathlib import Path import click +import tomllib import yaml - from cookiecutter.main import cookiecutter diff --git a/docs/dev/guides/bootstrap.md b/docs/dev/guides/bootstrap.md index e12574192..3f940b913 100644 --- a/docs/dev/guides/bootstrap.md +++ b/docs/dev/guides/bootstrap.md @@ -64,13 +64,10 @@ Edit `pulp-glue-my-plugin/pulp_glue/my_plugin/context.py` to define context clas ```python import typing as t -from pulp_glue.common.context import ( - PulpEntityContext, - PluginRequirement -) +from pulp_glue.common.context import PulpEntityContext, PluginRequirement -class PulpMyResourceContext(): +class PulpMyResourceContext: """Context for working with my custom resource.""" ID_PREFIX = "my_resource" @@ -79,12 +76,12 @@ class PulpMyResourceContext(): def example_action(self, data: t.Dict[str, t.Any]) -> t.Dict[str, t.Any]: """Execute an example action with specific data. - Args: - data: The data dictionary to send to the API + Args: + data: The data dictionary to send to the API - Returns: - The action result - """ + Returns: + The action result + """ response = self.call( operation="example_action", body=data, @@ -137,7 +134,7 @@ from pulp_cli.common.generic import pass_entity_context @click.group() @pass_pulp_context -@click.pass_context +@click.pass_context def my_resource(ctx: click.Context, pulp_ctx: PulpContext, /) -> None: """My custom commands.""" ctx.obj = PulpMyResourceContext(pulp_ctx) diff --git a/docs/dev/learn/architecture.md b/docs/dev/learn/architecture.md index 78ab29cb2..2877274ca 100644 --- a/docs/dev/learn/architecture.md +++ b/docs/dev/learn/architecture.md @@ -26,7 +26,7 @@ A plugin must register itself with the main app by specifying its main module as === "setup.py" ```python - entry_points={ + entry_points = { "pulp_cli.plugins": [ "myplugin=pulpcore.cli.myplugin", ], @@ -40,6 +40,7 @@ The plugin should then attach subcommands to the `pulpcore.cli.common.main` comm ```python from pulp_cli.generic import pulp_command + @pulp_command() def my_command(): pass @@ -139,7 +140,9 @@ class PulpMyResourceContext(PulpEntityContext): NEEDS_PLUGINS = [PluginRequirement("my_plugin", specifier=">=1.0.0")] def show(self) -> t.Dict[str, t.Any]: - if self.pulp_ctx.has_plugin(PluginRequirement("my_plugin", specifier=">=1.2.3", inverted=True)): + if self.pulp_ctx.has_plugin( + PluginRequirement("my_plugin", specifier=">=1.2.3", inverted=True) + ): # Versioned workaroud # see bug-tracker/12345678 return lookup_my_content_legacy(self.pulp_href) @@ -149,7 +152,7 @@ class PulpMyResourceContext(PulpEntityContext): # In pulp_cli_my_plugin @main.command() @pass_pulp_context -def my_command(pulp_ctx:PulpContext) -> None: +def my_command(pulp_ctx: PulpContext) -> None: pulp_ctx.needs_plugin(PluginRequirement("my_plugin", specifier=">=1.1.0")) # From here on we can assume `my_plugin>=1.1.0`. ``` diff --git a/lint_requirements.txt b/lint_requirements.txt deleted file mode 100644 index ec0bf54df..000000000 --- a/lint_requirements.txt +++ /dev/null @@ -1,17 +0,0 @@ -# Lint requirements -black==25.1.0 -flake8==7.3.0 -flake8-pyproject==1.2.3 -isort==6.0.1 -mypy==1.17.1 -shellcheck-py==0.11.0.1 - -# Type annotation stubs -types-pygments -types-PyYAML -types-requests -types-setuptools -types-toml - -# Install the actual bits for mypy --r test_requirements.txt diff --git a/pulp-glue/pulp_glue/common/openapi.py b/pulp-glue/pulp_glue/common/openapi.py index f660c93cd..449436efa 100644 --- a/pulp-glue/pulp_glue/common/openapi.py +++ b/pulp-glue/pulp_glue/common/openapi.py @@ -527,9 +527,9 @@ def _send_request( ) ) if content_type: - assert request.headers["content-type"].startswith( - content_type - ), f"{request.headers['content-type']} != {content_type}" + assert request.headers["content-type"].startswith(content_type), ( + f"{request.headers['content-type']} != {content_type}" + ) for key, value in request.headers.items(): self._debug_callback(2, f" {key}: {value}") if request.body is not None: diff --git a/pulp-glue/pyproject.toml b/pulp-glue/pyproject.toml index 695aa6644..b44af1c1e 100644 --- a/pulp-glue/pyproject.toml +++ b/pulp-glue/pyproject.toml @@ -25,7 +25,7 @@ classifiers = [ dependencies = [ "importlib_resources>=5.4.0,<6.2;python_version<'3.9'", "multidict>=6.0.5,<6.7", - "packaging>=20.0,<=26.2", # CalVer + "packaging>=20.0,<=26.4", # CalVer "requests>=2.24.0,<2.33", "tomli>=2.0.0,<2.1;python_version<'3.11'", ] @@ -36,29 +36,45 @@ repository = "https://github.com/pulp/pulp-cli" changelog = "https://pulpproject.org/pulp-cli/changes/" [tool.setuptools.packages.find] -where = ["."] +# This section is managed by the cookiecutter templates. +where = ["src"] include = ["pulp_glue.*"] namespaces = true [tool.setuptools.package-data] +# This section is managed by the cookiecutter templates. "*" = ["py.typed", "locale/*/LC_MESSAGES/*.mo"] -[tool.black] -line-length = 100 - -[tool.isort] -profile = "black" -line_length = 100 [tool.mypy] +# This section is managed by the cookiecutter templates. strict = true +warn_unused_ignores = false show_error_codes = true -files = "pulp_glue/**/*.py, tests/**/*.py" +files = "src/**/*.py, tests/**/*.py" +mypy_path = ["src"] namespace_packages = true explicit_package_bases = true +plugins = ["pydantic.mypy"] [[tool.mypy.overrides]] +# This section is managed by the cookiecutter templates. module = [ "schema.*", ] ignore_missing_imports = true + + +[tool.ruff] +# This section is managed by the cookiecutter templates. +line-length = 100 + +[tool.ruff.lint] +# This section is managed by the cookiecutter templates. +select = ["E4", "E7", "E9", "F"] +extend-select = ["FURB", "I", "INT", "PTH", "SIM1", "TID", "T10", "UP"] + +[tool.ruff.lint.flake8-tidy-imports.banned-api] +# This section is managed by the cookiecutter templates. +"distutils".msg = "The 'distutils' module has been deprecated since Python 3.9." + diff --git a/pulp_cli/__init__.py b/pulp_cli/__init__.py index 519f6bf9e..da091f078 100644 --- a/pulp_cli/__init__.py +++ b/pulp_cli/__init__.py @@ -5,6 +5,7 @@ from types import ModuleType import click + from pulp_glue.common.i18n import get_translation from pulp_cli.config import CONFIG_LOCATIONS, config, config_options, validate_config diff --git a/pulp_cli/config.py b/pulp_cli/config.py index 940bc0af9..f81a4d102 100644 --- a/pulp_cli/config.py +++ b/pulp_cli/config.py @@ -6,6 +6,7 @@ import click import tomli_w + from pulp_glue.common.i18n import get_translation from pulp_cli.generic import HEADER_REGEX, REGISTERED_OUTPUT_FORMATTERS, _unset, pulp_group diff --git a/pulp_cli/generic.py b/pulp_cli/generic.py index 5167f9e29..a3bdec87b 100644 --- a/pulp_cli/generic.py +++ b/pulp_cli/generic.py @@ -10,6 +10,7 @@ import requests import schema as s import yaml + from pulp_glue.common.authentication import OAuth2ClientCredentialsAuth from pulp_glue.common.context import ( DATETIME_FORMATS, @@ -979,8 +980,7 @@ def _option_callback( if context_class is None: raise click.ClickException( _( - "The type '{plugin}:{resource_type}' " - "is not valid for the {option_name} option." + "The type '{plugin}:{resource_type}' is not valid for the {option_name} option." ).format(plugin=plugin, resource_type=resource_type, option_name=param.name) ) entity_ctx: PulpEntityContext = context_class(pulp_ctx, pulp_href=pulp_href, entity=entity) @@ -1269,9 +1269,7 @@ def _type_callback(ctx: click.Context, param: click.Parameter, value: t.Optional pulp_labels_option = pulp_option( "--labels", "pulp_labels", - help=_( - "JSON dictionary of labels to set on {entity} (or " "@file containing a JSON dictionary)" - ), + help=_("JSON dictionary of labels to set on {entity} (or @file containing a JSON dictionary)"), callback=load_labels_callback, ) diff --git a/pulpcore/cli/ansible/__init__.py b/pulpcore/cli/ansible/__init__.py index 3de06da8b..a31eefdfa 100644 --- a/pulpcore/cli/ansible/__init__.py +++ b/pulpcore/cli/ansible/__init__.py @@ -1,6 +1,7 @@ import typing as t import click + from pulp_glue.common.i18n import get_translation from pulp_cli.generic import pulp_group diff --git a/pulpcore/cli/ansible/content.py b/pulpcore/cli/ansible/content.py index b3b5bb4d6..ab2b918b6 100644 --- a/pulpcore/cli/ansible/content.py +++ b/pulpcore/cli/ansible/content.py @@ -1,6 +1,7 @@ import typing as t import click + from pulp_glue.ansible.context import ( PulpAnsibleCollectionVersionContext, PulpAnsibleCollectionVersionSignatureContext, diff --git a/pulpcore/cli/ansible/distribution.py b/pulpcore/cli/ansible/distribution.py index 900af7650..39d3396d2 100644 --- a/pulpcore/cli/ansible/distribution.py +++ b/pulpcore/cli/ansible/distribution.py @@ -1,6 +1,7 @@ import typing as t import click + from pulp_glue.ansible.context import PulpAnsibleDistributionContext, PulpAnsibleRepositoryContext from pulp_glue.common.context import ( EntityDefinition, @@ -140,7 +141,7 @@ def update( if version is not None: if dist_body["repository"]: distribution_ctx.update(body={"repository": ""}, non_blocking=True) - body["repository_version"] = f'{repo["versions_href"]}{version}/' + body["repository_version"] = f"{repo['versions_href']}{version}/" else: if dist_body["repository_version"]: distribution_ctx.update(body={"repository_version": ""}, non_blocking=True) @@ -149,7 +150,7 @@ def update( # keep current repository, change version if dist_body["repository"]: distribution_ctx.update(body={"repository": ""}, non_blocking=True) - body["repository_version"] = f'{dist_body["repository"]}versions/{version}/' + body["repository_version"] = f"{dist_body['repository']}versions/{version}/" elif dist_body["repository_version"]: # 'dummy' vars are to get us around a mypy/1.2 complaint about '_' repository_href, dummy, dummy = dist_body["repository_version"].partition("versions") diff --git a/pulpcore/cli/ansible/remote.py b/pulpcore/cli/ansible/remote.py index 4e91feb3b..2cdb1fdc7 100644 --- a/pulpcore/cli/ansible/remote.py +++ b/pulpcore/cli/ansible/remote.py @@ -2,6 +2,7 @@ import click import yaml + from pulp_glue.ansible.context import ( PulpAnsibleCollectionRemoteContext, PulpAnsibleRoleRemoteContext, diff --git a/pulpcore/cli/ansible/repository.py b/pulpcore/cli/ansible/repository.py index ab7e53b6f..b0d4b7d80 100644 --- a/pulpcore/cli/ansible/repository.py +++ b/pulpcore/cli/ansible/repository.py @@ -2,6 +2,7 @@ import click import schema as s + from pulp_glue.ansible.context import ( PulpAnsibleCollectionRemoteContext, PulpAnsibleCollectionVersionContext, diff --git a/pulpcore/cli/common/acs.py b/pulpcore/cli/common/acs.py index 8324467a1..4fcb4fead 100644 --- a/pulpcore/cli/common/acs.py +++ b/pulpcore/cli/common/acs.py @@ -1,6 +1,7 @@ import typing as t import click + from pulp_glue.common.context import PulpACSContext, PulpRemoteContext from pulp_glue.common.i18n import get_translation diff --git a/pulpcore/cli/common/debug.py b/pulpcore/cli/common/debug.py index da2a5341f..7bd08f33c 100644 --- a/pulpcore/cli/common/debug.py +++ b/pulpcore/cli/common/debug.py @@ -3,6 +3,7 @@ import click from packaging.specifiers import SpecifierSet + from pulp_glue.common.context import PluginRequirement from pulp_glue.common.i18n import get_translation diff --git a/pulpcore/cli/container/__init__.py b/pulpcore/cli/container/__init__.py index a6661c288..717109c06 100644 --- a/pulpcore/cli/container/__init__.py +++ b/pulpcore/cli/container/__init__.py @@ -1,6 +1,7 @@ import typing as t import click + from pulp_glue.common.i18n import get_translation from pulp_cli.generic import pulp_group diff --git a/pulpcore/cli/container/content.py b/pulpcore/cli/container/content.py index 37b676d47..87e40ed09 100644 --- a/pulpcore/cli/container/content.py +++ b/pulpcore/cli/container/content.py @@ -2,6 +2,7 @@ import typing as t import click + from pulp_glue.common.context import PluginRequirement, PulpEntityContext from pulp_glue.container.context import ( PulpContainerBlobContext, diff --git a/pulpcore/cli/container/distribution.py b/pulpcore/cli/container/distribution.py index 0130077aa..f6294d290 100644 --- a/pulpcore/cli/container/distribution.py +++ b/pulpcore/cli/container/distribution.py @@ -1,6 +1,7 @@ import typing as t import click + from pulp_glue.common.context import ( EntityDefinition, EntityFieldDefinition, @@ -144,7 +145,7 @@ def update( # keep current repository, change version if distribution["repository"]: distribution_ctx.update(body={"repository": ""}, non_blocking=True) - body["repository_version"] = f'{distribution["repository"]}versions/{version}/' + body["repository_version"] = f"{distribution['repository']}versions/{version}/" elif distribution["repository_version"]: # 'dummy' vars are to get us around a mypy/1.2 complaint about '_' repository_href, dummy, dummy = distribution["repository_version"].partition("versions") diff --git a/pulpcore/cli/container/namespace.py b/pulpcore/cli/container/namespace.py index 2caef5658..d1bc50609 100644 --- a/pulpcore/cli/container/namespace.py +++ b/pulpcore/cli/container/namespace.py @@ -1,4 +1,5 @@ import click + from pulp_glue.common.i18n import get_translation from pulp_glue.container.context import PulpContainerNamespaceContext diff --git a/pulpcore/cli/container/remote.py b/pulpcore/cli/container/remote.py index 3c1d1673b..594ab8bc6 100644 --- a/pulpcore/cli/container/remote.py +++ b/pulpcore/cli/container/remote.py @@ -1,4 +1,5 @@ import click + from pulp_glue.common.i18n import get_translation from pulp_glue.container.context import PulpContainerRemoteContext diff --git a/pulpcore/cli/container/repository.py b/pulpcore/cli/container/repository.py index 83d2f08cf..833bd404c 100644 --- a/pulpcore/cli/container/repository.py +++ b/pulpcore/cli/container/repository.py @@ -2,6 +2,7 @@ import typing as t import click + from pulp_glue.common.context import EntityFieldDefinition, PulpRemoteContext, PulpRepositoryContext from pulp_glue.common.i18n import get_translation from pulp_glue.container.context import ( diff --git a/pulpcore/cli/core/access_policy.py b/pulpcore/cli/core/access_policy.py index 54d761cfb..4fd4a4d32 100644 --- a/pulpcore/cli/core/access_policy.py +++ b/pulpcore/cli/core/access_policy.py @@ -1,4 +1,5 @@ import click + from pulp_glue.common.context import PulpEntityContext from pulp_glue.common.i18n import get_translation from pulp_glue.core.context import PulpAccessPolicyContext diff --git a/pulpcore/cli/core/artifact.py b/pulpcore/cli/core/artifact.py index 9ab12ce9b..ebd9d95be 100644 --- a/pulpcore/cli/core/artifact.py +++ b/pulpcore/cli/core/artifact.py @@ -1,6 +1,7 @@ import typing as t import click + from pulp_glue.common.context import PulpEntityContext from pulp_glue.common.i18n import get_translation from pulp_glue.core.context import PulpArtifactContext diff --git a/pulpcore/cli/core/content.py b/pulpcore/cli/core/content.py index cef178c80..a2785d9c9 100644 --- a/pulpcore/cli/core/content.py +++ b/pulpcore/cli/core/content.py @@ -1,4 +1,5 @@ import click + from pulp_glue.common.context import PulpContentContext from pulp_glue.common.i18n import get_translation diff --git a/pulpcore/cli/core/content_guard.py b/pulpcore/cli/core/content_guard.py index b0a2ab5ab..2f68e8eca 100644 --- a/pulpcore/cli/core/content_guard.py +++ b/pulpcore/cli/core/content_guard.py @@ -1,6 +1,7 @@ import typing as t import click + from pulp_glue.certguard.context import PulpRHSMCertGuardContext, PulpX509CertGuardContext from pulp_glue.common.context import PulpContentGuardContext, PulpEntityContext from pulp_glue.common.i18n import get_translation diff --git a/pulpcore/cli/core/distribution.py b/pulpcore/cli/core/distribution.py index 8066696ce..e6a95c2a3 100644 --- a/pulpcore/cli/core/distribution.py +++ b/pulpcore/cli/core/distribution.py @@ -1,4 +1,5 @@ import click + from pulp_glue.common.context import PluginRequirement, PulpDistributionContext from pulp_cli.generic import ( diff --git a/pulpcore/cli/core/domain.py b/pulpcore/cli/core/domain.py index 3316751ec..17d694b03 100644 --- a/pulpcore/cli/core/domain.py +++ b/pulpcore/cli/core/domain.py @@ -1,4 +1,5 @@ import click + from pulp_glue.common.context import PulpContext from pulp_glue.common.i18n import get_translation from pulp_glue.core.context import PulpDomainContext diff --git a/pulpcore/cli/core/export.py b/pulpcore/cli/core/export.py index 394594734..7e0cc75ef 100644 --- a/pulpcore/cli/core/export.py +++ b/pulpcore/cli/core/export.py @@ -2,6 +2,7 @@ import typing as t import click + from pulp_glue.common.context import ( DEFAULT_LIMIT, EntityDefinition, @@ -58,8 +59,7 @@ def _version_list_callback( if context_class is None: raise click.ClickException( _( - "The type '{plugin}:{resource_type}' " - "is not valid for the {option_name} option." + "The type '{plugin}:{resource_type}' is not valid for the {option_name} option." ).format(plugin=plugin, resource_type=resource_type, option_name=param.name) ) repository_ctx: PulpRepositoryContext = context_class( diff --git a/pulpcore/cli/core/exporter.py b/pulpcore/cli/core/exporter.py index 5fb650843..5d579f40b 100644 --- a/pulpcore/cli/core/exporter.py +++ b/pulpcore/cli/core/exporter.py @@ -1,6 +1,7 @@ import typing as t import click + from pulp_glue.common.context import EntityFieldDefinition, PulpRepositoryContext from pulp_glue.common.i18n import get_translation from pulp_glue.core.context import PulpExporterContext diff --git a/pulpcore/cli/core/generic.py b/pulpcore/cli/core/generic.py index dff515176..c833a5501 100644 --- a/pulpcore/cli/core/generic.py +++ b/pulpcore/cli/core/generic.py @@ -2,6 +2,7 @@ import typing as t import click + from pulp_glue.common.context import DATETIME_FORMATS, PluginRequirement, PulpEntityContext from pulp_glue.common.i18n import get_translation from pulp_glue.core.context import PulpTaskContext, PulpWorkerContext diff --git a/pulpcore/cli/core/group.py b/pulpcore/cli/core/group.py index 5e4a71390..aa11d8f1f 100644 --- a/pulpcore/cli/core/group.py +++ b/pulpcore/cli/core/group.py @@ -1,6 +1,7 @@ import typing as t import click + from pulp_glue.common.context import PluginRequirement, PulpEntityContext from pulp_glue.common.i18n import get_translation from pulp_glue.core.context import ( diff --git a/pulpcore/cli/core/importer.py b/pulpcore/cli/core/importer.py index 58be2cba8..59c09e641 100644 --- a/pulpcore/cli/core/importer.py +++ b/pulpcore/cli/core/importer.py @@ -1,6 +1,7 @@ import typing as t import click + from pulp_glue.common.i18n import get_translation from pulp_glue.core.context import PulpImporterContext diff --git a/pulpcore/cli/core/orphan.py b/pulpcore/cli/core/orphan.py index 8cde66f31..1cdd0b0a6 100644 --- a/pulpcore/cli/core/orphan.py +++ b/pulpcore/cli/core/orphan.py @@ -1,6 +1,7 @@ import typing as t import click + from pulp_glue.common.context import PluginRequirement, PulpViewSetContext from pulp_glue.common.i18n import get_translation from pulp_glue.core.context import PulpOrphanContext diff --git a/pulpcore/cli/core/publication.py b/pulpcore/cli/core/publication.py index b735a1c78..1ea923efd 100644 --- a/pulpcore/cli/core/publication.py +++ b/pulpcore/cli/core/publication.py @@ -1,4 +1,5 @@ import click + from pulp_glue.common.context import ( PluginRequirement, PulpPublicationContext, diff --git a/pulpcore/cli/core/remote.py b/pulpcore/cli/core/remote.py index 0e553bc09..d72415764 100644 --- a/pulpcore/cli/core/remote.py +++ b/pulpcore/cli/core/remote.py @@ -1,4 +1,5 @@ import click + from pulp_glue.common.context import PulpRemoteContext from pulp_cli.generic import ( diff --git a/pulpcore/cli/core/repository.py b/pulpcore/cli/core/repository.py index f382119b0..d320e7787 100644 --- a/pulpcore/cli/core/repository.py +++ b/pulpcore/cli/core/repository.py @@ -2,6 +2,7 @@ import typing as t import click + from pulp_glue.common.context import ( EntityDefinition, PulpGenericRepositoryContext, @@ -57,8 +58,7 @@ def _version_list_callback( if context_class is None: raise click.ClickException( _( - "The type '{plugin}:{resource_type}' " - "is not valid for the {option_name} option." + "The type '{plugin}:{resource_type}' is not valid for the {option_name} option." ).format(plugin=plugin, resource_type=resource_type, option_name=param.name) ) repository_ctx: PulpRepositoryContext = context_class( diff --git a/pulpcore/cli/core/role.py b/pulpcore/cli/core/role.py index 08cf3890a..19d885628 100644 --- a/pulpcore/cli/core/role.py +++ b/pulpcore/cli/core/role.py @@ -2,6 +2,7 @@ import typing as t import click + from pulp_glue.core.context import PulpRoleContext from pulp_cli.generic import ( diff --git a/pulpcore/cli/core/show.py b/pulpcore/cli/core/show.py index 944e443e4..43eb34060 100644 --- a/pulpcore/cli/core/show.py +++ b/pulpcore/cli/core/show.py @@ -1,4 +1,5 @@ import click + from pulp_glue.common.i18n import get_translation from pulp_cli.generic import PulpCLIContext, pass_pulp_context, pulp_command diff --git a/pulpcore/cli/core/signing_service.py b/pulpcore/cli/core/signing_service.py index e06a6d39f..a0f503b8d 100644 --- a/pulpcore/cli/core/signing_service.py +++ b/pulpcore/cli/core/signing_service.py @@ -1,4 +1,5 @@ import click + from pulp_glue.common.i18n import get_translation from pulp_glue.core.context import PulpSigningServiceContext diff --git a/pulpcore/cli/core/status.py b/pulpcore/cli/core/status.py index e74388b2f..6415fe6b2 100644 --- a/pulpcore/cli/core/status.py +++ b/pulpcore/cli/core/status.py @@ -1,6 +1,7 @@ import time import click + from pulp_glue.common.i18n import get_translation from pulp_cli.generic import PulpCLIContext, pass_pulp_context, pulp_command diff --git a/pulpcore/cli/core/task.py b/pulpcore/cli/core/task.py index 0a9686d54..50fb900ed 100644 --- a/pulpcore/cli/core/task.py +++ b/pulpcore/cli/core/task.py @@ -6,6 +6,7 @@ import click import requests + from pulp_glue.common.context import DATETIME_FORMATS, PluginRequirement, PulpEntityContext from pulp_glue.common.exceptions import PulpException from pulp_glue.common.i18n import get_translation diff --git a/pulpcore/cli/core/task_group.py b/pulpcore/cli/core/task_group.py index 54a8634dd..79dc73569 100644 --- a/pulpcore/cli/core/task_group.py +++ b/pulpcore/cli/core/task_group.py @@ -1,6 +1,7 @@ import typing as t import click + from pulp_glue.common.context import PulpEntityContext from pulp_glue.common.i18n import get_translation from pulp_glue.core.context import PulpTaskGroupContext diff --git a/pulpcore/cli/core/upload.py b/pulpcore/cli/core/upload.py index 8ba617b58..2f02da144 100644 --- a/pulpcore/cli/core/upload.py +++ b/pulpcore/cli/core/upload.py @@ -1,4 +1,5 @@ import click + from pulp_glue.common.i18n import get_translation from pulp_glue.core.context import PulpUploadContext diff --git a/pulpcore/cli/core/upstream_pulp.py b/pulpcore/cli/core/upstream_pulp.py index 70a80ac96..99e58f11e 100644 --- a/pulpcore/cli/core/upstream_pulp.py +++ b/pulpcore/cli/core/upstream_pulp.py @@ -1,4 +1,5 @@ import click + from pulp_glue.common.context import PluginRequirement, PulpEntityContext from pulp_glue.common.i18n import get_translation from pulp_glue.core.context import PulpUpstreamPulpContext diff --git a/pulpcore/cli/core/user.py b/pulpcore/cli/core/user.py index 36e67e013..57e7323d6 100644 --- a/pulpcore/cli/core/user.py +++ b/pulpcore/cli/core/user.py @@ -1,6 +1,7 @@ import typing as t import click + from pulp_glue.common.context import PluginRequirement, PulpEntityContext from pulp_glue.common.i18n import get_translation from pulp_glue.core.context import PulpDomainContext, PulpUserContext, PulpUserRoleContext diff --git a/pulpcore/cli/core/worker.py b/pulpcore/cli/core/worker.py index 4b2a48645..0cf27332d 100644 --- a/pulpcore/cli/core/worker.py +++ b/pulpcore/cli/core/worker.py @@ -1,4 +1,5 @@ import click + from pulp_glue.common.i18n import get_translation from pulp_glue.core.context import PulpWorkerContext diff --git a/pulpcore/cli/file/__init__.py b/pulpcore/cli/file/__init__.py index 434ce899d..aaa1d02b3 100644 --- a/pulpcore/cli/file/__init__.py +++ b/pulpcore/cli/file/__init__.py @@ -1,6 +1,7 @@ import typing as t import click + from pulp_glue.common.i18n import get_translation from pulp_glue.file.context import PulpFileACSContext, PulpFileRemoteContext diff --git a/pulpcore/cli/file/content.py b/pulpcore/cli/file/content.py index d11e437e6..7dec2bbd8 100644 --- a/pulpcore/cli/file/content.py +++ b/pulpcore/cli/file/content.py @@ -1,6 +1,7 @@ import typing as t import click + from pulp_glue.common.context import PluginRequirement, PulpEntityContext, PulpRepositoryContext from pulp_glue.common.i18n import get_translation from pulp_glue.core.context import PulpArtifactContext diff --git a/pulpcore/cli/file/distribution.py b/pulpcore/cli/file/distribution.py index f624303b0..172edf99e 100644 --- a/pulpcore/cli/file/distribution.py +++ b/pulpcore/cli/file/distribution.py @@ -1,4 +1,5 @@ import click + from pulp_glue.common.context import PluginRequirement from pulp_glue.common.i18n import get_translation from pulp_glue.file.context import ( diff --git a/pulpcore/cli/file/publication.py b/pulpcore/cli/file/publication.py index f3e5c091a..8da90c608 100644 --- a/pulpcore/cli/file/publication.py +++ b/pulpcore/cli/file/publication.py @@ -1,4 +1,5 @@ import click + from pulp_glue.common.context import PluginRequirement from pulp_glue.common.i18n import get_translation from pulp_glue.file.context import ( diff --git a/pulpcore/cli/file/remote.py b/pulpcore/cli/file/remote.py index 8320cbdda..ac771b59d 100644 --- a/pulpcore/cli/file/remote.py +++ b/pulpcore/cli/file/remote.py @@ -1,4 +1,5 @@ import click + from pulp_glue.common.i18n import get_translation from pulp_glue.file.context import PulpFileRemoteContext diff --git a/pulpcore/cli/file/repository.py b/pulpcore/cli/file/repository.py index 3fa65d23c..9996b599f 100644 --- a/pulpcore/cli/file/repository.py +++ b/pulpcore/cli/file/repository.py @@ -2,6 +2,7 @@ import click import schema as s + from pulp_glue.common.context import ( EntityFieldDefinition, PluginRequirement, diff --git a/pulpcore/cli/python/__init__.py b/pulpcore/cli/python/__init__.py index 4a1102a84..c22ed0451 100644 --- a/pulpcore/cli/python/__init__.py +++ b/pulpcore/cli/python/__init__.py @@ -1,6 +1,7 @@ import typing as t import click + from pulp_glue.common.context import PluginRequirement from pulp_cli.generic import PulpCLIContext, pass_pulp_context, pulp_group diff --git a/pulpcore/cli/python/content.py b/pulpcore/cli/python/content.py index dda42625f..0d17816ce 100644 --- a/pulpcore/cli/python/content.py +++ b/pulpcore/cli/python/content.py @@ -1,6 +1,7 @@ import typing as t import click + from pulp_glue.common.context import PluginRequirement, PulpEntityContext from pulp_glue.common.i18n import get_translation from pulp_glue.core.context import PulpArtifactContext diff --git a/pulpcore/cli/python/distribution.py b/pulpcore/cli/python/distribution.py index 3ac6f8c41..39f67fb31 100644 --- a/pulpcore/cli/python/distribution.py +++ b/pulpcore/cli/python/distribution.py @@ -1,4 +1,5 @@ import click + from pulp_glue.common.context import PluginRequirement from pulp_glue.common.i18n import get_translation from pulp_glue.python.context import ( diff --git a/pulpcore/cli/python/publication.py b/pulpcore/cli/python/publication.py index a3196d43d..eedc7dd7b 100644 --- a/pulpcore/cli/python/publication.py +++ b/pulpcore/cli/python/publication.py @@ -1,4 +1,5 @@ import click + from pulp_glue.common.i18n import get_translation from pulp_glue.python.context import PulpPythonPublicationContext, PulpPythonRepositoryContext diff --git a/pulpcore/cli/python/remote.py b/pulpcore/cli/python/remote.py index cb8a9f64f..499fac8fd 100644 --- a/pulpcore/cli/python/remote.py +++ b/pulpcore/cli/python/remote.py @@ -2,6 +2,7 @@ import typing as t import click + from pulp_glue.common.context import PluginRequirement from pulp_glue.common.i18n import get_translation from pulp_glue.python.context import PulpPythonRemoteContext diff --git a/pulpcore/cli/python/repository.py b/pulpcore/cli/python/repository.py index eaf016016..c6bd8f570 100644 --- a/pulpcore/cli/python/repository.py +++ b/pulpcore/cli/python/repository.py @@ -2,6 +2,7 @@ import click import schema as s + from pulp_glue.common.context import ( EntityFieldDefinition, PluginRequirement, diff --git a/pulpcore/cli/rpm/__init__.py b/pulpcore/cli/rpm/__init__.py index 751c6e56b..f81de3994 100644 --- a/pulpcore/cli/rpm/__init__.py +++ b/pulpcore/cli/rpm/__init__.py @@ -1,6 +1,7 @@ import typing as t import click + from pulp_glue.common.i18n import get_translation from pulp_glue.rpm.context import PulpRpmACSContext, PulpRpmRemoteContext, PulpUlnRemoteContext diff --git a/pulpcore/cli/rpm/comps.py b/pulpcore/cli/rpm/comps.py index 215b8e04d..b7472e405 100644 --- a/pulpcore/cli/rpm/comps.py +++ b/pulpcore/cli/rpm/comps.py @@ -2,6 +2,7 @@ import typing as t import click + from pulp_glue.common.context import EntityFieldDefinition, PulpEntityContext from pulp_glue.rpm.context import PulpRpmCompsXmlContext, PulpRpmRepositoryContext diff --git a/pulpcore/cli/rpm/content.py b/pulpcore/cli/rpm/content.py index e2ec59b63..7b941cd5f 100644 --- a/pulpcore/cli/rpm/content.py +++ b/pulpcore/cli/rpm/content.py @@ -3,6 +3,7 @@ from uuid import uuid4 import click + from pulp_glue.common.context import PluginRequirement, PulpContentContext, PulpEntityContext from pulp_glue.common.i18n import get_translation from pulp_glue.core.context import PulpArtifactContext diff --git a/pulpcore/cli/rpm/copy.py b/pulpcore/cli/rpm/copy.py index 6380116fa..f8544bab9 100644 --- a/pulpcore/cli/rpm/copy.py +++ b/pulpcore/cli/rpm/copy.py @@ -2,6 +2,7 @@ import typing as t import click + from pulp_glue.rpm.context import PulpRpmCopyContext from pulp_cli.generic import ( diff --git a/pulpcore/cli/rpm/distribution.py b/pulpcore/cli/rpm/distribution.py index 14be52a11..63cb7c768 100644 --- a/pulpcore/cli/rpm/distribution.py +++ b/pulpcore/cli/rpm/distribution.py @@ -1,4 +1,5 @@ import click + from pulp_glue.common.context import PluginRequirement from pulp_glue.common.i18n import get_translation from pulp_glue.rpm.context import PulpRpmDistributionContext, PulpRpmRepositoryContext diff --git a/pulpcore/cli/rpm/prune.py b/pulpcore/cli/rpm/prune.py index e8bc77085..efc56ed9c 100644 --- a/pulpcore/cli/rpm/prune.py +++ b/pulpcore/cli/rpm/prune.py @@ -2,6 +2,7 @@ import typing as t import click + from pulp_glue.common.exceptions import PulpException from pulp_glue.rpm.context import PulpRpmPruneContext, PulpRpmRepositoryContext diff --git a/pulpcore/cli/rpm/publication.py b/pulpcore/cli/rpm/publication.py index b5cf225b4..95a9ebd9e 100644 --- a/pulpcore/cli/rpm/publication.py +++ b/pulpcore/cli/rpm/publication.py @@ -1,4 +1,5 @@ import click + from pulp_glue.common.context import PluginRequirement from pulp_glue.common.i18n import get_translation from pulp_glue.rpm.context import PulpRpmPublicationContext, PulpRpmRepositoryContext @@ -61,8 +62,7 @@ def publication(ctx: click.Context, pulp_ctx: PulpCLIContext, /, publication_typ "repo_config", needs_plugins=[PluginRequirement("rpm", specifier=">=3.24.0")], help=_( - "A JSON dictionary describing config.repo file (or " - "@file containing a JSON dictionary)" + "A JSON dictionary describing config.repo file (or @file containing a JSON dictionary)" ), callback=load_json_callback, ), diff --git a/pulpcore/cli/rpm/remote.py b/pulpcore/cli/rpm/remote.py index b7c63ae0c..f17d634ae 100644 --- a/pulpcore/cli/rpm/remote.py +++ b/pulpcore/cli/rpm/remote.py @@ -1,4 +1,5 @@ import click + from pulp_glue.common.i18n import get_translation from pulp_glue.rpm.context import PulpRpmRemoteContext, PulpUlnRemoteContext diff --git a/pulpcore/cli/rpm/repository.py b/pulpcore/cli/rpm/repository.py index 29423afcc..8b9ce6cb3 100644 --- a/pulpcore/cli/rpm/repository.py +++ b/pulpcore/cli/rpm/repository.py @@ -2,6 +2,7 @@ import click import schema as s + from pulp_glue.common.context import ( EntityFieldDefinition, PluginRequirement, @@ -212,8 +213,7 @@ def repository(ctx: click.Context, pulp_ctx: PulpCLIContext, /, repo_type: str) "repo_config", needs_plugins=[PluginRequirement("rpm", specifier=">=3.24.0")], help=_( - "A JSON dictionary describing config.repo file (or " - "@file containing a JSON dictionary)" + "A JSON dictionary describing config.repo file (or @file containing a JSON dictionary)" ), callback=load_json_callback, ), diff --git a/pyproject.toml b/pyproject.toml index fc3acb785..29e7ab584 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,7 +56,7 @@ rpm = "pulpcore.cli.rpm" [tool.setuptools.packages.find] # This section is managed by the cookiecutter templates. -where = ["."] +where = ["src"] include = ["pulpcore.cli.*", "pulp_cli", "pytest_pulp_cli"] namespaces = true @@ -69,6 +69,7 @@ namespaces = true # This section is co-managed by the cookiecutter templates. # Changes to existing keys should be preserved. app_label = "" +src_layout = true repository = "https://github.com/pulp/pulp-cli" glue = true docs = true @@ -76,6 +77,7 @@ translations = true main_package = "common" binary_dependencies = "" unittests = true +paralleltests = false [tool.bumpversion] # This section is managed by the cookiecutter templates. @@ -98,19 +100,19 @@ values = [ [[tool.bumpversion.files]] # This section is managed by the cookiecutter templates. -filename = "./pulp_cli/__init__.py" +filename = "./src/pulp_cli/__init__.py" search = "__version__ = \"{current_version}\"" replace = "__version__ = \"{new_version}\"" [[tool.bumpversion.files]] # This section is managed by the cookiecutter templates. -filename = "./pulp-glue/pulp_glue/common/__init__.py" +filename = "./pulp-glue/src/pulp_glue/common/__init__.py" search = "__version__ = \"{current_version}\"" replace = "__version__ = \"{new_version}\"" [[tool.bumpversion.files]] # This section is managed by the cookiecutter templates. -filename = "./pulpcore/cli/common/__init__.py" +filename = "./src/pulpcore/cli/common/__init__.py" search = "__version__ = \"{current_version}\"" replace = "__version__ = \"{new_version}\"" @@ -196,26 +198,6 @@ name = "Misc" showcontent = true -[tool.black] -# This section is managed by the cookiecutter templates. -line-length = 100 -exclude = "cookiecutter" - -[tool.isort] -# This section is managed by the cookiecutter templates. -profile = "black" -line_length = 100 -extend_skip = ["pulp-glue", "cookiecutter"] - -[tool.flake8] -# This section is managed by the cookiecutter templates. -exclude = ["./docs/*", "./cookiecutter/*"] -ignore = ["W503", "Q000", "Q003", "D100", "D104", "D106", "D200", "D202", "D205", "D400", "D401", "D402"] -# E203: whitespace before ':'; https://github.com/psf/black/issues/279 -# E401: multiple imports on one line -extend-ignore = ["E203", "E401"] -max-line-length = 100 - [tool.pytest.ini_options] markers = [ "live: integration tests that run against a live server", @@ -235,9 +217,11 @@ markers = [ strict = true warn_unused_ignores = false show_error_codes = true -files = "pulpcore/**/*.py, tests/*.py, pulp_cli/**/*.py, pytest_pulp_cli/**/*.py" +files = "src/**/*.py, tests/**/*.py" +mypy_path = ["src", "pulp-glue/src"] namespace_packages = true explicit_package_bases = true +plugins = ["pydantic.mypy"] [[tool.mypy.overrides]] # This section is managed by the cookiecutter templates. @@ -248,3 +232,74 @@ module = [ "schema.*", ] ignore_missing_imports = true + + +[tool.uv.sources] +# This section is managed by the cookiecutter templates. +pulp-glue = { workspace = true } +pulp-docs = { git = "https://github.com/pulp/pulp-docs" } + +[tool.uv.workspace] +# This section is managed by the cookiecutter templates. +members = ["pulp-glue"] + +[tool.uv.dependency-groups] +# This section is managed by the cookiecutter templates. +docs = {requires-python = ">=3.11"} + +[tool.uv.build-backend] +# This section is managed by the cookiecutter templates. +module-name = ["pulpcore.cli", "pulp_cli", "pytest_pulp_cli"] +namespace = true +source-exclude = ["*.pot", "*.po", "**/*\\~"] + + +[tool.ruff] +# This section is managed by the cookiecutter templates. +line-length = 100 +extend-exclude = ["cookiecutter/bootstrap", "cookiecutter/ci", "cookiecutter/docs"] + +[tool.ruff.lint] +# This section is managed by the cookiecutter templates. +select = ["E4", "E7", "E9", "F"] +extend-select = ["FURB", "I", "INT", "PTH", "SIM1", "TID", "T10", "UP"] + +[tool.ruff.lint.isort] +# This section is managed by the cookiecutter templates. +sections = { second-party = ["pulp_glue"] } +section-order = ["future", "standard-library", "third-party", "second-party", "first-party", "local-folder"] + +[tool.ruff.lint.flake8-tidy-imports.banned-api] +# This section is managed by the cookiecutter templates. +"distutils".msg = "The 'distutils' module has been deprecated since Python 3.9." +"pulpcore.cli.common.generic".msg = "This module moved to 'pulp_cli.generic'." + + +[dependency-groups] +dev = [ + {include-group = "lint"}, + "pylsp-mypy>=0.7.0", + "pylsp-rope>=0.1.17,<0.1.19", +] +lint = [ + {include-group = "test"}, + "mypy~=1.17.0", + "ruff~=0.16.0", + "shellcheck-py~=0.11.0.1", + "types-pygments", + "types-pyyaml", + "types-requests", + "types-setuptools", + "types-toml", +] +test = [ + "pygments", + "pytest>=7.0.0,<9.3", + "pytest-xdist>=3.8.0,<3.9", + "python-gnupg>=0.5.0,<0.6", + "secretstorage", + "trustme>=1.1.0,<1.3", +] +docs = [ + "pulp-docs", +] diff --git a/pytest_pulp_cli/__init__.py b/pytest_pulp_cli/__init__.py index f802c5d68..197ee0ea1 100644 --- a/pytest_pulp_cli/__init__.py +++ b/pytest_pulp_cli/__init__.py @@ -211,7 +211,6 @@ def pulp_container_log(pulp_container_log_stream: t.IO[bytes]) -> t.Iterator[Non print(logs.decode()) else: - # MyPy complains about an incompatible redefinition. # I don't think this quite applies to the fixtures do dependency injection. @pytest.fixture diff --git a/test_requirements.txt b/test_requirements.txt deleted file mode 100644 index 85e523210..000000000 --- a/test_requirements.txt +++ /dev/null @@ -1,10 +0,0 @@ -# Test requirements -pytest>=7.0.0,<8.5 -pytest-subtests>=0.12.0,<0.15 -python-gnupg>=0.5.0,<0.6 -trustme>=1.1.0,<1.3 -jinja2>=3.1.4,<3.2 - -# No pinning here, because we only switch on optional dependencies here. -pygments -SecretStorage diff --git a/tests/scripts/config.source b/tests/scripts/config.source index 5901cc62e..cfa0a62f8 100644 --- a/tests/scripts/config.source +++ b/tests/scripts/config.source @@ -80,4 +80,28 @@ expect_deny () { fi } +# Expects the provided test to pass +# Supresses all output, which is redirected to ASSERTION_OUTPUT and +# ASSERTION_ERROUTPUT so as not to overwrite the latest OUTPUT and ERROUTPUT. +# That way we can test several assertions in a row. +# Reports verbosely on failure. +assert () { + if { + [[ "$@" ]] + } 1>log.out 2>log.err + then + echo "SUCCESS [$@]" >&3 + ASSERTION_OUTPUT="$(cat log.out)" + ASSERTION_ERROUTPUT="$(cat log.err)" + else + echo "FAILURE [$@]" >&3 + echo "=== STDOUT ===" >&3 + cat log.out >&3 + echo "=== STDERR ===" >&3 + cat log.err >&3 + echo "==============" >&3 + false + fi +} + set -eu