Skip to content

Commit

Permalink
Automated template update from cookiecutter-scverse (#70)
Browse files Browse the repository at this point in the history
* Automated template update from cookiecutter-scverse

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix merge conflicts

* update pre-commit

* Update pre-commit and fix complaints

---------

Co-authored-by: grst <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Gregor Sturm <[email protected]>
  • Loading branch information
4 people authored Apr 5, 2023
1 parent 05efcaa commit 133cefc
Show file tree
Hide file tree
Showing 19 changed files with 210 additions and 176 deletions.
4 changes: 2 additions & 2 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/scverse/cookiecutter-scverse",
"commit": "7cc5403b05e299d7a4bb169c2bd8c27a2a7676f3",
"commit": "57f6267716826dad73baba46dc3c00fe7262c459",
"context": {
"cookiecutter": {
"project_name": "infercnvpy",
Expand All @@ -19,5 +19,5 @@
}
},
"directory": null,
"checkout": "v0.1.3"
"checkout": "v0.2.0"
}
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ body:
**Note**: Please read [this guide](https://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports)
detailing how to provide the necessary information for us to reproduce your bug. In brief:
* Please provide exact steps how to reproduce the bug in a clean Python environment.
* In case it's not clear what's causing this bug, please provide the data or the data generation procecure.
* Sometimes it is not possible to share the data but usually it is possible to replicate problems on publicly
* In case it's not clear what's causing this bug, please provide the data or the data generation procedure.
* Sometimes it is not possible to share the data, but usually it is possible to replicate problems on publicly
available datasets or to share a subset of your data.
- type: textarea
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Temp files
.DS_Store
*~
buck-out/

# Compiled files
.venv/
__pycache__/
.mypy_cache/
.ruff_cache/

# Distribution / packaging
/build/
Expand Down
53 changes: 12 additions & 41 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ default_stages:
minimum_pre_commit_version: 2.16.0
repos:
- repo: https://github.com/psf/black
rev: 23.1.0
rev: "23.3.0"
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-prettier
Expand All @@ -16,6 +16,17 @@ repos:
- id: prettier
# doesn't work in combination with jupytext hook yet. See https://github.com/mwouts/jupytext/issues/580
exclude: "docs/notebooks/.*\\.md"
# Newer versions of node don't work on systems that have an older version of GLIBC
# (in particular Ubuntu 18.04 and Centos 7)
# EOL of Centos 7 is in 2024-06, we can probably get rid of this then.
# See https://github.com/scverse/cookiecutter-scverse/issues/143 and
# https://github.com/jupyterlab/jupyterlab/issues/12675
language_version: "17.9.1"
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.260
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/asottile/blacken-docs
rev: 1.13.0
hooks:
Expand All @@ -24,21 +35,6 @@ repos:
exclude: "docs/notebooks/.*"
additional_dependencies:
- black==22.6.0 # Matches hook
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/asottile/yesqa
rev: v1.4.0
hooks:
- id: yesqa
additional_dependencies:
- flake8-tidy-imports
- flake8-docstrings
- flake8-rst-docstrings
- flake8-comprehensions
- flake8-bugbear
- flake8-blind-except
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand All @@ -49,31 +45,6 @@ repos:
args: [--fix=lf]
- id: trailing-whitespace
- id: check-case-conflict
- repo: https://github.com/PyCQA/autoflake
rev: v2.0.2
hooks:
- id: autoflake
args:
- --in-place
- --remove-all-unused-imports
- --remove-unused-variable
- --ignore-init-module-imports
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
- flake8-tidy-imports
- flake8-docstrings
- flake8-rst-docstrings
- flake8-comprehensions
- flake8-bugbear
- flake8-blind-except
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py3-plus, --py38-plus, --keep-runtime-typing]
- repo: local
hooks:
- id: forbid-to-commit
Expand Down
6 changes: 0 additions & 6 deletions docs/_templates/autosummary/class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ Attributes

{% for item in attributes %}

{{ item }}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. autoattribute:: {{ [objname, item] | join(".") }}
{%- endfor %}

Expand All @@ -56,9 +53,6 @@ Methods
{% for item in methods %}
{%- if item != '__init__' %}

{{ item }}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. automethod:: {{ [objname, item] | join(".") }}
{%- endif -%}
{%- endfor %}
Expand Down
5 changes: 3 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
napoleon_include_init_with_doc = False
napoleon_use_rtype = True # having a separate entry generally helps readability
napoleon_use_param = True
myst_heading_anchors = 3 # create anchors for h1-h3
myst_heading_anchors = 6 # create anchors for h1-h6
myst_enable_extensions = [
"amsmath",
"colon_fence",
Expand All @@ -87,6 +87,7 @@
}

intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
"scanpy": ("https://scanpy.readthedocs.io/en/stable/", None),
"anndata": ("https://anndata.readthedocs.io/en/stable/", None),
"h5py": ("https://docs.h5py.org/en/stable/", None),
Expand All @@ -96,7 +97,6 @@
"matplotlib": ("https://matplotlib.org/", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None),
"python": ("https://docs.python.org/3", None),
"scipy": ("https://docs.scipy.org/doc/scipy/reference/", None),
"seaborn": ("https://seaborn.pydata.org/", None),
"sklearn": ("https://scikit-learn.org/stable/", None),
Expand All @@ -121,6 +121,7 @@
html_theme_options = {
"repository_url": repository_url,
"use_repository_button": True,
"path_to_docs": "docs/",
}

pygments_style = "default"
Expand Down
17 changes: 10 additions & 7 deletions docs/extensions/typed_returns.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
# code from https://github.com/theislab/scanpy/blob/master/docs/extensions/typed_returns.py
# with some minor adjustment
from __future__ import annotations

import re
from collections.abc import Generator, Iterable

from sphinx.application import Sphinx
from sphinx.ext.napoleon import NumpyDocstring


def _process_return(lines):
def _process_return(lines: Iterable[str]) -> Generator[str, None, None]:
for line in lines:
m = re.fullmatch(r"(?P<param>\w+)\s+:\s+(?P<type>[\w.]+)", line)
if m:
# Once this is in scanpydoc, we can use the fancy hover stuff
if m := re.fullmatch(r"(?P<param>\w+)\s+:\s+(?P<type>[\w.]+)", line):
yield f'-{m["param"]} (:class:`~{m["type"]}`)'
else:
yield line


def _parse_returns_section(self, section):
lines_raw = list(_process_return(self._dedent(self._consume_to_next_section())))
lines = self._format_block(":returns: ", lines_raw)
def _parse_returns_section(self: NumpyDocstring, section: str) -> list[str]:
lines_raw = self._dedent(self._consume_to_next_section())
if lines_raw[0] == ":":
del lines_raw[0]
lines = self._format_block(":returns: ", list(_process_return(lines_raw)))
if lines and lines[-1]:
lines.append("")
return lines
Expand Down
148 changes: 95 additions & 53 deletions docs/template_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ If your project is private, there are ways to enable docs rendering on [readthed
check code for errors, inconsistencies and code styles, before the code
is committed.
This template uses a number of pre-commit checks. In this section we'll detail what is used, where they're defined, and how to modify these checks.
#### Pre-commit CI
We recommend setting up [pre-commit.ci][] to enforce consistency checks on every commit
and pull-request.
Expand All @@ -142,78 +146,116 @@ Once authorized, pre-commit.ci should automatically be activated.
#### Overview of pre-commit hooks used by the template
The following pre-commit checks are for code style and format:
- [black](https://black.readthedocs.io/en/stable/): standard code
formatter in Python.
- [isort](https://pycqa.github.io/isort/): sort module imports into
sections and types.
- [prettier](https://prettier.io/docs/en/index.html): standard code
formatter for non-Python files (e.g. YAML).
- [blacken-docs](https://github.com/asottile/blacken-docs): black on
python code in docs.
The following pre-commit checks are for errors and inconsistencies:
- [flake8](https://flake8.pycqa.org/en/latest/): standard check for errors in Python files.
- [flake8-tidy-imports](https://github.com/adamchainz/flake8-tidy-imports):
tidy module imports.
- [flake8-docstrings](https://github.com/PyCQA/flake8-docstrings):
The following pre-commit hooks are for code style and format:
- [black](https://black.readthedocs.io/en/stable/):
standard code formatter in Python.
- [blacken-docs](https://github.com/asottile/blacken-docs):
black on Python code in docs.
- [prettier](https://prettier.io/docs/en/index.html):
standard code formatter for non-Python files (e.g. YAML).
- [ruff][] based checks:
- [isort](https://beta.ruff.rs/docs/rules/#isort-i) (rule category: `I`):
sort module imports into sections and types.
- [pydocstyle](https://beta.ruff.rs/docs/rules/#pydocstyle-d) (rule category: `D`):
pydocstyle extension of flake8.
- [flake8-rst-docstrings](https://github.com/peterjc/e8-rst-docstrings):
extension of `flake8-docstrings` for `rst` docs.
- [flake8-comprehensions](https://github.com/adamchainz/e8-comprehensions):
- [flake8-tidy-imports](https://beta.ruff.rs/docs/rules/#flake8-tidy-imports-tid) (rule category: `TID`):
tidy module imports.
- [flake8-comprehensions](https://beta.ruff.rs/docs/rules/#flake8-comprehensions-c4) (rule category: `C4`):
write better list/set/dict comprehensions.
- [flake8-bugbear](https://github.com/PyCQA/flake8-bugbear):
find possible bugs and design issues in program.
- [flake8-blind-except](https://github.com/elijahandrews/flake8-blind-except):
checks for blind, catch-all `except` statements.
- [yesqa](https://github.com/asottile/yesqa):
remove unneccesary `# noqa` comments, follows additional dependencies listed above.
- [autoflake](https://github.com/PyCQA/autoflake):
remove unused imports and variables.
- [pre-commit-hooks](https://github.com/pre-commit/pre-commit-hooks): generic pre-commit hooks.
- [pyupgrade](https://beta.ruff.rs/docs/rules/#pyupgrade-up) (rule category: `UP`):
upgrade syntax for newer versions of the language.
The following pre-commit hooks are for errors and inconsistencies:
- [pre-commit-hooks](https://github.com/pre-commit/pre-commit-hooks): generic pre-commit hooks for text files.
- **detect-private-key**: checks for the existence of private keys.
- **check-ast**: check whether files parse as valid python.
- **end-of-file-fixer**:check files end in a newline and only a newline.
- **end-of-file-fixer**: check files end in a newline and only a newline.
- **mixed-line-ending**: checks mixed line ending.
- **trailing-whitespace**: trims trailing whitespace.
- **check-case-conflict**: check files that would conflict with case-insensitive file systems.
- [pyupgrade](https://github.com/asottile/pyupgrade):
upgrade syntax for newer versions of the language.
- **forbid-to-commit**: Make sure that `*.rej` files cannot be commited. These files are created by the
[automated template sync](#automated-template-sync) if there's a merge conflict and need to be addressed manually.
- **forbid-to-commit**: Make sure that `*.rej` files cannot be commited.
These files are created by the [automated template sync](#automated-template-sync)
if there's a merge conflict and need to be addressed manually.
- [ruff][] based checks:
- [pyflakes](https://beta.ruff.rs/docs/rules/#pyflakes-f) (rule category: `F`):
various checks for errors.
- [pycodestyle](https://beta.ruff.rs/docs/rules/#pycodestyle-e-w) (rule category: `E`, `W`):
various checks for errors.
- [flake8-bugbear](https://beta.ruff.rs/docs/rules/#flake8-bugbear-b) (rule category: `B`):
find possible bugs and design issues in program.
- [flake8-blind-except](https://beta.ruff.rs/docs/rules/#flake8-blind-except-ble) (rule category: `BLE`):
checks for blind, catch-all `except` statements.
- [Ruff-specific rules](https://beta.ruff.rs/docs/rules/#ruff-specific-rules-ruf) (rule category: `RUF`):
- `RUF100`: remove unneccesary `# noqa` comments ()

### How to disable or add pre-commit checks
#### How to add or remove pre-commit checks

- To ignore lint warnigs from **flake8**, see [Ignore certain lint warnings](#how-to-ignore-certain-lint-warnings).
- You can add or remove pre-commit checks by simply deleting relevant lines in the `.pre-commit-config.yaml` file.
Some pre-commit checks have additional options that can be specified either in the `pyproject.toml` or tool-specific
config files, such as `.prettierrc.yml` for **prettier** and `.flake8` for **flake8**.
The [pre-commit checks](#pre-commit-checks) check for both correctness and stylistic errors.
In some cases it might overshoot and you may have good reasons to ignore certain warnings.
This section shows you where these checks are defined, and how to enable/ disable them.

### How to ignore certain lint warnings
##### pre-commit

The [pre-commit checks](#pre-commit-checks) include [flake8](https://flake8.pycqa.org/en/latest/) which checks
for errors in Python files, including stylistic errors.
You can add or remove pre-commit checks by simply deleting relevant lines in the `.pre-commit-config.yaml` file under the repository root.
Some pre-commit checks have additional options that can be specified either in the `pyproject.toml` (for `ruff` and `black`) or tool-specific
config files, such as `.prettierrc.yml` for **prettier**.

In some cases it might overshoot and you may have good reasons to ignore certain warnings.
##### Ruff

To ignore an specific error on a per-case basis, you can add a comment `# noqa` to the offending line. You can also
specify the error ID to ignore, with e.g. `# noqa: E731`. Check the [flake8 guide][] for reference.
This template configures `ruff` through the `[tool.ruff]` entry in the `pyproject.toml`.
For further information `ruff` configuration, see [the docs](https://beta.ruff.rs/docs/configuration/).

Alternatively, you can disable certain error messages for the entire project. To do so, edit the `.flake8`
file in the root of the repository. Add one line per linting code you wish to ignore and don't forget to add a comment.
Ruff assigns code to the rules it checks (e.g. `E401`) and groups them under a rule category (e.g. `E`).
Rule categories are selectively enabled by including them under the `select` key:

```toml
[tool.ruff]
...
# line break before a binary operator -> black does not adhere to PEP8
W503
# line break occured after a binary operator -> black does not adhere to PEP8
W504
...
select = [
"F", # Errors detected by Pyflakes
"E", # Error detected by Pycodestyle
"W", # Warning detected by Pycodestyle
"I", # isort
...
]
```
The `ignore` entry is used to disable specific rules for the entire project.
Add the rule code(s) you want to ignore and don't forget to add a comment explaining why.
You can find a long list of checks that this template disables by default sitting there already.
```toml
ignore = [
...
# __magic__ methods are are often self-explanatory, allow missing docstrings
"D105",
...
]
```
Checks can be ignored per-file (or glob pattern) with `[tool.ruff.per-file-ignores]`.
```toml
[tool.ruff.per-file-ignores]
"docs/*" = ["I"]
"tests/*" = ["D"]
"*/__init__.py" = ["F401"]
```
To ignore a specific rule on a per-case basis, you can add a `# noqa: <rule>[, <rule>, …]` comment to the offending line.
Specify the rule code(s) to ignore, with e.g. `# noqa: E731`. Check the [Ruff guide][] for reference.
```{note}
The `RUF100` check will remove rule codes that are no longer necessary from `noqa` comments.
If you want to add a code that comes from a tool other than Ruff,
add it to Ruff’s [`external = [...]`](https://beta.ruff.rs/docs/settings/#external) setting to prevent `RUF100` from removing it.
```
[flake8 guide]: https://flake8.pycqa.org/en/3.1.1/user/ignoring-errors.html
[ruff]: https://beta.ruff.rs/docs/
[ruff guide]: https://beta.ruff.rs/docs/configuration/#suppressing-errors
### API design
Expand Down
Loading

0 comments on commit 133cefc

Please sign in to comment.