Skip to content

Commit eca2b94

Browse files
authored
Update dependencies and tooling (#259)
- Migrates project management from poetry to uv - Removes pre-commit and runs linting through uv - Updates dependencies and GitHub Actions - Adds `pytest-lazy-fixtures` as a dev dependency - Migrates type checking to `pyright` - Adds Python 3.13 to the test suite
1 parent 4e478db commit eca2b94

File tree

14 files changed

+1455
-1625
lines changed

14 files changed

+1455
-1625
lines changed

.github/workflows/release.yml

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,26 @@ jobs:
1515
- name: Checkout
1616
uses: actions/checkout@v4
1717

18-
- name: Install poetry
19-
run: pipx install poetry
18+
- name: Install uv
19+
uses: astral-sh/setup-uv@v5
20+
with:
21+
enable-cache: true
22+
cache-dependency-glob: uv.lock
2023

2124
- name: Set up Python
2225
uses: actions/setup-python@v5
2326
with:
24-
python-version: "3.12"
27+
python-version-file: pyproject.toml
2528

26-
- name: Install dependencies and build project
29+
- name: Install and build project
2730
run: |
28-
poetry install --without docs,test
29-
poetry build
31+
uv sync --locked --no-default-groups
32+
uv build
3033
3134
- name: Upload build artifacts
3235
uses: actions/upload-artifact@v4
3336
with:
34-
name: poetry-build
37+
name: jekyllnb-build
3538
path: dist/
3639

3740
github:
@@ -46,7 +49,7 @@ jobs:
4649
- name: Download build artifacts
4750
uses: actions/download-artifact@v4
4851
with:
49-
name: poetry-build
52+
name: jekyllnb-build
5053
path: dist
5154

5255
- name: Get changes
@@ -75,6 +78,7 @@ jobs:
7578
pypi:
7679
name: PyPI
7780
runs-on: ubuntu-latest
81+
environment: pypi
7882
needs: build
7983

8084
steps:
@@ -84,26 +88,26 @@ jobs:
8488
- name: Download build artifacts
8589
uses: actions/download-artifact@v4
8690
with:
87-
name: poetry-build
91+
name: jekyllnb-build
8892
path: dist
8993

90-
- name: Install poetry
91-
run: pipx install poetry
94+
- name: Install uv
95+
uses: astral-sh/setup-uv@v5
96+
with:
97+
enable-cache: true
98+
cache-dependency-glob: uv.lock
9299

93100
- name: Set up Python
94101
uses: actions/setup-python@v5
95102
with:
96-
python-version: "3.12"
103+
python-version-file: pyproject.toml
97104

98105
- name: Publish to PyPI
99106
if: success() && github.event_name == 'push'
100-
run: poetry publish
101-
env:
102-
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
107+
run: uv publish
103108

104109
- name: Publish to TestPyPI
105110
if: success() && github.event_name == 'workflow_dispatch'
106-
run: poetry publish -r test-pypi
111+
run: uv publish
107112
env:
108-
POETRY_REPOSITORIES_TEST_PYPI_URL: https://test.pypi.org/legacy/
109-
POETRY_PYPI_TOKEN_TEST_PYPI: ${{ secrets.TEST_PYPI_TOKEN }}
113+
UV_PUBLISH_URL: https://test.pypi.org/legacy/

.github/workflows/test.yml

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,42 @@ on:
77
pull_request:
88

99
jobs:
10+
linting:
11+
name: Linting
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Install uv
18+
uses: astral-sh/setup-uv@v5
19+
with:
20+
enable-cache: true
21+
cache-dependency-glob: uv.lock
22+
23+
- name: Set up Python
24+
uses: actions/setup-python@v5
25+
with:
26+
python-version-file: pyproject.toml
27+
28+
- name: Test lock
29+
run: uv lock --check
30+
31+
- name: Install project
32+
run: uv sync --locked --all-extras --dev
33+
34+
- name: Format
35+
run: uv run ruff format --check
36+
37+
- name: Check
38+
run: uv run ruff check
39+
40+
- name: Type check
41+
run: uv run pyright jekyllnb
42+
1043
test:
1144
name: ${{ matrix.os.name }} / ${{ matrix.python-version }}
45+
needs: linting
1246
runs-on: ${{ matrix.os.image }}
1347
defaults:
1448
run:
@@ -30,34 +64,37 @@ jobs:
3064
- "3.10"
3165
- "3.11"
3266
- "3.12"
67+
- "3.13"
3368
fail-fast: false
3469

3570
steps:
3671
- name: Checkout
3772
uses: actions/checkout@v4
3873

39-
- name: Install poetry
40-
run: pipx install poetry
74+
- name: Install uv
75+
uses: astral-sh/setup-uv@v5
76+
with:
77+
enable-cache: true
78+
cache-dependency-glob: uv.lock
4179

4280
- name: Set up Python ${{ matrix.python-version }}
4381
uses: actions/setup-python@v5
4482
with:
4583
python-version: ${{ matrix.python-version }}
46-
cache: poetry
4784

48-
- name: Install dependencies
85+
- name: Install project
4986
run: |
50-
poetry install
51-
pip install pytest-github-actions-annotate-failures
87+
uv sync --locked --all-extras --dev
88+
uv pip install pytest-github-actions-annotate-failures
5289
5390
- name: Run tests
54-
run: poetry run pytest --cov-report xml:coverage.xml
91+
run: uv run pytest --cov-report xml:coverage.xml
5592

5693
- name: Upload coverage report
57-
uses: codecov/codecov-action@v4
94+
uses: codecov/codecov-action@v5
5895
if: success()
5996
with:
60-
file: coverage.xml
97+
files: coverage.xml
6198
fail_ci_if_error: true
6299
token: ${{ secrets.CODECOV_TOKEN }}
63100

.pre-commit-config.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@
1010
### Changed
1111

1212
- Dropped support for Python 3.6-3.8 ([#251](https://github.com/klane/jekyllnb/pull/251)).
13-
- Updated dependencies ([#251](https://github.com/klane/jekyllnb/pull/251)).
14-
- Removed `pytest-lazy-fixture` as a dev dependency since it [does not support `pytest` 8](https://github.com/TvoroG/pytest-lazy-fixture/issues/65) ([#251](https://github.com/klane/jekyllnb/pull/251)).
13+
- Updated dependencies ([#251](https://github.com/klane/jekyllnb/pull/251), [#259](https://github.com/klane/jekyllnb/pull/259)).
1514
- Removed `tox` as a dev dependency ([#251](https://github.com/klane/jekyllnb/pull/251)).
16-
- Migrated code formatting and linting to ruff ([#251](https://github.com/klane/jekyllnb/pull/251)).
15+
- Migrated code formatting and linting to `ruff` ([#251](https://github.com/klane/jekyllnb/pull/251)).
16+
- Migrated type checking to `pyright` ([#259](https://github.com/klane/jekyllnb/pull/259)).
17+
- Migrated project management to `uv` ([#259](https://github.com/klane/jekyllnb/pull/259)).
18+
- Removed `pre-commit` as a dev dependency ([#259](https://github.com/klane/jekyllnb/pull/259)).
1719

1820
### Fixed
1921

2022
- Fixed CI pipelines that were broken due to the [deprecated `set-output` command](https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/) ([#251](https://github.com/klane/jekyllnb/pull/251)).
23+
- Replaced `pytest-lazy-fixture` with `pytest-lazy-fixtures` since `pytest-lazy-fixture` [does not support `pytest` 8](https://github.com/TvoroG/pytest-lazy-fixture/issues/65) ([#251](https://github.com/klane/jekyllnb/pull/251), [#259](https://github.com/klane/jekyllnb/pull/259)).
2124

2225
## [0.3.1]
2326

jekyllnb/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
from .exporter import JekyllExporter
33
from .preprocessor import JekyllPreprocessor
44

5-
__all__ = ["__version__", "JekyllExporter", "JekyllPreprocessor"]
5+
__all__ = ["JekyllExporter", "JekyllPreprocessor", "__version__"]

jekyllnb/exporter.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
1+
from collections.abc import ItemsView
12
from pathlib import Path
2-
from typing import Any, Callable, ClassVar, Literal, Optional
3+
from typing import Any, ClassVar, Literal, Optional
34

45
from nbconvert.exporters import MarkdownExporter
56
from nbconvert.filters.strings import path2url
67
from traitlets import default
78
from traitlets.config import Config
9+
from typing_extensions import override
810

911

1012
class JekyllExporter(MarkdownExporter):
1113
"""Exporter to write Markdown with Jekyll metadata."""
1214

13-
# path to available template files
14-
extra_template_basedirs: ClassVar[list[str]] = [
15-
str(Path(__file__).parent / "templates")
16-
]
17-
18-
# enabled preprocessors
19-
preprocessors: ClassVar[list[str]] = ["jekyllnb.JekyllPreprocessor"]
20-
2115
# placeholder to store notebook resources
2216
resources: ClassVar[dict[str, Any]] = {}
2317

18+
@override
2419
def from_filename(
2520
self, filename: str, resources: Optional[dict[str, Any]] = None, **kwargs
2621
) -> tuple[str, dict[str, Any]]:
@@ -41,12 +36,22 @@ def from_filename(
4136

4237
return super().from_filename(filename, resources=resources, **kwargs)
4338

39+
@override
40+
@default("extra_template_basedirs")
41+
def _default_extra_template_basedirs(self) -> list[str]:
42+
return [str(Path(__file__).parent / "templates")]
43+
44+
@default("preprocessors")
45+
def _default_preprocessors(self) -> list[Any]:
46+
return ["jekyllnb.JekyllPreprocessor"]
47+
4448
@default("template_name")
45-
def _template_name_default(self) -> Literal["jekyll"]:
49+
def _default_template_name(self) -> Literal["jekyll"]:
4650
"""Specify default template name."""
4751
return "jekyll"
4852

4953
@property
54+
@override
5055
def default_config(self) -> Config:
5156
"""Specify default configuration."""
5257
config = Config({"JekyllPreprocessor": {"enabled": True}})
@@ -62,10 +67,10 @@ def _jekyll_path(self, path: str) -> str:
6267

6368
return f"{{{{ site.baseurl }}}}/{path2url(path)}"
6469

65-
def default_filters(self) -> list[tuple[str, Callable]]:
70+
@override
71+
def default_filters(self) -> ItemsView[str, Any]: # type:ignore[override]
6672
"""Specify default filters."""
6773
# convert image path to one compatible with Jekyll
68-
return [
69-
*super().default_filters(),
70-
("jekyllpath", self._jekyll_path),
71-
]
74+
filters = dict(super().default_filters())
75+
filters["jekyllpath"] = self._jekyll_path
76+
return filters.items()

jekyllnb/jekyllnb.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
from typing import Any, Literal, Optional
55

66
from nbconvert.nbconvertapp import NbConvertApp, nbconvert_aliases, nbconvert_flags
7+
from nbconvert.writers.files import FilesWriter
78
from traitlets import Bool, Unicode, default, observe
89
from traitlets.config import catch_config_error
10+
from typing_extensions import override
911

1012
from .__version__ import __version__
1113

@@ -48,31 +50,34 @@ class JekyllNB(NbConvertApp):
4850
).tag(config=True)
4951

5052
@default("export_format")
51-
def _export_format_default(self) -> Literal["jekyll"]:
53+
def _default_export_format(self) -> Literal["jekyll"]:
5254
"""Specify default export format."""
5355
return "jekyll"
5456

5557
@observe("export_format")
5658
def _export_format_changed(self, change: dict[str, Any]) -> None:
5759
"""Ensure export format is jekyll."""
58-
default_format = self._export_format_default()
60+
default_format = self._default_export_format()
5961

6062
if change["new"].lower() != default_format:
6163
raise ValueError(
6264
f"Invalid export format {change['new']}, value must be {default_format}"
6365
)
6466

67+
@override
6568
@catch_config_error
6669
def initialize(self, argv: Optional[Any] = None) -> None:
6770
"""Initialize application, notebooks, writer, and postprocessor."""
6871
super().initialize(argv)
69-
self.writer.build_directory = os.path.join(self.site_dir, self.page_dir)
72+
if isinstance(self.writer, FilesWriter):
73+
self.writer.build_directory = os.path.join(self.site_dir, self.page_dir)
7074

7175
if self.auto_folder:
7276
self.output_files_dir = os.path.join(
7377
super().output_files_dir, "{notebook_name}"
7478
)
7579

80+
@override
7681
def init_single_notebook_resources(self, notebook_filename: str) -> dict[str, Any]:
7782
"""Initialize resources.
7883

jekyllnb/preprocessor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
from nbconvert.preprocessors import Preprocessor
44
from nbformat import NotebookNode
5+
from typing_extensions import override
56

67

78
class JekyllPreprocessor(Preprocessor):
89
"""Preprocessor to add Jekyll metadata."""
910

11+
@override
1012
def preprocess(
1113
self, nb: NotebookNode, resources: dict[str, Any]
1214
) -> tuple[NotebookNode, dict[str, Any]]:

0 commit comments

Comments
 (0)