Skip to content

Commit

Permalink
Migrate from Poetry to uv (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
srstevenson authored Feb 7, 2025
1 parent 1c57fc6 commit 76e4e69
Show file tree
Hide file tree
Showing 9 changed files with 624 additions and 813 deletions.
24 changes: 12 additions & 12 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,28 @@ opportunity to help you.
Changes are managed using GitHub pull requests. If you're new to pull requests,
read the [documentation][pr docs] to learn how they work.

[Poetry][poetry] is used for managing dependencies and packaging, and you will
need it installed. If you're not familiar with Poetry, we suggest reading its
documentation before you begin.
[uv] is used for managing dependencies and packaging, and you will need it
installed. If you're not familiar with uv, we suggest reading its documentation
before you begin.

After cloning the repository, you can implement your changes as follows:

1. Install the project and its dependencies into an isolated virtual environment
with `poetry install`.
2. Before making your changes, run the linters and test suite with
`poetry run poe check`, and ensure they pass. This checks your development
environment is correctly configured, and there aren't outstanding issues
before you start coding. If they don't pass, you can open a GitHub issue for
help debugging.
with `uv sync --dev`.
2. Before making your changes, run the tests with `uv run pytest`, and ensure
they pass. This checks your development environment is correctly configured,
and there aren't outstanding issues before you start coding. If they don't
pass, you can open a GitHub issue for help debugging.
3. Checkout a new branch for your changes, branching from `main`, with a
sensible name for your changes.
4. Implement your changes.
5. If you introduced new functionality or fixed a bug, add appropriate automated
tests to prevent future regressions.
6. Ensure you've updated any docstrings or documentation files (including
`README.md`) which are affected by your change.
7. Run the linters and test suite again with `poetry run poe check`, and fix any
problems.
7. Run the linter with `uv run ruff check .`, formatter with
`uv run ruff format .`, type checker with `uv run mypy .`, and tests with
`uv run pytest`, and fix any problems.
8. Commit your changes, following [these guidelines][commit guidelines] for your
commit messages.
9. Fork the base repository on GitHub, push your branch to your fork, and open a
Expand All @@ -76,5 +76,5 @@ After cloning the repository, you can implement your changes as follows:
[commit guidelines]:
https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
[mre]: https://stackoverflow.com/help/minimal-reproducible-example
[poetry]: https://python-poetry.org/
[pr docs]: https://docs.github.com/en/github/collaborating-with-pull-requests
[uv]: https://docs.astral.sh/uv/
28 changes: 20 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,36 @@ jobs:
- "3.11"
- "3.12"
- "3.13"
env:
UV_PYTHON: ${{ matrix.python }}
steps:
- uses: actions/checkout@v4

- name: Set up Python
- name: Setup uv
uses: astral-sh/setup-uv@v5

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}

- name: Install dependencies
run: |
python3 -m pip install coverage poetry
poetry install
run: uv sync --dev

- name: Run formatter
run: uv run ruff format --check .

- name: Run linter
run: uv run ruff check .

- name: Run type checker
run: uv run mypy .

- name: Run checks
run: poetry run poe check
- name: Run tests
run: uv run pytest

- name: Create XML coverage report
run: poetry run coverage xml
- name: Create test coverage report
run: uv run coverage xml

- name: Upload test coverage report
uses: codecov/[email protected]
26 changes: 0 additions & 26 deletions .github/workflows/stale.yml

This file was deleted.

