Skip to content

Commit

Permalink
Improve ruff configuration and remove isort
Browse files Browse the repository at this point in the history
  • Loading branch information
nat-n committed Sep 27, 2023
1 parent 8f73c77 commit ad92424
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 36 deletions.
2 changes: 1 addition & 1 deletion poethepoet/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 7 additions & 9 deletions poethepoet/env/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}.")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions poethepoet/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional


# ruff: noqa: N818
class PoeException(RuntimeError):
cause: Optional[str]

Expand Down
1 change: 1 addition & 0 deletions poethepoet/helpers/command/ast.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions poethepoet/helpers/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 33 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 ."
Expand Down Expand Up @@ -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"]
Expand All @@ -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"
Expand All @@ -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"]


Expand Down

0 comments on commit ad92424

Please sign in to comment.