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

Switch to uv #127

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
41 changes: 16 additions & 25 deletions .github/workflows/workflow-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ on:

env:
PIP_NO_CACHE_DIR: "off"
POETRY_VIRTUALENVS_IN_PROJECT: "true"
POETRY_NO_INTERACTION: "1"
DOCKER_BUILDKIT: "1"
COMPOSE_DOCKER_CLI_BUILD: "1"

Expand All @@ -28,7 +26,7 @@ env:
CACHE_REGISTRY_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCKER_COMPOSE_SERVICE_NAME: "devtools"
MAIN_PY_VERSION: "3.11"
POETRY_DOCKER_IMAGE: "yakimka/poetry:1.8.2-py3.11-slim"
UV_DOCKER_IMAGE: "ghcr.io/astral-sh/uv:latest"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -68,7 +66,7 @@ jobs:
path: |
.venv
.cache
key: py${{ matrix.python-version }}-${{ hashFiles('./poetry.lock') }}
key: py${{ matrix.python-version }}-${{ hashFiles('./uv.lock') }}

- name: Build docker dev image
run: |
Expand Down Expand Up @@ -118,7 +116,7 @@ jobs:
with:
path: |
.venv
key: pypy${{ matrix.pypy-version }}-${{ hashFiles('./poetry.lock') }}
key: pypy${{ matrix.pypy-version }}-${{ hashFiles('./uv.lock') }}

- name: Pull docker image
run: |
Expand All @@ -132,9 +130,9 @@ jobs:
if [ ! -d .venv ]; then
python -m venv .venv;
fi
&& .venv/bin/pip install poetry
&& .venv/bin/poetry install
&& .venv/bin/pip install --no-deps -e .
&& .venv/bin/pip install uv
&& .venv/bin/uv sync
&& .venv/bin/uv pip install --no-deps -e .
&& .venv/bin/pytest
"

Expand Down Expand Up @@ -162,7 +160,7 @@ jobs:
with:
path: |
.venv
key: free-threading${{ matrix.image-name }}-${{ hashFiles('./poetry.lock') }}
key: free-threading${{ matrix.image-name }}-${{ hashFiles('./uv.lock') }}

- name: Pull docker image
run: |
Expand Down Expand Up @@ -197,18 +195,11 @@ jobs:
run: |
docker login "$REGISTRY" -u "$REGISTRY_USERNAME" --password="${REGISTRY_TOKEN}" || true

- name: Pull and spin dev container
run: |
docker run -v $(pwd):/code -w /code --rm -d --name=poetry ${POETRY_DOCKER_IMAGE} sleep infinity

- run: echo "PROJECT_VERSION=$(docker exec poetry poetry version --short)" >> $GITHUB_ENV
- run:
echo "PROJECT_VERSION=$(grep -m 1 '^version' pyproject.toml | cut -d '"' -f2)" >> $GITHUB_ENV

- name: Login to PyPI
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
echo "Login"
docker exec poetry poetry config pypi-token.pypi $PYPI_TOKEN || true
- run:
echo $PROJECT_VERSION

- name: Check if tag version matches project version
if: startsWith(github.ref, 'refs/tags/')
Expand All @@ -218,10 +209,10 @@ jobs:
echo $PROJECT_VERSION
if [[ "$TAG" != "$PROJECT_VERSION" ]]; then exit 1; fi

- name: Build and publish (dry-run)
if: github.actor != 'dependabot[bot]'
run: docker exec poetry poetry publish --dry-run

