Skip to content

Commit 12415eb

Browse files
Merge pull request #21 from MITLibraries/IN-1425-uv
Migrate Python CLI template to uv
2 parents c11ba5c + ef3fb16 commit 12415eb

File tree

9 files changed

+1040
-853
lines changed

9 files changed

+1040
-853
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
name: CI
2-
on: push
2+
on:
3+
pull_request:
4+
paths-ignore:
5+
- '.github/**'
36
jobs:
47
test:
5-
uses: mitlibraries/.github/.github/workflows/python-shared-test.yml@main
8+
uses: mitlibraries/.github/.github/workflows/python-uv-shared-test.yml@main
69
lint:
7-
uses: mitlibraries/.github/.github/workflows/python-shared-lint.yml@main
10+
uses: mitlibraries/.github/.github/workflows/python-uv-shared-lint.yml@main

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
default_language_version:
2-
python: python3.12 # set for project python version
2+
python: python3.12
33
repos:
44
- repo: local
55
hooks:
66
- id: black-apply
77
name: black-apply
8-
entry: pipenv run black
8+
entry: uv run black
99
language: system
1010
pass_filenames: true
1111
types: ["python"]
1212
- id: mypy
1313
name: mypy
14-
entry: pipenv run mypy
14+
entry: uv run mypy
1515
language: system
1616
pass_filenames: true
1717
types: ["python"]
1818
exclude: "tests/"
1919
- id: ruff-apply
2020
name: ruff-apply
21-
entry: pipenv run ruff check --fix
21+
entry: uv run ruff check --fix
2222
language: system
2323
pass_filenames: true
2424
types: ["python"]
2525
- id: pip-audit
2626
name: pip-audit
27-
entry: pipenv run pip-audit
27+
entry: uv run pip-audit
2828
language: system
2929
pass_filenames: false

Dockerfile

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
FROM python:3.12-slim as build
1+
FROM python:3.13-slim
2+
3+
RUN apt-get update && \
4+
apt-get install -y --no-install-recommends git ca-certificates && \
5+
rm -rf /var/lib/apt/lists/*
6+
7+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
8+
ENV UV_SYSTEM_PYTHON=1
9+
210
WORKDIR /app
3-
COPY . .
411

5-
RUN pip install --no-cache-dir --upgrade pip pipenv
12+
# Copy project metadata
13+
COPY pyproject.toml uv.lock* ./
614

7-
RUN apt-get update && apt-get upgrade -y && apt-get install -y git
15+
# Copy CLI application
16+
COPY my_app ./my_app
817

9-
COPY Pipfile* /
10-
RUN pipenv install
18+
# Install package into the system Python environment
19+
RUN uv pip install --system .
1120

12-
ENTRYPOINT ["pipenv", "run", "my_app"]
21+
ENTRYPOINT ["my-app"]

Makefile

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,40 @@ help: # Preview Makefile commands
55
@awk 'BEGIN { FS = ":.*#"; print "Usage: make <target>\n\nTargets:" } \
66
/^[-_[:alpha:]]+:.?*#/ { printf " %-15s%s\n", $$1, $$2 }' $(MAKEFILE_LIST)
77

8-
#######################
9-
# Dependency commands
10-
#######################
8+
# ensure OS binaries aren't called if naming conflict with Make recipes
9+
.PHONY: help venv install update test coveralls lint black mypy ruff safety lint-apply black-apply ruff-apply
1110

12-
install: # Install Python dependencies
13-
pipenv install --dev
14-
pipenv run pre-commit install
11+
##############################################
12+
# Python Environment and Dependency commands
13+
##############################################
1514

16-
update: install # Update Python dependencies
17-
pipenv clean
18-
pipenv update --dev
15+
install: .venv .git/hooks/pre-commit # Install Python dependencies and create virtual environment if not exists
16+
uv sync --dev
17+
18+
.venv: # Creates virtual environment if not found
19+
@echo "Creating virtual environment at .venv..."
20+
uv venv .venv
21+
22+
.git/hooks/pre-commit: # Sets up pre-commit hook if not setup
23+
@echo "Installing pre-commit hooks..."
24+
uv run pre-commit install
25+
26+
venv: .venv # Create the Python virtual environment
27+
28+
update: # Update Python dependencies
29+
uv lock --upgrade
30+
uv sync --dev
1931

2032
######################
2133
# Unit test commands
2234
######################
2335

2436
test: # Run tests and print a coverage report
25-
pipenv run coverage run --source=my_app -m pytest -vv
26-
pipenv run coverage report -m
37+
uv run coverage run --source=my_app -m pytest -vv
38+
uv run coverage report -m
2739

2840
coveralls: test # Write coverage data to an LCOV report
29-
pipenv run coverage lcov -o ./coverage/lcov.info
41+
uv run coverage lcov -o ./coverage/lcov.info
3042

3143
####################################
3244
# Code quality and safety commands
@@ -35,23 +47,27 @@ coveralls: test # Write coverage data to an LCOV report
3547
lint: black mypy ruff safety # Run linters
3648

3749
black: # Run 'black' linter and print a preview of suggested changes
38-
pipenv run black --check --diff .
50+
uv run black --check --diff .
3951

4052
mypy: # Run 'mypy' linter
41-
pipenv run mypy .
53+
uv run mypy .
4254

4355
ruff: # Run 'ruff' linter and print a preview of errors
44-
pipenv run ruff check .
56+
uv run ruff check .
4557

46-
safety: # Check for security vulnerabilities and verify Pipfile.lock is up-to-date
47-
pipenv run pip-audit
48-
pipenv verify
58+
safety: # Check for security vulnerabilities
59+
uv run pip-audit
4960

50-
lint-apply: # Apply changes with 'black' and resolve 'fixable errors' with 'ruff'
51-
black-apply ruff-apply
61+
lint-apply: black-apply ruff-apply # Apply changes with 'black' and resolve 'fixable errors' with 'ruff'
5262

5363
black-apply: # Apply changes with 'black'
54-
pipenv run black .
64+
uv run black .
5565

5666
ruff-apply: # Resolve 'fixable errors' with 'ruff'
57-
pipenv run ruff check --fix .
67+
uv run ruff check --fix .
68+
69+
##############################
70+
# CLI convenience commands
71+
##############################
72+
my-app: # CLI without any arguments, utilizing uv script entrypoint
73+
uv run my-app

Pipfile

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)