Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linter updates #4815

Merged
merged 4 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
33 changes: 5 additions & 28 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
1 change: 0 additions & 1 deletion requirements-devel.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def recursive_data_files(directory, install_directory):
"coverage[toml]",
"pyflakes",
"fixtures",
"isort",
"mccabe",
"mypy",
"testscenarios",
Expand Down
2 changes: 1 addition & 1 deletion snapcraft/elf/_elf_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions snapcraft_legacy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
11 changes: 7 additions & 4 deletions snapcraft_legacy/ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,5 +32,5 @@ select = [
"E721", # Allowing type comparison
]

[mccabe]
[lint.mccabe]
max-complexity = 10
8 changes: 4 additions & 4 deletions snapcraft_legacy/storeapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/meta/test_appstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 3 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading