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 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
208 changes: 29 additions & 179 deletions poetry.lock

Large diffs are not rendered by default.

22 changes: 11 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,9 @@ privacy = [
project-name = "Temporal Python"
sidebar-expand-depth = 2

[tool.ruff]
target-version = "py38"

[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
13 changes: 7 additions & 6 deletions temporalio/api/batch/v1/message_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion temporalio/api/batch/v1/message_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""

import builtins
import sys

import google.protobuf.descriptor
import google.protobuf.message
import google.protobuf.timestamp_pb2
import sys

import temporalio.api.common.v1.message_pb2
import temporalio.api.enums.v1.batch_operation_pb2
import temporalio.api.enums.v1.reset_pb2
Expand Down
1 change: 1 addition & 0 deletions temporalio/api/cluster/v1/message_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion temporalio/api/cluster/v1/message_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""

import builtins
import collections.abc
import sys

import google.protobuf.descriptor
import google.protobuf.internal.containers
import google.protobuf.message
import google.protobuf.timestamp_pb2
import sys

import temporalio.api.enums.v1.cluster_pb2
import temporalio.api.enums.v1.common_pb2
import temporalio.api.version.v1.message_pb2
Expand Down
1 change: 1 addition & 0 deletions temporalio/api/cluster/v1/message_pb2_grpc.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""

import grpc
Loading
Loading