From d230f3d497816f34120b9b22468c81d2d8afe78a Mon Sep 17 00:00:00 2001 From: James McKinney <26463+jpmckinney@users.noreply.github.com> Date: Fri, 6 Sep 2024 01:14:42 -0400 Subject: [PATCH] python: Switch from pip-tools to uv --- .github/workflows/lint.yml | 37 ++++++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 11 ++++++++++ docs/deploy/deploy.rst | 2 -- docs/develop/update/mysql.rst | 2 +- docs/develop/update/python.rst | 2 +- requirements_test.in | 1 - requirements_test.txt | 37 ++++------------------------------ salt/core/locale.sls | 3 +-- salt/lib.sls | 14 ++++++------- 9 files changed, 62 insertions(+), 47 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..f4479b032 --- /dev/null +++ b/.github/workflows/lint.yml @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..2b712a5aa --- /dev/null +++ b/.pre-commit-config.yaml @@ -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)$ diff --git a/docs/deploy/deploy.rst b/docs/deploy/deploy.rst index 42f0f7e22..06ec495eb 100644 --- a/docs/deploy/deploy.rst +++ b/docs/deploy/deploy.rst @@ -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 diff --git a/docs/develop/update/mysql.rst b/docs/develop/update/mysql.rst index 09574fba8..5d9367da5 100644 --- a/docs/develop/update/mysql.rst +++ b/docs/develop/update/mysql.rst @@ -4,7 +4,7 @@ Configure MySQL Specify the version ------------------- -The `default version `__ is 8.0. +The `default version `__ is 8.0 (`LTS `__). To override the version, update the server's Pillar file: diff --git a/docs/develop/update/python.rst b/docs/develop/update/python.rst index 3615e6ee4..7c458a62c 100644 --- a/docs/develop/update/python.rst +++ b/docs/develop/update/python.rst @@ -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 `__ +- Install ``requirements.txt`` with ``uv pip sync`` from `uv `__ - Reload uWSGI (if configured below) if the repository's contents changed Add configuration files diff --git a/requirements_test.in b/requirements_test.in index 8ca1e01a4..547de5c5b 100644 --- a/requirements_test.in +++ b/requirements_test.in @@ -1,3 +1,2 @@ -pip-tools pytest requests diff --git a/requirements_test.txt b/requirements_test.txt index 7ec418bb5..41bdcba9d 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -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 diff --git a/salt/core/locale.sls b/salt/core/locale.sls index e8e70a36f..2142b253b 100644 --- a/salt/core/locale.sls +++ b/salt/core/locale.sls @@ -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 diff --git a/salt/lib.sls b/salt/lib.sls index 074cbd7d9..ef6d949f8 100644 --- a/salt/lib.sls +++ b/salt/lib.sls @@ -131,10 +131,10 @@ 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) }} @@ -142,17 +142,17 @@ unset {{ setting_name }} in {{ filename }}: - 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 }}