Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change poetry to uv #358

Merged
merged 6 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 51 additions & 63 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,30 @@ jobs:
python-version: ['3.9','3.10','3.11','3.12']

steps:
- uses: actions/checkout@v4

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

- name: Install poetry
run: pipx install poetry

- name: Install python dependencies
run: |
poetry env use ${{ matrix.python-version }}
poetry install --with dev --extras all

- name: Run test suite
env:
# show timings of tests
PYTEST_ADDOPTS: "--durations=0"
run: poetry run pytest --run-extra-mlips --cov janus_core --cov-append .

- name: Report coverage to Coveralls
uses: coverallsapp/github-action@v2
with:
parallel: true
flag-name: run-${{ matrix.python-version }}
file: coverage.xml
base-path: janus_core
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "0.5.7"
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: uv sync --all-extras

- name: Run test suite
env:
# show timings of tests
PYTEST_ADDOPTS: "--durations=0"
run: uv run pytest --run-extra-mlips --cov janus_core --cov-append .

- name: Report coverage to Coveralls
uses: coverallsapp/github-action@v2
with:
parallel: true
flag-name: run-${{ matrix.python-version }}
file: coverage.xml
base-path: janus_core

coverage:
needs: tests
Expand All @@ -54,50 +50,42 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4

- name: Check all sources documented
run: |
diff -y --suppress-common-lines \
<(git ls-files janus_core/** | sed '/.py$/!d; s/\/__init__.py//; s#/#.#g; s/.py$//' | sort) \
<(sed -nr '/automodule/{s/.*::\s*//;p}' docs/source/apidoc/* | sort)
- uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Check all sources documented
run: |
diff -y --suppress-common-lines \
<(git ls-files janus_core/** | sed '/.py$/!d; s/\/__init__.py//; s#/#.#g; s/.py$//' | sort) \
<(sed -nr '/automodule/{s/.*::\s*//;p}' docs/source/apidoc/* | sort)

- name: Install poetry
run: pipx install poetry
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "0.5.7"
python-version: "3.12"

- name: Install python dependencies
run: |
poetry env use 3.11
poetry install --with docs
- name: Install dependencies
run: uv sync

- name: Build docs
run: cd docs && poetry run make
- name: Build docs
run: cd docs && uv run make html

pre-commit:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install poetry
run: pipx install poetry
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "0.5.7"
python-version: "3.12"

- name: Install python dependencies
run: |
poetry env use 3.11
poetry install --with pre-commit,docs,dev --extras "chgnet m3gnet"
- name: Install dependencies
run: uv sync

- name: Run pre-commit
run: |
poetry run pre-commit install
poetry run pre-commit run --all-files || ( git status --short ; git diff ; exit 1 )
- name: Run pre-commit
run: |
uv run pre-commit install
uv run pre-commit run --all-files || ( git status --short ; git diff ; exit 1 )
53 changes: 23 additions & 30 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,28 @@ jobs:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
container: sphinxdoc/sphinx

steps:
- uses: actions/checkout@v4

- name: Install poetry
run: |
apt update
apt upgrade -y
apt install -y pipx
pipx install poetry

- name: add deps
run: |
apt install -y python3-dev build-essential

- name: sphinx
run: |
export PATH="$HOME/.local/bin:$PATH"
poetry install --with docs
cd docs
poetry run make html

- name: upload
uses: actions/upload-pages-artifact@v3
with:
# Upload entire repository
path: './docs/build/html/.'

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "0.5.7"
python-version: "3.12"

- name: Install dependencies
run: uv sync

- name: Build docs
run: cd docs && uv run make html

- name: upload
uses: actions/upload-pages-artifact@v3
with:
# Upload entire repository
path: './docs/build/html/.'

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
82 changes: 37 additions & 45 deletions .github/workflows/publish-on-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,42 @@ jobs:
publish:
runs-on: ubuntu-latest
if: github.repository == 'stfc/janus-core' && startsWith(github.ref, 'refs/tags/v')
environment:
name: release

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install poetry
run: pipx install poetry

- name: Build project for distribution
run: |
poetry env use 3.11
poetry build

