Skip to content
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

upgrade: Ruff #13

Merged
merged 1 commit into from
Oct 1, 2023
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
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
2 changes: 1 addition & 1 deletion Make.build
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ check:
.PHONY: setup
setup:
$(INSTALL) pip
$(INSTALL) --requirement requirements.dev.txt
$(INSTALL) --constraint constraints.txt --requirement requirements.dev.txt
5 changes: 3 additions & 2 deletions 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 Expand Up @@ -74,7 +75,7 @@ test: lint
.PHONY: upgrade
upgrade:
$(VENV) $(INSTALL) --upgrade pip wheel
$(VENV) $(INSTALL) --upgrade --editable .[dev]
$(VENV) $(INSTALL) --constraint constraints.txt --upgrade --editable .[dev]

.PHONY: venv
venv:
Expand Down
1 change: 1 addition & 0 deletions constraints.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyyaml<5.4
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
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
Loading