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

Use ruff to auto-format code and sort imports. #566

Merged
merged 9 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
208 changes: 29 additions & 179 deletions poetry.lock

Large diffs are not rendered by default.

27 changes: 16 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ script = "build.py"
# a setup file, but we are using setuptools Rust manually in our build.py which
# needs a setup file.
# TODO(cretz): Find a way to not require a setup file since that is going away
# at some point in Poetry. Revisit Maturin or fine some other approach.
# at some point in Poetry. Revisit Maturin or find some other approach.
generate-setup-file = true

[tool.poetry.urls]
Expand All @@ -41,10 +41,8 @@ types-protobuf = ">=3.20"
typing-extensions = "^4.2.0"

[tool.poetry.dev-dependencies]
black = "^23.1.0"
cibuildwheel = "^2.17.0"
grpcio-tools = "^1.48.0"
isort = "^5.11.5"
mypy = "^1.0.0"
mypy-protobuf = "^3.3.0"
psutil = "^5.9.3"
Expand All @@ -54,6 +52,7 @@ pydoctor = "^23.4.1"
pytest = "^7.4"
pytest-asyncio = "^0.21"
pytest-timeout = "^2.2"
ruff = "^0.5.0"
setuptools = ">=65.0.0"
setuptools-rust = ">=1.3.0"
toml = "^0.10.2"
Expand All @@ -64,16 +63,19 @@ wheel = "^0.42.0"
opentelemetry = ["opentelemetry-api", "opentelemetry-sdk"]
grpc = ["grpcio"]

[tool.poetry.group.dev.dependencies]
ruff = "^0.5.0"

[tool.poe.tasks]
build-develop = "python scripts/setup_bridge.py develop"
build-develop-with-release = { cmd = "python scripts/setup_bridge.py develop", env = { TEMPORAL_BUILD_RELEASE = "1" }}
fix-wheel = "python scripts/fix_wheel.py"
format = [{cmd = "black ."}, {cmd = "isort ."}]
format = [{cmd = "ruff check --select I --fix"}, {cmd = "ruff format"}, ]
gen-docs = "python scripts/gen_docs.py"
gen-protos = "python scripts/gen_protos.py"
lint = [
{cmd = "black --check ."},
{cmd = "isort --check-only ."},
{cmd = "ruff check --select I"},
{cmd = "ruff format --check"},
{ref = "lint-types"},
{ref = "lint-docs"},
]
Expand Down Expand Up @@ -125,11 +127,6 @@ build-verbosity = "1"
before-all = "curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain stable -y && yum install -y openssl-devel"
environment = { PATH = "$PATH:$HOME/.cargo/bin", CARGO_NET_GIT_FETCH_WITH_CLI = "true" }

[tool.isort]
profile = "black"
skip_gitignore = true
extend_skip = ["./temporalio/bridge/sdk-core", "./temporalio/bridge/target"]

[tool.mypy]
ignore_missing_imports = true
exclude = [
Expand Down Expand Up @@ -177,6 +174,14 @@ privacy = [
project-name = "Temporal Python"
sidebar-expand-depth = 2

[tool.ruff]
target-version = "py38"
extend-exclude = [
"temporalio/api",
"temporalio/bridge",
"tests/worker/workflow_sandbox/testmodules/proto",
dandavison marked this conversation as resolved.
Show resolved Hide resolved
]

[build-system]
build-backend = "poetry.core.masonry.api"
requires = ["poetry-core>=1.0.0", "setuptools", "wheel", "setuptools-rust", "protoc-wheel-0"]
14 changes: 6 additions & 8 deletions temporalio/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,19 @@


@overload
def defn(fn: CallableType) -> CallableType:
...
def defn(fn: CallableType) -> CallableType: ...


@overload
def defn(
*, name: Optional[str] = None, no_thread_cancel_exception: bool = False
) -> Callable[[CallableType], CallableType]:
...
) -> Callable[[CallableType], CallableType]: ...


@overload
def defn(
*, no_thread_cancel_exception: bool = False, dynamic: bool = False
) -> Callable[[CallableType], CallableType]:
...
) -> Callable[[CallableType], CallableType]: ...


def defn(
Expand Down Expand Up @@ -364,7 +361,7 @@ async def wait_for_worker_shutdown() -> None:


def wait_for_worker_shutdown_sync(
timeout: Optional[Union[timedelta, float]] = None
timeout: Optional[Union[timedelta, float]] = None,
) -> None:
"""Synchronously block while waiting for shutdown to be called on the
worker.
Expand Down Expand Up @@ -539,7 +536,8 @@ def _apply_to_callable(
fn=fn,
# iscoroutinefunction does not return true for async __call__
# TODO(cretz): Why can't MyPy handle this?
is_async=inspect.iscoroutinefunction(fn) or inspect.iscoroutinefunction(fn.__call__), # type: ignore
is_async=inspect.iscoroutinefunction(fn)
or inspect.iscoroutinefunction(fn.__call__), # type: ignore
no_thread_cancel_exception=no_thread_cancel_exception,
),
)
Expand Down
Loading
Loading