nox: Better handle execution with protected pip

This commit is contained in:
Pradyun Gedam 2019-10-07 15:41:42 +05:30
parent a6b06059c9
commit 4048daeddf
No known key found for this signature in database
GPG Key ID: DA17C4B29CB32E4B
1 changed files with 15 additions and 8 deletions

View File

@ -47,14 +47,18 @@ def get_author_list():
return sorted(authors, key=lambda x: x.lower())
def protected_pip(*arguments):
"""Get arguments for session.run, that use a "protected" pip.
def run_with_protected_pip(session, *arguments):
"""Do a session.run("pip", *arguments), using a "protected" pip.
This invokes a wrapper script, that forwards calls to original virtualenv
(stable) version, and not the code being tested. This ensures pip being
used is not the code being tested.
"""
return ("python", LOCATIONS["protected-pip"]) + arguments
env = {"VIRTUAL_ENV": session.virtualenv.location}
command = ("python", LOCATIONS["protected-pip"]) + arguments
kwargs = {"env": env, "silent": True}
session.run(*command, **kwargs)
def should_update_common_wheels():
@ -84,15 +88,18 @@ def should_update_common_wheels():
def test(session):
# Get the common wheels.
if should_update_common_wheels():
session.run(*protected_pip(
run_with_protected_pip(
session,
"wheel",
"-w", LOCATIONS["common-wheels"],
"-r", REQUIREMENTS["common-wheels"],
))
)
# Install sources and dependencies
session.run(*protected_pip("install", "."))
session.run(*protected_pip("install", "-r", REQUIREMENTS["tests"]))
# Install sources
run_with_protected_pip(session, "install", ".")
# Install test dependencies
run_with_protected_pip(session, "install", "-r", REQUIREMENTS["tests"])
# Parallelize tests as much as possible, by default.
arguments = session.posargs or ["-n", "auto"]