Skip to content

Commit

Permalink
Update pre-commit versions and contributing doc (#67)
Browse files Browse the repository at this point in the history
* Fix new linting issues based on updated pre-commits
* Add doctests to suite of tests
  • Loading branch information
grovduck authored Mar 22, 2024
1 parent 1ebb271 commit 8cde040
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 43 deletions.
12 changes: 4 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.278
rev: v0.3.2
hooks:
- id: ruff

- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.2.0
rev: v1.9.0
hooks:
- id: mypy
exclude: ^tests/|^setup.py
exclude: ^tests/
args: [--ignore-missing-imports]
10 changes: 5 additions & 5 deletions docs/pages/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@ This will install development dependencies in an isolated environment and drop y
Use [pre-commit](https://pre-commit.com/) to run linting, type-checking, and formatting:

```bash
$ pre-commit run --all-files
$ hatch run pre-commit run --all-files
```

...or install it to run automatically before every commit with:

```bash
$ pre-commit install
$ hatch run pre-commit install
```

You can run pre-commit hooks separately and pass additional arguments to them. For example, to run `black` on a single file:
You can run pre-commit hooks separately and pass additional arguments to them. For example, to run `ruff-format` on a single file:

```bash
$ pre-commit run black --files=src/sknnr/_base.py
$ hatch run pre-commit run ruff-format --files=src/sknnr/_base.py
```

### Testing

Unit tests are *not* run by `pre-commit`, but can be run manually using `hatch` [scripts](https://hatch.pypa.io/latest/config/environment/overview/#scripts):
Unit tests are _not_ run by `pre-commit`, but can be run manually using `hatch` [scripts](https://hatch.pypa.io/latest/config/environment/overview/#scripts):

```bash
$ hatch run test:all
Expand Down
54 changes: 27 additions & 27 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ license = ""
requires-python = ">=3.8"
authors = [
{ name = "Matt Gregory", email = "[email protected]" },
{ name = "Aaron Zuspan", email = "[email protected]" }
]
dependencies = [
"numpy",
"scikit-learn>=1.2",
"scipy",
{ name = "Aaron Zuspan", email = "[email protected]" },
]
dependencies = ["numpy", "scikit-learn>=1.2", "scipy"]

[project.urls]
Homepage = "https://github.com/lemma-osu/sknnr"
Expand All @@ -30,32 +26,20 @@ path = "src/sknnr/__about__.py"
packages = ["src/sknnr"]

[tool.hatch.build.targets.sdist]
include = [
"/src",
]
include = ["/src"]

[tool.hatch.envs.default]
dependencies = [
"pre-commit",
]
dependencies = ["pre-commit"]

[tool.hatch.envs.test]
dependencies = [
"pytest",
"pytest-cov",
"pandas"
]
dependencies = ["pytest", "pytest-cov", "pandas"]

[tool.hatch.envs.test.scripts]
all = "pytest {args}"
coverage = "pytest --cov=src/sknnr {args}"
all = "pytest . {args} --doctest-modules"
coverage = "pytest . --cov=src/sknnr {args} --doctest-modules"

[tool.hatch.envs.docs]
dependencies = [
"mkdocs",
"mkdocs-material",
"mkdocstrings[python]"
]
dependencies = ["mkdocs", "mkdocs-material", "mkdocstrings[python]"]

[tool.hatch.envs.docs.scripts]
serve = "mkdocs serve --config-file docs/mkdocs.yml --watch ./README.md"
Expand All @@ -69,9 +53,25 @@ markers = [

[tool.ruff]
target-version = "py38"
select = ["E", "I", "F", "B", "FA", "UP", "ISC", "PT", "NPY", "Q", "RET", "SIM", "PERF"]
fix = true
show-fixes = true

[tool.ruff.isort]
known-first-party = ["sknnr"]
[tool.ruff.lint]
select = [
"E",
"I",
"F",
"B",
"FA",
"UP",
"ISC",
"PT",
"NPY",
"Q",
"RET",
"SIM",
"PERF",
]

[tool.ruff.lint.isort]
known-first-party = ["sknnr"]
6 changes: 3 additions & 3 deletions src/sknnr/datasets/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
from dataclasses import dataclass
from importlib import resources
from typing import TYPE_CHECKING, TextIO
from typing import IO, TYPE_CHECKING

import numpy as np
from numpy.typing import NDArray
Expand Down Expand Up @@ -54,7 +54,7 @@ def _dataset_as_frame(dataset: Dataset) -> Dataset:
)


def _open_text(module_name: str, file_name: str) -> TextIO:
def _open_text(module_name: str, file_name: str) -> IO[str]:
"""Open a file as text.
This is a compatibility port for importlib.resources.open_text, which is deprecated
Expand All @@ -68,7 +68,7 @@ def _open_text(module_name: str, file_name: str) -> TextIO:

def _load_csv_data(
file_name: str,
) -> tuple[NDArray[np.int64], NDArray[np.float64], NDArray[np.unicode_]]:
) -> tuple[NDArray[np.int64], NDArray[np.float64], NDArray[np.str_]]:
"""Load data from a CSV file in the data module.
Notes
Expand Down

0 comments on commit 8cde040

Please sign in to comment.