Skip to content

Commit

Permalink
Clean up create constraints (#159)
Browse files Browse the repository at this point in the history
* clean up create constraints

* fix constraint

* fix constraint

* fix test

* debug

* try again

* try again
  • Loading branch information
blink1073 authored Nov 29, 2022
1 parent 96c3c0b commit 3fb4e48
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/actions/install-minimums/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ runs:
echo "::group::Create Constraints file"
CONSTRAINTS_FILE=${{inputs.constraints_file_path}}
python -m pip install -U pip build pkginfo packaging
python -m pip install -U pip build packaging
cd ${{ inputs.working-directory }}
python -m build --wheel .
python ${{ github.action_path }}/create_constraints_file.py $CONSTRAINTS_FILE dist/*.whl
Expand Down
23 changes: 17 additions & 6 deletions .github/actions/install-minimums/create_constraints_file.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
import sys
from zipfile import ZipFile

from packaging.requirements import Requirement
from pkginfo import Wheel

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

# Extract the minimum versions from the requirements in the wheel.
w = Wheel(fname)
for req in w.requires_dist:
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:
continue
if "~" in specifier.operator or ">" in specifier.operator:
spec = str(specifier).replace("~", "=")
spec = spec.replace(">=", "==")
spec = spec.replace(">", "==")
constraints.add(f"{r.name}{spec}\n")
constraints[r.name] = spec

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

# Write the constraints to to a pip constraints file.
with open(output_file, "w") as fid:
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,11 @@ jobs:
dependency_type: minimum
- run: |
pip install -e ".[test]"
# NOTE: keep this version in sync with README
# NOTE: keep the python version in sync with README
python --version
python --version | grep "3.8"
cat $PIP_CONSTRAINT
cat $PIP_CONSTRAINT | grep "jupyter-core=="
pip list | grep "jupyter-core" | grep "4.10.0"
hatch run check_minimum
base_setup_pre:
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "foobar"
authors = [{name = "Sir Robin", email = "robin@camelot.uk"}]
dynamic = ["description", "version"]
readme = "README.md"
dependencies = ["jupyter_core>=4.10.0"]
dependencies = ["jupyter_core>=4.12,!=~5.0"]
optional-dependencies.test = ["pytest"]

[tool.jupyter-releaser]
Expand All @@ -18,7 +18,7 @@ hooks.after-populate-release = ["bash ./.github/scripts/bump_tag.sh"]
source = "nodejs"

[tool.hatch.envs.default.scripts]
check_minimum = "python -c 'from jupyter_core import __version__; assert __version__ == \"4.10.0\"'"
check_minimum = "python -c 'from jupyter_core import __version__; assert __version__ == \"4.12.0\"'"
check_pre = "python -c 'import os; assert os.environ[\"PIP_PRE\"] == \"1\"'"

[tool.pytest.ini_options]
Expand Down

0 comments on commit 3fb4e48

Please sign in to comment.