From 9e6d56a0b27a9df1d8f29cb46e1738be34517bba Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Thu, 4 Apr 2024 09:56:37 -0500 Subject: [PATCH] Do not use constraints file for downstream test (#233) --- .github/actions/base-setup/action.yml | 20 ++--------- .../base-setup/create_constraints_file.py | 35 +++++++++++++++++++ .../actions/base-setup/setup_constraints.sh | 11 ++++++ 3 files changed, 48 insertions(+), 18 deletions(-) create mode 100644 .github/actions/base-setup/create_constraints_file.py create mode 100644 .github/actions/base-setup/setup_constraints.sh diff --git a/.github/actions/base-setup/action.yml b/.github/actions/base-setup/action.yml index 780a085..143ed0e 100644 --- a/.github/actions/base-setup/action.yml +++ b/.github/actions/base-setup/action.yml @@ -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 @@ -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 diff --git a/.github/actions/base-setup/create_constraints_file.py b/.github/actions/base-setup/create_constraints_file.py new file mode 100644 index 0000000..2d26770 --- /dev/null +++ b/.github/actions/base-setup/create_constraints_file.py @@ -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) diff --git a/.github/actions/base-setup/setup_constraints.sh b/.github/actions/base-setup/setup_constraints.sh new file mode 100644 index 0000000..192be2c --- /dev/null +++ b/.github/actions/base-setup/setup_constraints.sh @@ -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