-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not use constraints file for downstream test (#233)
- Loading branch information
Showing
3 changed files
with
48 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |