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

Replace black with ruff #470

Merged
merged 3 commits into from
May 2, 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
31 changes: 10 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,23 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-yaml
- id: check-merge-conflict

# Automatic source code formatting
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
args: [--safe, --quiet]
files: \.pyi?
types: [file]

- repo: local
hooks:
- id: ruff
name: Run ruff
stages: [commit]
name: lint with ruff
language: system
entry: ruff
entry: ruff check --force-exclude
types: [python]
require_serial: true

# Re-enable after https://github.com/DiamondLightSource/dodal/issues/311
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v1.7.1
# hooks:
# - id: mypy
# files: 'src/.*\.py$'
# additional_dependencies: [types-requests, pydantic]
# args: ["--ignore-missing-imports", "--show-traceback", "--no-strict-optional"]
Comment on lines -27 to -34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should: If we're going to remove this can we close #311?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in the template typing is not handled in precommit, you do it with tox -e type-checking (in dodal it is currently tox -e mypy), which also runs in CI. Will add a closes.

- id: ruff-format
name: format with ruff
language: system
entry: ruff format --force-exclude
types: [python]
require_serial: true
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
# Common links that should be available on every page
rst_epilog = """
.. _Diamond Light Source: http://www.diamond.ac.uk
.. _black: https://github.com/psf/black
.. _ruff: https://beta.ruff.rs/docs/
.. _mypy: http://mypy-lang.org/
.. _pre-commit: https://pre-commit.com/
Expand Down
13 changes: 4 additions & 9 deletions docs/developer/how-to/lint.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Run linting using pre-commit
============================

Code linting is handled by black_ and ruff_ run under pre-commit_.
Code linting is handled by ruff_ run under pre-commit_.

Running pre-commit
------------------
Expand All @@ -21,19 +21,14 @@ This will result in pre-commits being enabled on every repo your user clones fro
Fixing issues
-------------

If black reports an issue you can tell it to reformat all the files in the
If ruff reports an issue you can tell it to reformat all the files in the
repository::

$ black .

Likewise with ruff::

$ ruff --fix .
$ ruff check --fix .

Ruff may not be able to automatically fix all issues; in this case, you will have to fix those manually.

VSCode support
--------------

The ``.vscode/settings.json`` will run black formatting as well as
ruff checking on save. Issues will be highlighted in the editor window.
The ``.vscode/settings.json`` will run formatting as well as ruff checking on save. Issues will be highlighted in the editor window.
3 changes: 1 addition & 2 deletions docs/developer/reference/standards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ Code Standards

The code in this repository conforms to standards set by the following tools:

- black_ for code formatting
- ruff_ for style checks
- ruff_ for style checks and code formatting
- mypy_ for static type checking

.. seealso::
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ requires-python = ">=3.10"

[project.optional-dependencies]
dev = [
"black",
"mypy",
"mockito",
"pipdeptree",
Expand Down
3 changes: 1 addition & 2 deletions src/dodal/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@

class UpdatingDirectoryProvider(DirectoryProvider, ABC):
@abstractmethod
def update(self) -> None:
...
def update(self) -> None: ...
8 changes: 2 additions & 6 deletions tests/devices/unit_tests/test_focusing_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ def not_ok(_):
def test_mirror_set_voltage_sets_and_waits_happy_path(
vfm_mirror_voltages_with_set: VFMMirrorVoltages,
):
vfm_mirror_voltages_with_set._channel14_voltage_device._setpoint_v.set.return_value = (
NullStatus()
)
vfm_mirror_voltages_with_set._channel14_voltage_device._setpoint_v.set.return_value = NullStatus()
vfm_mirror_voltages_with_set._channel14_voltage_device._demand_accepted.sim_put(
MirrorVoltageDemand.OK
)
Expand Down Expand Up @@ -103,9 +101,7 @@ def test_mirror_set_voltage_sets_and_waits_set_fail(
def test_mirror_set_voltage_sets_and_waits_settle_timeout_expires(
vfm_mirror_voltages_with_set_timing_out: VFMMirrorVoltages,
):
vfm_mirror_voltages_with_set_timing_out._channel14_voltage_device._setpoint_v.set.return_value = (
NullStatus()
)
vfm_mirror_voltages_with_set_timing_out._channel14_voltage_device._setpoint_v.set.return_value = NullStatus()

status: StatusBase = vfm_mirror_voltages_with_set_timing_out.voltage_channels[
0
Expand Down
Loading