Skip to content

Commit

Permalink
Add uv
Browse files Browse the repository at this point in the history
  • Loading branch information
fpgmaas committed Sep 3, 2024
1 parent 6b521d4 commit 5f29e10
Show file tree
Hide file tree
Showing 44 changed files with 1,269 additions and 1,767 deletions.
9 changes: 4 additions & 5 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "Cookiecutter Poetry",
"name": "Cookiecutter uv",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bullseye",
"features": {
"ghcr.io/devcontainers-contrib/features/cookiecutter:2": {},
"ghcr.io/devcontainers-contrib/features/poetry:2": {}
"ghcr.io/devcontainers-contrib/features/cookiecutter:2": {}
},

// Use 'postCreateCommand' to run commands after the container is created.
Expand All @@ -20,8 +19,8 @@
"python.testing.pytestArgs": ["tests"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.defaultInterpreterPath": "/workspaces/cookiecutter-poetry/.venv/bin/python",
"python.testing.pytestPath": "/workspaces/cookiecutter-poetry/.venv/bin/pytest"
"python.defaultInterpreterPath": "/workspaces/cookiecutter-uv/.venv/bin/python",
"python.testing.pytestPath": "/workspaces/cookiecutter-uv/.venv/bin/pytest"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env bash

# Install Dependencies
poetry install --with dev
uv sync

# Install pre-commit hooks
poetry run pre-commit install --install-hooks
uv run pre-commit install --install-hooks
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Steps to reproduce the behavior:

- OS: e.g. [Ubuntu 18.04]
- Language Version: [e.g. Python 3.8]
- Virtual environment: [e.g. Poetry 1.1.13]
- Virtual environment: [e.g. uv 1.0.0]

**Additional context**

Expand Down
42 changes: 0 additions & 42 deletions .github/actions/setup-poetry-env/action.yml

This file was deleted.

25 changes: 25 additions & 0 deletions .github/actions/setup-python-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: 'Setup Python Environment'
description: 'Set up Python environment for the given Python version'

inputs:
python-version:
description: 'Python version for setup-python'
required: true
default: '3.12'

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

- name: Install uv
run: pipx install uv
env:
UV_VERSION: '0.4.2'
shell: bash

- name: Install Python dependencies
run: uv sync --frozen
shell: bash
20 changes: 10 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ jobs:
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}

- name: Set up the environment
uses: ./.github/actions/setup-poetry-env
uses: ./.github/actions/setup-python-env

- name: Run pre-commit
run: poetry run pre-commit run -a --show-diff-on-failure
run: uv run pre-commit run -a --show-diff-on-failure

- name: Inspect dependencies
run: poetry run deptry .
run: uv run deptry .

- name: Check Poetry lock file consistency
run: poetry lock --check
- name: Check lock file consistency
run: uv sync --locked

tests-and-type-check:
runs-on: ubuntu-latest
Expand All @@ -44,15 +44,15 @@ jobs:
uses: actions/checkout@v4

- name: Set up the environment
uses: ./.github/actions/setup-poetry-env
uses: ./.github/actions/setup-python-env
with:
python-version: ${{ matrix.python-version }}

- name: Run tests
run: poetry run pytest tests --cov --cov-config=pyproject.toml --cov-report=xml
run: uv run pytest tests --cov --cov-config=pyproject.toml --cov-report=xml

- name: Check typing
run: poetry run mypy
run: uv run mypy

- name: Upload coverage reports to Codecov with GitHub Action on Python 3.11 for Ubuntu
uses: codecov/codecov-action@v3
Expand All @@ -65,7 +65,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up the environment
uses: ./.github/actions/setup-poetry-env
uses: ./.github/actions/setup-python-env

- name: Check if documentation can be built
run: poetry run mkdocs build -s
run: uv run mkdocs build -s
51 changes: 39 additions & 12 deletions .github/workflows/on-release-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,53 @@ on:
branches: [main]

jobs:

set-version:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

