Skip to content

Commit

Permalink
Switch from Poetry to uv
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Jun 12, 2024
1 parent 3dd7c2d commit 5290caf
Show file tree
Hide file tree
Showing 11 changed files with 1,222 additions and 1,205 deletions.
38 changes: 19 additions & 19 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Build

env:
POETRY_VERSION: "1.8.3"
PYTHON_VERSION: "3.12"

on:
Expand Down Expand Up @@ -37,20 +36,21 @@ jobs:
with:
python-version: "${{ env.PYTHON_VERSION }}"

- name: Set up Poetry
- name: Set up uv
run: |
pip install poetry==${{ env.POETRY_VERSION }}
curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Publish to Test PyPI
id: build
env:
POETRY_PYPI_TOKEN_TEST_PYPI: ${{ secrets.TEST_PYPI_API_TOKEN }}
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
run: |
version=$(./scripts/version dev)
echo "version=$version" >> $GITHUB_OUTPUT
poetry version $version
poetry config repositories.test-pypi https://test.pypi.org/legacy/
poetry publish --build -r test-pypi
sed -i -e "s/0.0.0/$version/" pyproject.toml
uv tool run -- hatchling build
uv tool run -- twine upload -r testpypi dist/*
test-install:
# We test the install on a clean machine to avoid poetry behavior attempting to
Expand All @@ -66,11 +66,9 @@ jobs:
with:
python-version: "${{ env.PYTHON_VERSION }}"

- name: Set up Poetry
- name: Set up uv
run: |
pip install poetry==${{ env.POETRY_VERSION }}
poetry init --name 'test-project' --no-interaction
poetry source add test-pypi https://test.pypi.org/simple/ --priority=explicit
curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Wait for package to be available
run: >
Expand All @@ -80,23 +78,25 @@ jobs:
do sleep 10;
done
&&
sleep 120
# We sleep for an additional 120 seconds as it seems to take a bit longer for
sleep 180
# We sleep for an additional 180 seconds as it seems to take a bit longer for
# the package to be consistently available
# Note: The above will not sleep forever due to the job level timeout
- name: Install release from Test PyPI
run: >
poetry add
--source test-pypi
packse==${{ needs.build-and-publish.outputs.build-version }}
run: |
uv pip install \
--system \
--extra-index-url https://test.pypi.org/simple/ \
--index-strategy unsafe-best-match \
packse==${{ needs.build-and-publish.outputs.build-version }}
- name: Check release version
run: |
installed=$(poetry run python -c "import pkg_resources; print(pkg_resources.get_distribution('packse').version)")
installed=$(python3 -c "import pkg_resources; print(pkg_resources.get_distribution('packse').version)")
test $installed = ${{ needs.build-and-publish.outputs.build-version }}
- name: Check CLI help
run: |
poetry run -- packse --help
packse --help
19 changes: 4 additions & 15 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Check

env:
POETRY_VERSION: "1.8.3"

on:
pull_request:
Expand Down Expand Up @@ -29,32 +28,22 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Poetry
- name: Set up uv
run: |
pipx install poetry==${{ env.POETRY_VERSION }}
curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: "${{ matrix.python-version }}"
cache: poetry

- name: Install packages
run: |
poetry install

- name: Check Python lint
run: |
poetry run -- ruff check . --config pyproject.toml
uv tool run -- ruff check . --config pyproject.toml
- name: Check Python formatting
run: |
poetry run -- ruff format --check . --config pyproject.toml
- name: Check packaging
run: |
poetry check
poetry lock --check
uv tool run -- ruff format --check . --config pyproject.toml
typos:
runs-on: ubuntu-latest
Expand Down
20 changes: 9 additions & 11 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ env:
# Enable colored output
# https://github.com/actions/runner/issues/241
PY_COLORS: 1
POETRY_VERSION: "1.8.3"

permissions:
id-token: write # Needed for AWS CodeArtifact OIDC
Expand Down Expand Up @@ -36,15 +35,14 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Poetry
- name: Set up uv
run: |
pipx install poetry==${{ env.POETRY_VERSION }}
curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: poetry

- name: Install zsh
run: |
Expand All @@ -53,7 +51,7 @@ jobs:
- name: Install packages
run: |
poetry install --extras index
uv sync --extra index
- name: Collect scenarios
run: |
Expand All @@ -72,29 +70,29 @@ jobs:

- name: View scenarios
run: |
poetry run packse view $SCENARIOS
uv run -- packse view $SCENARIOS
- name: Build scenarios
run: |
poetry run packse build --skip-root --no-hash $SCENARIOS
uv run -- packse build --skip-root --no-hash $SCENARIOS
- name: Publish scenarios [local]
if: github.ref != 'refs/heads/main'
run: |
# Start the local index server, do not allow packages from PyPI
index_url=$(poetry run packse index up --bg --offline --dist-dir "./published")
index_url=$(uv run -- packse index up --bg --offline --dist-dir "./published")
# Publish the packages
poetry run packse publish --anonymous --index-url "$index_url" dist/*
uv run -- packse publish --anonymous --index-url "$index_url" dist/*
# Shutdown the index server
poetry run packse index down
uv run -- packse index down
- name: Publish scenarios [gh pages]
if: github.ref == 'refs/heads/main'
run: |
commit=$(./scripts/version parts | jq -r ".short_hash")
poetry run packse index build --no-hash --dist-dir ./dist $SCENARIOS
uv run -- packse index build --no-hash --dist-dir ./dist $SCENARIOS
git fetch origin gh-pages
git branch gh-pages FETCH_HEAD
Expand Down
21 changes: 11 additions & 10 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Release

env:
POETRY_VERSION: "1.8.3"

permissions:
contents: write # Needed for GH pages updates
Expand Down Expand Up @@ -29,18 +28,20 @@ jobs:
with:
python-version: "3.12"

- name: Set up Poetry
- name: Set up uv
run: |
pip install poetry==${{ env.POETRY_VERSION }}
curl -LsSf https://astral.sh/uv/install.sh | sh
# Note: If build and publish steps are ever separated, the version must
# be set before building
- name: Publish package
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }}
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
poetry version "${GITHUB_REF#refs/*/}"
poetry publish --build
sed -i -e "s/0.0.0/${GITHUB_REF#refs/*/}/" pyproject.toml
uv tool run -- hatchling build
uv tool run -- twine upload -r testpypi dist/*
release-scenarios:
name: Publish scenarios
Expand All @@ -53,17 +54,17 @@ jobs:
with:
python-version: "3.12"

- name: Set up Poetry
- name: Set up uv
run: |
pip install poetry==${{ env.POETRY_VERSION }}
curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Install packages
run: |
poetry install --all-extras
uv sync --all-extras
- name: Publish scenarios to GitHub Pages
run: |
poetry run packse index build --no-hash scenarios/
uv run -- packse index build --no-hash scenarios/
git fetch origin gh-pages
git branch gh-pages FETCH_HEAD
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ env:
# https://github.com/pytest-dev/pytest/issues/7443
# https://github.com/actions/runner/issues/241
PY_COLORS: 1
POETRY_VERSION: "1.8.3"

on:
pull_request:
Expand Down Expand Up @@ -41,20 +40,19 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Poetry
- name: Set up uv
run: |
pipx install poetry==${{ env.POETRY_VERSION }}
curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: poetry

- name: Install packages
run: |
poetry install --all-extras
uv sync --all-extras --dev
- name: Run tests
run: |
poetry run -- pytest tests
uv run -- pytest tests
20 changes: 18 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@

This document outlines a few tips for contributing to packse.

## Getting started

packse uses `uv`'s preview interface:

Install the project:

```
uv sync
```

Check that packse is available

```
uv run -- packse --help
```

## Running tests

packse uses `pytest`:

```
poetry run pytest
uv run -- pytest
```

## Updating snapshots
Expand All @@ -17,7 +33,7 @@ you should examine whether the changes are correct. If so, you can re-run the
tests with the `--snapshot-update` flag:

```
poetry run pytest --snapshot-update
uv run -- pytest --snapshot-update
```

And then commit the results. In at least some cases, this may commit a snapshot
Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ Python packaging scenarios.

## Installation

Only a local installation is supported at this time:
Install from PyPI:

```bash
poetry install
uv pip install packse
```
Once installed, the `packse` command-line interface will be available.

Depending on your Poetry configuration, you may need to use `poetry run packse` instead or activate Poetry's
virtual environment.
Once installed, the `packse` command-line interface will be available.

## Usage

Expand Down Expand Up @@ -161,9 +159,10 @@ packse publish dist/example-cd797223 --index-url http://localhost:3141 --anonymo
Packages can also be published to the index by placing their distributions in the configured `--dist-dir`. This defaults
to `./dist` which is also the default location used in `packse build`.

By default, the index will fallback to PyPI for missing packages. To test in isolation, use the `--offline` flag.
By default, the index will fallback to PyPI for missing packages. To test in isolation, use the `--offline` flag.

To stop an index running in the background use `packse index down`:

```
packse index down
```
Expand Down
Loading

0 comments on commit 5290caf

Please sign in to comment.