Skip to content

Commit

Permalink
Fix failures from updates to linting tools
Browse files Browse the repository at this point in the history
- all ruff failures
- newer black
- stricter mypy
- some changes in setuptools packaging normalization
- silence some sphinx warnings that we can't seem to be able to fix
  • Loading branch information
BenjaminSchubert committed Jan 26, 2025
1 parent c52fa0f commit 43a08f5
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 55 deletions.
10 changes: 4 additions & 6 deletions .github/scripts/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
from dataclasses import InitVar, dataclass, field
from typing import Any, Literal
from xml.etree import ElementTree
from xml.etree import ElementTree as ET

from tabulate import tabulate

Expand All @@ -21,7 +21,7 @@ class TestCase:
summary: str | None

@classmethod
def from_junit(cls, tree: ElementTree.Element) -> TestCase:
def from_junit(cls, tree: ET.Element) -> TestCase:
children = tree.getchildren()
assert len(children) <= 1

Expand Down Expand Up @@ -75,7 +75,7 @@ def __post_init__(self, total: int) -> None:
self.successes = total - self.errors - self.failures - self.skipped

@classmethod
def from_junit(cls, tree: ElementTree.Element) -> TestSuite:
def from_junit(cls, tree: ET.Element) -> TestSuite:
attrs = tree.attrib

