Finish pinning system rewrite (#8934)

* add oldest pyproject.toml file that works

* make single oldest_constraints.txt file

* remove unused merge_requirements.py

* remove unused import

* make conditional right

* simplify pip_install.py

* fix typo

* bump min dns-lexicon dependency

* fix zope import warning

* pin back wheel

* refactor pinning script

* Add oldest script.

* add pip comment

* add pipstrap extra

* simplify pinning scripts

* remove pipstrap extra

* update contributing

* Add design doc

* Update tools/pinning/DESIGN.md

Co-authored-by: ohemorange <erica@eff.org>

* Update tools/pinning/DESIGN.md

Co-authored-by: ohemorange <erica@eff.org>

* Update tools/pinning/DESIGN.md

Co-authored-by: ohemorange <erica@eff.org>

* Update tools/pinning/DESIGN.md

Co-authored-by: ohemorange <erica@eff.org>

* rename normal to current

* no dummies

* script improvements

* mention need to update setup.py

* try and clarify poetry behavior

* tweak section title

Co-authored-by: ohemorange <erica@eff.org>
This commit is contained in:
Brad Warren
2021-07-22 12:00:30 -07:00
committed by GitHub
co-authored by ohemorange
parent 10eecf9c97
commit 08839758bd
26 changed files with 583 additions and 452 deletions
+10 -38
View File
@@ -1,54 +1,23 @@
#!/usr/bin/env python
# pip installs packages using pinned package versions. If CERTBOT_OLDEST is set
# to 1, a combination of tools/oldest_constraints.txt and
# tools/dev_constraints.txt is used, otherwise, tools/requirements.txt is used.
# to 1, tools/oldest_constraints.txt is used, otherwise, tools/requirements.txt
# is used.
from __future__ import absolute_import
from __future__ import print_function
import contextlib
import os
import re
import shutil
import subprocess
import sys
import tempfile
import merge_requirements as merge_module
import readlink
# Once this code doesn't need to support Python 2, we can simply use
# tempfile.TemporaryDirectory.
@contextlib.contextmanager
def temporary_directory():
dirpath = tempfile.mkdtemp()
try:
yield dirpath
finally:
shutil.rmtree(dirpath)
def find_tools_path():
return os.path.dirname(readlink.main(__file__))
def certbot_oldest_processing(tools_path, constraints_path):
# The order of the files in this list matters as files specified later can
# override the pinnings found in earlier files.
pinning_files = [os.path.join(tools_path, 'dev_constraints.txt'),
os.path.join(tools_path, 'oldest_constraints.txt')]
with open(constraints_path, 'w') as fd:
fd.write(merge_module.main(*pinning_files))
def certbot_normal_processing(tools_path, constraints_path):
repo_path = os.path.dirname(tools_path)
requirements = os.path.normpath(os.path.join(
repo_path, 'tools/requirements.txt'))
shutil.copy(requirements, constraints_path)
def call_with_print(command, env=None):
if not env:
env = os.environ
@@ -66,17 +35,20 @@ def pip_install_with_print(args_str, env=None):
def main(args):
tools_path = find_tools_path()
with temporary_directory() as working_dir:
with tempfile.TemporaryDirectory() as working_dir:
if os.environ.get('CERTBOT_NO_PIN') == '1':
# With unpinned dependencies, there is no constraint
pip_install_with_print(' '.join(args))
else:
# Otherwise, we merge requirements to build the constraints and pin dependencies
constraints_path = os.path.join(working_dir, 'constraints.txt')
# Otherwise, we pick the constraints file based on the environment
# variable CERTBOT_OLDEST.
repo_path = os.path.dirname(tools_path)
if os.environ.get('CERTBOT_OLDEST') == '1':
certbot_oldest_processing(tools_path, constraints_path)
constraints_path = os.path.normpath(os.path.join(
repo_path, 'tools', 'oldest_constraints.txt'))
else:
certbot_normal_processing(tools_path, constraints_path)
constraints_path = os.path.normpath(os.path.join(
repo_path, 'tools', 'requirements.txt'))
env = os.environ.copy()
env["PIP_CONSTRAINT"] = constraints_path