Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
5dacc1d
Create uv.lock
michplunkett Dec 10, 2024
786cb37
Update pyproject.toml
michplunkett Dec 10, 2024
e2ef18e
Update Makefile
michplunkett Dec 10, 2024
eed3c17
Update pyproject.toml
michplunkett Dec 10, 2024
7beaf01
Update requirements.txt
michplunkett Dec 10, 2024
67d995f
Update requirements.txt
michplunkett Dec 10, 2024
e204dd1
Update Makefile
michplunkett Dec 10, 2024
e95c771
Update pyproject.toml
michplunkett Dec 10, 2024
e35ab1b
Update Makefile
michplunkett Dec 10, 2024
26a2620
Update README.md
michplunkett Dec 10, 2024
1641e9d
Update README.md
michplunkett Dec 10, 2024
bc64d04
Update run-tests.yml
michplunkett Dec 10, 2024
a3dc03e
Update run-tests.yml
michplunkett Dec 10, 2024
7aac830
Update Makefile
michplunkett Dec 10, 2024
8eb37b7
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
49ed227
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
60c5c87
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
ab8f223
Update pyproject.toml
michplunkett Dec 10, 2024
7408bf9
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
61a344e
Update uv.lock
michplunkett Dec 10, 2024
897de55
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
8f888c7
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
828a9a1
Update run-tests.yml
michplunkett Dec 10, 2024
15cfad4
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
f5e555e
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
311b853
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
2206b06
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
5d8c943
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
18951f7
Update requirements.txt
michplunkett Dec 10, 2024
7c897c1
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
251895c
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
730b2c3
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
3828bea
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
a943896
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
7ac77ec
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
02f75c0
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
80769c8
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
6110f68
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
215cadb
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
8bf9b90
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
cdc97ad
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
cdf8181
Update requirements.txt
michplunkett Dec 10, 2024
8564338
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
f86f039
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
f65d632
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
c813fad
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
3c314ca
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
553dcbe
Update run-tests.yml
michplunkett Dec 10, 2024
8f5abfe
Update Makefile
michplunkett Dec 10, 2024
280d565
Update requirements-up-to-date.yml
michplunkett Dec 10, 2024
fba298e
Update pyproject.toml
michplunkett Dec 10, 2024
c8243e9
Update uv.lock
michplunkett Dec 10, 2024
bed18fb
Update requirements.txt
michplunkett Dec 10, 2024
afb45bb
Update pyproject.toml
michplunkett Dec 10, 2024
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
53 changes: 25 additions & 28 deletions .github/workflows/requirements-up-to-date.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,42 @@ on:
branches: [ main ]

jobs:
validate-dependencies:
check-dependency-changes:
runs-on: ubuntu-latest
steps:
- name: checkout code
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-depth: 0 # Ensure full history is fetched

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

- name: check for changes in pyproject.toml and poetry.lock
id: check-deps
- name: Check if uv.lock or pyproject.toml has changed
id: check-changes
run: |
echo "Checking pyproject.toml and poetry.lock for changes..."
BASE_BRANCH=${{ github.event.pull_request.base.ref }}
HEAD_BRANCH=${{ github.event.pull_request.head.ref }}
CHANGES=$(git diff --name-only origin/$BASE_BRANCH -- origin/$HEAD_BRANCH | grep -E "^(pyproject.toml|poetry.lock)$" || true)
echo "Changed files: $CHANGES"
if [ ! -z "$CHANGES" ]; then
echo "Checking if requirements.txt has also been updated..."
if ! git diff --name-only origin/$BASE_BRANCH -- origin/$HEAD_BRANCH | grep -q "requirements.txt"; then
echo "ERROR: pyproject.toml or poetry.lock has changed, but requirements.txt has not been updated."
echo "Please update requirements.txt by running 'make create-requirements'."
exit 1
fi
echo "Checking for changes in uv.lock or pyproject.toml..."
CHANGES=$(git diff --name-only origin/main --)

if echo "$CHANGES" | grep -qE "^(uv.lock|pyproject.toml)$"; then
echo "uv.lock or pyproject.toml has changed."
echo "files_changed=true" >> $GITHUB_ENV
else
echo "No changes detected in uv.lock or pyproject.toml."
echo "files_changed=false" >> $GITHUB_ENV
fi

