Skip to content

Commit 16bf2ef

Browse files
authored
test: docs, test, CI (#30)
* chore: remove default test environment configuration from hatch * test: general improvements * test: fixes Signed-off-by: nstarman <nstarman@users.noreply.github.com>
1 parent 814ab1b commit 16bf2ef

12 files changed

Lines changed: 2086 additions & 107 deletions

File tree

.github/workflows/ci.yml

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@ jobs:
2222
runs-on: ubuntu-latest
2323
steps:
2424
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
25-
- uses: actions/setup-python@v5
26-
with:
27-
python-version: "3.x"
25+
- name: Install uv
26+
uses: astral-sh/setup-uv@v6
27+
- name: Install the project
28+
run: uv sync --locked --group dev
29+
2830
- uses: pre-commit/action@v3.0.1
2931
with:
3032
extra_args: --hook-stage manual --all-files
3133
- name: Run PyLint
3234
run: |
3335
echo "::add-matcher::$GITHUB_WORKSPACE/.github/matchers/pylint.json"
34-
pipx run nox -s pylint
36+
uv run nox -s pylint
3537
3638
checks:
3739
name: Check Python ${{ matrix.python-version }} on ${{ matrix.runs-on }}
@@ -43,25 +45,17 @@ jobs:
4345
python-version: ["3.10", "3.12"]
4446
runs-on: [ubuntu-latest, macos-latest, windows-latest]
4547

46-
# include:
47-
# - python-version: pypy-3.10
48-
# runs-on: ubuntu-latest
49-
5048
steps:
5149
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
5250

53-
- uses: actions/setup-python@v5
51+
- name: Install uv and set the python version
52+
uses: astral-sh/setup-uv@v6
5453
with:
5554
python-version: ${{ matrix.python-version }}
56-
allow-prereleases: true
57-
58-
- name: Install package
59-
run: python -m pip install .[test]
6055

6156
- name: Test package
6257
run: >-
63-
python -m pytest -ra --cov --cov-report=xml --cov-report=term
64-
--durations=20
58+
uv run pytest --cov --cov-report=xml --cov-report=term --durations=20
6559
6660
- name: Upload coverage report
6761
uses: codecov/codecov-action@fdcc8476540edceab3de004e990f80d881c6cc00 # v5.5.0

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ repos:
6060
rev: "v2.4.1"
6161
hooks:
6262
- id: codespell
63+
args: [--skip=uv.lock]
6364

6465
- repo: https://github.com/shellcheck-py/shellcheck-py
6566
rev: "v0.10.0.1"

README.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,39 @@ dictionary. 😢 </br> This repository defines a light-weight immutable map
1010
[![PyPI platforms][pypi-platforms]][pypi-link]
1111
[![PyPI version][pypi-version]][pypi-link]
1212

13-
<!-- [![Conda-Forge][conda-badge]][conda-link] -->
14-
1513
```bash
1614
pip install xmmutablemap
1715
```
1816

19-
## Documentation
17+
<details>
18+
<summary>using <code>uv</code></summary>
19+
20+
```bash
21+
uv add xmmutablemap
22+
```
23+
24+
</details>
25+
<details>
26+
<summary>from source, using pip</summary>
2027

21-
<!-- [![Documentation Status][rtd-badge]][rtd-link] -->
28+
```bash
29+
pip install git+https://github.com/GalacticDynamics/xmmutablemap.git
30+
```
31+
32+
</details>
33+
<details>
34+
<summary>building from source</summary>
35+
36+
```bash
37+
cd /path/to/parent
38+
git clone https://github.com/GalacticDynamics/xmmutablemap.git
39+
cd xmmutablemap
40+
pip install -e . # editable mode
41+
```
42+
43+
</details>
44+
45+
## Documentation
2246

2347
`xmutablemap` provides the class `ImmutableMap`, which is a full implementation
2448
of
@@ -46,14 +70,8 @@ We welcome contributions!
4670
<!-- prettier-ignore-start -->
4771
[actions-badge]: https://github.com/GalacticDynamics/xmmutablemap/workflows/CI/badge.svg
4872
[actions-link]: https://github.com/GalacticDynamics/xmmutablemap/actions
49-
[conda-badge]: https://img.shields.io/conda/vn/conda-forge/xmmutablemap
50-
[conda-link]: https://github.com/conda-forge/xmmutablemap-feedstock
51-
<!-- [github-discussions-badge]: https://img.shields.io/static/v1?label=Discussions&message=Ask&color=blue&logo=github
52-
[github-discussions-link]: https://github.com/GalacticDynamics/xmmutablemap/discussions -->
5373
[pypi-link]: https://pypi.org/project/xmmutablemap/
5474
[pypi-platforms]: https://img.shields.io/pypi/pyversions/xmmutablemap
5575
[pypi-version]: https://img.shields.io/pypi/v/xmmutablemap
56-
[zenodo-badge]: https://zenodo.org/badge/755708966.svg
57-
[zenodo-link]: https://zenodo.org/doi/10.5281/zenodo.10850557
5876

5977
<!-- prettier-ignore-end -->

conftest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Doctest configuration."""
2+
3+
from collections.abc import Callable, Iterable, Sequence
4+
from doctest import ELLIPSIS, NORMALIZE_WHITESPACE
5+
6+
from sybil import Document, Region, Sybil
7+
from sybil.parsers import myst, rest
8+
9+
optionflags = ELLIPSIS | NORMALIZE_WHITESPACE
10+
11+
parsers: Sequence[Callable[[Document], Iterable[Region]]] = [
12+
myst.DocTestDirectiveParser(optionflags=optionflags),
13+
myst.PythonCodeBlockParser(doctest_optionflags=optionflags),
14+
myst.SkipParser(),
15+
]
16+
17+
docs = Sybil(parsers=parsers, patterns=["*.md"])
18+
python = Sybil(
19+
parsers=[*parsers, rest.DocTestParser(optionflags=optionflags)],
20+
patterns=["*.py"],
21+
)
22+
23+
24+
pytest_collect_file = (docs + python).pytest()

noxfile.py

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from __future__ import annotations
1+
"""Nox sessions."""
22

33
import shutil
44
from pathlib import Path
@@ -8,47 +8,73 @@
88
DIR = Path(__file__).parent.resolve()
99

1010
nox.needs_version = ">=2024.3.2"
11-
nox.options.sessions = ["lint", "pylint", "tests"]
11+
nox.options.sessions = [
12+
"tests",
13+
# Linting
14+
"lint",
15+
"pylint",
16+
# Testing
17+
"test",
18+
# Packaging
19+
"build",
20+
]
1221
nox.options.default_venv_backend = "uv|virtualenv"
1322

1423

1524
@nox.session
16-
def lint(session: nox.Session) -> None:
17-
"""
18-
Run the linter.
19-
"""
20-
session.install("pre-commit")
25+
def lint(session: nox.Session, /) -> None:
26+
"""Run the linter."""
2127
session.run(
22-
"pre-commit", "run", "--all-files", "--show-diff-on-failure", *session.posargs
28+
"uv",
29+
"run",
30+
"pre-commit",
31+
"run",
32+
"--all-files",
33+
"--show-diff-on-failure",
34+
*session.posargs,
2335
)
2436

2537

2638
@nox.session
2739
def pylint(session: nox.Session) -> None:
28-
"""
29-
Run PyLint.
30-
"""
40+
"""Run PyLint."""
3141
# This needs to be installed into the package environment, and is slower
3242
# than a pre-commit check
33-
session.install(".", "pylint")
34-
session.run("pylint", "xmmutablemap", *session.posargs)
43+
if shutil.which("uv"):
44+
session.run("uv", "sync", "--group", "pylint")
45+
session.run("uv", "run", "pylint", "xmmutablemap", *session.posargs)
46+
else:
47+
# Fallback to regular pip if uv is not available
48+
session.install("pylint>=3.3.8")
49+
session.install("-e", ".")
50+
session.run("pylint", "xmmutablemap", *session.posargs)
51+
52+
53+
# =============================================================================
54+
# Testing
55+
56+
57+
@nox.session
58+
def test(session: nox.Session) -> None:
59+
"""Run the tests."""
60+
session.run("uv", "sync", "--group", "test")
61+
session.run("uv", "run", "pytest", *session.posargs)
3562

3663

3764
@nox.session
3865
def tests(session: nox.Session) -> None:
39-
"""
40-
Run the unit and regular tests.
41-
"""
42-
session.install(".[test]")
43-
session.run("pytest", *session.posargs)
66+
"""Run the lints and tests."""
67+
session.notify("lint")
68+
session.notify("test")
69+
70+
71+
# =============================================================================
72+
# Packaging
4473

4574

4675
@nox.session
4776
def build(session: nox.Session) -> None:
48-
"""
49-
Build an SDist and wheel.
50-
"""
51-
77+
"""Build an SDist and wheel."""
5278
build_path = DIR.joinpath("build")
5379
if build_path.exists():
5480
shutil.rmtree(build_path)

0 commit comments

Comments
 (0)