tests = [
Expand Down Expand Up @@ -139,9 +139,7 @@ def main() -> None:
testsuites = [
TestSuite.from_junit(testsuite)
for file in files
for testsuite in ElementTree.parse(file).findall( # noqa: S314
"testsuite"
)
for testsuite in ET.parse(file).findall("testsuite") # noqa: S314
]

summary = tabulate(
Expand Down
4 changes: 4 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
("py:class", "dwas._steps.parametrize.T"),
("py:class", "dwas._steps.handlers.StepHandler"),
]
suppress_warnings = [
# See https://github.com/sphinx-doc/sphinx/issues/12589
"autosummary.import_cycle",
]

# Theme options
html_theme = "furo"
Expand Down
1 change: 1 addition & 0 deletions dwasfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Contains the dwas configuration for this project.
"""

from pathlib import Path

import dwas
Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ disable = [
# Ruff
[tool.ruff]
target-version = "py38"

[tool.ruff.lint]
select = ["ALL"]
ignore = [
##
# Typing
"ANN101", # Don't annotate 'self'
"ANN102", # Don't annotate 'cls'
"ANN401", # Allow typing with ANY
##
# Format
Expand All @@ -162,7 +162,6 @@ ignore = [
"FIX", # We want to put fixmes longterm
"TD", # We want to be able to add todos without issu links
"INP001", # Not every .py file is part of a package
"PT004", # Don't add `_` in front of fixtures returning nothing
"S101", # Allow asserts
"TID252", # We want relative imports
"PLR2004", # Disable magic numbers check
Expand All @@ -183,7 +182,7 @@ ignore = [
flake8-pytest-style.parametrize-values-type = "tuple"
flake8-pytest-style.parametrize-values-row-type = "tuple"
flake8-pytest-style.fixture-parentheses = false
lint.isort.known-first-party = ["dwas"]
isort.known-first-party = ["dwas"]

[tool.ruff.lint.per-file-ignores]
"docs/*" = ["D"]
Expand Down
27 changes: 14 additions & 13 deletions src/dwas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
While ``dwas`` is not at version 1.0.0, it does not guarantee API stability.
"""

from ._config import Config
from ._exceptions import BaseDwasException
from ._steps import (
Expand All @@ -34,23 +35,23 @@
# XXX: The order here is important, it declares the order in which the entries
# are documented in the public docs.
__all__ = [
"StepRunner",
"BaseDwasException",
"Config",
"DefaultsAlreadySetException",
"MismatchedNumberOfParametersException",
"ParameterConflictException",
"Step",
"StepWithSetup",
"StepWithDependentSetup",
"StepRunner",
"StepWithArtifacts",
"StepWithCleanup",
"Config",
"register_step",
"register_managed_step",
"register_step_group",
"step",
"StepWithDependentSetup",
"StepWithSetup",
"build_parameters",
"managed_step",
"parametrize",
"build_parameters",
"register_managed_step",
"register_step",
"register_step_group",
"set_defaults",
"BaseDwasException",
"DefaultsAlreadySetException",
"MismatchedNumberOfParametersException",
"ParameterConflictException",
"step",
]
5 changes: 4 additions & 1 deletion src/dwas/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ def __init__(
self.n_jobs = n_jobs

self.is_interactive = (
sys.__stdout__.isatty() and sys.__stderr__.isatty()
sys.__stdout__ is not None
and sys.__stdout__.isatty()
and sys.__stderr__ is not None
and sys.__stderr__.isatty()
)

self.environ = {
Expand Down
3 changes: 3 additions & 0 deletions src/dwas/_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ def __init__(self, summary: StepSummary) -> None:
self._summary = summary

def _refresh_in_context() -> None:
assert sys.__stdout__ is not None
assert sys.__stderr__ is not None

with _io.redirect_streams(
sys.__stdout__, sys.__stderr__
), _io.log_file(None):
Expand Down
8 changes: 5 additions & 3 deletions src/dwas/_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ColorFormatter(logging.Formatter):
{
logging.DEBUG: Fore.CYAN,
logging.INFO: "",
logging.WARN: Fore.YELLOW,
logging.WARNING: Fore.YELLOW,
logging.ERROR: Fore.RED + Style.BRIGHT,
logging.FATAL: Back.RED + Fore.WHITE + Style.BRIGHT,
}
Expand All @@ -32,8 +32,10 @@ def formatMessage(self, record: logging.LogRecord) -> str:

def formatException(
self,
ei: tuple[type[BaseException], BaseException, TracebackType | None]
| tuple[None, None, None],
ei: (
tuple[type[BaseException], BaseException, TracebackType | None]
| tuple[None, None, None]
),
) -> str:
output = super().formatException(ei)
return f"{Fore.CYAN}\ndwas > " + "\ndwas > ".join(output.splitlines())
Expand Down
16 changes: 8 additions & 8 deletions src/dwas/_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ def compute_replacement(requirements: list[str]) -> list[str]:
replacements.append(requirement)
else:
if requirement not in except_replacements:
except_replacements[
requirement
] = compute_replacement(graph[requirement])
except_replacements[requirement] = (
compute_replacement(graph[requirement])
)
replacements.extend(except_replacements[requirement])

return replacements
Expand Down Expand Up @@ -264,10 +264,10 @@ def compute_only_replacement(
replacements = []
for requirement in requirements:
if requirement not in only_replacements:
only_replacements[
requirement
] = compute_only_replacement(
requirement, graph[requirement]
only_replacements[requirement] = (
compute_only_replacement(
requirement, graph[requirement]
)
)
replacements.extend(only_replacements[requirement])

Expand Down Expand Up @@ -665,7 +665,7 @@ def _compute_slowest_chains(
total_time_per_step: dict[str, tuple[list[str], timedelta]] = {}

def compute_chain(step: str) -> tuple[list[str], timedelta]:
precomputed_result = total_time_per_step.get(step, None)
precomputed_result = total_time_per_step.get(step)
if precomputed_result is not None:
return precomputed_result

Expand Down
20 changes: 10 additions & 10 deletions src/dwas/_steps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@
)

__all__ = [
"DefaultsAlreadySetException",
"MismatchedNumberOfParametersException",
"ParameterConflictException",
"Step",
"StepRunner",
"StepWithArtifacts",
"StepWithCleanup",
"StepWithDependentSetup",
"StepWithSetup",
"build_parameters",
"managed_step",
"parametrize",
"build_parameters",
"register_managed_step",
"register_step",
"register_step_group",
"set_defaults",
"step",
"Step",
"StepRunner",
"StepWithDependentSetup",
"StepWithSetup",
"StepWithArtifacts",
"StepWithCleanup",
"DefaultsAlreadySetException",
"MismatchedNumberOfParametersException",
"ParameterConflictException",
]
6 changes: 2 additions & 4 deletions src/dwas/_steps/parametrize.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,15 @@ def parametrize(
arg_names: str,
args_values: Sequence[Any],
ids: Sequence[str | None] | None = None,
) -> Callable[[T], T]:
...
) -> Callable[[T], T]: ...


@overload
def parametrize(
arg_names: Sequence[str],
args_values: Sequence[Sequence[Any]],
ids: Sequence[str | None] | None = None,
) -> Callable[[T], T]:
...
) -> Callable[[T], T]: ...


def parametrize(
Expand Down
2 changes: 1 addition & 1 deletion src/dwas/_steps/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from __future__ import annotations

from pathlib import Path # noqa: TCH003 required for Sphinx
from pathlib import Path # noqa: TC003 required for Sphinx
from typing import TYPE_CHECKING, Any, Callable, Protocol, runtime_checkable

if TYPE_CHECKING:
Expand Down
6 changes: 3 additions & 3 deletions src/dwas/_subproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ def _run() -> subprocess.CompletedProcess[None]:
stdout_reader.join()
stderr_reader.join()

ret: subprocess.CompletedProcess[
None
] = subprocess.CompletedProcess(command, proc.returncode)
ret: subprocess.CompletedProcess[None] = (
subprocess.CompletedProcess(command, proc.returncode)
)
self._remove(proc)
ret.check_returncode()
return ret
Expand Down
2 changes: 1 addition & 1 deletion src/dwas/predefined/_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import shutil
from contextlib import suppress
from pathlib import Path # noqa: TCH003 required for sphinx documentation
from pathlib import Path # noqa: TC003 required for sphinx documentation

from .. import Step, StepRunner, build_parameters, set_defaults

Expand Down
2 changes: 1 addition & 1 deletion tests/predefined/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_exposes_sdists_and_wheels(self, cache_path):
cli(cache_path=cache_path, steps=["output_artifacts"])
artifacts = json.loads(Path("artifacts.json").read_text("utf-8"))
assert list(artifacts.keys()) == ["sdists", "wheels"]
assert Path(artifacts["sdists"][0]).name == "test-package-0.0.0.tar.gz"
assert Path(artifacts["sdists"][0]).name == "test_package-0.0.0.tar.gz"
assert (
Path(artifacts["wheels"][0]).name
== "test_package-0.0.0-py3-none-any.whl"
Expand Down

0 comments on commit 43a08f5

Please sign in to comment.