1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.9
52 changes: 25 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![CI status](https://github.com/srstevenson/nb-clean/workflows/CI/badge.svg)](https://github.com/srstevenson/nb-clean/actions)
[![Coverage](https://img.shields.io/codecov/c/gh/srstevenson/nb-clean?label=Coverage)](https://app.codecov.io/gh/srstevenson/nb-clean)

`nb-clean` cleans Jupyter notebooks of cell execution counts, metadata, outputs,
nb-clean cleans Jupyter notebooks of cell execution counts, metadata, outputs,
and (optionally) empty cells, preparing them for committing to version control.
It provides both a Git filter and pre-commit hook to automatically clean
notebooks before they're staged, and can also be used with other version control
Expand All @@ -17,24 +17,24 @@ integration pipelines.

> [!NOTE]
>
> `nb-clean` 2.0.0 introduced a new command line interface to make cleaning
> nb-clean 2.0.0 introduced a new command line interface to make cleaning
> notebooks in place easier. If you upgrade from a previous release, you'll need
> to migrate to the new interface as described under
> [Migrating to `nb-clean` 2](#migrating-to-nb-clean-2).
> [Migrating to nb-clean 2](#migrating-to-nb-clean-2).
## Installation

`nb-clean` requires Python 3.9 or later. To install the latest release from
[PyPI] with [pip], use:
nb-clean requires Python 3.9 or later. To run the latest release of nb-clean in
an ephemeral virtual environment, use [uv]:

```bash
python3 -m pip install nb-clean
uvx nb-clean
```

`nb-clean` can also be installed with [Conda]:
To add nb-clean as a dependency to a Python project managed with uv, use:

```bash
conda install -c conda-forge nb-clean
uv add --dev nb-clean
```

## Usage
Expand Down Expand Up @@ -90,9 +90,9 @@ field:
nb-clean check --preserve-cell-metadata tags -- notebook.ipynb
```

`nb-clean` will exit with status code 0 if the notebook is clean, and status
code 1 if it is not. `nb-clean` will also print details of cell execution
counts, metadata, outputs, and empty cells it finds.
nb-clean will exit with status code 0 if the notebook is clean, and status code
1 if it is not. nb-clean will also print details of cell execution counts,
metadata, outputs, and empty cells it finds.

### Cleaning (interactive)

Expand Down Expand Up @@ -193,14 +193,14 @@ To preserve notebook `language_info.version` metadata, use:
nb-clean add-filter --preserve-notebook-metadata
```

By default, `nb-clean` will not delete all notebook metadata. To completely
remove all notebook metadata:
By default, nb-clean will not delete all notebook metadata. To completely remove
all notebook metadata:

```bash
nb-clean add-filter --remove-all-notebook-metadata
```

`nb-clean` will configure a filter in the Git repository in which it is run, and
nb-clean will configure a filter in the Git repository in which it is run, and
won't mutate your global or system Git configuration. To remove the filter, run:

```bash
Expand All @@ -209,8 +209,8 @@ nb-clean remove-filter

### Cleaning (pre-commit hook)

`nb-clean` can also be used as a [pre-commit] hook. You may prefer this to the
Git filter if your project already uses the pre-commit framework.
nb-clean can also be used as a [pre-commit] hook. You may prefer this to the Git
filter if your project already uses the pre-commit framework.

Note that the Git filter and pre-commit hook work differently, with different
effects on your working directory. The pre-commit hook operates on the notebook
Expand All @@ -220,7 +220,7 @@ directory dirty. This means cell outputs are still visible to you in your local
Jupyter instance when using the Git filter, but not when using the pre-commit
hook.

After installing [pre-commit], add the `nb-clean` hook by adding the following
After installing [pre-commit], add the nb-clean hook by adding the following
snippet to `.pre-commit-config.yaml` in the root of your repository:

```yaml
Expand All @@ -231,7 +231,7 @@ repos:
- id: nb-clean
```
You can pass additional arguments to `nb-clean` with an `args` array. The
You can pass additional arguments to nb-clean with an `args` array. The
following example shows how to preserve only two specific metadata fields. Note
that, in the example, the final item `--` in the arg list is mandatory. The
option `--preserve-cell-metadata` may take an arbitrary number of field
Expand All @@ -253,7 +253,7 @@ repos:
```

Run `pre-commit install` to ensure the hook is installed, and
`pre-commit autoupdate` to update the hook to the latest release of `nb-clean`.
`pre-commit autoupdate` to update the hook to the latest release of nb-clean.

### Preserving all nbformat metadata

Expand All @@ -262,15 +262,15 @@ To ignore or preserve specifically the metadata defined in the
use the following options:
`--preserve-cell-metadata collapsed scrolled deletable editable format name tags jupyter execution`.

### Migrating to `nb-clean` 2
### Migrating to nb-clean 2

The following table maps from the command line interface of `nb-clean` 1.6.0 to
that of `nb-clean` >=2.0.0.
The following table maps from the command line interface of nb-clean 1.6.0 to
that of nb-clean >=2.0.0.

The examples in the table use long flags, but short flags can also be used
instead.

| Description | `nb-clean` 1.6.0 | `nb-clean` >=2.0.0 |
| Description | nb-clean 1.6.0 | nb-clean >=2.0.0 |
| ------------------------------------------- | ---------------------------------------------------------------- | ----------------------------------------------------------- |
| Clean notebook | `nb-clean clean --input notebook.ipynb \| sponge notebook.ipynb` | `nb-clean clean notebook.ipynb` |
| Clean notebook (remove empty cells) | `nb-clean clean --input notebook.ipynb --remove-empty` | `nb-clean clean --remove-empty-cells notebook.ipynb` |
Expand All @@ -285,11 +285,9 @@ instead.

Copyright © Scott Stevenson.

`nb-clean` is distributed under the terms of the [ISC license].
nb-clean is distributed under the terms of the [ISC license].

[conda]: https://docs.conda.io/
[isc license]: https://opensource.org/licenses/ISC
[papermill]: https://papermill.readthedocs.io/
[pip]: https://pip.pypa.io/
[pre-commit]: https://pre-commit.com/
[pypi]: https://pypi.org/project/nb-clean/
[uv]: https://docs.astral.sh/uv/
Loading

0 comments on commit 76e4e69

Please sign in to comment.