Skip to content

Commit

Permalink
upgrade: Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
rchui committed Oct 1, 2023
1 parent c7cd257 commit f401ae7
Show file tree
Hide file tree
Showing 25 changed files with 120 additions and 172 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
28 changes: 8 additions & 20 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'

Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.8.14
3.8
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 5 additions & 10 deletions laminar/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions laminar/configurations/datastores.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 5 additions & 9 deletions laminar/utils/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -73,7 +69,7 @@ def exists(*, uri: str) -> bool:
try:
with open(uri, "rb"):
return True
except IOError:
except OSError:
return False


Expand Down
9 changes: 3 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
logger = logging.getLogger(__name__)


class TestFlow(Flow):
...
class TestFlow(Flow): ...


@TestFlow.register
Expand Down Expand Up @@ -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
Expand Down
48 changes: 35 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
]
3 changes: 1 addition & 2 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
black
build
coverage[toml]
flake8
flake8-type-checking
Flake8-pyproject
isort
mypy
Expand All @@ -11,6 +9,7 @@ pytest
pytest-asyncio
pytest-cov
rstcheck
ruff
snooty-lextudio
sphinx
sphinx-immaterial
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ boto3-stubs[batch]
cloudpickle
smart_open
svix-ksuid

# Constraints
pyyaml<5.4
8 changes: 4 additions & 4 deletions tests/configurations/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 4 additions & 8 deletions tests/configurations/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions tests/configurations/test_schedulers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"}}

Expand Down
3 changes: 1 addition & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 1 addition & 2 deletions tests/flows/test_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from laminar.configurations import datastores, executors


class BranchFlow(Flow):
...
class BranchFlow(Flow): ...


@BranchFlow.register
Expand Down
Loading

0 comments on commit f401ae7

Please sign in to comment.