Skip to content

Commit

Permalink
ENH: run pip-install action with uv (#61)
Browse files Browse the repository at this point in the history
* BEHAVIOR: set editable flag if installing with `uv`
  • Loading branch information
redeboer authored Mar 5, 2024
1 parent d89c45e commit 27ac0fd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
".vscode/*",
"pyproject.toml"
],
"ignoreWords": ["mhutchie", "noqa", "noreply", "taplo"],
"ignoreWords": ["elif", "mhutchie", "noqa", "noreply", "taplo"],
"language": "en-US",
"version": "0.2",
"words": []
Expand Down
58 changes: 45 additions & 13 deletions pip-install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@ runs:
run: |
echo PYTHON_VERSION=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))') | tee -a $GITHUB_ENV
shell: bash
- run: echo "PIP_CACHE_DIR=~/.cache/pip/" >> $GITHUB_ENV
- run: |
echo "PIP_CACHE_DIR=~/.cache/pip/" >> $GITHUB_ENV
echo "UV_CACHE_DIR=~/.cache/uv/" >> $GITHUB_ENV
shell: bash
- if: runner.os == 'macOS'
run: echo "PIP_CACHE_DIR=~/Library/Caches/pip" >> $GITHUB_ENV
run: |
echo "PIP_CACHE_DIR=~/Library/Caches/pip" >> $GITHUB_ENV
echo "UV_CACHE_DIR=~/Library/Caches/uv" >> $GITHUB_ENV
shell: bash
- name: Set cache identifier
run: |
Expand All @@ -48,21 +52,49 @@ runs:
pip-${{ env.CACHE_IDENTIFIER }}-${{ runner.os }}-py${{ env.PYTHON_VERSION }}-${{ hashFiles('.constraints/py3.*.txt', 'setup.cfg') }}
restore-keys: |
pip-${{ env.CACHE_IDENTIFIER }}-${{ runner.os }}-py${{ env.PYTHON_VERSION }}
path: ${{ env.PIP_CACHE_DIR }}
- name: Set editable flag
path: |
${{ env.PIP_CACHE_DIR }}
${{ env.UV_CACHE_DIR }}
- name: Deterimine package configuration file
run: |
if [ -f pyproject.toml ]; then
if grep -q "\[project\]" pyproject.toml; then
echo 'SETUP_FILE=pyproject.toml' | tee -a $GITHUB_ENV
fi
elif [ -f setup.cfg ]; then
if grep -q "\[metadata\]" setup.cfg && grep -q "\[options\]" setup.cfg; then
echo 'SETUP_FILE=setup.cfg' | tee -a $GITHUB_ENV
fi
fi
shell: bash

- name: Form pip install statement
run: |
if [[ -z '${{ inputs.editable}}' ]]; then
echo 'EDITABLE=' | tee -a $GITHUB_ENV
if [[ $SETUP_FILE == setup.cfg ]] || [[ "${{ env.PYTHON_VERSION }}" == "3.6" ]]; then
echo 'PIP_INSTALL=pip install' | tee -a $GITHUB_ENV
else
echo 'EDITABLE=-e' | tee -a $GITHUB_ENV
curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.cargo/env
echo 'PIP_INSTALL=uv pip install --system' | tee -a $GITHUB_ENV
fi
shell: bash
- run: ${{ format('python3 -m pip install {0} .[{1}] {2}', env.EDITABLE, inputs.extras, inputs.additional-packages ) }}
if: hashFiles('.constraints/py3.*.txt') == ''

- if: hashFiles('.constraints/py3.*.txt')
name: Set constraints flag
run: |
echo 'CONSTRAINTS=-c .constraints/py${{ env.PYTHON_VERSION }}.txt' | tee -a $GITHUB_ENV
shell: bash

- if: inputs.editable || env.SETUP_FILE == 'pyproject.toml'
name: Set editable flag
run: |
echo 'EDITABLE=--editable' | tee -a $GITHUB_ENV
shell: bash
- run: ${{ format('python3 -m pip install {0} .[{1}] {2} -c .constraints/py{3}.txt', env.EDITABLE, inputs.extras, inputs.additional-packages, env.PYTHON_VERSION ) }}
if: hashFiles('.constraints/py3.*.txt') != ''

- run: |
${{ env.PIP_INSTALL }} ${{ env.CONSTRAINTS }} ${{ env.EDITABLE }} ${{ format('.[{0}] {1}', inputs.extras, inputs.additional-packages ) }}
shell: bash
- run: python3 -m pip install ${{ inputs.specific-packages }}
if: inputs.specific-packages
- if: inputs.specific-packages
run: ${{ env.PIP_INSTALL }} ${{ inputs.specific-packages }}
shell: bash

0 comments on commit 27ac0fd

Please sign in to comment.