- name: Check prerelease
id: check-prerelease
run: |
[[ "$(poetry version --short)" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo prerelease=true >> $GITHUB_OUTPUT

- name: Get version from pyproject.toml
run: |
export PYTHONPATH=$(pwd)
echo "VERSION=$(poetry version --short)" >> $GITHUB_ENV

- name: Check version matches tag
if: ${{ ! contains(github.ref, env.VERSION) }}
run: |
echo "Git tag does not match version in pyproject.toml"
exit 1

- name: Create Release
uses: ncipollo/release-action@v1
with:
artifacts: "dist/*"
token: ${{ secrets.GITHUB_TOKEN }}
draft: false
prerelease: steps.check-prerelease.outputs.prerelease == 'true'
skipIfReleaseExists: true

- name: Publish to PyPI
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
run: poetry publish
- name: Checkout repository
uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "0.5.7"
python-version: "3.12"

- name: Install dependencies
run: uv sync

- name: Build
run: uv build

- name: Get version from pyproject.toml
run: echo "VERSION=$(uvx --from=toml-cli toml get --toml-path=pyproject.toml project.version)" >> $GITHUB_ENV

- name: Check version matches tag
if: ${{ ! contains(github.ref, env.VERSION) }}
run: |
echo "Git tag does not match version in pyproject.toml"
exit 1

- name: Create Release
uses: ncipollo/release-action@v1
with:
artifacts: "dist/*"
token: ${{ secrets.GITHUB_TOKEN }}
draft: false
prerelease: steps.check-prerelease.outputs.prerelease == 'true'
skipIfReleaseExists: true

- name: Publish to PyPI
run: uv publish
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ or to install all supported MLIPs:
python3 -m pip install janus-core[all]
```

Individual `extras` are listed in [Getting Started](https://stfc.github.io/janus-core/getting_started/getting_started.html#installation), as well as in [pyproject.toml](pyproject.toml) under `[tool.poetry.extras]`.
Individual `extras` are listed in [Getting Started](https://stfc.github.io/janus-core/getting_started/getting_started.html#installation), as well as in [pyproject.toml](pyproject.toml) under `[project.optional-dependencies]`.


### Further help
Expand Down Expand Up @@ -282,19 +282,18 @@ This is also the case the calculations performed using the CLI, with the same in

## Development

We recommend installing poetry for dependency management when developing for `janus-core`:
We recommend installing uv for dependency management when developing for `janus-core`:

1. Install [poetry](https://python-poetry.org/docs/#installation)
2. (Optional) Create a virtual environment
3. Install `janus-core` with dependencies:
1. Install [uv](https://docs.astral.sh/uv/getting-started/installation)
2. Install `janus-core` with dependencies in a virtual environment:

```shell
git clone https://github.com/stfc/janus-core
cd janus-core
python3 -m pip install --upgrade pip
poetry install --with pre-commit,dev,docs # install with useful dev dependencies
pre-commit install # install pre-commit hooks
pytest -v # discover and run all tests
uv sync --all-extras # Create a virtual environment and install all dependencies
source .venv/bin/activate
pre-commit install # Install pre-commit hooks
pytest -v # Discover and run all tests
```


Expand Down
27 changes: 18 additions & 9 deletions docs/source/developer_guide/get_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,36 @@
Getting started
===============

We recommend `installing poetry <https://python-poetry.org/docs/#installation>`_ for dependency management when developing for ``janus-core``.
We recommend `installing uv <https://docs.astral.sh/uv/getting-started/installation/>`_ for dependency management when developing for ``janus-core``.

This provides a number of useful features, including:

- Dependency management (``poetry [add,update,remove]`` etc.) and organization (groups)
- Storing the versions of all installations in a ``poetry.lock`` file, for reproducible builds
- Improved dependency resolution
- Virtual environment management (optional)
- Building and publishing tools
- `Dependency management <https://docs.astral.sh/uv/concepts/projects/dependencies/>`_ (``uv [add,remove]`` etc.) and organization (`groups <https://docs.astral.sh/uv/concepts/projects/dependencies/#dependency-groups>`_)

- Storing the versions of all installations in a `uv.lock <https://docs.astral.sh/uv/concepts/projects/sync/>`_ file, for reproducible builds

- Improved `dependency resolution <https://docs.astral.sh/uv/concepts/resolution/>`_

- Virtual environment management

- `Building and publishing <https://docs.astral.sh/uv/guides/publish/>`_ tools

* Currently, an external build backend, such as `pdm <https://pypi.org/project/pdm-backend>`_, is required


Dependencies useful for development can then be installed by running::

poetry install --with pre-commit,dev,docs
uv sync
source .venv/bin/activate


Extras, such as optional MLIPs, can also be installed by running::

poetry install --with pre-commit,dev,docs --extras "alignn sevennet"
uv sync --extra alignn --extra sevennet

or to install all supported MLIPs::

poetry install --with pre-commit,dev,docs --extras all
uv sync --all-extras


Running unit tests
Expand Down
Loading
Loading