diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0515f81b..b3b8b0ff 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,7 +25,7 @@ repos: - id: python-no-log-warn - id: text-unicode-replacement-char - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.14.14 + rev: v0.15.0 hooks: - id: ruff-format - id: ruff-check diff --git a/src/_pytask/collect_command.py b/src/_pytask/collect_command.py index 8f4be939..bd75eecc 100644 --- a/src/_pytask/collect_command.py +++ b/src/_pytask/collect_command.py @@ -200,9 +200,9 @@ def _print_collected_tasks( for node in sorted( deps, key=( - lambda x: x.path.as_posix() - if isinstance(x, PPathNode) - else x.name + lambda x: ( + x.path.as_posix() if isinstance(x, PPathNode) else x.name + ) ), ): text = format_node_name(node, (common_ancestor,)) @@ -211,9 +211,9 @@ def _print_collected_tasks( products: list[Any] = list(tree_leaves(task.produces)) for node in sorted( products, - key=lambda x: x.path.as_posix() - if isinstance(x, PPathNode) - else x.name, + key=lambda x: ( + x.path.as_posix() if isinstance(x, PPathNode) else x.name + ), ): text = format_node_name(node, (common_ancestor,)) task_branch.add(Text.assemble(FILE_ICON, "")) diff --git a/src/_pytask/compat.py b/src/_pytask/compat.py index e1442f18..779cce97 100644 --- a/src/_pytask/compat.py +++ b/src/_pytask/compat.py @@ -99,7 +99,7 @@ def import_optional_dependency( return None # Handle submodules: if we have submodule, grab parent module from sys.modules - parent = name.split(".")[0] + parent = name.split(".", maxsplit=1)[0] if parent != name: install_name = parent module_to_get = sys.modules[install_name] diff --git a/src/_pytask/dag.py b/src/_pytask/dag.py index d8c8b325..538462d8 100644 --- a/src/_pytask/dag.py +++ b/src/_pytask/dag.py @@ -95,9 +95,11 @@ def _add_product( # another task that is a dependency in the current task. Thus, draw an edge # connecting the two nodes. tree_map( - lambda x: dag.add_edge(x.value.signature, x.signature) - if isinstance(x, PythonNode) and isinstance(x.value, PythonNode) - else None, + lambda x: ( + dag.add_edge(x.value.signature, x.signature) + if isinstance(x, PythonNode) and isinstance(x.value, PythonNode) + else None + ), task.depends_on, ) return dag diff --git a/tests/test_capture.py b/tests/test_capture.py index afb25d60..7abefe93 100644 --- a/tests/test_capture.py +++ b/tests/test_capture.py @@ -208,7 +208,8 @@ def test_init_capturing(self): try: capman = CaptureManager(CaptureMethod.FD) capman.start_capturing() - pytest.raises(AssertionError, capman.start_capturing) + with pytest.raises(AssertionError): + capman.start_capturing() capman.stop_capturing() finally: capouter.stop_capturing() @@ -364,7 +365,8 @@ def test_text(self): def test_unicode_and_str_mixture(self): f = capture.CaptureIO() f.write("\u00f6") - pytest.raises(TypeError, f.write, b"hello") + with pytest.raises(TypeError): + f.write(b"hello") def test_write_bytes_to_buffer(self): """In python3, stdout / stderr are text io wrappers (exposing a buffer property @@ -394,7 +396,8 @@ def test_unicode_and_str_mixture(self): sio = io.StringIO() f = capture.TeeCaptureIO(sio) f.write("\u00f6") - pytest.raises(TypeError, f.write, b"hello") + with pytest.raises(TypeError): + f.write(b"hello") def test_dontreadfrominput(): @@ -403,11 +406,15 @@ def test_dontreadfrominput(): f = DontReadFromInput() assert f.buffer is f assert not f.isatty() - pytest.raises(OSError, f.read) - pytest.raises(OSError, f.readlines) + with pytest.raises(OSError): + f.read() + with pytest.raises(OSError): + f.readlines() iter_f = iter(f) - pytest.raises(OSError, next, iter_f) - pytest.raises(UnsupportedOperation, f.fileno) + with pytest.raises(OSError): + next(iter_f) + with pytest.raises(UnsupportedOperation): + f.fileno() f.close() # just for completeness @@ -474,7 +481,8 @@ def test_simple(self, tmpfile): cap = capture.FDCapture(fd) data = b"hello" os.write(fd, data) - pytest.raises(AssertionError, cap.snap) + with pytest.raises(AssertionError): + cap.snap() cap.done() cap = capture.FDCapture(fd) cap.start() @@ -495,7 +503,8 @@ def test_simple_fail_second_start(self, tmpfile): fd = tmpfile.fileno() cap = capture.FDCapture(fd) cap.done() - pytest.raises(AssertionError, cap.start) + with pytest.raises(AssertionError): + cap.start() def test_stderr(self): cap = capture.FDCapture(2) @@ -546,7 +555,8 @@ def test_simple_resume_suspend(self): assert s == "but now yes\n" cap.suspend() cap.done() - pytest.raises(AssertionError, cap.suspend) + with pytest.raises(AssertionError): + cap.suspend() assert repr(cap) == ( "".format( # noqa: UP032 @@ -631,7 +641,8 @@ def test_reset_twice_error(self): with self.getcapture() as cap: print("hello") out, err = cap.readouterr() - pytest.raises(ValueError, cap.stop_capturing) + with pytest.raises(ValueError): + cap.stop_capturing() assert out == "hello\n" assert not err @@ -688,8 +699,8 @@ def test_stdin_nulled_by_default(self): print("XX this test may well hang instead of crashing") print("XX which indicates an error in the underlying capturing") print("XX mechanisms") - with self.getcapture(): - pytest.raises(OSError, sys.stdin.read) + with self.getcapture(), pytest.raises(OSError): + sys.stdin.read() class TestTeeStdCapture(TestStdCapture): @@ -829,6 +840,5 @@ def test_fdcapture_invalid_fd_without_fd_reuse(self, tmp_path): def test__get_multicapture() -> None: assert isinstance(_get_multicapture(CaptureMethod.NO), MultiCapture) - pytest.raises(ValueError, _get_multicapture, "unknown").match( - r"^unknown capturing method: 'unknown'" - ) + with pytest.raises(ValueError, match=r"^unknown capturing method: 'unknown'"): + _get_multicapture("unknown")