- name: Build and publish
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
if: startsWith(github.ref, 'refs/tags/')
run: docker exec poetry poetry publish
run: |
docker run -v $(pwd):/code -w /code --rm -d ${UV_DOCKER_IMAGE}
publish dist/*.* --token=$PYPI_TOKEN
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Thank you for considering contributing to Picodi! Below are some guidelines to h

## Making Changes

1. After cloning the repository, install dependencies by running `poetry install`.
1. After cloning the repository, install dependencies by running `uv sync`.
This will create a virtual environment in project directory and install all dependencies.
2. Make your changes.
3. If you are adding new functionality, add tests for it.
Expand Down
10 changes: 4 additions & 6 deletions Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# https://github.com/python-poetry/poetry/discussions/1879#discussioncomment-216865
# `python-base` sets up all our shared environment variables
ARG PYTHON_VERSION=3.11
FROM python:${PYTHON_VERSION}-slim-bullseye as python-base
Expand All @@ -8,10 +7,9 @@ ENV PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_VERSION=1.8.2 \
UV_VERSION=0.4.20 \
UV_PYTHON_DOWNLOADS=never \
VENV_PATH="/opt/venv" \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_NO_INTERACTION=1 \
CODE_PATH="/opt/code"

ENV XDG_CACHE_HOME="$CODE_PATH/.cache" \
Expand Down Expand Up @@ -53,7 +51,7 @@ RUN set -ex \
&& rm -rf /var/lib/apt/lists/*

RUN python -m venv $VENV_PATH
RUN pip install poetry==$POETRY_VERSION
RUN pip install uv==$UV_VERSION


# `development` image is used during development / testing
Expand All @@ -65,4 +63,4 @@ COPY --from=builder-base $VENV_PATH $VENV_PATH

USER $USER_NAME

CMD ["poetry", "install"]
CMD ["uv", "sync"]
23 changes: 11 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ all: help

.PHONY: pre-commit
pre-commit: ## Run pre-commit with args
$(RUN) poetry run pre-commit $(args)
$(RUN) uv run pre-commit $(args)

.PHONY: poetry
poetry: ## Run poetry with args
$(RUN) poetry $(args)
.PHONY: uv
uv: ## Run uv with args
$(RUN) uv $(args)

.PHONY: lint
lint: ## Run flake8, mypy, other linters and verify formatting
Expand All @@ -23,27 +23,26 @@ lint: ## Run flake8, mypy, other linters and verify formatting

.PHONY: mypy
mypy: ## Run mypy
$(RUN) poetry run mypy $(args)
$(RUN) uv run mypy $(args)

.PHONY: test
test: ## Run tests
$(RUN) poetry run pytest --cov=tests --cov=picodi $(args)
$(RUN) poetry run pytest --dead-fixtures
$(RUN) uv run pytest --cov=tests --cov=picodi $(args)
$(RUN) uv run pytest --dead-fixtures

.PHONY: test-docs
test-docs: ## Check docs
$(MAKE) -C docs test
$(RUN) poetry run pytest --markdown-docs -m markdown-docs $(args)
$(RUN) uv run pytest --markdown-docs -m markdown-docs $(args)

.PHONY: package
package: ## Run packages (dependencies) checks
$(RUN) poetry check
$(RUN) poetry run pip check
$(RUN) uv pip check

.PHONY: build-package
build-package: ## Build package
$(RUN) poetry build $(args)
$(RUN) poetry export --format=requirements.txt --output=dist/requirements.txt
$(RUN) uv build $(args)
$(RUN) uv export --format=requirements-txt --output-file=dist/requirements --locked --no-dev --no-emit-project

.PHONY: checks
checks: lint package test ## Run linting and tests
Expand Down
17 changes: 8 additions & 9 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ run_ci () {
# Testing filesystem and permissions:
touch .perm && rm -f .perm

poetry install
poetry run pre-commit run --all-files
poetry run mypy
poetry check
poetry run pip check
poetry run pytest --cov=tests --cov=picodi --cov-report=xml --junitxml=jcoverage.xml
poetry run pytest --dead-fixtures
poetry build
poetry export --format=requirements.txt --output=dist/requirements.txt
uv sync
uv run pre-commit run --all-files
uv run mypy
uv run pip check
uv run pytest --cov=tests --cov=picodi --cov-report=xml --junitxml=jcoverage.xml
uv run pytest --dead-fixtures
uv build
uv export --format=requirements-txt --output-file=dist/requirements --locked --no-dev --no-emit-project
# print shasum of the built packages
shasum dist/*
# trying to build the docs
Expand Down
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= poetry run sphinx-build
SPHINXBUILD ?= uv run sphinx-build
SOURCEDIR = .
BUILDDIR = _build

Expand Down
Loading
Loading