Skip to content

Commit f90105f

Browse files
authored
Switch environment manager to uv (#17)
## Describe your changes Switch environment managers from `poetry` to `uv`. ## Checklist before requesting a review - [x] The code runs successfully. ```commandline michaelp@MacBook-Air-18 python-project-template % make test uv run pytest -vs tests/ ========= test session starts ========= platform darwin -- Python 3.12.0, pytest-8.3.4, pluggy-1.5.0 -- /Users/michaelp/Documents/GitHub/python-project-template/.venv/bin/python3 cachedir: .pytest_cache rootdir: /Users/michaelp/Documents/GitHub/python-project-template configfile: pyproject.toml collected 1 item tests/test_example.py::test_example PASSED ========= 1 passed in 0.00s ========= michaelp@MacBook-Air-18 python-project-template % make run uv run python -m project oh, what up? michaelp@MacBook-Air-18 python-project-template % ```
1 parent 1a7c1b9 commit f90105f

File tree

7 files changed

+579
-276
lines changed

7 files changed

+579
-276
lines changed

.github/workflows/requirements-up-to-date.yml

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,42 @@ on:
66
branches: [ main ]
77

88
jobs:
9-
validate-dependencies:
9+
check-dependency-changes:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- name: checkout code
12+
- name: Checkout repository
1313
uses: actions/checkout@v4
1414
with:
15-
fetch-depth: 0
15+
fetch-depth: 0 # Ensure full history is fetched
1616

17-
- name: fetch all history
18-
run: git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
17+
- name: Fetch main branch
18+
run: git fetch origin main
1919

20-
- name: check for changes in pyproject.toml and poetry.lock
21-
id: check-deps
20+
- name: Check if uv.lock or pyproject.toml has changed
21+
id: check-changes
2222
run: |
23-
echo "Checking pyproject.toml and poetry.lock for changes..."
24-
BASE_BRANCH=${{ github.event.pull_request.base.ref }}
25-
HEAD_BRANCH=${{ github.event.pull_request.head.ref }}
26-
CHANGES=$(git diff --name-only origin/$BASE_BRANCH -- origin/$HEAD_BRANCH | grep -E "^(pyproject.toml|poetry.lock)$" || true)
27-
echo "Changed files: $CHANGES"
28-
if [ ! -z "$CHANGES" ]; then
29-
echo "Checking if requirements.txt has also been updated..."
30-
if ! git diff --name-only origin/$BASE_BRANCH -- origin/$HEAD_BRANCH | grep -q "requirements.txt"; then
31-
echo "ERROR: pyproject.toml or poetry.lock has changed, but requirements.txt has not been updated."
32-
echo "Please update requirements.txt by running 'make create-requirements'."
33-
exit 1
34-
fi
23+
echo "Checking for changes in uv.lock or pyproject.toml..."
24+
CHANGES=$(git diff --name-only origin/main --)
25+
26+
if echo "$CHANGES" | grep -qE "^(uv.lock|pyproject.toml)$"; then
27+
echo "uv.lock or pyproject.toml has changed."
28+
echo "files_changed=true" >> $GITHUB_ENV
29+
else
30+
echo "No changes detected in uv.lock or pyproject.toml."
31+
echo "files_changed=false" >> $GITHUB_ENV
3532
fi
3633
37-
- name: validate requirements.txt update
38-
if: steps.check-deps.outputs.poetry_updated == 'true'
34+
- name: Validate requirements.txt changes
35+
if: env.files_changed == 'true'
3936
run: |
40-
BASE_BRANCH=${{ github.event.pull_request.base.ref }}
41-
HEAD_BRANCH=${{ github.event.pull_request.head.ref }}
42-
REQUIREMENTS_CHANGE=$(git diff --name-only origin/$BASE_BRANCH -- origin/$HEAD_BRANCH | grep -q "requirements.txt")
43-
echo "requirements.txt changed: $REQUIREMENTS_CHANGE"
44-
if [ ! -z "$REQUIREMENTS_CHANGE" ]; then
45-
echo "requirements.txt updated correctly."
37+
echo "Validating requirements.txt update..."
38+
CHANGED_FILES=$(git diff --name-only origin/main --)
39+
40+
# Check if requirements.txt has been updated
41+
if echo "$CHANGED_FILES" | grep -q "^requirements.txt$"; then
42+
echo "requirements.txt has been updated."
4643
else
47-
echo "ERROR: pyproject.toml or poetry.lock has changed, but requirements.txt has not been updated."
44+
echo "ERROR: pyproject.toml or uv.lock has changed, but requirements.txt has not been updated."
4845
echo "Please update requirements.txt by running 'make create-requirements'."
4946
exit 1
5047
fi

.github/workflows/run-tests.yml

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,24 @@ on:
66
branches: [ main ]
77

88
jobs:
9-
Test:
9+
test:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
python-version: [ '3.11', '3.12' ]
13+
python-version: [ '3.11', '3.12', '3.13' ]
1414
steps:
1515
- uses: actions/checkout@v4
16-
- uses: actions/setup-python@v4
17-
with:
18-
python-version: ${{ matrix.python-version }}
19-
- name: Cache Poetry install
20-
uses: actions/cache@v2
21-
with:
22-
path: ~/.local
23-
key: poetry-1.5.1
24-
- uses: snok/install-poetry@v1
25-
with:
26-
version: 1.5.1
27-
virtualenvs-create: true
28-
virtualenvs-in-project: true
29-
- name: cache deps
30-
id: cache-deps
31-
uses: actions/cache@v2
16+
17+
- name: Install uv
18+
uses: astral-sh/setup-uv@v4
3219
with:
33-
path: .venv
34-
key: pydeps-${{ hashFiles('**/poetry.lock') }}
35-
- run: poetry install --no-interaction --no-root
36-
if: steps.cache-deps.outputs.cache-hit != 'true'
37-
- run: poetry install --no-interaction
38-
- run: poetry run pytest tests/
20+
version: 0.5.7
21+
22+
- name: Set up Python
23+
run: uv python install ${{ matrix.python-version }}
24+
25+
- name: Install the project
26+
run: uv sync --all-extras
27+
28+
- name: Run tests
29+
run: uv run pytest tests

Makefile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@
22
# https://www.gnu.org/software/make/manual/html_node/Introduction.html
33
default: create-requirements lint
44

5+
.PHONY: env
6+
env:
7+
uv venv
8+
59
.PHONY: lint
610
lint:
7-
pre-commit run --all-files
11+
uv run pre-commit run --all-files
812

913
.PHONY: create-requirements
1014
create-requirements:
11-
poetry export --format=requirements.txt > requirements.txt
15+
uv pip compile --generate-hashes pyproject.toml > requirements.txt
1216

1317
.PHONY: test
1418
test:
15-
pytest -vs test/
19+
uv run pytest -vs tests/
1620

1721
.PHONY: test-and-fail
1822
test-and-fail:
19-
pytest -vsx test/
23+
uv run pytest -vsx tests/
2024

2125
.PHONY: run
2226
run:
23-
python -m project
27+
uv run python -m project

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Poetry Python 🐍 Project Template
2-
This repository is a template for a python 🐍 project using the poetry container. The intent is to do all the basic
2+
This repository is a template for a python 🐍 project using the `uv` container. The intent is to do all the basic
33
lifting for a python project so that people can hit the ground running with their ideas.
44

55
### To make this project your own
@@ -14,18 +14,20 @@ lifting for a python project so that people can hit the ground running with thei
1414
- [responses](https://github.com/getsentry/responses): This is used in conjunction with Pytest and Requests to mock API calls in the test module.
1515

1616
### Project Requirements
17-
- Python version: `^3.11`
18-
- [Poetry](https://python-poetry.org/)
17+
- `uv` version: `0.5.7`
18+
- Download at: [link](https://docs.astral.sh/uv/).
1919

2020
### Instructions to Run the Project
21-
1. Go into the base directory of the repository and type `poetry shell` into the terminal.
21+
1. Go into the base directory of the repository and type `make env` or `uv env` into the terminal.
2222
2. Use the `make run` command.
2323

2424
### Technical Notes
25-
- Any modules should be added via the `poetry add [module]` command.
26-
- Example: `poetry add black`
25+
- Any modules should be added via the `uv add [module]` command.
26+
- Example: `uv add pre-commit`
2727

2828
## Standard Commands
29+
- `make create-requirements`: Creates and/or updates the `requirements.txt` file.
30+
- `make env`: Creates or activates a `uv` virtual environment.
2931
- `make lint`: Runs `pre-commit`.
30-
- `make test`: Runs test cases in the `tests` directory.
3132
- `make run`: Runs the `main` function in the `project` folder.
33+
- `make test`: Runs test cases in the `tests` directory.

pyproject.toml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
[tool.poetry]
2-
name = "poetry-python-project"
1+
[project]
2+
name = "python-project-template"
33
version = "0.1.0"
4-
description = "This repository is a template for a python project using the poetry container. The intent is to do all the basic lifting for a python project so that people can hit the ground running with their ideas."
4+
description = "This repository is a template for a uv project using the poetry container. The intent is to do all the basic lifting for a python project so that people can hit the ground running with their ideas."
55
authors = ["michplunkett"]
66
readme = "README.md"
7-
8-
[tool.poetry.dependencies]
9-
python = "^3.11"
10-
requests = "^2.28.2"
11-
pytest = "^7.3.1"
12-
responses = "^0.23.1"
13-
pre-commit = "^3.4.0"
14-
15-
[build-system]
16-
requires = ["poetry-core"]
17-
build-backend = "poetry.core.masonry.api"
7+
requires-python = ">=3.12.0"
8+
dependencies = [
9+
"pre-commit>=4.0.1",
10+
"pytest>=8.3.4",
11+
"requests>=2.32.3",
12+
"responses>=0.25.3",
13+
]

0 commit comments

Comments
 (0)