From 9e1b9cf610b27c6b9d905af81598444d705e9f61 Mon Sep 17 00:00:00 2001 From: Jiri Popelka Date: Tue, 14 Nov 2023 09:14:33 +0100 Subject: [PATCH] Use ruff-format instead of black https://docs.astral.sh/ruff/formatter Use default line length, i.e. 89 chars. --- .pre-commit-config.yaml | 19 +++++------- docs/conf.py | 6 ++-- docs/rpmdeplint.rst | 13 ++++----- pyproject.toml | 4 ++- rpmdeplint/analyzer.py | 23 +++++++++------ rpmdeplint/cli.py | 3 +- tests/acceptance/test_check.py | 21 +++++++------ tests/acceptance/test_check_conflicts.py | 34 ++++++++++++---------- tests/acceptance/test_check_repoclosure.py | 4 +-- tests/acceptance/test_check_sat.py | 2 +- 10 files changed, 70 insertions(+), 59 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0630a06..a3e4b9f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,21 +3,14 @@ # pre-commit install -t pre-commit -t pre-push repos: - - repo: https://github.com/psf/black - rev: 23.9.1 - hooks: - - id: black - - repo: https://github.com/pre-commit/mirrors-prettier - rev: v3.0.3 - hooks: - - id: prettier - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.291 + rev: v0.1.5 hooks: + - id: ruff-format - id: ruff args: [--fix, --exit-non-zero-on-fix] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-added-large-files - id: check-ast @@ -29,11 +22,15 @@ repos: - id: mixed-line-ending - id: trailing-whitespace - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.5.1 + rev: v1.7.0 hooks: - id: mypy additional_dependencies: [types-requests, types-six] exclude: docs/conf.py + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v3.1.0 + hooks: + - id: prettier - repo: https://github.com/packit/pre-commit-hooks rev: v1.2.0 hooks: diff --git a/docs/conf.py b/docs/conf.py index 10391dd..d0dda66 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -9,8 +9,8 @@ copyright = "2016, Red Hat" author = "rpmdeplint contributors" -version = "1.0" -release = "1.0" +version = "2.0" +release = "2.0" language = None @@ -47,7 +47,7 @@ ( "rpmdeplint", "rpmdeplint", - "a tool to find errors in RPM packages in the context of their dependency graph", + "a tool to find errors in RPM packages in the context of their dependency graph", # noqa: E501 [author], 1, ) diff --git a/docs/rpmdeplint.rst b/docs/rpmdeplint.rst index bd13bcf..f776b66 100644 --- a/docs/rpmdeplint.rst +++ b/docs/rpmdeplint.rst @@ -11,8 +11,8 @@ Synopsis Description ~~~~~~~~~~~ -The :program:`rpmdeplint` command will test dependency satisfiability of given -RPM packages against given repositories. +The :program:`rpmdeplint` command tests the dependency satisfiability of +specified RPM packages against given repositories. Options ~~~~~~~ @@ -22,13 +22,13 @@ Options Load yum repository specified by name or by URL/path. If the repo is already configured in :file:`/etc/yum.repos.d/{*}.repo` - you can just specify its name, like:: + simply specify its name like:: --repo=fedora - Otherwise, specify a name and the baseurl or metalink. The NAME is for + Otherwise, specify a name and the base URL or metalink. The NAME is for descriptive purposes only in this case. It has no impact on dependency - resolution. If rpmdeplint finds a dependency problem relating to a package + resolution. If rpmdeplint identifies a dependency issue relating to a package in this repo, the NAME will appear in the error message. Examples:: --repo=fedora,https://download.fedoraproject.org/pub/fedora/linux/development/rawhide/Everything/x86_64/os/ @@ -99,8 +99,7 @@ check-repoclosure check-conflicts Checks for undeclared file conflicts in the given RPM packages: that is, when - one of the given package contains a file which is also contained in some - other package. + a given package contains a file also contained in another package. This command will not report a file as conflicting between two packages if: diff --git a/pyproject.toml b/pyproject.toml index aed6c23..408d892 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -77,5 +77,7 @@ select = [ ignore = [ "SIM115", # open-file-with-context-handler ] -line-length = 100 target-version = "py39" + +[tool.mypy] +python_version = "3.9" diff --git a/rpmdeplint/analyzer.py b/rpmdeplint/analyzer.py index 9348d0d..b8c59ab 100644 --- a/rpmdeplint/analyzer.py +++ b/rpmdeplint/analyzer.py @@ -111,7 +111,8 @@ def packages_with_problems(self) -> list[str]: @property def package_dependencies(self) -> dict[str, dict[str, list]]: """ - Dict in the form {package: {'dependencies': list of packages, 'problems': list of problems}} + Dict in the form {package: {'dependencies': list of packages, + 'problems': list of problems}} """ return dict(self._packagedeps) @@ -141,7 +142,8 @@ def __init__( self.pool = Pool() self.pool.setarch(arch) - #: List of :py:class:`solv.Solvable` to be tested (corresponding to *packages* parameter) + # List of :py:class:`solv.Solvable` to be tested + # (corresponding to *packages* parameter) self.solvables: list[XSolvable] = [] self.commandline_repo = self.pool.add_repo("@commandline") for rpmpath in packages: @@ -153,9 +155,8 @@ def __init__( ) self.solvables.append(solvable) - self.repos_by_name = ( - {} - ) #: Mapping of {repo name: :py:class:`rpmdeplint.repodata.Repo`} + # Mapping of {repo name: :py:class:`rpmdeplint.repodata.Repo`} + self.repos_by_name = {} for repo in repos: try: repo.download_repodata() @@ -236,7 +237,8 @@ def _select_obsoleted_by(self, solvables: Iterable[XSolvable]) -> Selection: sel = self.pool.Selection() for solvable in solvables: # Select every solvable with the same name and lower EVR. - # XXX are there some special cases with arch-noarch upgrades which this does not handle? + # XXX are there some special cases with arch-noarch upgrades + # which this does not handle? sel.add( self.pool.select( f"{solvable.name}.{solvable.arch} < {solvable.evr}", @@ -268,7 +270,8 @@ def find_repoclosure_problems(self) -> list[str]: solver = self.pool.Solver() # This selection matches packages obsoleted by our packages under test. obs_sel = self._select_obsoleted_by(self.solvables) - # This selection matches packages obsoleted by other existing packages in the repo. + # This selection matches packages obsoleted + # by other existing packages in the repo. existing_obs_sel = self._select_obsoleted_by( s for s in self.pool.solvables if s.repo.name != "@commandline" ) @@ -491,11 +494,13 @@ def find_upgrade_problems(self) -> list[str]: continue # it's kept, so no problem here if action == transaction.SOLVER_TRANSACTION_UPGRADED: problems.append( - f"{solvable} would be upgraded by {other} from repo {other.repo.name}" + f"{solvable} would be upgraded by {other} " + f"from repo {other.repo.name}" ) elif action == transaction.SOLVER_TRANSACTION_OBSOLETED: problems.append( - f"{solvable} would be obsoleted by {other} from repo {other.repo.name}" + f"{solvable} would be obsoleted by {other} " + f"from repo {other.repo.name}" ) else: raise RuntimeError(f"Unrecognised transaction step type {action}") diff --git a/rpmdeplint/cli.py b/rpmdeplint/cli.py index a1b474d..565843c 100644 --- a/rpmdeplint/cli.py +++ b/rpmdeplint/cli.py @@ -168,7 +168,8 @@ def add_common_dependency_analyzer_args(parser): action="append", dest="repos", default=[], - help="Name and optional (baseurl or metalink or local path) of a repo to test against", + help="Name and optional (baseurl or metalink or local path) " + "of a repo to test against", ) parser.add_argument( "-R", diff --git a/tests/acceptance/test_check.py b/tests/acceptance/test_check.py index a702bae..64c289f 100644 --- a/tests/acceptance/test_check.py +++ b/tests/acceptance/test_check.py @@ -70,15 +70,18 @@ def cleanUp(): + [p.get_built_rpm("i386") for p in test_packages] ) assert exitcode == 3 - assert err == ( - "Problems with dependency set:\n" - "nothing provides doesnotexist needed by e-1.0-1.i386\n" - "Dependency problems with repos:\n" - "package d-0.1-1.i386 requires libfoo.so.4, but none of the providers can be installed\n" - "Undeclared file conflicts:\n" - "f-0.1-1.i386 provides /usr/share/thing which is also provided by b-0.1-1.i386\n" - "Upgrade problems:\n" - "a-4.0-1.i386 would be upgraded by a-5.0-1.i386 from repo base\n" + assert ( + err + == ( + "Problems with dependency set:\n" + "nothing provides doesnotexist needed by e-1.0-1.i386\n" + "Dependency problems with repos:\n" + "package d-0.1-1.i386 requires libfoo.so.4, but none of the providers can be installed\n" # noqa: E501 + "Undeclared file conflicts:\n" + "f-0.1-1.i386 provides /usr/share/thing which is also provided by b-0.1-1.i386\n" # noqa: E501 + "Upgrade problems:\n" + "a-4.0-1.i386 would be upgraded by a-5.0-1.i386 from repo base\n" + ) ) diff --git a/tests/acceptance/test_check_conflicts.py b/tests/acceptance/test_check_conflicts.py index 0dba02e..cc52262 100644 --- a/tests/acceptance/test_check_conflicts.py +++ b/tests/acceptance/test_check_conflicts.py @@ -49,7 +49,7 @@ def cleanUp(): assert exitcode == 3 assert err == ( "Undeclared file conflicts:\n" - "a-0.1-1.i386 provides /usr/share/thing which is also provided by b-0.1-1.i386\n" + "a-0.1-1.i386 provides /usr/share/thing which is also provided by b-0.1-1.i386\n" # noqa: E501 ) @@ -87,7 +87,7 @@ def cleanUp(): assert exitcode == 3 assert err == ( "Undeclared file conflicts:\n" - "a-0.1-1.i386 provides /usr/share/thing which is also provided by b-0.1-1.i386\n" + "a-0.1-1.i386 provides /usr/share/thing which is also provided by b-0.1-1.i386\n" # noqa: E501 ) @@ -258,17 +258,20 @@ def cleanUp(): ] ) assert exitcode == 3 - assert err == ( - "Undeclared file conflicts:\n" - "x-0.1-1.i386 provides /usr/share/thing which is also provided by b-0.1-1.i386\n" - "x-0.1-1.i386 provides /usr/share/thing which is also provided by y-0.1-1.i386\n" - "x-0.1-1.i386 provides /usr/share/thing which is also provided by z-0.1-1.i386\n" - "y-0.1-1.i386 provides /usr/share/thing which is also provided by b-0.1-1.i386\n" - "y-0.1-1.i386 provides /usr/share/thing which is also provided by x-0.1-1.i386\n" - "y-0.1-1.i386 provides /usr/share/thing which is also provided by z-0.1-1.i386\n" - "z-0.1-1.i386 provides /usr/share/thing which is also provided by b-0.1-1.i386\n" - "z-0.1-1.i386 provides /usr/share/thing which is also provided by x-0.1-1.i386\n" - "z-0.1-1.i386 provides /usr/share/thing which is also provided by y-0.1-1.i386\n" + assert ( + err + == ( + "Undeclared file conflicts:\n" + "x-0.1-1.i386 provides /usr/share/thing which is also provided by b-0.1-1.i386\n" # noqa: E501 + "x-0.1-1.i386 provides /usr/share/thing which is also provided by y-0.1-1.i386\n" # noqa: E501 + "x-0.1-1.i386 provides /usr/share/thing which is also provided by z-0.1-1.i386\n" # noqa: E501 + "y-0.1-1.i386 provides /usr/share/thing which is also provided by b-0.1-1.i386\n" # noqa: E501 + "y-0.1-1.i386 provides /usr/share/thing which is also provided by x-0.1-1.i386\n" # noqa: E501 + "y-0.1-1.i386 provides /usr/share/thing which is also provided by z-0.1-1.i386\n" # noqa: E501 + "z-0.1-1.i386 provides /usr/share/thing which is also provided by b-0.1-1.i386\n" # noqa: E501 + "z-0.1-1.i386 provides /usr/share/thing which is also provided by x-0.1-1.i386\n" # noqa: E501 + "z-0.1-1.i386 provides /usr/share/thing which is also provided by y-0.1-1.i386\n" # noqa: E501 + ) ) @@ -343,7 +346,7 @@ def cleanUp(): assert exitcode == 3 assert err == ( "Undeclared file conflicts:\n" - "b-0.1-1.i386 provides /usr/share/thing which is also provided by a-0.1-1.x86_64\n" + "b-0.1-1.i386 provides /usr/share/thing which is also provided by a-0.1-1.x86_64\n" # noqa: E501 ) @@ -399,7 +402,8 @@ def test_finds_conflicts_in_installonly_packages(request, dir_server): installPath="usr/share/licenses/kernel-core/COPYING", sourceFile=SourceFile("COPYING", "content\n"), ) - # The modern mechanism for telling DNF a package is installonly is to add this virtual provide. + # The modern mechanism for telling DNF a package is installonly + # is to add this virtual provide. kernel1.add_provides("installonlypkg(kernel)") baserepo = YumRepoBuild([kernel1]) baserepo.make("i386") diff --git a/tests/acceptance/test_check_repoclosure.py b/tests/acceptance/test_check_repoclosure.py index 109e6a2..9d5d69c 100644 --- a/tests/acceptance/test_check_repoclosure.py +++ b/tests/acceptance/test_check_repoclosure.py @@ -45,7 +45,7 @@ def cleanUp(): assert exitcode == 3 assert err == ( "Dependency problems with repos:\n" - "package b-0.1-1.i386 requires libfoo.so.4, but none of the providers can be installed\n" + "package b-0.1-1.i386 requires libfoo.so.4, but none of the providers can be installed\n" # noqa: E501 ) @@ -84,7 +84,7 @@ def cleanUp(): assert exitcode == 3 assert err == ( "Dependency problems with repos:\n" - "package b-0.1-1.i386 requires libfoo.so.4, but none of the providers can be installed\n" + "package b-0.1-1.i386 requires libfoo.so.4, but none of the providers can be installed\n" # noqa: E501 ) diff --git a/tests/acceptance/test_check_sat.py b/tests/acceptance/test_check_sat.py index ef83722..933b10a 100644 --- a/tests/acceptance/test_check_sat.py +++ b/tests/acceptance/test_check_sat.py @@ -38,7 +38,7 @@ def cleanUp(): assert exitcode == 3 assert ( err - == "Problems with dependency set:\nnothing provides doesnotexist needed by a-0.1-1.i386\n" + == "Problems with dependency set:\nnothing provides doesnotexist needed by a-0.1-1.i386\n" # noqa: E501 ) assert out == ""