Skip to content

Commit

Permalink
chore: remove references to black from the project (#2674)
Browse files Browse the repository at this point in the history
# Description

There are a few mentions of `black` in the project, but they seem
inconsistent;

- In `.github/workflows/docs.yml`, we use black to validate the
formatting of Python code in the docs. However, there is no set-up or
instructions to format code locally. Of course this is not a big issue;
fixing the formatting is trivial when this gives an error by installing
`black`.
  ```yaml
  - uses: psf/black@stable
    with:
      src: docs/src/python
  ``` 
- In `.github/workflows/python_build.yml` `black` seems to be installed
but unused.
- There is some configuration for `black` in `python/pyproject.toml`,
even though the formatter for the project is `ruff`.

This PR aims to solve these inconsistencies:

- Remove the references to `black` listed above.
- Use `ruff` as a formatter for the `docs` to be consistent with the
`python` directory.
- Add a small `Makefile` to the `docs` directory, with a `format` and a
`check` command.

## Considered alternative

I also considered adding the `make` commands to `python/Makefile`,
similar to the `build-docs` command:
  ```make
  .PHONY: format-docs-py
  format-docs-py: ## Format python files in the docs directory
	  $(info --- format Python code in docs ---)
	  (cd ../docs; ruff format .)
  
  .PHONY: check-docs-py
check-docs-py: ## Check if python files in the docs directory are
formatted
	  $(info --- check Python code in docs ---)
	  (cd ../docs; ruff format --check .)
  ```

However, this solution has the disadvantage that we need to either
install the complete virtual environment in the `docs.yml` workflow, or
hardcode the version of `ruff` there, e.g.

```
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - run: |
          cd python
          # Should be the same as in python/pyproject.toml
          pip install ruff==0.5.2 
          make check-docs-py
```

---------

Co-authored-by: R. Tyler Croy <[email protected]>
Co-authored-by: Ion Koutsouris <[email protected]>
  • Loading branch information
3 people authored Jul 21, 2024
1 parent 9bb17a4 commit be6e372
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: psf/black@stable
with:
src: docs/src/python
- run: |
cd docs
make check
build-deploy:
needs:
Expand Down
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.DEFAULT_GOAL := help

.PHONY: install-ruff
install-ruff: ## install ruff
$(info --- Installing ruff ---)
pip install ruff==0.5.2

.PHONY: format
format: install-ruff ## format code with ruff
$(info --- format Python code in docs ---)
ruff format .

.PHONY: check
check: install-ruff ## check if code is formatted with ruff
$(info --- format Python code in docs ---)
ruff format --check .

.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
4 changes: 0 additions & 4 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ warn_return_any = false
implicit_reexport = true
strict_equality = true

[tool.black]
include = '\.pyi?$'
exclude = "venv"

[tool.ruff.lint]
select = [
# pycodestyle error
Expand Down

0 comments on commit be6e372

Please sign in to comment.