Skip to content

Commit

Permalink
Use ruff format instead of black
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanluoyc committed Feb 12, 2024
1 parent a006d7c commit 1d91976
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 50 deletions.
16 changes: 5 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 0 additions & 1 deletion docs/lxm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ user = "<TODO>"
[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 = "<absolute path to your home directory>/lxm3-staging"

8 changes: 2 additions & 6 deletions lxm3/xm_cluster/packaging/container_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
9 changes: 3 additions & 6 deletions lxm3/xm_cluster/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
25 changes: 4 additions & 21 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
4 changes: 1 addition & 3 deletions tests/execution_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1d91976

Please sign in to comment.