Skip to content

Commit

Permalink
Switch dependency management to uv (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebarron authored Dec 17, 2024
1 parent 07b18ac commit a43c5d3
Show file tree
Hide file tree
Showing 7 changed files with 4,112 additions and 4,910 deletions.
34 changes: 6 additions & 28 deletions .github/workflows/deploy-mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Publish docs via GitHub Pages
on:
push:
tags:
- 'v*'
- "v*"
workflow_dispatch:

jobs:
Expand All @@ -17,33 +17,11 @@ jobs:
with:
fetch-depth: 0

- name: Set up Python 3.11
id: setup-python
uses: actions/setup-python@v5
- name: Install a specific version of uv
uses: astral-sh/setup-uv@v3
with:
python-version: "3.11"

- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
version: 1.6.1
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root

- name: Install root project
run: poetry install --no-interaction
enable-cache: true
version: "0.4.x"

- name: Deploy docs
env:
Expand All @@ -59,5 +37,5 @@ jobs:
# Only push docs if no letters in git tag after the first character
# (usually the git tag will have v as the first character)
if ! echo $VERSION | sed 's/^.//' | grep -q "[A-Za-z]"; then
poetry run mike deploy $VERSION latest --update-aliases --push
uv run --group docs mike deploy $VERSION latest --update-aliases --push
fi
46 changes: 13 additions & 33 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,64 +42,44 @@ jobs:
# Note: we use ci for a "clean install", checking the lockfile
npm ci
- name: Install and configure Poetry
uses: snok/install-poetry@v1
- name: Install a specific version of uv
uses: astral-sh/setup-uv@v3
with:
version: 1.7.0
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

- name: Check Poetry lockfile up to date
run: |
poetry check --lock
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
enable-cache: true
version: "0.4.x"

# Note: we don't install the "watchfiles" group on CI because it gives
# threading errors when running tests. See
# https://github.com/developmentseed/lonboard/pull/234
# https://github.com/manzt/anywidget/issues/374
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root --without watchfiles

- name: Install root project
run: poetry install --no-interaction --without watchfiles
run: uv sync --no-group watchfiles

- name: Build JS bundle
run: |
npm run build
- name: Run tests
run: poetry run pytest
run: uv run pytest

- name: Run tests (all deps)
run: |
poetry install -E geopandas -E cli
poetry run pytest
uv sync --extra geopandas --extra cli
uv run pytest
# Ensure docs build without warnings
- name: Check docs
if: matrix.python-version == 3.9
run: poetry run mkdocs build --strict
if: "${{ matrix.python-version == 3.11 }}"
run: uv run --group docs mkdocs build --strict

- name: Cache pre-commit virtualenvs
uses: actions/cache@v4
if: matrix.python-version == 3.9
if: "${{ matrix.python-version == 3.11 }}"
with:
path: ~/.cache/pre-commit
key: pre-commit-3|${{ hashFiles('.pre-commit-config.yaml') }}

# TODO: switch this to run on e.g. 3.11 (how to get the if statement to
# work?)
# Run pre-commit (only for python-3.9)
- name: run pre-commit
if: matrix.python-version == 3.9
if: "${{ matrix.python-version == 3.11 }}"
run: |
poetry run pre-commit run --show-diff-on-failure --color=always --all-files
uv run pre-commit run --show-diff-on-failure --color=always --all-files
35 changes: 9 additions & 26 deletions DEVELOP.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,23 @@

## Python

To install Python, I recommend [pyenv](https://github.com/pyenv/pyenv). After installing pyenv, install a Python version with e.g.:
Install [uv](https://docs.astral.sh/uv/).

```
pyenv install 3.11.4
```

then set that as your global Python version with

```
pyenv global 3.11.4
```

This project uses [Poetry](https://python-poetry.org/) to manage Python dependencies.

After installing Poetry, run
To register the current uv-managed Python environment with JupyterLab, run

```
poetry install
```

to install all dependencies.

To register the current Poetry-managed Python environment with JupyterLab, run

```
poetry run python -m ipykernel install --user --name "lonboard"
uv run python -m ipykernel install --user --name "lonboard"
```

JupyterLab is an included dev dependency, so to start JupyterLab you can run

```
ANYWIDGET_HMR=1 poetry run jupyter lab
ANYWIDGET_HMR=1 uv run jupyter lab
```

Note that `ANYWIDGET_HMR=1` is necessary to turn on "hot-reloading", so that any
updates you make in JavaScript code are automatically updated in your notebook.

Then you should see a tile on the home screen that lets you open a Jupyter Notebook in the `lonboard` environment. You should also be able to open up an example notebook from the `examples/` folder.

## JavaScript
Expand Down Expand Up @@ -82,10 +65,10 @@ Push a new tag to the main branch of the format `v*`. A new version will be publ

## Documentation website

The documentation website is generated with `mkdocs` and [`mkdocs-material`](https://squidfunk.github.io/mkdocs-material). After `poetry install`, you can serve the docs website locally with
The documentation website is generated with `mkdocs` and [`mkdocs-material`](https://squidfunk.github.io/mkdocs-material). You can serve the docs website locally with

```
poetry run mkdocs serve
uv run mkdocs serve
```

Publishing documentation happens automatically via CI when a new tag is published of the format `v*`. It can also be triggered manually through the Github Actions dashboard on [this page](https://github.com/developmentseed/lonboard/actions/workflows/deploy-mkdocs.yml). Note that publishing docs manually is **not advised if there have been new code additions since the last release** as the new functionality will be associated in the documentation with the tag of the _previous_ release. In this case, prefer publishing a new patch or minor release, which will publish both a new Python package and the new documentation for it.
Loading

0 comments on commit a43c5d3

Please sign in to comment.