Skip to content

Commit

Permalink
Improve requirements installation
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
  • Loading branch information
s0undt3ch committed Jul 26, 2023
1 parent 7f228ef commit ce4a380
Showing 1 changed file with 43 additions and 34 deletions.
77 changes: 43 additions & 34 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
or os.environ.get("GITHUB_ACTIONS")
) is None
CI_RUN = PIP_INSTALL_SILENT is False
SKIP_REQUIREMENTS_INSTALL = "SKIP_REQUIREMENTS_INSTALL" in os.environ
SKIP_REQUIREMENTS_INSTALL = os.environ.get("SKIP_REQUIREMENTS_INSTALL", "0") == "1"
EXTRA_REQUIREMENTS_INSTALL = os.environ.get("EXTRA_REQUIREMENTS_INSTALL")

# Paths
Expand Down Expand Up @@ -138,53 +138,62 @@ def tests(session):
"--progress-bar=off",
"Cython<3.0",
"--no-build-isolation",
SALT_REQUIREMENT,
"pyyaml<=6.0.1",
silent=PIP_INSTALL_SILENT,
)
salt_requirements = []
pytest_requirements = []
if python_version_info <= (3, 7) and "3005" in SALT_REQUIREMENT:
salt_requirements.append("importlib-metadata<5.0.0")
salt_requirements.append(SALT_REQUIREMENT)
if session.python is not False and system_service is False:
session.install(
*salt_requirements,
silent=PIP_INSTALL_SILENT,
# Use salt's pinned requirements
env={"USE_STATIC_REQUIREMENTS": "1"},
)
env["USE_STATIC_REQUIREMENTS"] = "1"

pytest_version_requirement = os.environ.get("PYTEST_VERSION_REQUIREMENT") or None
if pytest_version_requirement:
pytest_requirements = []
if not pytest_version_requirement.startswith("pytest"):
pytest_version_requirement = f"pytest{pytest_version_requirement}"
pytest_requirements.append(pytest_version_requirement)
session.install(*pytest_requirements, silent=PIP_INSTALL_SILENT)
if system_service:
session.install(".", silent=PIP_INSTALL_SILENT)
else:
session.install("-e", ".", silent=PIP_INSTALL_SILENT)
pip_list = session_run_always(
session, "pip", "list", "--format=json", silent=True, log=False, stderr=None
)
if pip_list:
for requirement in json.loads(pip_list.splitlines()[0]):
if requirement["name"] == "msgpack-python":
logger.warning(
"Found msgpack-python installed. Installing msgpack to override it"
)
session.install("msgpack=={}".format(requirement["version"]))
break
session.install("-r", os.path.join("requirements", "tests.txt"), silent=PIP_INSTALL_SILENT)

if EXTRA_REQUIREMENTS_INSTALL:
session.log(
"Installing the following extra requirements because the EXTRA_REQUIREMENTS_INSTALL "
"environment variable was set: EXTRA_REQUIREMENTS_INSTALL='%s'",
EXTRA_REQUIREMENTS_INSTALL,
with tempfile.NamedTemporaryFile(
"w", prefix="reqs-constraints-", suffix=".txt", delete=False
) as tfile:
with open(tfile.name, "w") as wfh:
for req in [*salt_requirements, *pytest_requirements]:
wfh.write(f"{req}\n")
if system_service:
session.install(
"-c", tfile.name, *pytest_requirements, silent=PIP_INSTALL_SILENT, env=env
)
session.install("-c", tfile.name, ".", silent=PIP_INSTALL_SILENT, env=env)
else:
session.install(
"-c",
tfile.name,
*salt_requirements,
*pytest_requirements,
silent=PIP_INSTALL_SILENT,
env=env,
)
session.install("-c", tfile.name, "-e", ".", silent=PIP_INSTALL_SILENT)
session.install(
"-c",
tfile.name,
"-r",
os.path.join("requirements", "tests.txt"),
silent=PIP_INSTALL_SILENT,
env=env,
)
install_command = ["--progress-bar=off"]
install_command += [req.strip() for req in EXTRA_REQUIREMENTS_INSTALL.split()]
session.install(*install_command, silent=PIP_INSTALL_SILENT)

if EXTRA_REQUIREMENTS_INSTALL:
session.log(
"Installing the following extra requirements because the EXTRA_REQUIREMENTS_INSTALL "
"environment variable was set: EXTRA_REQUIREMENTS_INSTALL='%s'",
EXTRA_REQUIREMENTS_INSTALL,
)
install_command = ["--progress-bar=off", "-c", tfile.name]
install_command += [req.strip() for req in EXTRA_REQUIREMENTS_INSTALL.split()]
session.install(*install_command, silent=PIP_INSTALL_SILENT, env=env)

session.run("coverage", "erase")

Expand Down

0 comments on commit ce4a380

Please sign in to comment.