Skip to content

Improve linting. #586

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

Merged
merged 3 commits into from
Mar 29, 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
8 changes: 3 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,12 @@ extend-include = ["*.ipynb"]
[tool.ruff.lint]
select = ["ALL"]
ignore = [
"FBT", # flake8-boolean-trap
"TRY", # ignore tryceratops.
# Others.
"ANN101", # type annotating self
"ANN102", # type annotating cls
"ANN101",
"ANN102",
"ANN401", # flake8-annotate typing.Any
"COM812", # Comply with ruff-format.
"ISC001", # Comply with ruff-format.
"FBT",
"PD901", # Avoid generic df for dataframes.
"S101", # raise errors for asserts.
"S603", # Call check with subprocess.run.
Expand Down
2 changes: 1 addition & 1 deletion src/_pytask/_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def get_annotations( # noqa: C901, PLR0912, PLR0915

if not isinstance(ann, dict):
msg = f"{obj!r}.__annotations__ is neither a dict nor None"
raise ValueError(msg)
raise ValueError(msg) # noqa: TRY004

if not ann:
return {}
Expand Down
29 changes: 11 additions & 18 deletions src/_pytask/dag_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,24 +188,17 @@ def build_dag(raw_config: dict[str, Any]) -> nx.DiGraph:
session = Session(exit_code=ExitCode.CONFIGURATION_FAILED)

else:
try:
session.hook.pytask_log_session_header(session=session)
import_optional_dependency("pygraphviz")
check_for_optional_program(
session.config["layout"],
extra="The layout program is part of the graphviz package that you "
"can install with conda.",
)
session.hook.pytask_collect(session=session)
session.dag = create_dag(session=session)
session.hook.pytask_unconfigure(session=session)
dag = _refine_dag(session)

except Exception:
raise

else:
return dag
session.hook.pytask_log_session_header(session=session)
import_optional_dependency("pygraphviz")
check_for_optional_program(
session.config["layout"],
extra="The layout program is part of the graphviz package that you "
"can install with conda.",
)
session.hook.pytask_collect(session=session)
session.dag = create_dag(session=session)
session.hook.pytask_unconfigure(session=session)
return _refine_dag(session)


def _refine_dag(session: Session) -> nx.DiGraph:
Expand Down
4 changes: 2 additions & 2 deletions src/_pytask/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
]


def relative_to(path: Path, source: Path, include_source: bool = True) -> Path:
def relative_to(path: Path, source: Path, *, include_source: bool = True) -> Path:
"""Make a path relative to another path.

In contrast to :meth:`pathlib.Path.relative_to`, this function allows to keep the
Expand Down Expand Up @@ -191,7 +191,7 @@ def _insert_missing_modules(modules: dict[str, ModuleType], module_name: str) ->
# sys.meta_path explicitly and raise the error ourselves to fall back to
# creating a dummy module.
if not sys.meta_path:
raise ModuleNotFoundError
raise ModuleNotFoundError # noqa: TRY301
importlib.import_module(module_name)
except ModuleNotFoundError:
module = ModuleType(
Expand Down
2 changes: 1 addition & 1 deletion src/_pytask/warnings_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def parse_warning_filter( # noqa: PLR0912, C901
lineno = int(lineno_)
if lineno < 0:
msg = "number is negative"
raise ValueError(msg)
raise ValueError(msg) # noqa: TRY301
except ValueError as e:
raise Exit( # noqa: B904
error_template.format(error=f"invalid lineno {lineno_!r}: {e}")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
],
)
def test_relative_to(path, source, include_source, expected):
result = relative_to(path, source, include_source)
result = relative_to(path, source, include_source=include_source)
assert result == expected


Expand Down