Skip to content

Commit

Permalink
Use ruff instead of flake8, isort, black and pyupgrade (#202)
Browse files Browse the repository at this point in the history
* Use ruff linter and formatter, add more linter rules
* Remove other unnecessary hooks
  • Loading branch information
danielhollas authored Feb 7, 2024
1 parent 3d7c9d2 commit 3d2cfb1
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 62 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ jobs:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
default-image:
- '' # use the application default
- aiidalab/aiidalab-docker-stack:latest # This is the old stack
- '' # use the application default
- aiidalab/aiidalab-docker-stack:latest # This is the old stack

steps:

Expand Down
47 changes: 9 additions & 38 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-json
- id: check-yaml
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace

Expand All @@ -17,25 +17,13 @@ repos:
hooks:
- id: yamlfmt

- repo: https://github.com/mgedmin/check-manifest
rev: '0.49'
hooks:
- id: check-manifest

- repo: https://github.com/psf/black
rev: 23.12.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.1
hooks:
- id: black
- id: ruff-format
exclude: ^docs/

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
args: [--count, --show-source, --statistics]
additional_dependencies:
- flake8-bugbear
- flake8-unused-arguments==0.0.9
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
Expand All @@ -47,24 +35,7 @@ repos:
- types-tabulate
- types-toml

- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.5.0
hooks:
- id: setup-cfg-fmt

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
args: [--profile, black, --filter-files]

- repo: https://github.com/sirosen/check-jsonschema
rev: 0.27.3
hooks:
- id: check-github-workflows

- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
- repo: https://github.com/mgedmin/check-manifest
rev: '0.49'
hooks:
- id: pyupgrade
args: [--py38-plus]
- id: check-manifest
6 changes: 3 additions & 3 deletions aiidalab_launch/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@
pass_app_state = click.make_pass_decorator(ApplicationState, ensure=True)


def exception_handler(exception_type, exception, traceback): # noqa: U100
def exception_handler(exception_type, exception, _traceback):
click.echo(f"Unexpected {exception_type.__name__}: {exception}", err=True)
click.echo(
"Use verbose mode `aiidalab-launch --verbose` to see full stack trace", err=True
)


def with_profile(cmd):
def callback(ctx, param, value): # noqa: U100
def callback(ctx, _param, value):
app_state = ctx.ensure_object(ApplicationState)
name = value or app_state.config.default_profile
LOGGER.info(f"Using profile: {name}")
Expand Down Expand Up @@ -320,7 +320,7 @@ async def _async_start(
if not force:
conflict = False
with spinner("Check for potential conflicts...", delay=0.1):
async for p in _find_mount_point_conflict(
async for _p in _find_mount_point_conflict(
app_state.docker_client,
profile,
app_state.config.profiles,
Expand Down
13 changes: 4 additions & 9 deletions aiidalab_launch/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,10 @@ def confirm_with_value(value: str, text: str, abort: bool = False) -> bool:
def get_docker_mount(
container: docker.models.containers.Container, destination: PurePosixPath
) -> docker.types.Mount:
try:
mount = [
mount
for mount in container.attrs["Mounts"]
if mount["Destination"] == str(destination)
][0]
except IndexError:
raise ValueError(f"No mount point for {destination}.")
return mount
for mount in container.attrs["Mounts"]:
if mount["Destination"] == str(destination):
return mount
raise ValueError(f"No mount point for {destination}.")


def is_volume_readonly(
Expand Down
25 changes: 25 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# TODO: Move entire setup.cfg to pyproject.toml

[tool.ruff]
line-length = 88
show-fixes = true
target-version = "py38"

[tool.ruff.lint]
# TODO: Fixup all instances of B904 and enable this rule
ignore = ["E501", "B904"]
select = [
"ARG", # flake8-unused-arguments
"B", # flake8-bugbear
"E", # pycodestyle
"F", # pyflake
"I", # isort
"PLE", # pylint error rules
"PLW", # pylint warning rules
"PLC", # pylint convention rules
"RUF", # ruff-specific rules
"UP" # pyupgrade
]

[tool.ruff.lint.per-file-ignores]
"tests/*" = ["ARG001"]
8 changes: 0 additions & 8 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ tests =
pytest-cov~=4.1.0
responses~=0.23.1

[flake8]
ignore =
E501
W503
E203
per-file-ignores =
tests/*: U100, U101

[mypy]
warn_unused_configs = True
disallow_untyped_calls = True
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_add_remove_profile():
result: Result = runner.invoke(cli.cli, ["profile", "list"])
assert "new-profile" not in result.output

# Remove new-profile (again should fail)
# Remove new-profile (again - should fail)
result: Result = runner.invoke(
cli.cli, ["profile", "remove", "new-profile"], input="y\n"
)
Expand Down Expand Up @@ -251,7 +251,7 @@ def assert_status_down():
assert get_volume(instance.profile.home_mount)
assert get_volume(instance.profile.conda_volume_name())

# Start instance again should be noop.
# Start instance again - should be noop.
caplog.set_level(logging.DEBUG)
result: Result = runner.invoke(
cli.cli, ["start", "--no-browser", "--no-pull", "--wait=300"]
Expand Down

0 comments on commit 3d2cfb1

Please sign in to comment.