Skip to content

Commit

Permalink
precommit: drop Black in favor of Ruff (#19380)
Browse files Browse the repository at this point in the history
  • Loading branch information
awaelchli committed Jan 31, 2024
1 parent 1ebcfae commit 7faf678
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
16 changes: 1 addition & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,11 @@ repos:
- flake8-return

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.3"
rev: "v0.1.15"
hooks:
- id: ruff
args: ["--fix", "--preview"]

- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
name: Format code
exclude: docs/source-app

- repo: https://github.com/asottile/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
args: ["--line-length=120"]
exclude: docs/source-app

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
hooks:
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ ignore-init-module-imports = true
"S113", # todo: Probable use of requests call without timeout
"S301", # todo: `pickle` and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue
"S324", # todo: Probable use of insecure hash functions in `hashlib`
"S403", # todo: `pickle`, `cPickle`, `dill`, and `shelve` modules are possibly insecure
"S404", # todo: `subprocess` module is possibly insecure
"S602", # todo: `subprocess` call with `shell=True` identified, security issue
"S603", # todo: `subprocess` call: check for execution of untrusted input
"S605", # todo: Starting a process with a shell: seems safe, but may be changed in the future; consider rewriting without `shell`
Expand All @@ -107,6 +109,8 @@ ignore-init-module-imports = true
"S113", # todo: Probable use of requests call without timeout
"S311", # todo: Standard pseudo-random generators are not suitable for cryptographic purposes
"S108", # todo: Probable insecure usage of temporary file or directory: "/tmp/sys-customizations-sync"
"S403", # `pickle`, `cPickle`, `dill`, and `shelve` modules are possibly insecure
"S404", # `subprocess` module is possibly insecure
"S602", # todo: `subprocess` call with `shell=True` identified, security issue
"S603", # todo: `subprocess` call: check for execution of untrusted input
"S605", # todo: Starting a process with a shell: seems safe, but may be changed in the future; consider rewriting without `shell`
Expand Down
10 changes: 6 additions & 4 deletions tests/tests_pytorch/utilities/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import pytest
import torch
from lightning.fabric.utilities.imports import _TORCH_GREATER_EQUAL_2_1
from lightning.pytorch import LightningModule, Trainer
from lightning.pytorch.demos.boring_classes import BoringModel
from lightning.pytorch.utilities.compile import from_compiled, to_uncompiled
Expand All @@ -26,7 +25,8 @@
from tests_pytorch.helpers.runif import RunIf


@pytest.mark.skipif(sys.platform == "darwin" and not _TORCH_GREATER_EQUAL_2_1, reason="Fix for MacOS in PyTorch 2.1")
# https://github.com/pytorch/pytorch/issues/95708
@pytest.mark.skipif(sys.platform == "darwin", reason="fatal error: 'omp.h' file not found")
@RunIf(dynamo=True)
@mock.patch("lightning.pytorch.trainer.call._call_and_handle_interrupt")
def test_trainer_compiled_model(_, tmp_path, monkeypatch, mps_count_0):
Expand Down Expand Up @@ -112,7 +112,8 @@ def has_dynamo(fn):
assert not has_dynamo(to_uncompiled_model.predict_step)


@pytest.mark.skipif(sys.platform == "darwin" and not _TORCH_GREATER_EQUAL_2_1, reason="Fix for MacOS in PyTorch 2.1")
# https://github.com/pytorch/pytorch/issues/95708
@pytest.mark.skipif(sys.platform == "darwin", reason="fatal error: 'omp.h' file not found")
@RunIf(dynamo=True)
def test_trainer_compiled_model_that_logs(tmp_path):
class MyModel(BoringModel):
Expand All @@ -137,7 +138,8 @@ def training_step(self, batch, batch_idx):
assert set(trainer.callback_metrics) == {"loss"}


@pytest.mark.skipif(sys.platform == "darwin" and not _TORCH_GREATER_EQUAL_2_1, reason="Fix for MacOS in PyTorch 2.1")
# https://github.com/pytorch/pytorch/issues/95708
@pytest.mark.skipif(sys.platform == "darwin", reason="fatal error: 'omp.h' file not found")
@RunIf(dynamo=True)
def test_trainer_compiled_model_test(tmp_path):
model = BoringModel()
Expand Down

0 comments on commit 7faf678

Please sign in to comment.