From ad9242496ccb2848dea29dc27ba65a00666b9b19 Mon Sep 17 00:00:00 2001 From: Nat Noordanus Date: Wed, 27 Sep 2023 22:48:00 +0200 Subject: [PATCH] Improve ruff configuration and remove isort --- poethepoet/config.py | 2 +- poethepoet/env/parse.py | 16 ++++----- poethepoet/exceptions.py | 1 + poethepoet/helpers/command/ast.py | 1 + poethepoet/helpers/python.py | 4 +-- poetry.lock | 2 +- pyproject.toml | 56 ++++++++++++++++++------------- 7 files changed, 46 insertions(+), 36 deletions(-) diff --git a/poethepoet/config.py b/poethepoet/config.py index 7962d015c..7348204ba 100644 --- a/poethepoet/config.py +++ b/poethepoet/config.py @@ -4,7 +4,7 @@ try: import tomllib as tomli except ImportError: - import tomli # type: ignore + import tomli from typing import Any, Dict, List, Mapping, Optional, Sequence, Tuple, Union diff --git a/poethepoet/env/parse.py b/poethepoet/env/parse.py index fdfbfa55d..65ff7c514 100644 --- a/poethepoet/env/parse.py +++ b/poethepoet/env/parse.py @@ -3,7 +3,7 @@ from typing import Iterable, Optional, Sequence -class ParserException(ValueError): +class ParseError(ValueError): def __init__(self, issue: str, offset: int, lines: Iterable[str]): self.line_num, self.position = self._get_line_number(offset, lines) super().__init__(f"{issue} at line {self.line_num} position {self.position}.") @@ -79,27 +79,25 @@ def parse_env_file(content_lines: Sequence[str]): if ( # ruff: noqa: E501 - re.match(WHITESPACE_PATTERN, content[cursor:], re.MULTILINE).end() # type: ignore + re.match(WHITESPACE_PATTERN, content[cursor:], re.MULTILINE).end() # type: ignore[union-attr] == len(content) - cursor ): # The rest of the input is whitespace or semicolons break # skip any immediate whitespace - cursor += re.match( # type: ignore + cursor += re.match( # type: ignore[union-attr] r"[\s\t\n]*", content[cursor:] ).span()[1] var_name_match = re.match(VARNAME_PATTERN, content[cursor:]) if var_name_match: cursor += var_name_match.span()[1] - raise ParserException( + raise ParseError( "Expected assignment operator", cursor, content_lines ) - raise ParserException( - "Expected variable assignment", cursor, content_lines - ) + raise ParseError("Expected variable assignment", cursor, content_lines) var_name = match.group(1) cursor += match.end() @@ -157,7 +155,7 @@ def parse_env_file(content_lines: Sequence[str]): SINGLE_QUOTE_VALUE_PATTERN, content[cursor:], re.MULTILINE ) if match is None: - raise ParserException("Unmatched single quote", cursor, content_lines) + raise ParseError("Unmatched single quote", cursor, content_lines) var_content.append(match.group(1)) cursor += match.end() state = ParserState.SCAN_VALUE @@ -169,7 +167,7 @@ def parse_env_file(content_lines: Sequence[str]): DOUBLE_QUOTE_VALUE_PATTERN, content[cursor:], re.MULTILINE ) if match is None: - raise ParserException("Unmatched double quote", cursor, content_lines) + raise ParseError("Unmatched double quote", cursor, content_lines) new_var_content, backslashes_or_dquote = match.groups() var_content.append(new_var_content) cursor += match.end() diff --git a/poethepoet/exceptions.py b/poethepoet/exceptions.py index 68d916e1e..a7011c928 100644 --- a/poethepoet/exceptions.py +++ b/poethepoet/exceptions.py @@ -1,6 +1,7 @@ from typing import Optional +# ruff: noqa: N818 class PoeException(RuntimeError): cause: Optional[str] diff --git a/poethepoet/helpers/command/ast.py b/poethepoet/helpers/command/ast.py index 1c544fc43..02ebc715d 100644 --- a/poethepoet/helpers/command/ast.py +++ b/poethepoet/helpers/command/ast.py @@ -1,3 +1,4 @@ +# ruff: noqa: N806 r""" This module implements a heirarchical parser and AST along the lines of the following grammar which is a subset of bash syntax. diff --git a/poethepoet/helpers/python.py b/poethepoet/helpers/python.py index f13cdab64..d190c7097 100644 --- a/poethepoet/helpers/python.py +++ b/poethepoet/helpers/python.py @@ -281,7 +281,7 @@ def _get_name_node_abs_range(source: str, node: ast.Name): ) total_start_chars_offset = prev_lines_offset + own_line_offset - name_content = re.match( # type: ignore + name_content = re.match( # type: ignore[union-attr] IDENTIFIER_PATTERN, source[total_start_chars_offset:] ).group() while not name_content.isidentifier() and name_content: @@ -311,7 +311,7 @@ def _get_name_source_segment(source: str, node: ast.Name): # The name probably extends to the first ascii char outside of [a-zA-Z\d_] # regex will always match with valid arguments to this function - # type: ignore + # type: ignore[union-attr] partial_result = re.match(IDENTIFIER_PATTERN, partial_result).group() # This bit is a nasty hack, but probably always gets skipped diff --git a/poetry.lock b/poetry.lock index 3bfe748cd..6fded3931 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2965,4 +2965,4 @@ poetry-plugin = ["poetry"] [metadata] lock-version = "2.0" python-versions = ">=3.8" -content-hash = "d84a9e34df074bb3e3d197eca20c9812e2f5fe4bc40b5b5adae59fd8dc2afd4a" +content-hash = "a38b7a0d7be477112b19b613b8964f173d72ece95d79efb7746d756cea3e4ad3" diff --git a/pyproject.toml b/pyproject.toml index f48b93963..282c93b02 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,13 +19,12 @@ poetry = {version = "^1.0", allow-prereleases = true, optional = true} [tool.poetry.group.ci.dependencies] black = "^23.3.0" -isort = "^5.12.0" mypy = "^1.1.1" pylint = "^2.13.0" pytest = "^7.1.2" pytest-cov = "^3.0.0" rstcheck = { version = "^6.1.2", python = "<4" } -ruff = "^0.0.291" +ruff = "^0.0.291" virtualenv = "^20.14.1" @@ -57,16 +56,12 @@ _clean_docs.script = "shutil:rmtree('docs/_build', ignore_errors=1)" [tool.poe.tasks.format] help = "Run all formating tools on the code base" - sequence = ["format-ruff", "format-isort", "format-black"] + sequence = ["format-ruff", "format-black"] [tool.poe.tasks.format-ruff] help = "Run ruff fixer on code base" cmd = "ruff check . --fix-only" - [tool.poe.tasks.format-isort] - help = "Run isort on the code base" - cmd = "isort ." - [tool.poe.tasks.format-black] help = "Run black on the code base" cmd = "black ." @@ -131,17 +126,9 @@ _clean_docs.script = "shutil:rmtree('docs/_build', ignore_errors=1)" cmd = "pylint poethepoet" [tool.poe.tasks.style] - help = "Validate code style" - sequence = ["style-isort", "style-black"] - - [tool.poe.tasks.style-black] help = "Validate black code style" cmd = "black . --check --diff" - [tool.poe.tasks.style-isort] - help = "Validate isort code style" - cmd = "isort . --check --diff" - [tool.poe.tasks.check] help = "Run all checks on the code base" sequence = ["docs-check", "style", "types", "lint", "test"] @@ -167,7 +154,7 @@ ignore_messages = [ "Hyperlink target \"ref-env-vars\" is not referenced.", "Hyperlink target \"sequence-composition\" is not referenced.", "Hyperlink target \"graph-composition\" is not referenced.", - " No directive entry for \"autoclass\" in module \"docutils.parsers.rst.languages.en\"" + "No directive entry for \"autoclass\" in module \"docutils.parsers.rst.languages.en\"" ] ignore_directives = [ "include" @@ -184,15 +171,38 @@ markers = [ ] -[tool.isort] -profile = "black" - - [tool.ruff] select = [ - "E", "F", "I", "W", "UP", "YTT","ASYNC","C4", - "T10", "G", "PIE", "PYI", "PT", "Q", "SIM", "TCH", "PTH", "PERF","RUF"] -ignore = ["C408", "PT015", "SIM118", "PTH109", "PTH123", "RUF012"] + "E", # error + "F", # pyflakes + "I", # isort + "W", # warning + "N", # pep8-naming + "UP", # pyupgrade + "YTT", # flake8-2020 + "ASYNC", # flake8-async + "C4", # flake8-comprehensions + "T10", # flake8-debugger + "G", # flake8-logging-format + "PIE", # flake8-pie + "PYI", # flake8-pyi + "PT", # flake8-pytest-style + "Q", # flake8-quotes + "SIM", # flake8-simplify + "TCH", # flake8-type-checking + "PTH", # flake8-use-pathlib + "PGH", # pygrep-hooks + "PERF", # perflint + "RUF" # ruff-specific rules +] +ignore = [ + "C408", # unnecessary-collection-call + "PT015", # pytest-assert-always-false + "SIM118", # in-dict-keys + "PTH109", # os-getcwd + "PTH123", # builtin-open + "RUF012" # mutable-class-default +] fixable = ["E", "F", "I"]