1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#!/usr/bin/env python3
"""Installs the minimum version of all stactools dependencies, with pip.
Assumptions:
- You've installed the development dependencies: `pip install '.[dev]'`
- All of the dependencies in pyproject.toml are specified with `>=`
For more context on the approach and rationale behind testing against minimum
requirements, see
https://www.gadom.ski/2022/02/18/dependency-protection-with-python-and-github-actions.html.
"""
import subprocess
import sys
from pathlib import Path
from packaging.requirements import Requirement
assert sys.version_info[0] == 3
if sys.version_info[1] < 11:
import tomli as toml
else:
import tomllib as toml
root = Path(__file__).parents[1]
with open(root / "pyproject.toml", "rb") as f:
pyproject_toml = toml.load(f)
requirements = []
for install_requires in filter(
bool,
(i.strip() for i in pyproject_toml["project"]["dependencies"]),
):
requirement = Requirement(install_requires)
assert len(requirement.specifier) == 1
specifier = list(requirement.specifier)[0]
assert specifier.operator == ">="
install_requires = install_requires.replace(">=", "==")
requirements.append(install_requires)
subprocess.run(["pip", "install", *requirements])
|