- name: validate requirements.txt update
if: steps.check-deps.outputs.poetry_updated == 'true'
- name: Validate requirements.txt changes
if: env.files_changed == 'true'
run: |
BASE_BRANCH=${{ github.event.pull_request.base.ref }}
HEAD_BRANCH=${{ github.event.pull_request.head.ref }}
REQUIREMENTS_CHANGE=$(git diff --name-only origin/$BASE_BRANCH -- origin/$HEAD_BRANCH | grep -q "requirements.txt")
echo "requirements.txt changed: $REQUIREMENTS_CHANGE"
if [ ! -z "$REQUIREMENTS_CHANGE" ]; then
echo "requirements.txt updated correctly."
echo "Validating requirements.txt update..."
CHANGED_FILES=$(git diff --name-only origin/main --)

# Check if requirements.txt has been updated
if echo "$CHANGED_FILES" | grep -q "^requirements.txt$"; then
echo "requirements.txt has been updated."
else
echo "ERROR: pyproject.toml or poetry.lock has changed, but requirements.txt has not been updated."
echo "ERROR: pyproject.toml or uv.lock has changed, but requirements.txt has not been updated."
echo "Please update requirements.txt by running 'make create-requirements'."
exit 1
fi
39 changes: 15 additions & 24 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,24 @@ on:
branches: [ main ]

jobs:
Test:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.11', '3.12' ]
python-version: [ '3.11', '3.12', '3.13' ]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Cache Poetry install
uses: actions/cache@v2
with:
path: ~/.local
key: poetry-1.5.1
- uses: snok/install-poetry@v1
with:
version: 1.5.1
virtualenvs-create: true
virtualenvs-in-project: true
- name: cache deps
id: cache-deps
uses: actions/cache@v2

- name: Install uv
uses: astral-sh/setup-uv@v4
with:
path: .venv
key: pydeps-${{ hashFiles('**/poetry.lock') }}
- run: poetry install --no-interaction --no-root
if: steps.cache-deps.outputs.cache-hit != 'true'
- run: poetry install --no-interaction
- run: poetry run pytest tests/
version: 0.5.7

- name: Set up Python
run: uv python install ${{ matrix.python-version }}

- name: Install the project
run: uv sync --all-extras

- name: Run tests
run: uv run pytest tests
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@
# https://www.gnu.org/software/make/manual/html_node/Introduction.html
default: create-requirements lint

.PHONY: env
env:
uv venv

.PHONY: lint
lint:
pre-commit run --all-files
uv run pre-commit run --all-files

.PHONY: create-requirements
create-requirements:
poetry export --format=requirements.txt > requirements.txt
uv pip compile --generate-hashes pyproject.toml > requirements.txt

.PHONY: test
test:
pytest -vs test/
uv run pytest -vs tests/

.PHONY: test-and-fail
test-and-fail:
pytest -vsx test/
uv run pytest -vsx tests/

.PHONY: run
run:
python -m project
uv run python -m project
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Poetry Python 🐍 Project Template
This repository is a template for a python 🐍 project using the poetry container. The intent is to do all the basic
This repository is a template for a python 🐍 project using the `uv` 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.

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

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

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

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

## Standard Commands
- `make create-requirements`: Creates and/or updates the `requirements.txt` file.
- `make env`: Creates or activates a `uv` virtual environment.
- `make lint`: Runs `pre-commit`.
- `make test`: Runs test cases in the `tests` directory.
- `make run`: Runs the `main` function in the `project` folder.
- `make test`: Runs test cases in the `tests` directory.
24 changes: 10 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
[tool.poetry]
name = "poetry-python-project"
[project]
name = "python-project-template"
version = "0.1.0"
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."
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."
authors = ["michplunkett"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.11"
requests = "^2.28.2"
pytest = "^7.3.1"
responses = "^0.23.1"
pre-commit = "^3.4.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
requires-python = ">=3.12.0"
dependencies = [
"pre-commit>=4.0.1",
"pytest>=8.3.4",
"requests>=2.32.3",
"responses>=0.25.3",
]
Loading
Loading