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 2467505a3..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@v4" - - 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 c447319f8..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@v4" + - 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 598704053..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@v4" + - 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 32d27a908..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@v4" + - uses: "actions/checkout@v6" with: repository: "pulp/pulp-cli" - path: "pulp-cli" - - uses: "actions/checkout@v4" + 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 11a84e3f7..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@v4" - - 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@v4" + - 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 b0ed6acc2..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,40 +9,48 @@ 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: - "lint" # Keep the workflow tag the same as pulpdocs_ref. - uses: "pulp/pulp-docs/.github/workflows/docs-ci.yml@rewrite-as-mkdocs-plugin" + uses: "pulp/pulp-docs/.github/workflows/docs-ci.yml@main" with: - pulpdocs_ref: "rewrite-as-mkdocs-plugin" + pulpdocs_ref: "main" 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@v4" + - 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 bdb93d434..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@v4" + - 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 98504944c..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@v4" - name: "Download wheels" - uses: "actions/download-artifact@v4" + 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 aa7b131cf..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@v4" + - 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 718362ba1..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@v4" + - 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 7cc84993c..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@v4" - - 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@v4" + 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@v4" - - 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@v4" + 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/lint_requirements.txt b/lint_requirements.txt deleted file mode 100644 index a4f9cd3cb..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.10.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/pyproject.toml b/pulp-glue/pyproject.toml index 54e386f84..f59d00fe9 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/pyproject.toml b/pyproject.toml index 24d9399fc..c4c34c611 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~=2.4.0", + "ruff~=0.16.0", + "shellcheck-py~=0.11.0.1", + "types-pygments", + "types-pyyaml", + "types-requests", + "types-setuptools", + "types-toml", +] +test = [ + "pygments>=2.19.2", + "pytest>=7.0.0,<9.3", + "pytest-xdist>=3.8.0,<3.9", + "python-gnupg>=0.5.0,<0.6", + "secretstorage>=3.5.0", + "trustme>=1.1.0,<1.3", +] +docs = [ + "pulp-docs", +] 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