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

Replace Poetry with uv for dependency management and workflows #612

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
706ca2b
Update pyproject.toml
cpaniaguam Dec 17, 2024
1363f32
Replace poetry installation with uv setup in GitHub Actions workflow
cpaniaguam Dec 17, 2024
077d9ff
Replace Poetry setup with uv in linting and type checking workflow
cpaniaguam Dec 17, 2024
26d4323
Remove unused virtualenv configuration from UV setup in GitHub Actions
cpaniaguam Dec 17, 2024
aec6970
Replace Poetry setup with uv in GitHub Actions test workflow
cpaniaguam Dec 17, 2024
6f962af
Refactor linting and type checking to use action
cpaniaguam Dec 17, 2024
2d601bd
Add step to install development dependencies in linting workflow
cpaniaguam Dec 17, 2024
145f395
Update linting workflow to install dev dependencies with system flag
cpaniaguam Dec 17, 2024
b3ee6fb
Update documentation build workflow
cpaniaguam Dec 17, 2024
5887487
Refactor build and publish workflow
cpaniaguam Dec 17, 2024
3067f1c
Replace Poetry environment setup with a new Python environment setup …
cpaniaguam Dec 17, 2024
41dd30b
Refactor linting workflow to use custom environment setup
cpaniaguam Dec 17, 2024
ae28863
Refactor setup environment action
cpaniaguam Dec 17, 2024
0119314
Restore linting and type checking
cpaniaguam Dec 17, 2024
fb9d29b
Specify bash as the shell for the install step in the setup environme…
cpaniaguam Dec 17, 2024
c9a1cd2
Refactor linting workflow to use custom environment setup
cpaniaguam Dec 17, 2024
479e41b
Specify bash as the shell for the Python installation step in the set…
cpaniaguam Dec 17, 2024
bc7ff02
Update installation command for hssm in setup environment action
cpaniaguam Dec 17, 2024
8a20706
Refactor test workflow to use custom environment setup
cpaniaguam Dec 17, 2024
ccd41c6
Refactor build_docs workflow to use custom environment setup
cpaniaguam Dec 17, 2024
c01d79d
Refactor build_and_publish workflow to use custom environment setup
cpaniaguam Dec 17, 2024
5bf7d0a
Update .gitignore to include coverage.xml and additional lock files
cpaniaguam Dec 17, 2024
076805a
Merge branch 'main' into migrate-to-uv
cpaniaguam Dec 17, 2024
54e8ced
Update CONTRIBUTING.md to replace Poetry with uv
cpaniaguam Dec 17, 2024
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
32 changes: 32 additions & 0 deletions .github/setup-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Setup Python environment
description: Set up Python environment for the repository
inputs:
python-version:
description: "The Python version to set up"
required: true

runs:
using: "composite"
steps:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}

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

- name: Install uv
uses: astral-sh/setup-uv@v4
with:
# Install a specific version of uv.
version: "0.5.9"

- name: Set up Python ${{ inputs.python-version }}
run: uv python install ${{ inputs.python-version }}
shell: bash

- name: Install hssm
if: steps.cache.outputs.cache-hit != 'true'
run: uv pip install --system ".[dev]"
shell: bash
35 changes: 0 additions & 35 deletions .github/setup-poetry-env/action.yml

This file was deleted.

39 changes: 20 additions & 19 deletions .github/workflows/build_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ jobs:
name: Lint and type-check
uses: ./.github/workflows/linting_and_type_checking.yml

run_fast_tests:
name: Run fast tests
uses: ./.github/workflows/run_fast_tests.yml

run_slow_tests:
name: Run slow tests
uses: ./.github/workflows/run_slow_tests.yml
run_tests:
name: Run tests
uses: ./.github/workflows/run_tests.yml

publish:
name: Build wheel and publish to test-PyPI, and then PyPI, and publish docs
Expand All @@ -31,26 +27,31 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Poetry environment
uses: ./.github/setup-poetry-env
- name: Setup environment
uses: ./.github/setup-env
with:
python-version: ${{ matrix.python-version }}

- name: Setup test-PyPI credentials
run: |
poetry config repositories.testpypi https://test.pypi.org/legacy/
poetry config pypi-token.testpypi ${{ secrets.TEST_PYPI_TOKEN }}

- name: Build the wheel
run: poetry build
run: python -m build

- name: Publish to test-PyPI
run: poetry publish -r testpypi
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }}
run: |
python -m twine upload --repository testpypi dist/*

- name: Publish to PyPI
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
run: poetry publish
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
python -m twine upload dist/*

- name: Install doc dependencies
run: |
$HOME/.cargo/bin/uv pip install -e '.[dev]'

- name: Build and publish docs
run: poetry run mkdocs gh-deploy --force
run: mkdocs gh-deploy --force
9 changes: 6 additions & 3 deletions .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Poetry environment
uses: ./.github/setup-poetry-env
- name: Setup environment
uses: ./.github/setup-env
with:
python-version: ${{ matrix.python-version }}

- name: Install dev dependencies
run: uv pip install --system -e ".[dev]"

- name: Run mkdocs
run: poetry run mkdocs gh-deploy --force
run: uv run mkdocs gh-deploy --force
10 changes: 5 additions & 5 deletions .github/workflows/linting_and_type_checking.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Poetry environment
uses: ./.github/setup-poetry-env
- name: Setup environment
uses: ./.github/setup-env
with:
python-version: ${{ matrix.python-version }}

- name: Run mypy
run: poetry run mypy src/hssm
run: mypy src/hssm

- name: Check formatting
run: poetry run ruff format --check .
run: ruff format --check .

- name: Linting
run: poetry run ruff check src/hssm
run: ruff check src/hssm
10 changes: 3 additions & 7 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,13 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Poetry environment
uses: ./.github/setup-poetry-env
- name: Setup environment
uses: ./.github/setup-env
with:
python-version: ${{ matrix.python-version }}

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

- name: Run tests and collect coverage
run: poetry run pytest -n=auto --cov=. --cov-report=xml --cov-report=term-missing --exitfirst --capture=no tests/
run: uv run pytest -n=auto --cov=. --cov-report=xml --cov-report=term-missing --exitfirst --capture=no tests/
env:
PYTENSOR_FLAGS: ${{ env.PYTENSOR_FLAGS }}

Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ htmlcov/
.mypy_cache/
.ruff_cache/
tests/__pycache__
coverage.xml

# Jupyter Notebook
.ipynb_checkpoints
Expand All @@ -52,8 +53,9 @@ env/
venv/
ENV/

# Also ignore poetry.lock
# Also ignore lock files
poetry.lock
uv.lock

# Editor cruft
.idea/
Expand Down
11 changes: 5 additions & 6 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ The preferred workflow for contributing to HSSM is to fork the GitHub repository
```

> [!Note]
> If your changes require libraries not included in `hssm`, you'll need to use Poetry to update the dependency files. Please visit the [official Poetry documentation](https://python-poetry.org/docs/) and follow the installation instructions to install Poetry on your system.
> If your changes require libraries not included in `hssm`, you'll need to use `uv` to update the dependency files. Please visit the [official `uv` documentation](https://docs.astral.sh/uv/) and follow the installation instructions.
>
> After installing Poetry, you can add the new libraries (dependencies) to [`pyproject.toml`](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#writing-your-pyproject-toml) by running:
> After installing `uv`, you can add the new libraries (dependencies) to [`pyproject.toml`](https://docs.astral.sh/uv/guides/projects/#managing-dependencies) by running:
> ```
> poetry add <package-name>
> uv add <package-name>
> ```
> Replace `<package-name>` with the name of the library you need to add. This command will update the `pyproject.toml` file and install the new dependency. It will also add changes to the [`poetry.lock`](https://python-poetry.org/docs/basic-usage/#committing-your-poetrylock-file-to-version-control) file.
> Replace `<package-name>` with the name of the library you need to add. This command will update the `pyproject.toml` file and install the new dependency. It will also add changes to the [`uv.lock`](https://docs.astral.sh/uv/guides/projects/#uvlock) file.
>
> Remember to commit the newly changed files.
> ```
> git add pyproject.toml poetry.lock
> git add pyproject.toml uv.lock
> git commit -m "Add <package-name> dependency"
> ```

Expand All @@ -85,4 +85,3 @@ The preferred workflow for contributing to HSSM is to fork the GitHub repository
- Click the ‘Pull request’ button to send your changes to the project’s maintainers for review.

**This guide is adapted from the [ArviZ contribution guide](https://github.com/arviz-devs/arviz/blob/main/CONTRIBUTING.md)**

84 changes: 42 additions & 42 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
[tool.poetry]
[project]
name = "HSSM"
version = "0.2.4"
description = "Bayesian inference for hierarchical sequential sampling models."
authors = [
"Alexander Fengler <alexander_fengler@brown.edu>",
"Paul Xu <yang_xu@brown.edu>",
"Aisulu Omar <aisulu_omar@brown.edu>",
"Michael Frank <michael_frank@brown.edu>",
{name = "Alexander Fengler", email = "alexander_fengler@brown.edu"},
{name = "Paul Xu", email = "yang_xu@brown.edu"},
{name = "Aisulu Omar", email = "aisulu_omar@brown.edu"},
{name = "Michael Frank", email = "michael_frank@brown.edu"}
]
readme = "README.md"
license = "Copyright 2023, Brown University, Providence, RI."
packages = [{ include = "hssm", from = "src" }]
license = "LicenseRef-Proprietary" # TODO: Update license
repository = "https://github.com/lnccbrown/HSSM"
keywords = ["HSSM", "sequential sampling models", "bayesian", "bayes", "mcmc"]

[tool.poetry.dependencies]
python = ">=3.10,<=3.12"
pymc = ">=5.16.2,<5.17.0"
arviz = "^0.19.0"
onnx = "^1.16.0"
ssm-simulators = "^0.7.5"
huggingface-hub = "^0.24.6"
bambi = ">=0.14.0,<0.15.0"
numpyro = "^0.15.2"
hddm-wfpt = "^0.1.4"
seaborn = "^0.13.2"
tqdm = "^4.66.0"
jax = { version = "^0.4.25", extras = ["cuda12"], optional = true }
numpy = ">=1.26.4,<2.0.0"
requires-python = ">=3.10,<3.13"

[tool.poetry.group.dev.dependencies]
pytest = "^8.3.1"
mypy = "^1.11.1"
pre-commit = "^2.20.0"
jupyterlab = "^4.2.4"
ipykernel = "^6.29.5"
ipywidgets = "^8.1.2"
ruff = "^0.6.2"
graphviz = "^0.20.3"
pytest-xdist = "^3.6.1"
onnxruntime = "^1.17.1"
mkdocs = "^1.6.0"
mkdocs-material = "^9.5.21"
mkdocstrings-python = "^1.10.0"
mkdocs-jupyter = "^0.24.8"
pytest-cov = "^6.0.0"
coverage = "^7.6.4"
dependencies = [
"pymc>=5.16.2,<5.17.0",
"arviz>=0.19.0",
"onnx>=1.16.0",
"ssm-simulators>=0.7.5",
"huggingface-hub>=0.24.6",
"bambi>=0.14.0,<0.15.0",
"numpyro>=0.15.2",
"hddm-wfpt>=0.1.4",
"seaborn>=0.13.2",
"tqdm>=4.66.0",
"numpy>=1.26.4,<2.0.0"
]

[tool.poetry.extras]
cuda12 = ["jax"]
[project.optional-dependencies]
cuda12 = ["jax[cuda12]"]
dev = [
"pytest>=8.3.1",
"mypy>=1.11.1",
"pre-commit>=2.20.0",
"jupyterlab>=4.2.4",
"ipykernel>=6.29.5",
"ipywidgets>=8.1.2",
"ruff>=0.6.2",
"graphviz>=0.20.3",
"pytest-xdist>=3.6.1",
"onnxruntime>=1.17.1",
"mkdocs>=1.6.0",
"mkdocs-material>=9.5.21",
"mkdocstrings-python>=1.10.0",
"mkdocs-jupyter>=0.24.8",
"pytest-cov>=6.0.0",
"coverage>=7.6.4"
]

[tool.ruff]
line-length = 88
Expand Down Expand Up @@ -168,5 +168,5 @@ ignore_missing_imports = true
testpaths = ["tests"]

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
requires = ["hatchling"]
build-backend = "hatchling.build"
Loading