Skip to content

Commit

Permalink
fix: simplify and prepare for next release (#301)
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii authored Oct 28, 2023
1 parent e03df78 commit 1d6bbeb
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 64 deletions.
7 changes: 4 additions & 3 deletions docs/_includes/interactive_repo_review.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
<App
header={false}
deps={[
"sp-repo-review==2023.09.21",
"sp-repo-review==2023.10.27",
"repo-review==0.10.0",
"validate-pyproject==0.14",
"scikit-build-core==0.5.1",
"validate-pyproject==0.15",
"scikit-build-core==0.6.0",
"cibuildwheel==2.16.2",
]}
/>,
);
Expand Down
74 changes: 29 additions & 45 deletions docs/pages/guides/style.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,20 @@ Here is the snippet to add Black to your `.pre-commit-config.yml`:

```yaml
- repo: https://github.com/psf/black-pre-commit-mirror
rev: "23.10.0"
rev: "23.10.1"
hooks:
- id: black
```

{% details You can add a Black badge to your repo as well %}

[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

```md
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
```

```rst
```
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black
```
Expand All @@ -142,13 +144,13 @@ look like Black, but run 30x faster. Here is the snippet to add Black to your

{% details You can add a Ruff badge to your repo as well %}

[![Code style: Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/format.json))](https://github.com/astral-sh/ruff)
[![Code style: Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/format.json)](https://github.com/astral-sh/ruff)

```md
[![Code style: Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/format.json))](https://github.com/astral-sh/ruff)
[![Code style: Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/format.json)](https://github.com/astral-sh/ruff)
```

```rst
```
.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/format.json
:target: https://github.com/astral-sh/ruff
```
Expand All @@ -157,13 +159,13 @@ look like Black, but run 30x faster. Here is the snippet to add Black to your

{% endtab %} {% endtabs %}

In _very_ specific situations, you may want to retain special formatting. After
carefully deciding that it is a special use case, you can use `# fmt: on` and
`# fmt: off` around a code block to have it keep custom formatting. _Always_
consider refactoring before you try this option! Most of the time, you can find
a way to make the Blacked code look better by rewriting your code; factor out
long unreadable portions into a variable, avoid writing matrices as 1D lists,
etc.
In _very_ specific situations, like when making a 2D array, you may want to
retain special formatting. After carefully deciding that it is a special use
case, you can use `# fmt: on` and `# fmt: off` around a code block to have it
keep custom formatting. _Always_ consider refactoring before you try this
option! Most of the time, you can find a way to make the Blacked code look
better by rewriting your code; factor out long unreadable portions into a
variable, avoid writing matrices as 1D lists, etc.

{% details Documentation / README snippets support %}

Expand All @@ -177,7 +179,7 @@ markdown and restructured text. Note that because black is in
rev: "1.16.0"
hooks:
- id: blacken-docs
additional_dependencies: [black==23.10.0]
additional_dependencies: [black==23.*]
```
{% enddetails %}
Expand All @@ -195,7 +197,7 @@ pre-commit hook.
```yaml
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.1"
rev: "v0.1.3"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
Expand All @@ -209,7 +211,6 @@ inspect and undo changes in git.
```toml
[tool.ruff]
src = ["src"]
exclude = []
[tool.ruff.lint]
extend-select = [
Expand Down Expand Up @@ -239,15 +240,8 @@ extend-select = [
]
ignore = [
"PLR", # Design related pylint codes
"E501", # Line too long
"PT004", # Use underscore for non-returning fixture (use usefixture instead)
]
typing-modules = ["mypackage._compat.typing"]
unfixable = [
"T20", # Removes print statements
"F841", # Removes unused variables
]
flake8-unused-arguments.ignore-variadic-names = true
isort.required-imports = ["from __future__ import annotations"]
[tool.ruff.lint.per-file-ignores]
Expand Down Expand Up @@ -283,7 +277,7 @@ without this).
> ```
>
> This selects the minimum version you want to target (primarily for `"UP"` and
> `"I"`) {% rr RF002 %},
> `"I"`) {% rr RF002 %}

Here are some good error codes to enable on most (but not all!) projects:

Expand Down Expand Up @@ -839,7 +833,8 @@ limiting the default checks or by starting off a new project using them, you can
get some very nice linting, including catching some problematic code that
otherwise is hard to catch. PyLint is generally not a good candidate for
pre-commit, since it needs to have your package installed - it is less static of
check than Flake8. Here is a suggested pyproject.toml entry to get you started:
check than Ruff or Flake8. Here is a suggested `pyproject.toml` entry to get you
started:

```toml
[tool.pylint]
Expand Down Expand Up @@ -871,34 +866,23 @@ You can replace `src` with the module name.

## Jupyter notebook support

### NBQA

You can adapt most tools to notebooks using
[nbQA](https://github.com/nbQA-dev/nbQA). The most useful one is probably Ruff:
### Ruff

```yaml
- repo: https://github.com/nbQA-dev/nbQA
rev: "1.7.0"
hooks:
- id: nbqa-ruff
additional_dependencies: [ruff==0.0.275]
```

You can pass extra flags to Ruff via the hook, like
`args: ["--extend-ignore=F821,F401"]`.

{: .note-title }

> Native notebook support
>
> Ruff 0.257 added experimental notebook support! You currently have to enable
> checking `.ipynb` files both in Ruff and pre-commit to use it.
Ruff natively supports notebooks. You have to enable checking `.ipynb` files in
pre-commit to use it with `types_or: [python, pyi, jupyter]`. This should be on
both hooks if using both the linter and the formatter.

### Black

For Black, just make sure you use the `id: black-jupyter` hook instead of
`id: black`; that will also include notebooks.

### NBQA

You can adapt other tools to notebooks using
[nbQA](https://github.com/nbQA-dev/nbQA). However, check to see if the tool
natively supports notebooks first, several of them do now.

### Stripping output

You also might like the following hook, which cleans Jupyter outputs:
Expand Down
7 changes: 0 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ messages_control.disable = [

[tool.ruff]
src = ["src"]
exclude = []

[tool.ruff.lint]
extend-select = [
Expand All @@ -160,15 +159,9 @@ extend-select = [
]
ignore = [
"PLR", # Design related pylint codes
"E501", # Line too long
"PT004", # Incorrect check, usefixtures is the correct way to do this
"RUF012", # Would require a lot of ClassVar's
]
unfixable = [
"T20", # Removes print statements
"F841", # Removes unused variables
]
flake8-unused-arguments.ignore-variadic-names = true

[tool.ruff.lint.flake8-tidy-imports.banned-api]
"typing.Callable".msg = "Use collections.abc.Callable instead."
Expand Down
6 changes: 3 additions & 3 deletions {{cookiecutter.project_name}}/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ ci:

repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: "23.10.0"
rev: "23.10.1"
hooks:
- id: black-jupyter

- repo: https://github.com/adamchainz/blacken-docs
rev: "1.16.0"
hooks:
- id: blacken-docs
additional_dependencies: [black==23.10.0]
additional_dependencies: [black==23.*]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.5.0"
Expand Down Expand Up @@ -45,7 +45,7 @@ repos:
args: [--prose-wrap=always]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.1"
rev: "v0.1.3"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
Expand Down
6 changes: 0 additions & 6 deletions {{cookiecutter.project_name}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,7 @@ extend-select = [
]
ignore = [
"PLR", # Design related pylint codes
"E501", # Line too long
]
unfixable = [
"T20", # Removes print statements
"F841", # Removes unused variables
]
flake8-unused-arguments.ignore-variadic-names = true
isort.required-imports = ["from __future__ import annotations"]
# Uncomment if using a _compat.typing backport
# typing-modules = ["{{ cookiecutter.__project_slug }}._compat.typing"]
Expand Down

0 comments on commit 1d6bbeb

Please sign in to comment.