diff --git a/SConstruct.py b/SConstruct.py index d024d36..fe869b9 100644 --- a/SConstruct.py +++ b/SConstruct.py @@ -35,19 +35,16 @@ def _exec(command: str, env: Mapping | None = None) -> int: if "all" in COMMAND_LINE_TARGETS: COMMAND_LINE_TARGETS += ["quality", "format"] -# Ruff fixes and lints, hence its appearance twice. -if "format" in COMMAND_LINE_TARGETS: - COMMAND_LINE_TARGETS += ["black", "ruff"] if "quality" in COMMAND_LINE_TARGETS: - COMMAND_LINE_TARGETS += ["ruff", "lock", "type", "test", "coverage", "license"] + COMMAND_LINE_TARGETS += ["lint", "lock", "type", "test", "coverage", "license"] # Formatting targets, which might change files. Let's run them *before* the linters and friends. # This is why ruff is the first of the quality target, as it fixes things as well. -if "black" in COMMAND_LINE_TARGETS: - cmd = f"black SConstruct.py {_SUBJECT} {_TEST_SUBJECT} examples" +if "format" in COMMAND_LINE_TARGETS: + cmd = f"ruff format SConstruct.py {_SUBJECT} {_TEST_SUBJECT} examples" if _CHECK_ONLY: - cmd += " --check" + cmd += " --diff" _exec(cmd) # Quality target. @@ -57,9 +54,9 @@ def _exec(command: str, env: Mapping | None = None) -> int: # RUF100 means: remove #noqa when not relevant. # A lot are adding during generation because due to comments, some lines can be too long. They do not all # end up being too long, so let's clean up the not relevant one. - cmd = f"ruff {_SUBJECT} {param}" + cmd = f"ruff check {_SUBJECT} {param}" # Tries to fix what it can, forget about the rest. - cmd_test = f"ruff {_TEST_SUBJECT} --fix-only" + cmd_test = f"ruff check {_TEST_SUBJECT} --fix-only" if _CHECK_ONLY: cmd += " --no-fix" cmd_test += " --no-fix" diff --git a/pycgmes/utils/base.py b/pycgmes/utils/base.py index c2a65ee..6868f55 100644 --- a/pycgmes/utils/base.py +++ b/pycgmes/utils/base.py @@ -96,8 +96,7 @@ def cgmes_attribute_names_in_profile(self, profile: BaseProfile | None) -> set[F # The field is defined as a pydantic. Field, not a dataclass.field, # so access to metadata is a tad different. Furthermore, pyright is confused by extra. if ( - profile is None - or (profile in f.default.json_schema_extra["in_profiles"]) # pyright: ignore[reportGeneralTypeIssues] + profile is None or (profile in f.default.json_schema_extra["in_profiles"]) # pyright: ignore[reportAttributeAccessIssue] ) if f.name != "mRID" } @@ -113,7 +112,7 @@ def cgmes_attributes_in_profile(self, profile: BaseProfile | None) -> dict[str, with thus the parent class included in the attribute name. """ # What will be returned, has the qualname as key... - qual_attrs: dict[str, "CgmesAttribute"] = {} + qual_attrs: dict[str, CgmesAttribute] = {} # ... but we check existence with the unqualified (short) name. seen_attrs = set() diff --git a/pyproject.toml b/pyproject.toml index ca21d8c..65e269c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,7 +32,6 @@ poetry = ">=1.5.0" # key 'priority' in source pydantic = ">=2" # Used for dataclasses [tool.poetry.group.dev.dependencies] -black = "*" # Formatter coverage = { extras = ["toml"], version = "*" } # unit test coverage pyright = "*" # replaces mypy reuse = "*" # Check licence headers @@ -88,6 +87,8 @@ typeCheckingMode = "basic" line-length = 120 # Group violations by containing file. output-format = "grouped" + +[tool.ruff.lint] select = [ # See https://docs.astral.sh/ruff/rules/ "E", # Default, pyflake @@ -117,7 +118,11 @@ ignore = [ # revisit when https://github.com/astral-sh/ruff/issues/7806 is done "N999", "N815", # Formatting due to CamelCase coming from CGMES. ] -[tool.ruff.pep8-naming] + +[tool.ruff.lint.isort] +known-first-party = ["pycgmes", "tests"] # Useful if ruff does not run from the actual root of the project and to import form tests + +[tool.ruff.lint.pep8-naming] # extend= use the default ignored names and add those extend-ignore-names = [ "G", # makes sense in the context of graph @@ -126,6 +131,9 @@ extend-ignore-names = [ "N", # shortcut in stack ] +[tool.ruff.format] +docstring-code-format = true + [tool.pytest.ini_options] addopts = ["--import-mode=importlib",] # modern way to import tests