Skip to content
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
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: CI
on: push
on:
pull_request:
paths-ignore:
- '.github/**'
jobs:
test:
uses: mitlibraries/.github/.github/workflows/python-shared-test.yml@main
uses: mitlibraries/.github/.github/workflows/python-uv-shared-test.yml@main
lint:
uses: mitlibraries/.github/.github/workflows/python-shared-lint.yml@main
uses: mitlibraries/.github/.github/workflows/python-uv-shared-lint.yml@main
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
default_language_version:
python: python3.12 # set for project python version
python: python3.12
repos:
- repo: local
hooks:
- id: black-apply
name: black-apply
entry: pipenv run black
entry: uv run black
language: system
pass_filenames: true
types: ["python"]
- id: mypy
name: mypy
entry: pipenv run mypy
entry: uv run mypy
language: system
pass_filenames: true
types: ["python"]
exclude: "tests/"
- id: ruff-apply
name: ruff-apply
entry: pipenv run ruff check --fix
entry: uv run ruff check --fix
language: system
pass_filenames: true
types: ["python"]
- id: pip-audit
name: pip-audit
entry: pipenv run pip-audit
entry: uv run pip-audit
language: system
pass_filenames: false
23 changes: 16 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
FROM python:3.12-slim as build
FROM python:3.13-slim

RUN apt-get update && \
apt-get install -y --no-install-recommends git ca-certificates && \
rm -rf /var/lib/apt/lists/*

COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
ENV UV_SYSTEM_PYTHON=1

WORKDIR /app
COPY . .

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

RUN apt-get update && apt-get upgrade -y && apt-get install -y git
# Copy CLI application
COPY my_app ./my_app

COPY Pipfile* /
RUN pipenv install
# Install package into the system Python environment
RUN uv pip install --system .

ENTRYPOINT ["pipenv", "run", "my_app"]
ENTRYPOINT ["my-app"]
60 changes: 38 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,40 @@ help: # Preview Makefile commands
@awk 'BEGIN { FS = ":.*#"; print "Usage: make <target>\n\nTargets:" } \
/^[-_[:alpha:]]+:.?*#/ { printf " %-15s%s\n", $$1, $$2 }' $(MAKEFILE_LIST)

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

install: # Install Python dependencies
pipenv install --dev
pipenv run pre-commit install
##############################################
# Python Environment and Dependency commands
##############################################

update: install # Update Python dependencies
pipenv clean
pipenv update --dev
install: .venv .git/hooks/pre-commit # Install Python dependencies and create virtual environment if not exists
uv sync --dev

.venv: # Creates virtual environment if not found
@echo "Creating virtual environment at .venv..."
uv venv .venv

.git/hooks/pre-commit: # Sets up pre-commit hook if not setup
@echo "Installing pre-commit hooks..."
uv run pre-commit install

venv: .venv # Create the Python virtual environment

update: # Update Python dependencies
uv lock --upgrade
uv sync --dev

######################
# Unit test commands
######################

test: # Run tests and print a coverage report
pipenv run coverage run --source=my_app -m pytest -vv
pipenv run coverage report -m
uv run coverage run --source=my_app -m pytest -vv
uv run coverage report -m

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

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

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

mypy: # Run 'mypy' linter
pipenv run mypy .
uv run mypy .

ruff: # Run 'ruff' linter and print a preview of errors
pipenv run ruff check .
uv run ruff check .

safety: # Check for security vulnerabilities and verify Pipfile.lock is up-to-date
pipenv run pip-audit
pipenv verify
safety: # Check for security vulnerabilities
uv run pip-audit

lint-apply: # Apply changes with 'black' and resolve 'fixable errors' with 'ruff'
black-apply ruff-apply
lint-apply: black-apply ruff-apply # Apply changes with 'black' and resolve 'fixable errors' with 'ruff'

black-apply: # Apply changes with 'black'
pipenv run black .
uv run black .

ruff-apply: # Resolve 'fixable errors' with 'ruff'
pipenv run ruff check --fix .
uv run ruff check --fix .

##############################
# CLI convenience commands
##############################
my-app: # CLI without any arguments, utilizing uv script entrypoint
uv run my-app
Comment on lines +69 to +73
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to be complicated to discuss I fear in comments, but will try. Happy to realtime chat on this if helpful.

If this is related to the README update for how to run the app, my proposal was just my-app. This would work because my-app is built by uv as an entrypoint script here in the pyproject.toml. It would work without this Makefie command.

If possible, I'm feeling like we might benefit from leaning into those uv entrypoint scripts where possible. You can see an example of that in the timdex-embeddings CLI here where the Dockerfile is calling that uv entrypoint script directly. Nothing else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see! How about:

- To run the app:
  - Activate the virtual environment then run `my-app`
    - utilizes `uv` built entrypoint (see `project.scripts` in `pyproject.toml`)
    - does not support loading a `.env` file
...

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me! I think it's implied that one needs to operate from within the virtual environment, but I can see how technically pipenv didn't explicitly require that (kind of threw you into the venv at time of invocation).

Alternately, to lean into normalizing we should always be in a venv:

- To run the app:
  - `my-app`
    - requires activated project `uv` python environment
    - utilizes `uv` built entrypoint (see `project.scripts` in `pyproject.toml`)
    - does not support loading a `.env` file
...

But your call! Both work for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Precisely! See the latest commit, which applies your suggestion above.

23 changes: 0 additions & 23 deletions Pipfile

This file was deleted.

Loading