Skip to content

Commit

Permalink
python: Switch from pip-tools to uv
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Sep 6, 2024
1 parent 30c1ed7 commit d230f3d
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 47 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Lint
on: [push, pull_request]
env:
BASEDIR: https://raw.githubusercontent.com/open-contracting/standard-maintenance-scripts/main
jobs:
build:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
env:
PAT: ${{ secrets.PAT }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.PAT || github.token }}
- uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: pip
cache-dependency-path: '**/requirements*.txt'
- id: changed-files
uses: tj-actions/changed-files@v45
- uses: pre-commit/action@v3.0.1
continue-on-error: true
with:
extra_args: pip-compile --files ${{ steps.changed-files.outputs.all_changed_files }}
- if: ${{ env.PAT }}
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: '[github-actions] pre-commit autoupdate'
- shell: bash
run: curl -s -S --retry 3 $BASEDIR/tests/install.sh | bash -
- shell: bash
run: curl -s -S --retry 3 $BASEDIR/tests/script.sh | bash -
- run: pip install -r requirements_test.txt
- env:
STANDARD_MAINTENANCE_SCRIPTS_FILES: requirements_test.in
run: pytest /tmp/test_requirements.py
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ci:
autoupdate_schedule: quarterly
skip: [pip-compile]
repos:
- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.4.4
hooks:
- id: pip-compile
name: pip-compile requirements_test.in
args: [requirements_test.in, -o, requirements_test.txt]
files: ^requirements_test\.(in|txt)$
2 changes: 0 additions & 2 deletions docs/deploy/deploy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ For a Django app, common changed states are:

Function: git.latest
A new commit was deployed
Function: cmd.run, Name: .ve/bin/pip-sync -q --pip-args "--exists-action w"
Requirements were installed
Function: cmd.run, Name: .ve/bin/python manage.py migrate --settings ... --noinput
Django migrations were applied
Function: cmd.run, Name: .ve/bin/python manage.py collectstatic --settings ... --noinput
Expand Down
2 changes: 1 addition & 1 deletion docs/develop/update/mysql.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Configure MySQL
Specify the version
-------------------

The `default version <https://endoflife.date/mysql>`__ is 8.0.
The `default version <https://endoflife.date/mysql>`__ is 8.0 (`LTS <https://endoflife.date/mysql>`__).

To override the version, update the server's Pillar file:

Expand Down
2 changes: 1 addition & 1 deletion docs/develop/update/python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ This will:
- Install packages for creating Python virtual environments
- Fetch the git repository into the ``target`` directory within the home directory of the ``user``
- Initialize a virtual environment in a ``.ve`` directory within the repository's directory
- Install ``requirements.txt`` with ``pip-sync`` from `pip-tools <https://pypi.org/project/pip-tools/>`__
- Install ``requirements.txt`` with ``uv pip sync`` from `uv <https://docs.astral.sh/uv/>`__
- Reload uWSGI (if configured below) if the repository's contents changed

Add configuration files
Expand Down
1 change: 0 additions & 1 deletion requirements_test.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pip-tools
pytest
requests
37 changes: 4 additions & 33 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,51 +1,22 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile requirements_test.in
#
build==0.9.0
# via pip-tools
# This file was autogenerated by uv via the following command:
# uv pip compile requirements_test.in -o requirements_test.txt
certifi==2024.7.4
# via requests
charset-normalizer==3.1.0
# via requests
click==8.0.1
# via pip-tools
exceptiongroup==1.1.1
# via pytest
idna==3.7
# via requests
iniconfig==1.1.1
# via pytest
packaging==20.9
# via
# build
# pytest
pep517==0.10.0
# via build
pip-tools==7.3.0
# via -r requirements_test.in
# via pytest
pluggy==0.13.1
# via pytest
pyparsing==2.4.7
# via packaging
pytest==7.3.1
# via -r requirements_test.in
requests==2.32.0
requests==2.32.3
# via -r requirements_test.in
toml==0.10.2
# via pep517
tomli==2.0.1
# via
# build
# pip-tools
# pytest
urllib3==2.2.2
# via requests
wheel==0.40.0
# via pip-tools

# The following packages are considered to be unsafe in a requirements file:
# pip
# setuptools
3 changes: 1 addition & 2 deletions salt/core/locale.sls
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ system_locale:
- require:
- locale: {{ pillar.locale }}_locale

# To avoid error when running "pip-sync -q".
# https://click.palletsprojects.com/en/7.x/python3/
# https://click.palletsprojects.com/en/latest/unicode-support/#surrogate-handling
/etc/default/locale:
file.keyvalue:
- key: LC_ALL
Expand Down
14 changes: 7 additions & 7 deletions salt/lib.sls
Original file line number Diff line number Diff line change
Expand Up @@ -131,28 +131,28 @@ unset {{ setting_name }} in {{ filename }}:
- onchanges:
- virtualenv: {{ directory }}-virtualenv
- watch_in:
- virtualenv: {{ directory }}-piptools
- virtualenv: {{ directory }}-uv

# This state only differs from the *-virtualenv state by installing pip-tools and not watching python.
{{ directory }}-piptools:
# This state only differs from the *-virtualenv state by installing uv and not watching python.
{{ directory }}-uv:
virtualenv.managed:
- name: {{ directory }}/.ve
- python: /usr/bin/python{{ salt['pillar.get']('python:version', 3) }}
- runas: {{ user }}
- user: {{ user }}
- require: {{ ([{'pkg': 'virtualenv'}] + [parent_directory])|yaml }}
- pip_pkgs:
- pip-tools
- uv

{{ directory }}-requirements:
cmd.run:
- name: .ve/bin/pip-sync -q --pip-args "--exists-action w"
- name: .ve/bin/uv pip sync --python=.ve/bin/python -q requirements.txt
- runas: {{ user }}
- cwd: {{ directory }}
- require:
- virtualenv: {{ directory }}-piptools
- virtualenv: {{ directory }}-uv
# Run the command if the virtual environment was reinstalled (64501d6) or the requirements file was changed.
- onchanges: {{ ([{'virtualenv': directory + '-piptools'}] + [requirements_file])|yaml }}
- onchanges: {{ ([{'virtualenv': directory + '-uv'}] + [requirements_file])|yaml }}
{% if watch_in %}
- watch_in:
- service: {{ watch_in }}
Expand Down

0 comments on commit d230f3d

Please sign in to comment.