Skip to content

Commit 7fc429f

Browse files
Parse (#1)
1 parent 31b887a commit 7fc429f

File tree

16 files changed

+454
-127
lines changed

16 files changed

+454
-127
lines changed

.github/workflows/check-python.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,23 @@ jobs:
4040
4141
lint:
4242
runs-on: ubuntu-latest
43+
env:
44+
ruff_args: ""
45+
python-version: '3.13'
4346
steps:
4447
- uses: actions/checkout@v4
45-
- name: Ruff
46-
uses: chartboost/ruff-action@v1
48+
- name: Set stricter linting rules for PR / `main`
49+
run: |
50+
if [[ "${{ github.event_name }}" == "pull_request" || ( "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ) ]]; then
51+
echo "ruff_args=--config ruff-main.toml" >> $GITHUB_ENV
52+
fi
53+
- name: Install uv
54+
uses: astral-sh/setup-uv@v5
55+
with:
56+
python-version: ${{ env.python-version }}
57+
- name: lint with ruff ${{ env.ruff_args }}
58+
run: |
59+
uv run --no-default-groups --group lint ruff check . ${{ env.ruff_args }}
4760
4861
type-check:
4962
env:

.github/workflows/publish-python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
publish:
3636
environment:
3737
name: pypi
38-
url: https://pypi.org/p/ttrpg-dice
38+
url: https://pypi.org/p/pytest-ipynb2
3939
permissions:
4040
id-token: write
4141
needs: [python-checks, build]

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
## [0.0.1] - 2025-02-12
11+
12+
### Added
13+
14+
- Initial release of `pytest-ipynb2`.
15+
- Added support for running tests in Jupyter Notebooks.
16+
- Implemented `Notebook` class for parsing notebooks and extracting code and test cells.
17+
- Added GitHub Actions workflows for CI/CD, including linting, testing, type-checking, and publishing.
18+
- Added `justfile` for common development tasks.
19+
- Configured `pyproject.toml` with project metadata, dependencies, and tool configurations.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# pytest-ipynb2
2+
3+
A pytest plugin to run tests in Jupyter Notebooks. Designed to integrate with [chmp/ipytest](https://github.com/chmp/ipytest).

docs/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Overview
2+
3+
A pytest plugin to run tests in Jupyter Notebooks. Designed to integrate with [chmp/ipytest](https://github.com/chmp/ipytest).

docs/python-api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# API
2+
3+
::: pytest_ipynb2

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ show-cov:
5858

5959
# serve python docs on localhost:3000
6060
docs:
61-
uv run jupyter book start --execute
61+
uv run mkdocs serve

mkdocs.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
site_name: "pytest-ipynb2"
2+
repo_url: https://github.com/MusicalNinjaDad/pytest-ipynb2
3+
repo_name: MusicalNinjaDad/pytest-ipynb2
4+
5+
watch:
6+
- pytest_ipynb2 # To update live preview when docstrings change
7+
8+
theme:
9+
name: "material"
10+
icon:
11+
logo: material/test-tube
12+
palette: # Palette toggles for auto-light-dark mode
13+
- media: "(prefers-color-scheme)"
14+
toggle:
15+
icon: material/link
16+
name: Switch to light mode
17+
- media: "(prefers-color-scheme: light)"
18+
scheme: default
19+
toggle:
20+
icon: material/toggle-switch
21+
name: Switch to dark mode
22+
- media: "(prefers-color-scheme: dark)"
23+
scheme: slate
24+
toggle:
25+
icon: material/toggle-switch-off-outline
26+
name: Switch to system preference
27+
features:
28+
- navigation.expand
29+
- navigation.path
30+
- toc.integrate
31+
- navigation.indexes
32+
33+
plugins:
34+
- search
35+
- mkdocstrings:
36+
handlers:
37+
python:
38+
options:
39+
members: true
40+
show_bases: false
41+
show_root_heading: true
42+
heading_level: 2
43+
show_root_full_path: false
44+
show_symbol_type_toc: true
45+
show_symbol_type_heading: true
46+
signature_crossrefs: true
47+
separate_signature: true
48+
show_signature_annotations: true
49+
docstring_section_style: spacy
50+
docstring_options:
51+
ignore_init_summary: true
52+
merge_init_into_class: true
53+
54+
markdown_extensions:
55+
- admonition
56+
- pymdownx.details
57+
- pymdownx.highlight
58+
- pymdownx.inlinehilite
59+
- pymdownx.snippets:
60+
url_download: true
61+
base_path: !relative $docs_dir
62+
- pymdownx.superfences
63+
- attr_list
64+
- pymdownx.emoji:
65+
emoji_index: !!python/name:material.extensions.emoji.twemoji
66+
emoji_generator: !!python/name:material.extensions.emoji.to_svg
67+
68+
nav:
69+
- index.md
70+
- python-api.md

pyproject.toml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
dependencies = [
1818
"ipython",
1919
"ipytest",
20+
"nbformat>=5.10.4",
2021
"pytest",
2122
"typing-extensions; python_version < '3.11'",
2223
]
@@ -52,9 +53,7 @@
5253
"pytype; python_version <= '3.12'",
5354
"typing_extensions", # required for Python3.10 and below
5455
]
55-
test = [
56-
"pytest-doctest-mkdocstrings",
57-
]
56+
test = ["pytest-doctest-mkdocstrings"]
5857
cov = [
5958
{include-group = "test"},
6059
"pytest-cov",
@@ -64,14 +63,15 @@
6463
"mkdocs",
6564
"mkdocstrings[python]",
6665
"mkdocs-material",
66+
"pymdown-extensions",
6767
]
6868
dev = [
69-
"jupyter",
7069
{include-group = "lint"},
7170
{include-group = "typing"},
7271
{include-group = "test"},
7372
{include-group = "cov"},
7473
{include-group = "doc"},
74+
"jupyter", # python's toml decoder won't accept a text entry at the start of the array, only at the end!!
7575
]
7676

7777
[tool.pytest.ini_options]
@@ -99,7 +99,7 @@ exclude_also = [
9999
show_contexts = true
100100

101101
[tool.pytype]
102-
inputs = ["pytest_ipynb2"]
102+
inputs = ["pytest_ipynb2"]
103103

104104
[tool.ruff]
105105
line-length = 120
@@ -163,5 +163,9 @@ inputs = ["pytest_ipynb2"]
163163
]
164164

165165
"**/*.ipynb" = [
166-
"T201", # Allow `print` in Jupyter notebooks
166+
"T201", # Allow `print` in Jupyter notebooks
167+
"ANN", # Missing type annotations
168+
"S101", # Use of `assert`
169+
"PLR2004", # Magic number comparisons
170+
"D1", # Don't REQUIRE docstrings in notebooks - but lint them if they are there
167171
]

pytest_ipynb2/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
"""Pytest plugin to run tests in Jupyter Notebooks."""
1+
"""Pytest plugin to run tests in Jupyter Notebooks."""
2+
3+
from ._ipynb_parser import Notebook

0 commit comments

Comments
 (0)