diff --git a/.ci/ansible/filter/repr.py b/.ci/ansible/filter/repr.py index 8455c344..c8c1678d 100644 --- a/.ci/ansible/filter/repr.py +++ b/.ci/ansible/filter/repr.py @@ -1,4 +1,5 @@ from __future__ import absolute_import, division, print_function + from packaging.version import parse as parse_version __metaclass__ = type diff --git a/.ci/scripts/calc_constraints.py b/.ci/scripts/calc_constraints.py index 60121874..e563bd25 100755 --- a/.ci/scripts/calc_constraints.py +++ b/.ci/scripts/calc_constraints.py @@ -7,11 +7,12 @@ import argparse import fileinput -import urllib.request import sys +import urllib.request + +import yaml from packaging.requirements import Requirement from packaging.version import Version -import yaml try: import tomllib diff --git a/.ci/scripts/check_gettext.sh b/.ci/scripts/check_gettext.sh deleted file mode 100755 index 942fe9f8..00000000 --- a/.ci/scripts/check_gettext.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -# WARNING: DO NOT EDIT! -# -# This file was generated by plugin_template, and is managed by it. Please use -# './plugin-template --github pulp_ostree' to update this file. -# -# For more info visit https://github.com/pulp/plugin_template - -# make sure this script runs at the repo root -cd "$(dirname "$(realpath -e "$0")")"/../.. - -set -uv - -MATCHES=$(grep -n -r --include \*.py "_(f") - -if [ $? -ne 1 ]; then - printf "\nERROR: Detected mix of f-strings and gettext:\n" - echo "$MATCHES" - exit 1 -fi diff --git a/.ci/scripts/check_pulpcore_imports.sh b/.ci/scripts/check_pulpcore_imports.sh index f71a5885..b3033e76 100755 --- a/.ci/scripts/check_pulpcore_imports.sh +++ b/.ci/scripts/check_pulpcore_imports.sh @@ -10,10 +10,10 @@ # make sure this script runs at the repo root cd "$(dirname "$(realpath -e "$0")")"/../.. -set -uv +set -u # check for imports not from pulpcore.plugin. exclude tests -MATCHES=$(grep -n -r --include \*.py "from pulpcore.*import" . | grep -v "tests\|plugin") +MATCHES="$(grep -n -r --include \*.py "from pulpcore.*import" pulp_ostree | grep -v "tests\|plugin")" if [ $? -ne 1 ]; then printf "\nERROR: Detected bad imports from pulpcore:\n" diff --git a/.ci/scripts/check_release.py b/.ci/scripts/check_release.py index 6e079995..0825480e 100755 --- a/.ci/scripts/check_release.py +++ b/.ci/scripts/check_release.py @@ -9,16 +9,16 @@ # /// import argparse -import re import os +import re import sys import tomllib import typing as t from pathlib import Path import yaml -from packaging.version import Version from git import Repo +from packaging.version import Version RELEASE_BRANCH_REGEX = r"^([0-9]+)\.([0-9]+)$" Y_CHANGELOG_EXTS = [".feature"] @@ -157,9 +157,9 @@ def main(options: argparse.Namespace, template_config: dict[str, t.Any]) -> int: if reasons: curr_version = Version(last_tag) - assert curr_version.base_version.startswith( - branch - ), "Current-version has to belong to the current branch!" + assert curr_version.base_version.startswith(branch), ( + "Current-version has to belong to the current branch!" + ) next_version = Version(f"{branch}.{curr_version.micro + 1}") print( f"A Z-release is needed for {branch}, " diff --git a/.ci/scripts/check_requirements.py b/.ci/scripts/check_requirements.py index d3da988b..f663f929 100755 --- a/.ci/scripts/check_requirements.py +++ b/.ci/scripts/check_requirements.py @@ -7,12 +7,12 @@ import tomllib import warnings + from packaging.requirements import Requirement CHECK_MATRIX = [ ("pyproject.toml", True, True, True), ("requirements.txt", True, True, True), - ("dev_requirements.txt", False, True, False), ("ci_requirements.txt", False, True, True), ("doc_requirements.txt", False, True, False), ("lint_requirements.txt", False, True, True), diff --git a/.ci/scripts/schema.py b/.ci/scripts/schema.py index 91191c5e..9c8e11b2 100644 --- a/.ci/scripts/schema.py +++ b/.ci/scripts/schema.py @@ -9,6 +9,7 @@ """ import json + from drf_spectacular.validation import JSON_SCHEMA_SPEC_PATH with open(JSON_SCHEMA_SPEC_PATH) as fh: diff --git a/.ci/scripts/skip_tests.py b/.ci/scripts/skip_tests.py index a68d000d..380a3da9 100755 --- a/.ci/scripts/skip_tests.py +++ b/.ci/scripts/skip_tests.py @@ -15,12 +15,13 @@ *: Error """ -import sys +import argparse import os import re -import git +import sys import textwrap -import argparse + +import git DOC_PATTERNS = [ r"^docs/", diff --git a/.ci/scripts/update_github.py b/.ci/scripts/update_github.py index 05356825..14688c09 100755 --- a/.ci/scripts/update_github.py +++ b/.ci/scripts/update_github.py @@ -6,6 +6,7 @@ # For more info visit https://github.com/pulp/plugin_template import os + from github import Github g = Github(os.environ.get("GITHUB_TOKEN")) diff --git a/.ci/scripts/validate_commit_message.py b/.ci/scripts/validate_commit_message.py index a4dc9004..2aab9085 100644 --- a/.ci/scripts/validate_commit_message.py +++ b/.ci/scripts/validate_commit_message.py @@ -6,9 +6,9 @@ import subprocess import sys import tomllib -import yaml from pathlib import Path +import yaml from github import Github diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 7aa433eb..00000000 --- a/.flake8 +++ /dev/null @@ -1,34 +0,0 @@ -# WARNING: DO NOT EDIT! -# -# This file was generated by plugin_template, and is managed by it. Please use -# './plugin-template --github pulp_ostree' to update this file. -# -# For more info visit https://github.com/pulp/plugin_template -[flake8] -exclude = ./docs/*,*/migrations/* -per-file-ignores = */__init__.py: F401 - -ignore = E203,W503,Q000,Q003,D100,D104,D106,D200,D205,D400,D401,D402,F824 -max-line-length = 100 - -# Flake8 builtin codes -# -------------------- -# E203: no whitespace around ':'. disabled until https://github.com/PyCQA/pycodestyle/issues/373 is fixed -# W503: This enforces operators before line breaks which is not pep8 or black compatible. -# F824: 'nonlocal' is unused: name is never assigned in scope - -# Flake8-quotes extension codes -# ----------------------------- -# Q000: double or single quotes only, default is double (don't want to enforce this) -# Q003: Change outer quotes to avoid escaping inner quotes - -# Flake8-docstring extension codes -# -------------------------------- -# D100: missing docstring in public module -# D104: missing docstring in public package -# D106: missing docstring in public nested class (complains about "class Meta:" and documenting those is silly) -# D200: one-line docstring should fit on one line with quotes -# D205: 1 blank line required between summary line and description -# D400: First line should end with a period -# D401: first line should be imperative (nitpicky) -# D402: first line should not be the function’s “signature” (false positives) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index bc12d14e..326457fe 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -36,20 +36,13 @@ jobs: run: | yamllint -s -d '{extends: relaxed, rules: {line-length: disable}}' .github/workflows - # run black separately from flake8 to get a diff - - name: "Run black" + - name: "Check formating" run: | - black --version - black --check --diff . + ruff format --check --diff - # Lint code. - - name: "Run flake8" + - name: "Lint code" run: | - flake8 - - - name: "Check for common gettext problems" - run: | - sh .ci/scripts/check_gettext.sh + ruff check - name: "Run extra lint checks" run: | diff --git a/.github/workflows/scripts/stage-changelog-for-default-branch.py b/.github/workflows/scripts/stage-changelog-for-default-branch.py index 61d8c526..ac416252 100755 --- a/.github/workflows/scripts/stage-changelog-for-default-branch.py +++ b/.github/workflows/scripts/stage-changelog-for-default-branch.py @@ -12,13 +12,15 @@ from git import Repo from git.exc import GitCommandError -helper = textwrap.dedent("""\ +helper = textwrap.dedent( + """\ Stage the changelog for a release on main branch. Example: $ python .github/workflows/scripts/stage-changelog-for-default-branch.py 3.4.0 - """) + """ +) parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter, description=helper) diff --git a/.github/workflows/scripts/update_backport_labels.py b/.github/workflows/scripts/update_backport_labels.py index 1118eb5f..2c682da5 100755 --- a/.github/workflows/scripts/update_backport_labels.py +++ b/.github/workflows/scripts/update_backport_labels.py @@ -5,10 +5,11 @@ # # For more info visit https://github.com/pulp/plugin_template +import os +import random + import requests import yaml -import random -import os def random_color(): diff --git a/dev_requirements.txt b/dev_requirements.txt deleted file mode 100644 index e66e9fb7..00000000 --- a/dev_requirements.txt +++ /dev/null @@ -1,11 +0,0 @@ -check-manifest -coverage -flake8 - -flake8-black - - -flake8-docstrings - -flake8-tuple -flake8-quotes diff --git a/lint_requirements.txt b/lint_requirements.txt index 2dbc9c7d..54374841 100644 --- a/lint_requirements.txt +++ b/lint_requirements.txt @@ -5,10 +5,8 @@ # # For more info visit https://github.com/pulp/plugin_template -black~=26.3 # Pin style to the year. https://black.readthedocs.io/en/stable/faq.html#how-stable-is-black-s-style bump-my-version check-manifest -flake8 -flake8-black packaging +ruff yamllint diff --git a/pulp_ostree/app/models.py b/pulp_ostree/app/models.py index e28222c5..4b556a2c 100755 --- a/pulp_ostree/app/models.py +++ b/pulp_ostree/app/models.py @@ -1,17 +1,16 @@ from logging import getLogger -from django.db import models from django.contrib.postgres.fields import ArrayField +from django.db import models from pulpcore.plugin.models import ( AutoAddObjPermsMixin, Content, + Distribution, Remote, Repository, - Distribution, ) from pulpcore.plugin.repo_version_utils import remove_duplicates, validate_duplicate_content - from pulpcore.plugin.util import get_domain_pk logger = getLogger(__name__) diff --git a/pulp_ostree/app/serializers.py b/pulp_ostree/app/serializers.py index 847d8a90..bbacbbe0 100755 --- a/pulp_ostree/app/serializers.py +++ b/pulp_ostree/app/serializers.py @@ -1,5 +1,4 @@ import tarfile - from gettext import gettext as _ from rest_framework import serializers diff --git a/pulp_ostree/app/tasks/importing.py b/pulp_ostree/app/tasks/importing.py index 2360710f..1c247d1f 100644 --- a/pulp_ostree/app/tasks/importing.py +++ b/pulp_ostree/app/tasks/importing.py @@ -1,11 +1,12 @@ import os import tarfile - from gettext import gettext +import gi from asgiref.sync import sync_to_async -from pulpcore.plugin.models import Artifact, Repository, ProgressReport +from pulpcore.plugin.models import Artifact, ProgressReport, Repository +from pulpcore.plugin.serializers import RepositoryVersionSerializer from pulpcore.plugin.stages import ( ArtifactSaver, ContentSaver, @@ -15,23 +16,20 @@ Stage, ) from pulpcore.plugin.sync import sync_to_async_iterable -from pulpcore.plugin.serializers import RepositoryVersionSerializer from pulp_ostree.app.models import ( OstreeCommit, - OstreeRef, OstreeConfig, OstreeObject, OstreeObjectType, + OstreeRef, OstreeSummary, ) +from pulp_ostree.app.tasks.stages import DeclarativeContentCreatorMixin, OstreeAssociateContent from pulp_ostree.app.tasks.utils import copy_to_local_storage, get_checksum_filepath -from pulp_ostree.app.tasks.stages import OstreeAssociateContent, DeclarativeContentCreatorMixin - -import gi gi.require_version("OSTree", "1.0") -from gi.repository import Gio, GLib, OSTree # noqa: E402: module level not at top of file +from gi.repository import Gio, GLib, OSTree # noqa: E402 def import_all_refs_and_commits(artifact_pk, repository_pk, repository_name): diff --git a/pulp_ostree/app/tasks/modifying.py b/pulp_ostree/app/tasks/modifying.py index 60f12acf..de17e3dc 100644 --- a/pulp_ostree/app/tasks/modifying.py +++ b/pulp_ostree/app/tasks/modifying.py @@ -2,7 +2,7 @@ from django.db.models import Q -from pulpcore.plugin.models import Repository, RepositoryVersion, Content +from pulpcore.plugin.models import Content, Repository, RepositoryVersion from pulpcore.plugin.util import get_domain from pulp_ostree.app.models import ( diff --git a/pulp_ostree/app/tasks/stages.py b/pulp_ostree/app/tasks/stages.py index 676e2190..893ab237 100644 --- a/pulp_ostree/app/tasks/stages.py +++ b/pulp_ostree/app/tasks/stages.py @@ -2,6 +2,7 @@ import shutil import tempfile +import gi from asgiref.sync import sync_to_async from pulpcore.plugin.models import Artifact @@ -13,17 +14,15 @@ from pulp_ostree.app.models import ( OstreeCommit, + OstreeCommitObject, OstreeContent, OstreeObject, OstreeRef, - OstreeCommitObject, ) from pulp_ostree.app.tasks.utils import compute_hash, get_checksum_filepath -import gi - gi.require_version("OSTree", "1.0") -from gi.repository import GLib, OSTree # noqa: E402: module level not at top of file +from gi.repository import GLib, OSTree # noqa: E402 class DeclarativeContentCreatorMixin: diff --git a/pulp_ostree/app/tasks/synchronizing.py b/pulp_ostree/app/tasks/synchronizing.py index c2f14c23..21c5e52d 100755 --- a/pulp_ostree/app/tasks/synchronizing.py +++ b/pulp_ostree/app/tasks/synchronizing.py @@ -1,41 +1,40 @@ -import os import logging - +import os from fnmatch import fnmatch from gettext import gettext as _ from pathlib import Path from urllib.parse import urljoin -from pulpcore.plugin.models import Repository, ProgressReport, Artifact, Remote +import gi + +from pulpcore.plugin.models import Artifact, ProgressReport, Remote, Repository +from pulpcore.plugin.serializers import RepositoryVersionSerializer from pulpcore.plugin.stages import ( - ArtifactSaver, ArtifactDownloader, + ArtifactSaver, ContentSaver, - DeclarativeVersion, DeclarativeArtifact, DeclarativeContent, + DeclarativeVersion, QueryExistingArtifacts, QueryExistingContents, RemoteArtifactSaver, ResolveContentFutures, Stage, ) -from pulpcore.plugin.serializers import RepositoryVersionSerializer from pulp_ostree.app.models import ( - OstreeRemote, - OstreeObjectType, OstreeCommit, OstreeConfig, + OstreeObjectType, + OstreeRemote, OstreeSummary, ) -from pulp_ostree.app.tasks.stages import OstreeAssociateContent, DeclarativeContentCreatorMixin -from pulp_ostree.app.tasks.utils import get_checksum_filepath, bytes_to_checksum - -import gi +from pulp_ostree.app.tasks.stages import DeclarativeContentCreatorMixin, OstreeAssociateContent +from pulp_ostree.app.tasks.utils import bytes_to_checksum, get_checksum_filepath gi.require_version("OSTree", "1.0") -from gi.repository import Gio, GLib, OSTree # noqa: E402: module level not at top of file +from gi.repository import Gio, GLib, OSTree # noqa: E402 log = logging.getLogger(__name__) diff --git a/pulp_ostree/app/viewsets.py b/pulp_ostree/app/viewsets.py index 5cc3e425..6f5e814a 100755 --- a/pulp_ostree/app/viewsets.py +++ b/pulp_ostree/app/viewsets.py @@ -5,15 +5,9 @@ from rest_framework.decorators import action from rest_framework.serializers import ValidationError -from pulpcore.plugin.viewsets import ( - ReadOnlyContentViewSet, - ContentFilter, - NAME_FILTER_OPTIONS, - SingleArtifactContentUploadViewSet, -) from pulpcore.plugin import viewsets as core -from pulpcore.plugin.models import RepositoryVersion from pulpcore.plugin.actions import ModifyRepositoryActionMixin +from pulpcore.plugin.models import RepositoryVersion from pulpcore.plugin.serializers import ( AsyncOperationResponseSerializer, RepositoryAddRemoveContentSerializer, @@ -21,6 +15,12 @@ ) from pulpcore.plugin.tasking import dispatch from pulpcore.plugin.util import get_objects_for_user +from pulpcore.plugin.viewsets import ( + NAME_FILTER_OPTIONS, + ContentFilter, + ReadOnlyContentViewSet, + SingleArtifactContentUploadViewSet, +) from . import models, serializers, tasks diff --git a/pulp_ostree/tests/functional/api/test_import.py b/pulp_ostree/tests/functional/api/test_import.py index c92f8c14..e5f696d5 100644 --- a/pulp_ostree/tests/functional/api/test_import.py +++ b/pulp_ostree/tests/functional/api/test_import.py @@ -1,13 +1,13 @@ -import pytest -import requests import os import shutil import subprocess import uuid +from urllib.parse import urljoin -from requests.exceptions import HTTPError +import pytest +import requests from requests.auth import HTTPBasicAuth -from urllib.parse import urljoin +from requests.exceptions import HTTPError from pulpcore.client.pulp_ostree import ( OstreeImportAll, diff --git a/pulp_ostree/tests/functional/conftest.py b/pulp_ostree/tests/functional/conftest.py index ae2754c3..217d5da4 100644 --- a/pulp_ostree/tests/functional/conftest.py +++ b/pulp_ostree/tests/functional/conftest.py @@ -1,7 +1,7 @@ -import pytest import uuid -from pulp_ostree.tests.functional.constants import OSTREE_FIXTURE_URL +import pytest + from pulpcore.client.pulp_ostree import ( ApiClient, ContentCommitsApi, @@ -10,11 +10,13 @@ ContentRefsApi, ContentSummariesApi, DistributionsOstreeApi, - RepositoriesOstreeApi, RemotesOstreeApi, + RepositoriesOstreeApi, RepositoriesOstreeVersionsApi, ) +from pulp_ostree.tests.functional.constants import OSTREE_FIXTURE_URL + # Api Bindings fixtures diff --git a/pulp_ostree/tests/functional/constants.py b/pulp_ostree/tests/functional/constants.py index fc204ed9..128ff2e2 100755 --- a/pulp_ostree/tests/functional/constants.py +++ b/pulp_ostree/tests/functional/constants.py @@ -4,10 +4,10 @@ from pulp_smash.constants import PULP_FIXTURES_BASE_URL from pulp_smash.pulp3.constants import ( + BASE_CONTENT_PATH, BASE_DISTRIBUTION_PATH, BASE_REMOTE_PATH, BASE_REPO_PATH, - BASE_CONTENT_PATH, ) OSTREE_COMMITS_NAME = "ostree.commit" diff --git a/pulp_ostree/tests/functional/utils.py b/pulp_ostree/tests/functional/utils.py index 28c5f0bb..7cdb66cf 100755 --- a/pulp_ostree/tests/functional/utils.py +++ b/pulp_ostree/tests/functional/utils.py @@ -1,26 +1,27 @@ """Utilities for tests for the ostree plugin.""" import subprocess - from functools import partial from unittest import SkipTest from pulp_smash import config, selectors -from pulp_smash.utils import uuid4 from pulp_smash.pulp3.utils import ( gen_remote, require_pulp_3, require_pulp_plugins, ) +from pulp_smash.utils import uuid4 -from pulp_ostree.tests.functional.constants import OSTREE_FIXTURE_URL - +from pulpcore.client.pulp_ostree import ApiClient as OstreeApiClient from pulpcore.client.pulpcore import ( ApiClient as CoreApiClient, +) +from pulpcore.client.pulpcore import ( ArtifactsApi, TasksApi, ) -from pulpcore.client.pulp_ostree import ApiClient as OstreeApiClient + +from pulp_ostree.tests.functional.constants import OSTREE_FIXTURE_URL cfg = config.get_config() configuration = cfg.get_bindings_config() diff --git a/pyproject.toml b/pyproject.toml index e39c9daf..238b7aec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -168,3 +168,30 @@ replace = "version = \"{new_version}\"" filename = "./pyproject.toml" search = "version = \"{current_version}\"" replace = "version = \"{new_version}\"" + + +[tool.ruff] +# This section is managed by the plugin template. Do not edit manually. +line-length = 100 +extend-exclude = [ + "docs/**", + "**/migrations/*.py", +] + +[tool.ruff.lint] +# This section is managed by the plugin template. Do not edit manually. +extend-select = [ + "I", + "INT", + "TID", + "T10", +] + +[tool.ruff.lint.flake8-tidy-imports.banned-api] +# This section is managed by the plugin template. Do not edit manually. +"pulpcore.app".msg = "The 'pulpcore' apis must only be consumed via 'pulpcore.plugin'." + +[tool.ruff.lint.isort] +# This section is managed by the plugin template. Do not edit manually. +sections = { second-party = ["pulpcore"] } +section-order = ["future", "standard-library", "third-party", "second-party", "first-party", "local-folder"] diff --git a/template_config.yml b/template_config.yml index 4208f5df..1af1505e 100644 --- a/template_config.yml +++ b/template_config.yml @@ -6,9 +6,7 @@ # After editing this file please always reapply the plugin template before committing any changes. --- -black: true check_commit_message: true -check_gettext: true check_manifest: true check_stray_pulpcore_imports: true ci_base_image: "ghcr.io/pulp/pulp-ci-centos9" @@ -23,10 +21,9 @@ deploy_to_pypi: true disabled_redis_runners: [] docker_fixtures: false extra_files: [] -flake8: true -flake8_ignore: [] github_org: "pulp" latest_release_branch: "2.6" +lint_ignore: [] lint_requirements: true os_required_packages: - "libgirepository1.0-dev" @@ -80,7 +77,6 @@ pulp_settings_s3: BACKEND: "django.contrib.staticfiles.storage.StaticFilesStorage" api_root: "/rerouted/djnd/" domain_enabled: true -pydocstyle: true release_email: "pulp-infra@redhat.com" release_user: "pulpbot" stalebot: true