From 4e78133d0e0b2d5623db3a60931a5f6d302b3c52 Mon Sep 17 00:00:00 2001 From: Ryan Chui Date: Sun, 1 Oct 2023 11:54:53 -0700 Subject: [PATCH] upgrade: Ruff --- .github/workflows/docs.yml | 6 +-- .github/workflows/integration.yaml | 28 +++-------- .python-version | 2 +- Makefile | 3 +- laminar/components.py | 15 ++---- laminar/configurations/datastores.py | 6 +-- laminar/utils/fs.py | 14 ++---- main.py | 9 ++-- pyproject.toml | 48 +++++++++++++----- requirements.dev.txt | 3 +- requirements.txt | 3 ++ tests/configurations/test_hooks.py | 8 +-- tests/configurations/test_layers.py | 12 ++--- tests/configurations/test_schedulers.py | 12 ++--- tests/conftest.py | 3 +- tests/flows/test_branch.py | 3 +- tests/flows/test_composition.py | 12 ++--- tests/flows/test_conditional_branching.py | 3 +- tests/flows/test_foreach.py | 3 +- tests/flows/test_grid.py | 6 +-- tests/flows/test_linear.py | 3 +- tests/flows/test_parameters.py | 3 +- tests/flows/test_resume.py | 12 ++--- tests/test_components.py | 60 ++++++++--------------- tests/test_types.py | 15 ++---- 25 files changed, 120 insertions(+), 172 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index bea4845..ecc4cb8 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -9,10 +9,8 @@ jobs: runs-on: ubuntu-latest if: "startsWith(github.ref, 'refs/tags/')" steps: - - uses: actions/checkout@v3 - - - name: Setup Python - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 with: python-version: '3.8' diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 38d408e..89f6291 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -14,11 +14,8 @@ jobs: PY_COLORS: '1' steps: - - name: checkout - uses: actions/checkout@v3 - - - name: setup - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 with: python-version: 3.${{ matrix.python-version }} architecture: x64 @@ -37,11 +34,8 @@ jobs: PY_COLORS: '1' steps: - - name: checkout - uses: actions/checkout@v3 - - - name: setup - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 with: python-version: '3.11' @@ -54,8 +48,7 @@ jobs: - name: check run: make check - - name: upload - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v3 with: name: dist path: dist @@ -69,16 +62,11 @@ jobs: PY_COLORS: '1' steps: - - name: checkout - uses: actions/checkout@v3 - - - name: setup - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 with: python-version: '3.11' - - - name: dist - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v3 with: name: dist path: dist diff --git a/.python-version b/.python-version index c7413b8..cc1923a 100644 --- a/.python-version +++ b/.python-version @@ -1 +1 @@ -3.8.14 +3.8 diff --git a/Makefile b/Makefile index f43692c..e56ec8a 100644 --- a/Makefile +++ b/Makefile @@ -39,12 +39,13 @@ env: venv upgrade format: $(VENV) black -C . $(VENV) isort . + $(VENV) ruff --fix --show-fixes --show-source . .PHONY: lint lint: $(VENV) black --version && black --check . $(VENV) isort --version && isort --check-only . - $(VENV) flake8 --version && flake8 . + $(VENV) ruff --version && ruff --diff . $(VENV) mypy --version && mypy . .PHONY: open diff --git a/laminar/components.py b/laminar/components.py index ec03c88..02cdccb 100644 --- a/laminar/components.py +++ b/laminar/components.py @@ -297,16 +297,13 @@ class A(Layer): return flow(execution=self.id, **artifacts) @overload - def layer(self, layer: str, **atributes: Any) -> Layer: - ... + def layer(self, layer: str, **atributes: Any) -> Layer: ... @overload - def layer(self, layer: Type[LayerT], **attributes: Any) -> LayerT: - ... + def layer(self, layer: Type[LayerT], **attributes: Any) -> LayerT: ... @overload - def layer(self, layer: LayerT, **attributes: Any) -> LayerT: - ... + def layer(self, layer: LayerT, **attributes: Any) -> LayerT: ... def layer(self, layer: Union[str, Type[Layer], Layer], **attributes: Any) -> Layer: """Get a registered flow layer. @@ -526,8 +523,7 @@ def __repr__(self) -> str: @overload @classmethod - def register(cls, layer: Type[LayerT]) -> Type[LayerT]: - ... + def register(cls, layer: Type[LayerT]) -> Type[LayerT]: ... @overload @classmethod @@ -538,8 +534,7 @@ def register( container: layers.Container = layers.Container(), foreach: layers.ForEach = layers.ForEach(), retry: layers.Retry = layers.Retry(), - ) -> Callable[[Type[LayerT]], Type[LayerT]]: - ... + ) -> Callable[[Type[LayerT]], Type[LayerT]]: ... @classmethod def register(cls, *args: Any, **kwargs: Any) -> Any: diff --git a/laminar/configurations/datastores.py b/laminar/configurations/datastores.py index 3ea313b..939a42b 100644 --- a/laminar/configurations/datastores.py +++ b/laminar/configurations/datastores.py @@ -176,12 +176,10 @@ class Accessor: layer: "Layer" @overload - def __getitem__(self, key: int) -> Any: - ... + def __getitem__(self, key: int) -> Any: ... @overload - def __getitem__(self, key: slice) -> List[Any]: - ... + def __getitem__(self, key: slice) -> List[Any]: ... def __getitem__(self, key: Union[int, slice]) -> Any: datastore = self.layer.execution.flow.configuration.datastore diff --git a/laminar/utils/fs.py b/laminar/utils/fs.py index 619877c..bb53662 100644 --- a/laminar/utils/fs.py +++ b/laminar/utils/fs.py @@ -12,23 +12,19 @@ @overload -def open(uri: str, mode: "Literal['r']") -> TextIO: - ... +def open(uri: str, mode: "Literal['r']") -> TextIO: ... @overload -def open(uri: str, mode: "Literal['rb']") -> BinaryIO: - ... +def open(uri: str, mode: "Literal['rb']") -> BinaryIO: ... @overload -def open(uri: str, mode: "Literal['w']") -> TextIO: - ... +def open(uri: str, mode: "Literal['w']") -> TextIO: ... @overload -def open(uri: str, mode: "Literal['wb']") -> BinaryIO: - ... +def open(uri: str, mode: "Literal['wb']") -> BinaryIO: ... @contextmanager # type: ignore @@ -73,7 +69,7 @@ def exists(*, uri: str) -> bool: try: with open(uri, "rb"): return True - except IOError: + except OSError: return False diff --git a/main.py b/main.py index 4233748..7a3ff9d 100644 --- a/main.py +++ b/main.py @@ -9,8 +9,7 @@ logger = logging.getLogger(__name__) -class TestFlow(Flow): - ... +class TestFlow(Flow): ... @TestFlow.register @@ -65,12 +64,10 @@ def __call__(self, two: Two, five: Five) -> None: print(self.end) -class DockerFlow(TestFlow): - ... +class DockerFlow(TestFlow): ... -class ThreadFlow(TestFlow): - ... +class ThreadFlow(TestFlow): ... flow: Flow diff --git a/pyproject.toml b/pyproject.toml index 8319b03..9b5d30c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,19 +66,6 @@ exclude_lines = [ "@overload", ] -[tool.flake8] -exclude = [ - ".venv", -] -ignore = [ - "E221", - "E251", - "W503", - "E203", -] -max-complexity = 10 -max-line-length = 120 - [tool.isort] line_length = 120 profile = "black" @@ -98,3 +85,38 @@ markers = [ "asyncio", "flow", ] + +[tool.ruff] +line-length = 120 +target-version = "py38" + +select = ["E", "F", "W", "I", "PGH", "UP"] +ignore = [ + "E701", # Multiple statements on one line (colon) + "PGH003", # Use specific rule codes when ignoring type issues + "PGH004", # Use specific rule codes when using `noqa` +] + +# Exclude a variety of commonly ignored directories. +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".hg", + ".mypy_cache", + ".nox", + ".pants.d", + ".pytype", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "venv", +] diff --git a/requirements.dev.txt b/requirements.dev.txt index 11ac7aa..4dc0641 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -1,8 +1,6 @@ black build coverage[toml] -flake8 -flake8-type-checking Flake8-pyproject isort mypy @@ -11,6 +9,7 @@ pytest pytest-asyncio pytest-cov rstcheck +ruff snooty-lextudio sphinx sphinx-immaterial diff --git a/requirements.txt b/requirements.txt index 91f5431..88c7bae 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,6 @@ boto3-stubs[batch] cloudpickle smart_open svix-ksuid + +# Constraints +pyyaml<6.0 diff --git a/tests/configurations/test_hooks.py b/tests/configurations/test_hooks.py index 93240c0..ab595a0 100644 --- a/tests/configurations/test_hooks.py +++ b/tests/configurations/test_hooks.py @@ -8,28 +8,28 @@ class TestAnnotation: def test_annotate(self) -> None: def func() -> Generator[None, None, None]: - ... + yield func = hooks.annotation.annotate(func, hooks.annotation.execution) assert hooks.annotation.get(func) == hooks.annotation.execution def test_execution(self) -> None: def func() -> Generator[None, None, None]: - ... + yield func = hooks.execution(func) assert hooks.annotation.get(func) == hooks.annotation.execution def test_retry(self) -> None: def func() -> Generator[None, None, None]: - ... + yield func = hooks.retry(func) assert hooks.annotation.get(func) == hooks.annotation.retry def test_submission(self) -> None: def func() -> Generator[None, None, None]: - ... + yield func = hooks.submission(func) assert hooks.annotation.get(func) == hooks.annotation.submission diff --git a/tests/configurations/test_layers.py b/tests/configurations/test_layers.py index db975ed..1b85d50 100644 --- a/tests/configurations/test_layers.py +++ b/tests/configurations/test_layers.py @@ -71,22 +71,18 @@ def _flow(self, flow: Flow) -> None: self.flow = flow @self.flow.register - class A(Layer): - ... + class A(Layer): ... @self.flow.register - class B(Layer): - ... + class B(Layer): ... @self.flow.register( foreach=ForEach(parameters=[Parameter(layer=A, attribute="foo"), Parameter(layer=B, attribute="bar")]) ) - class C(Layer): - ... + class C(Layer): ... @self.flow.register(foreach=ForEach(parameters=[Parameter(layer=C, attribute="foo", index=None)])) - class D(Layer): - ... + class D(Layer): ... self.A = A self.B = B diff --git a/tests/configurations/test_schedulers.py b/tests/configurations/test_schedulers.py index d5f7ce5..647799f 100644 --- a/tests/configurations/test_schedulers.py +++ b/tests/configurations/test_schedulers.py @@ -13,8 +13,7 @@ @asynccontextmanager async def coroutine(path: str) -> AsyncGenerator[Mock, None]: - async def func(*args: Any, **kwargs: Any) -> None: - ... + async def func(*args: Any, **kwargs: Any) -> None: ... with patch(path) as mock: mock.return_value = func @@ -38,16 +37,13 @@ async def test_schedule(self, layer: Layer) -> None: ) def test_runnable(self) -> None: - class A(Layer): - ... + class A(Layer): ... class B(Layer): - def __call__(self, a: A) -> None: - ... + def __call__(self, a: A) -> None: ... class C(Layer): - def __call__(self, a: A) -> None: - ... + def __call__(self, a: A) -> None: ... dependencies: Dict[str, Set[str]] = {"A": set(), "B": {"A"}, "C": {"A"}} diff --git a/tests/conftest.py b/tests/conftest.py index c8c1fba..81ecbbc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,8 +6,7 @@ @pytest.fixture() def flow() -> Flow: - class TestFlow(Flow): - ... + class TestFlow(Flow): ... flow = TestFlow(datastore=datastores.Memory(), executor=executors.Thread()) flow.execution("test-execution") diff --git a/tests/flows/test_branch.py b/tests/flows/test_branch.py index d370258..dde7f12 100644 --- a/tests/flows/test_branch.py +++ b/tests/flows/test_branch.py @@ -6,8 +6,7 @@ from laminar.configurations import datastores, executors -class BranchFlow(Flow): - ... +class BranchFlow(Flow): ... @BranchFlow.register diff --git a/tests/flows/test_composition.py b/tests/flows/test_composition.py index 28ad702..c5679af 100644 --- a/tests/flows/test_composition.py +++ b/tests/flows/test_composition.py @@ -7,8 +7,7 @@ from laminar.types import unwrap -class Flow1(Flow): - ... +class Flow1(Flow): ... @Flow1.register @@ -17,8 +16,7 @@ def __call__(self) -> None: self.foo = "bar" -class Flow2(Flow): - ... +class Flow2(Flow): ... @Flow2.register @@ -27,8 +25,7 @@ def __call__(self, parameters: Parameters) -> None: self.foo = parameters.foo -class Flow3(Flow): - ... +class Flow3(Flow): ... @Flow3.register @@ -53,8 +50,7 @@ def test_flow() -> None: assert flow3.execution(unwrap(execution.id)).layer(C).foo == "bar" -class CombinedFlow(Flow1, Flow2, Flow3): - ... +class CombinedFlow(Flow1, Flow2, Flow3): ... @pytest.mark.flow diff --git a/tests/flows/test_conditional_branching.py b/tests/flows/test_conditional_branching.py index 14db359..e35c3aa 100644 --- a/tests/flows/test_conditional_branching.py +++ b/tests/flows/test_conditional_branching.py @@ -6,8 +6,7 @@ from laminar.configurations import datastores, executors, hooks -class ConditionalFlow(Flow): - ... +class ConditionalFlow(Flow): ... @ConditionalFlow.register diff --git a/tests/flows/test_foreach.py b/tests/flows/test_foreach.py index 91d9a5b..5a25a97 100644 --- a/tests/flows/test_foreach.py +++ b/tests/flows/test_foreach.py @@ -10,8 +10,7 @@ from laminar.types import unwrap -class ForeachFlow(Flow): - ... +class ForeachFlow(Flow): ... @ForeachFlow.register diff --git a/tests/flows/test_grid.py b/tests/flows/test_grid.py index 89e81eb..e4370b1 100644 --- a/tests/flows/test_grid.py +++ b/tests/flows/test_grid.py @@ -9,8 +9,7 @@ from laminar.configurations.layers import ForEach, Parameter -class SingleGridFlow(Flow): - ... +class SingleGridFlow(Flow): ... @SingleGridFlow.register @@ -50,8 +49,7 @@ def test_grid() -> None: assert execution.layer(C).result == [("a", 1), ("b", 1), ("a", 2), ("b", 2), ("a", 3), ("b", 3)] -class MultiGridFlow(Flow): - ... +class MultiGridFlow(Flow): ... @MultiGridFlow.register diff --git a/tests/flows/test_linear.py b/tests/flows/test_linear.py index 3ad7c68..a25667a 100644 --- a/tests/flows/test_linear.py +++ b/tests/flows/test_linear.py @@ -6,8 +6,7 @@ from laminar.configurations import datastores, executors -class LinearFlow(Flow): - ... +class LinearFlow(Flow): ... @LinearFlow.register diff --git a/tests/flows/test_parameters.py b/tests/flows/test_parameters.py index 363defa..3aa5ba3 100644 --- a/tests/flows/test_parameters.py +++ b/tests/flows/test_parameters.py @@ -6,8 +6,7 @@ from laminar.configurations import datastores, executors -class ParameterFlow(Flow): - ... +class ParameterFlow(Flow): ... @ParameterFlow.register diff --git a/tests/flows/test_resume.py b/tests/flows/test_resume.py index 4fc03b2..eaf8423 100644 --- a/tests/flows/test_resume.py +++ b/tests/flows/test_resume.py @@ -6,14 +6,12 @@ from laminar.configurations import datastores, executors -class ResumeFlow(Flow): - ... +class ResumeFlow(Flow): ... @ResumeFlow.register class A(Layer): - def __call__(self) -> None: - ... + def __call__(self) -> None: ... @ResumeFlow.register @@ -27,8 +25,7 @@ def __call__(self, a: A) -> None: @ResumeFlow.register class C(Layer): - def __call__(self, b: B) -> None: - ... + def __call__(self, b: B) -> None: ... @pytest.mark.flow @@ -39,8 +36,7 @@ def test_flow() -> None: # Catch failure try: flow(execution=execution_id) - except RuntimeError: - ... + except RuntimeError: ... execution = flow.execution(execution_id) diff --git a/tests/test_components.py b/tests/test_components.py index 204daee..7bf4302 100644 --- a/tests/test_components.py +++ b/tests/test_components.py @@ -35,8 +35,7 @@ def test_equality(self) -> None: assert Layer() == "Layer" assert Layer() == Layer() - class Test(Layer): - ... + class Test(Layer): ... assert Layer() != Test() assert Layer() != 0 @@ -48,8 +47,7 @@ def test_pickle(self) -> None: def test_name(self) -> None: assert Layer().name == "Layer" - class Subclass(Layer): - ... + class Subclass(Layer): ... assert Subclass().name == "Subclass" @@ -59,33 +57,27 @@ def test_state(self) -> None: def test_dependencies(self, flow: Flow) -> None: @flow.register - class Dep1(Layer): - ... + class Dep1(Layer): ... @flow.register - class Dep2(Layer): - ... + class Dep2(Layer): ... @flow.register class Test(Layer): - def __call__(self, dep1: Dep1, dep2: Dep2) -> None: - ... + def __call__(self, dep1: Dep1, dep2: Dep2) -> None: ... assert flow.execution.layer(Test).dependencies == {"Dep1", "Dep2"} def test__dependencies(self, flow: Flow) -> None: @flow.register - class Dep1(Layer): - ... + class Dep1(Layer): ... @flow.register - class Dep2(Layer): - ... + class Dep2(Layer): ... @flow.register class Test(Layer): - def __call__(self, dep1: Dep1, dep2: Dep2) -> None: - ... + def __call__(self, dep1: Dep1, dep2: Dep2) -> None: ... assert flow.execution.layer(Test)._dependencies == {Dep1(), Dep2()} @@ -146,24 +138,20 @@ class TestFLow: def test_init(self) -> None: with pytest.raises(FlowError): - class InitFlow(Flow): - ... + class InitFlow(Flow): ... InitFlow(datastore=Memory()) def test_dependencies(self, flow: Flow) -> None: @flow.register - class Dep1(Layer): - ... + class Dep1(Layer): ... @flow.register - class Dep2(Layer): - ... + class Dep2(Layer): ... @flow.register class Test(Layer): - def __call__(self, dep1: Dep1, dep2: Dep2) -> None: - ... + def __call__(self, dep1: Dep1, dep2: Dep2) -> None: ... assert flow.dependencies == {"Dep1": set(), "Dep2": set(), "Parameters": set(), "Test": {"Dep1", "Dep2"}} assert flow.dependents == {"Dep1": {"Test"}, "Dep2": {"Test"}} @@ -187,8 +175,7 @@ def test_call_execute(self, flow: Flow) -> None: flow.execution = mock_execution @flow.register - class Test(Layer): - ... + class Test(Layer): ... flow() @@ -199,17 +186,14 @@ class Test(Layer): def test_register(self, flow: Flow) -> None: @flow.register - class Dep1(Layer): - ... + class Dep1(Layer): ... @flow.register - class Dep2(Layer): - ... + class Dep2(Layer): ... @flow.register class Test(Layer): - def __call__(self, dep1: Dep1, dep2: Dep2) -> None: - ... + def __call__(self, dep1: Dep1, dep2: Dep2) -> None: ... assert flow.registry == {"Dep1": Dep1(), "Dep2": Dep2(), "Test": Test(), "Parameters": Parameters()} assert flow.dependencies == {"Dep1": set(), "Dep2": set(), "Parameters": set(), "Test": {"Dep1", "Dep2"}} @@ -217,8 +201,7 @@ def __call__(self, dep1: Dep1, dep2: Dep2) -> None: def test_layer_duplicate(self, flow: Flow) -> None: @flow.register - class Test(Layer): - ... + class Test(Layer): ... with pytest.raises(FlowError): @@ -228,8 +211,7 @@ class Test(Layer): # type: ignore # noqa def test_layer(self, flow: Flow) -> None: @flow.register - class Test(Layer): - ... + class Test(Layer): ... assert flow.execution.layer("Test"), Test() assert flow.execution.layer(Test), Test() @@ -241,8 +223,6 @@ def test_results(self, flow: Flow) -> None: class TestExecution: - def test_execute(self) -> None: - ... + def test_execute(self) -> None: ... - def test_schedule(self) -> None: - ... + def test_schedule(self) -> None: ... diff --git a/tests/test_types.py b/tests/test_types.py index b5fd6fb..81efb72 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -5,13 +5,11 @@ from laminar import Flow, Layer, types -class HintFlow(Flow): - ... +class HintFlow(Flow): ... @HintFlow.register -class Ref(Layer): - ... +class Ref(Layer): ... flow = HintFlow() @@ -19,21 +17,18 @@ class Ref(Layer): class TestHints: def test_reference(self) -> None: - def test(a: "Ref") -> None: - ... + def test(a: "Ref") -> None: ... assert types.hints(flow.execution, test) == (Ref(flow=flow),) def test_forward_reference(self) -> None: - def test(a: "ForwardRef") -> None: - ... + def test(a: "ForwardRef") -> None: ... assert types.hints(flow.execution, test) == (ForwardRef(flow=flow),) @HintFlow.register -class ForwardRef(Layer): - ... +class ForwardRef(Layer): ... class TestUnwrap: