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 136474e
Show file tree
Hide file tree
Showing 7 changed files with 1,181 additions and 73 deletions.
25 changes: 11 additions & 14 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,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 +67,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 @@ -88,13 +87,11 @@ jobs:
- name: Install release from Test PyPI
run: >
poetry add
--source test-pypi
packse==${{ needs.build-and-publish.outputs.build-version }}
uv pip install --system --index-url https://test.pypi.org/simple/ 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
Expand Down
18 changes: 4 additions & 14 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,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
19 changes: 9 additions & 10 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,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 +52,7 @@ jobs:
- name: Install packages
run: |
poetry install --extras index
uv sync --extra index
- name: Collect scenarios
run: |
Expand All @@ -72,29 +71,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
9 changes: 4 additions & 5 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,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
52 changes: 25 additions & 27 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[tool.poetry]
[project]
name = "packse"
version = "0.0.0"
version = "1.0.0"
description = ""
authors = ["Zanie <[email protected]>"]
authors = [{ name = "Astral Software Inc.", email = "[email protected]" }]
readme = "README.md"
keywords = [
"uv", "packse", "requirements", "packaging", "testing"
Expand All @@ -21,35 +21,33 @@ classifiers = [
"Topic :: Software Development :: Testing",
"Topic :: Software Development :: Libraries",
]
requires-python = ">=3.12"
dependencies = [
"msgspec>=0.18.4",
"twine>=4.0.2",
"hatchling>=1.20.0",
"chevron-blue>=0.2.1",
"setuptools>=69.1.1",
"pyyaml>=6.0.1"
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.poetry.scripts]
[project.scripts]
packse = "packse.cli:entrypoint"

[tool.poetry.dependencies]
python = "^3.12"
msgspec = "^0.18.4"
twine = "^4.0.2"
hatchling = "^1.20.0"
chevron-blue = "^0.2.1"
setuptools = "^69.1.1"
pypiserver = { version ="^2.0.1", optional = true}
watchfiles = { version = "^0.21.0", optional = true}
pyyaml = "^6.0.1"

[tool.poetry.extras]
index = ["pypiserver"]
serve = ["pypiserver", "watchfiles"]
[project.optional-dependencies]
index = ["pypiserver>=2.0.1"]
serve = ["packse[index]", "watchfiles>=0.21.0"]

[tool.poetry.group.dev.dependencies]
syrupy = "^4.6.0"
pytest = "^7.4.3"
ruff = "^0.1.12"
psutil = "^5.9.7"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.uv]
dev-dependencies = [
"syrupy>=4.6.0",
"pytest>=7.4.3",
"psutil>=5.9.7",
]

[tool.ruff.lint]
extend-select = ["I", "W292"]
Expand Down
8 changes: 5 additions & 3 deletions src/packse/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ def start_index_server(

try:
# Wait for server to be ready
with server_log_path.open("rb") if server_log_path else nullcontext(
server_process.stdout
) as server_output:
with (
server_log_path.open("rb")
if server_log_path
else nullcontext(server_process.stdout) as server_output
):
line = ""
lines = []

Expand Down
Loading

0 comments on commit 136474e

Please sign in to comment.