diff --git a/tools/pip_install.py b/tools/pip_install.py index 168feb61a..f152bccc8 100755 --- a/tools/pip_install.py +++ b/tools/pip_install.py @@ -4,11 +4,15 @@ # is used. Before installing the requested packages, core Python packaging # tools like pip, setuptools, and wheel are updated to pinned versions to # increase stability of the install. +# +# cryptography is currently using this script in their CI at +# https://github.com/pyca/cryptography/blob/14d45c2259b01f1459eeab8bb7d85ce4cfb0841b/.github/downstream.d/certbot.sh#L8-L9. +# We should try to remember to keep their repo updated if we make any changes +# to this script which may break things for them. from __future__ import absolute_import from __future__ import print_function -import contextlib import os import subprocess import sys @@ -30,40 +34,35 @@ def pip_install_with_print(args_str, env): call_with_print(''.join(command), env=env) -@contextlib.contextmanager -def modified_environ(): +def pip_constrained_environ(): tools_path = find_tools_path() - with tempfile.TemporaryDirectory() as working_dir: - repo_path = os.path.dirname(tools_path) - if os.environ.get('CERTBOT_OLDEST') == '1': - constraints_path = os.path.normpath(os.path.join( - repo_path, 'tools', 'oldest_constraints.txt')) - else: - constraints_path = os.path.normpath(os.path.join( - repo_path, 'tools', 'requirements.txt')) + repo_path = os.path.dirname(tools_path) + if os.environ.get('CERTBOT_OLDEST') == '1': + constraints_path = os.path.normpath(os.path.join( + repo_path, 'tools', 'oldest_constraints.txt')) + else: + constraints_path = os.path.normpath(os.path.join( + repo_path, 'tools', 'requirements.txt')) - env = os.environ.copy() - # We set constraints for pip using an environment variable so that they - # are also used when installing build dependencies. See - # https://github.com/certbot/certbot/pull/8443 for more info. - env["PIP_CONSTRAINT"] = constraints_path - yield env + env = os.environ.copy() + # We set constraints for pip using an environment variable so that they + # are also used when installing build dependencies. See + # https://github.com/certbot/certbot/pull/8443 for more info. + env["PIP_CONSTRAINT"] = constraints_path + return env def pipstrap(env=None): if env is None: - context_manager = modified_environ() - else: - context_manager = contextlib.nullcontext(env) - with context_manager as env: - pip_install_with_print('pip setuptools wheel', env=env) + env = pip_constrained_environ() + pip_install_with_print('pip setuptools wheel', env=env) def main(args): - with modified_environ() as env: - pipstrap(env) - pip_install_with_print(' '.join(args), env=env) + env = pip_constrained_environ() + pipstrap(env) + pip_install_with_print(' '.join(args), env=env) if __name__ == '__main__': diff --git a/tools/pip_install_editable.py b/tools/pip_install_editable.py index dd1416e75..87be1b8f5 100755 --- a/tools/pip_install_editable.py +++ b/tools/pip_install_editable.py @@ -1,10 +1,5 @@ #!/usr/bin/env python # pip installs packages in editable mode using pip_install.py -# -# cryptography is currently using this script in their CI at -# https://github.com/pyca/cryptography/blob/a02fdd60d98273ca34427235c4ca96687a12b239/.travis/downstream.d/certbot.sh#L8-L9. -# We should try to remember to keep their repo updated if we make any changes -# to this script which may break things for them. import sys import pip_install