diff --git a/Makefile b/Makefile index f24e3b9bc1..5f88be85ea 100644 --- a/Makefile +++ b/Makefile @@ -17,10 +17,6 @@ test-black: test-codespell: tox run -e lint-codespell -.PHONY: test-isort -test-isort: - tox run -e lint-isort - .PHONY: test-mypy test-mypy: tox run -e lint-mypy @@ -39,8 +35,7 @@ test-pyright: .PHONY: test-ruff test-ruff: - ruff --config snapcraft_legacy/ruff.toml $(SOURCES_LEGACY) - ruff $(SOURCES) + ruff check .PHONY: test-shellcheck test-shellcheck: @@ -58,7 +53,7 @@ test-units: test-legacy-units tests: tests-static test-units .PHONY: tests-static -tests-static: test-black test-codespell test-ruff test-isort test-mypy test-pydocstyle test-pyright test-pylint test-shellcheck +tests-static: test-black test-codespell test-ruff test-mypy test-pydocstyle test-pyright test-pylint test-shellcheck .PHONY: lint lint: tests-static diff --git a/pyproject.toml b/pyproject.toml index 53c4391636..b9d7982fa5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,17 +10,6 @@ extend-exclude = ''' # en masse later. target_version = ["py310", "py311"] -[tool.isort] -# black-compatible isort configuration -multi_line_output = 3 -include_trailing_comma = true -force_grid_wrap = 0 -use_parentheses = true -ensure_newline_before_comments = true -line_length = 88 -skip_gitignore = true -skip = ["tests/spread/tools/snapd-testing-tools"] - [tool.pylint.main] ignore-paths = ["tests/legacy"] @@ -83,7 +72,7 @@ extend-exclude = [ "legacy", "tests/legacy", ] -select = [ +lint.select = [ "E", "F", # The rules built into Flake8 "I", # isort checking "PLC", "PLE", "PLR", "PLW", # Pylint @@ -102,7 +91,7 @@ select = [ "Q", # Consistent quotations "RET", # Return values ] -ignore = [ +lint.ignore = [ # These following copy the flake8 configuration #"E203", # Whitespace before ":" -- Commented because ruff doesn't currently check E203 "E501", # Line too long @@ -128,13 +117,6 @@ ignore = [ # Disabled because the current code breaks these rules without "noqa" comments # Most of these are probably worth enabling eventually. - # 3 instances of breaking N802, all from overriding do_GET in http.server.BaseHTTPRequestHandler - # We can probably noqa these and enable the rule - "N802", # Function names should be lowercase. - # 3 instances of N805, all PyDantic validators (which are classmethods). - # These have pylint disablers, but ruff doesn't understand those (yet). - # https://github.com/charliermarsh/ruff/issues/1203 - "N805", # First argument of a method should be named `self` # Annotation issues appear to be mostly in older code, so could be eventually enabled. # 39 instances of ANN001. "ANN001", # Missing type annotation for function argument @@ -144,24 +126,20 @@ ignore = [ "ANN206", # 4 instances - would break if run with optimization "S101", # Use of assert detected - # 1 instance, disabled for pylint - "BLE001", # Comprehensions - IDK, these ones flagged and they really could go either way. "C405", "C408", "C414", - "Q000", # 2 single-quoted strings - probably accidental "RET504", "RET506", # Return value related. "PLR2004", # Magic values - widely used - "PLC1901", # Checking for empty string vs. falsey - many of these "S603", # Untrusted input for subprocess calls "S604", # shell=True parameter to a function "S607", # Partial executable path for subprocess calls ] -[tool.ruff.pylint] +[tool.ruff.lint.pylint] max-args = 6 max-branches = 16 -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] "tests/**.py" = [ "D", # Ignore docstring rules in tests "ANN", # Ignore type annotations in tests @@ -175,9 +153,8 @@ max-branches = 16 ] "tests/unit/parts/plugins/test_kernel.py" = [ "E101", # Mixed tabs and spaces. Ruff gets confused by tabs in multiline strings - "W191", # Indentation contains tabs - another Ruff false positive ] "__init__.py" = ["I001"] # Imports in __init__ filesare allowed to be out of order -[tool.ruff.flake8-annotations] +[tool.ruff.lint.flake8-annotations] suppress-none-returning = true # We don't need to explicitly point out that a function doesn't return anything diff --git a/requirements-devel.txt b/requirements-devel.txt index 95c169a47a..b4d789bd7d 100644 --- a/requirements-devel.txt +++ b/requirements-devel.txt @@ -32,7 +32,6 @@ hupper==1.12.1 idna==3.7 importlib-metadata==7.0.1 iniconfig==2.0.0 -isort==5.13.2 jaraco.classes==3.3.1 jeepney==0.8.0 jsonschema==2.5.1 diff --git a/setup.py b/setup.py index b752880b6e..850faaec77 100755 --- a/setup.py +++ b/setup.py @@ -64,7 +64,6 @@ def recursive_data_files(directory, install_directory): "coverage[toml]", "pyflakes", "fixtures", - "isort", "mccabe", "mypy", "testscenarios", diff --git a/snapcraft/elf/_elf_file.py b/snapcraft/elf/_elf_file.py index f27d4e4f54..1f61ff5a7c 100644 --- a/snapcraft/elf/_elf_file.py +++ b/snapcraft/elf/_elf_file.py @@ -234,7 +234,7 @@ def is_elf(cls, path: Path) -> bool: # pylint: disable=too-many-branches - def _extract_attributes(self) -> None: # noqa: C901 + def _extract_attributes(self) -> None: # noqa: C901,PLR0912 with self.path.open("rb") as file: elf_file = elffile.ELFFile(file) diff --git a/snapcraft_legacy/__init__.py b/snapcraft_legacy/__init__.py index 385d291eb0..62ca6a9080 100644 --- a/snapcraft_legacy/__init__.py +++ b/snapcraft_legacy/__init__.py @@ -337,10 +337,10 @@ def _get_version(): __version__ = _get_version() # Workaround for potential import loops. -from snapcraft_legacy.internal import repo # noqa isort:skip +from snapcraft_legacy.internal import repo # noqa # For backwards compatibility with external plugins. -import snapcraft_legacy._legacy_loader # noqa isort:skip +import snapcraft_legacy._legacy_loader # noqa from snapcraft_legacy import common # noqa from snapcraft_legacy import extractors # noqa from snapcraft_legacy import file_utils # noqa @@ -363,4 +363,4 @@ def _get_version(): validate, ) -from snapcraft_legacy.project._project_options import ProjectOptions # noqa isort:skip +from snapcraft_legacy.project._project_options import ProjectOptions # noqa diff --git a/snapcraft_legacy/ruff.toml b/snapcraft_legacy/ruff.toml index a93c2ef9e1..e344c89068 100644 --- a/snapcraft_legacy/ruff.toml +++ b/snapcraft_legacy/ruff.toml @@ -7,16 +7,19 @@ extend-exclude = [ "stage", "prime", ] -ignore = ["E501"] +lint.ignore = [ + "E101", # Mixed spaces and tabs + "E501", +] line-length = 88 -select = [ +lint.select = [ "C9", "E", "F", "W", ] -[per-file-ignores] +[lint.per-file-ignores] "snapcraft_legacy/plugins/v2/_kernel_build.py" = [ "E101", # Mixed tabs and spaces. Ruff gets confused by tabs in multiline strings "W191", # Indentation contains tabs - another Ruff false positive @@ -29,5 +32,5 @@ select = [ "E721", # Allowing type comparison ] -[mccabe] +[lint.mccabe] max-complexity = 10 diff --git a/snapcraft_legacy/storeapi/__init__.py b/snapcraft_legacy/storeapi/__init__.py index e5678f039a..cd49b83bfa 100644 --- a/snapcraft_legacy/storeapi/__init__.py +++ b/snapcraft_legacy/storeapi/__init__.py @@ -16,10 +16,10 @@ import logging -from . import errors # isort:skip -from . import channels # isort:skip -from . import constants # isort:skip -from . import status # isort:skip +from . import errors +from . import channels +from . import constants +from . import status logger = logging.getLogger(__name__) diff --git a/tests/unit/meta/test_appstream.py b/tests/unit/meta/test_appstream.py index d8e6936455..0ceff374b0 100644 --- a/tests/unit/meta/test_appstream.py +++ b/tests/unit/meta/test_appstream.py @@ -139,7 +139,7 @@ def _expect_icon(self, icon): assert actual is not None assert actual.icon == expected.icon - def test_appstream_NxN_size_not_int_is_skipped(self): + def test_appstream_nxn_size_not_int_is_skipped(self): self._create_appstream_file(icon="icon", icon_type="stock") dir_name = os.path.join("usr", "share", "icons", "hicolor", "NxN") os.makedirs(dir_name) diff --git a/tox.ini b/tox.ini index c11b236a31..1edf261c4c 100644 --- a/tox.ini +++ b/tox.ini @@ -7,14 +7,13 @@ # * Additional test environment "noreq" runs all the tests without requirements.txt # * lint-shellcheck includes spread-shellcheck.py # * Additional ruff configuration for snapcraft_legacy -# * Include isort # * Do not use tmpfs for a temporary directory as it does not support user xattrs # * Legacy tests (inherited from integration tests) include coverage # * Pylint included [tox] env_list = # Environments to run when called with no parameters. - lint-{black,ruff,isort,mypy,pylint,pyright,shellcheck,codespell,yaml} + lint-{black,ruff,mypy,pylint,pyright,shellcheck,codespell,yaml} test-py310 test-legacy-py310 minversion = 4.5 @@ -87,7 +86,7 @@ find = git ls-files --empty-directory --deduplicate filter = file --mime-type -Nnf- | grep shellscript$ | cut -f1 -d: spread_filter = grep -E "^tests/spread/.*(spread|task)\.yaml$" -[testenv:lint-{black,ruff,docstyle,isort,shellcheck,codespell,yaml}] +[testenv:lint-{black,ruff,docstyle,shellcheck,codespell,yaml}] description = Lint the source code base = testenv, lint labels = lint @@ -99,9 +98,7 @@ commands_pre = shellcheck: bash -c '{[shellcheck]find} | {[shellcheck]spread_filter} > {env_tmp_dir}/spread_shellcheck_files' commands = black: black --check --diff {tty:--color} {posargs} . - ruff: ruff --diff --respect-gitignore setup.py snapcraft tests tools - ruff: ruff --config snapcraft_legacy/ruff.toml snapcraft_legacy tests/legacy - isort: isort --check snapcraft snapcraft_legacy tests setup.py tools + ruff: ruff check --diff --respect-gitignore {posargs} docstyle: pydocstyle snapcraft shellcheck: xargs -ra {env_tmp_dir}/shellcheck_files shellcheck shellcheck: xargs -ra {env_tmp_dir}/spread_shellcheck_files python3 tools/spread-shellcheck.py spread.yaml