From 1d919762e6269ebc149fbadb771258fd392fe869 Mon Sep 17 00:00:00 2001 From: Yicheng Luo Date: Mon, 12 Feb 2024 21:25:32 +0000 Subject: [PATCH] Use ruff format instead of black --- .pre-commit-config.yaml | 16 ++++-------- docs/configuration.rst | 4 +-- docs/lxm.toml | 1 - .../xm_cluster/packaging/container_builder.py | 8 ++---- lxm3/xm_cluster/requirements.py | 9 +++---- pyproject.toml | 25 +++---------------- tests/execution_test.py | 4 +-- 7 files changed, 17 insertions(+), 50 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c7b746f..932ab97 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,18 +8,12 @@ repos: - id: end-of-file-fixer - id: check-yaml - id: check-added-large-files -- repo: https://github.com/psf/black - rev: 23.3.0 - hooks: - - id: black - # It is recommended to specify the latest version of Python - # supported by your project here, or alternatively use - # pre-commit's default_language_version, see - # https://pre-commit.com/#top_level-default_language_version - language_version: python3.10 - exclude: ^lxm3/_vendor - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.0.283 + rev: v0.1.4 hooks: - id: ruff + args: [ --fix ] + # Run the formatter. + - id: ruff-format + exclude: ^lxm3/_vendor diff --git a/docs/configuration.rst b/docs/configuration.rst index 830ad37..03f4ba6 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -24,7 +24,7 @@ Environment variables The following environment variables can be used to configure the LXM3 launcher: -1. ``LXM_CONFIG``: Path to the configuration file. -2. ``LXM_PROJECT``: Name of the project to use. This is used as +1. ``LXM_CONFIG``: Path to the configuration file. +2. ``LXM_PROJECT``: Name of the project to use. This is used as the sub-directory used when staging jobs. 3. ``LXM_CLUSTER``: Name of default cluster to use for launching jobs. diff --git a/docs/lxm.toml b/docs/lxm.toml index ad1ebd5..f83c2c9 100644 --- a/docs/lxm.toml +++ b/docs/lxm.toml @@ -23,4 +23,3 @@ user = "" [clusters.storage] # Replace with the path to a staging directory on the cluster. lxm3 uses this directory for storing all files required to run your job. staging = "/lxm3-staging" - diff --git a/lxm3/xm_cluster/packaging/container_builder.py b/lxm3/xm_cluster/packaging/container_builder.py index cf89c8c..17e6d96 100644 --- a/lxm3/xm_cluster/packaging/container_builder.py +++ b/lxm3/xm_cluster/packaging/container_builder.py @@ -19,9 +19,7 @@ def pdm_dockerfile(base_image: str, lock_file: str): FROM {base_image} COPY --from=builder /requirements.txt /requirements.txt RUN pip install --no-cache-dir -r /requirements.txt -""".format( - base_image=base_image, lock_file=lock_file - ) +""".format(base_image=base_image, lock_file=lock_file) def python_container_dockerfile(base_image: str, requirements: str): @@ -31,9 +29,7 @@ def python_container_dockerfile(base_image: str, requirements: str): COPY {requirements} /requirements.txt RUN pip install --no-cache-dir -r /requirements.txt -""".format( - base_image=base_image, requirements=requirements - ) +""".format(base_image=base_image, requirements=requirements) def build_image_by_dockerfile(image_name: str, dockerfile: str, path: str): diff --git a/lxm3/xm_cluster/requirements.py b/lxm3/xm_cluster/requirements.py index f8275a6..587dee2 100644 --- a/lxm3/xm_cluster/requirements.py +++ b/lxm3/xm_cluster/requirements.py @@ -29,9 +29,7 @@ def __getitem__(cls, resource_name: str) -> "ResourceType": try: return super().__getitem__(resource_name.upper()) except KeyError: - raise KeyError( - f"Unknown {cls.__name__} {resource_name!r}" - ) # pylint: disable=raise-missing-from + raise KeyError(f"Unknown {cls.__name__} {resource_name!r}") # pylint: disable=raise-missing-from class ResourceType(enum.Enum, metaclass=_CaseInsensetiveResourceTypeMeta): @@ -54,9 +52,7 @@ def __str__(self): return self._name_ -def _enum_subset( - class_name: str, values: Iterable[ResourceType] -) -> type: # pylint: disable=g-bare-generic +def _enum_subset(class_name: str, values: Iterable[ResourceType]) -> type: # pylint: disable=g-bare-generic """Returns an enum subset class. The class is syntactically equivalent to an enum with the given resource @@ -204,6 +200,7 @@ class JobRequirements: service_tier: A service tier at which the job should run. replicas: Number of identical tasks to run within a job """ + # pyformat:enable task_requirements: ResourceDict diff --git a/pyproject.toml b/pyproject.toml index 6510112..f927e3b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -77,34 +77,17 @@ test = "pytest lxm3 tests" test-cov = "pytest --cov=lxm3 --cov-report=xml tests" cov = {composite = ["test-cov", "coverage report"]} docs = "sphinx-build -b html docs docs/build/html -j auto" -lint.shell = "ruff . && black --check --diff ." -fmt.shell = "black . && ruff --fix ." - -[tool.black] -line-length = 88 -target-version = ['py310'] -include = '\.pyi?$' -exclude = ''' -/( - \.eggs - | \.git - | docs - | .github - | third_party - | _vendor - | scratch - | .venv -)/ -''' +lint.shell = "ruff ." +fmt.shell = "ruff format ." [tool.ruff] -line-length = 120 select = [ "E", # pycodestyle "F", # pyflakes - "I", + "I", # isort ] exclude = ["_vendor", "xm", ".venv"] +ignore = ["E501"] [tool.ruff.extend-per-file-ignores] "__init__.py" = ["F401"] diff --git a/tests/execution_test.py b/tests/execution_test.py index 73faf67..47ec236 100644 --- a/tests/execution_test.py +++ b/tests/execution_test.py @@ -252,9 +252,7 @@ def main(_): """\ #!/usr/bin/env bash {} run.py $@ -""".format( - sys.executable - ), +""".format(sys.executable), ) executable = xm_cluster.Command( "foo", "./entrypoint.sh", resource_uri=tmpf.full_path