- name: Export tag
id: vars
run: echo tag=${GITHUB_REF#refs/*/} >> $GITHUB_OUTPUT
if: ${{ github.event_name == 'release' }}

- name: Update project version
run: |
sed -i "s/^version = \".*\"/version = \"$RELEASE_VERSION\"/" pyproject.toml
env:
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
if: ${{ github.event_name == 'release' }}

- name: Upload updated pyproject.toml
uses: actions/upload-artifact@v4
with:
name: pyproject-toml
path: pyproject.toml

publish:
runs-on: ubuntu-latest
needs: [set-version]
steps:
- name: Check out
uses: actions/checkout@v4

- name: Set up the environment
uses: ./.github/actions/setup-poetry-env
uses: ./.github/actions/setup-python-env

- name: Export tag
id: vars
run: echo tag=${GITHUB_REF#refs/*/} >> $GITHUB_OUTPUT
- name: Download updated pyproject.toml
uses: actions/download-artifact@v4
with:
name: pyproject-toml

- name: Build and publish
run: |
poetry version $RELEASE_VERSION
make build-and-publish
- name: Build package
run: uvx --from build pyproject-build --installer uv

- name: Publish package
run: uvx twine upload dist/*
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}

deploy-docs:
runs-on: ubuntu-latest
Expand All @@ -35,7 +62,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up the environment
uses: ./.github/actions/setup-poetry-env
uses: ./.github/actions/setup-python-env

- name: Deploy documentation
run: poetry run mkdocs gh-deploy --force
run: uv run mkdocs gh-deploy --force
29 changes: 1 addition & 28 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
example-project
cookiecutter-poetry-example
cookiecutter-uv-example

# From https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore

Expand Down Expand Up @@ -87,33 +87,6 @@ target/
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

Expand Down
26 changes: 9 additions & 17 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ You can contribute in many ways:

## Report Bugs

Report bugs at <https://github.com/fpgmaas/cookiecutter-poetry/issues
Report bugs at <https://github.com/fpgmaas/cookiecutter-uv/issues

If you are reporting a bug, please include:

Expand All @@ -33,7 +33,7 @@ Cookiecutter PyPackage could always use more documentation, whether as part of t

## Submit Feedback

The best way to send feedback is to file an issue at <https://github.com/fpgmaas/cookiecutter-poetry/issues.
The best way to send feedback is to file an issue at <https://github.com/fpgmaas/cookiecutter-uv/issues.

If you are proposing a new feature:

Expand All @@ -43,42 +43,34 @@ If you are proposing a new feature:

# Get Started!

Ready to contribute? Here\'s how to set up `cookiecutter-poetry` for local development.
Please note this documentation assumes you already have `poetry` and `git` installed and ready to go.
Ready to contribute? Here\'s how to set up `cookiecutter-uv` for local development.
Please note this documentation assumes you already have `uv` and `git` installed and ready to go.

1. Fork the `cookiecutter-poetry` repo on GitHub.
1. Fork the `cookiecutter-uv` repo on GitHub.

2. Clone your fork locally:

```bash
cd <directory_in_which_repo_should_be_created
git clone [email protected]:YOUR_NAME/cookiecutter-poetry.git
git clone [email protected]:YOUR_NAME/cookiecutter-uv.git
```

3. Now we need to install the environment.
Navigate into the project directory:

```bash
cd cookiecutter-poetry
```

If you are using `pyenv`, select a version to use locally.
(See installed versions with `pyenv versions`)

```bash
pyenv local <x.y.z
cd cookiecutter-uv
```

Then, install and activate the environment with:

```bash
poetry install
poetry shell
uv sync
```

4. Install pre-commit to run linters/formatters at commit time:

poetry run pre-commit install
uv run pre-commit install

5. Create a branch for local development:

Expand Down
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include cookiecutter.json
recursive-include hooks *
recursive-include {{cookiecutter.project_name}} *
Loading

0 comments on commit 5f29e10

Please sign in to comment.