Skip to content

Commit

Permalink
Do not use constraints file for downstream test (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Apr 4, 2024
1 parent 99c34f7 commit 9e6d56a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 18 deletions.
20 changes: 2 additions & 18 deletions .github/actions/base-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ runs:
set -eux
echo "::group::Upgrade packaging dependencies"
python -m pip install --upgrade pip
pipx install uv
if [ "$RUNNER_OS" != "Windows" ]; then
pipx install hatch --python $(which python)
else
Expand All @@ -126,25 +125,10 @@ runs:
shell: bash
run: |
set -eux
FLAGS=""
if [ $DEPENDENCY_TYPE == 'pre' ]; then
FLAGS="--prerelease=allow"
echo "PIP_PRE=1" >> $GITHUB_ENV
elif [ $DEPENDENCY_TYPE == 'minimum' ]; then
FLAGS="--resolution=lowest-direct"
fi
if [ "$RUNNER_OS" == "Windows" ]; then
if [ -n "$FLAGS" ]; then
echo "dependency_type not supported on Windows"
exit 1
else
exit 0
fi
fi
if [ -f pyproject.toml ]; then
uv pip compile $FLAGS --extra test pyproject.toml -o $HOME/constraints.txt
echo "PIP_CONSTRAINT=$HOME/constraints.txt" >> $GITHUB_ENV
elif [ -n "$FLAGS" ]; then
echo "Missing pyproject.toml needed for DEPENDENCY_TYPE: $DEPENDENCY_TYPE"
source ${{ github.action_path }}/setup_constraints.sh
fi
- name: Print Diagnostics
Expand Down
35 changes: 35 additions & 0 deletions .github/actions/base-setup/create_constraints_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import sys
from pathlib import Path
from zipfile import ZipFile

from packaging.requirements import Requirement

output_file = sys.argv[-2]
fname = sys.argv[-1]
constraints = {}

archive = ZipFile(fname)
reqs = []
for f in archive.namelist():
if f.endswith("METADATA"):
for li in archive.open(f).read().decode("utf-8").split("\n"):
if li.startswith("Requires-Dist"):
reqs.append(li.replace("Requires-Dist: ", ""))
archive.close()

for req in reqs:
r = Requirement(req)
for specifier in r.specifier:
if "!" in specifier.operator:
continue
if "~" in specifier.operator or ">" in specifier.operator:
spec = str(specifier).replace("~", "=")
spec = spec.replace(">=", "==")
spec = spec.replace(">", "==")
constraints[r.name] = spec

constraints_list = [f"{key}{value}\n" for (key, value) in constraints.items()]

# Write the constraints to to a pip constraints file.
with Path(output_file).open("w") as fid:
fid.writelines(constraints_list)
11 changes: 11 additions & 0 deletions .github/actions/base-setup/setup_constraints.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
python -m venv $HOME/.venv
source $HOME/.venv/bin/activate
pip install build packaging pkginfo
mkdir $HOME/dist
python -m build --outdir $HOME/dist --wheel .

SCRIPT_DIR=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
python $SCRIPT_DIR/create_constraints_file.py $HOME/constraints.txt $HOME/dist/*.whl
cat $HOME/constraints.txt
echo "PIP_CONSTRAINT=$HOME/constraints.txt" >> $GITHUB_ENV

0 comments on commit 9e6d56a

Please sign in to comment.