mirror of
https://github.com/certbot/certbot.git
synced 2026-04-21 22:26:59 -04:00
Summary of changes in this PR:
- Refactor files involved in the `certbot` module to be of a similar structure to every other package; that is, inside a directory inside the main repo root (see below).
- Make repo root README symlink to `certbot` README.
- Pull tests outside of the distributed module.
- Make `certbot/tests` not be a module so that `certbot` isn't added to Python's path for module discovery.
- Remove `--pyargs` from test calls, and make sure to call tests from repo root since without `--pyargs`, `pytest` takes directory names rather than package names as arguments.
- Replace mentions of `.` with `certbot` when referring to packages to install, usually editably.
- Clean up some unused code around executing tests in a different directory.
- Create public shim around main and make that the entry point.
New directory structure summary:
```
repo root ("certbot", probably, but for clarity all files I mention are relative to here)
├── certbot
│ ├── setup.py
│ ├── certbot
│ │ ├── __init__.py
│ │ ├── achallenges.py
│ │ ├── _internal
│ │ │ ├── __init__.py
│ │ │ ├── account.py
│ │ │ ├── ...
│ │ ├── ...
│ ├── tests
│ │ ├── account_test.py
│ │ ├── display
│ │ │ ├── __init__.py
│ │ │ ├── ...
│ │ ├── ... # note no __init__.py at this level
│ ├── ...
├── acme
│ ├── ...
├── certbot-apache
│ ├── ...
├── ...
```
* refactor certbot/ and certbot/tests/ to use the same structure as the other packages
* git grep -lE "\-e(\s+)\." | xargs sed -i -E "s/\-e(\s+)\./-e certbot/g"
* git grep -lE "\.\[dev\]" | xargs sed -i -E "s/\.\[dev\]/certbot[dev]/g"
* git grep -lE "\.\[dev3\]" | xargs sed -i -E "s/\.\[dev3\]/certbot[dev3]/g"
* Remove replacement of certbot into . in install_and_test.py
* copy license back out to main folder
* remove linter_plugin.py and CONTRIBUTING.md from certbot/MANIFEST.in because these files are not under certbot/
* Move README back into main folder, and make the version inside certbot/ a symlink
* symlink certbot READMEs the other way around
* move testdata into the public api certbot zone
* update source_paths in tox.ini to certbot/certbot to find the right subfolder for tests
* certbot version has been bumped down a directory level
* make certbot tests directory not a package and import sibling as module
* Remove unused script cruft
* change . to certbot in test_sdists
* remove outdated comment referencing a command that doesn't work
* Install instructions should reference an existing file
* update file paths in Dockerfile
* some package named in tox.ini were manually specified, change those to certbot
* new directory format doesn't work easily with pyargs according to http://doc.pytest.org/en/latest/goodpractices.html#tests-as-part-of-application-code
* remove other instance of pyargs
* fix up some references in _release.sh by searching for ' . ' and manual check
* another stray . in tox.ini
* fix paths in tools/_release.sh
* Remove final --pyargs call, and now-unnecessary call to modules instead of local files, since that's fixed by certbot's code being one layer deeper
* Create public shim around main and make that the entry point
* without pyargs, tests cannot be run from an empty directory
* Remove cruft for running certbot directly from main
* Have main shim take real arg
* add docs/api file for main, and fix up main comment
* Update certbot/docs/install.rst
Co-Authored-By: Brad Warren <bmw@users.noreply.github.com>
* Fix comments in readthedocs requirements files to refer to current package
* Update .[docs] reference in contributing.rst
* Move plugins tests to certbot tests directory
* add certbot tests to MANIFEST.in so packagers can run python setup.py test
* move examples directory inside certbot/
* Move CHANGELOG into certbot, and create a top-level symlink
* Remove unused sys and logging from main shim
* nginx http01 test no longer relies on certbot plugins common test
128 lines
5.3 KiB
Python
Executable file
128 lines
5.3 KiB
Python
Executable file
#!/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,
|
|
# tools/dev_constraints.txt, and local-oldest-requirements.txt contained in the
|
|
# top level of the package's directory is used, otherwise, a combination of
|
|
# certbot-auto's requirements file and tools/dev_constraints.txt is used. The
|
|
# other file always takes precedence over tools/dev_constraints.txt. If
|
|
# CERTBOT_OLDEST is set, this script must be run with `-e <package-name>` and
|
|
# no other arguments.
|
|
|
|
from __future__ import print_function, absolute_import
|
|
|
|
import subprocess
|
|
import os
|
|
import sys
|
|
import re
|
|
import shutil
|
|
import tempfile
|
|
|
|
import merge_requirements as merge_module
|
|
import readlink
|
|
import strip_hashes
|
|
|
|
|
|
def find_tools_path():
|
|
return os.path.dirname(readlink.main(__file__))
|
|
|
|
|
|
def certbot_oldest_processing(tools_path, args, test_constraints):
|
|
if args[0] != '-e' or len(args) != 2:
|
|
raise ValueError('When CERTBOT_OLDEST is set, this script must be run '
|
|
'with a single -e <path> argument.')
|
|
# remove any extras such as [dev]
|
|
pkg_dir = re.sub(r'\[\w+\]', '', args[1])
|
|
requirements = os.path.join(pkg_dir, 'local-oldest-requirements.txt')
|
|
shutil.copy(os.path.join(tools_path, 'oldest_constraints.txt'), test_constraints)
|
|
# packages like acme don't have any local oldest requirements
|
|
if not os.path.isfile(requirements):
|
|
return None
|
|
|
|
return requirements
|
|
|
|
|
|
def certbot_normal_processing(tools_path, test_constraints):
|
|
repo_path = os.path.dirname(tools_path)
|
|
certbot_requirements = os.path.normpath(os.path.join(
|
|
repo_path, 'letsencrypt-auto-source/pieces/dependency-requirements.txt'))
|
|
with open(certbot_requirements, 'r') as fd:
|
|
data = fd.readlines()
|
|
with open(test_constraints, 'w') as fd:
|
|
data = "\n".join(strip_hashes.process_entries(data))
|
|
fd.write(data)
|
|
|
|
|
|
def merge_requirements(tools_path, requirements, test_constraints, all_constraints):
|
|
# Order of the files in the merge function matters.
|
|
# Indeed version retained for a given package will be the last version
|
|
# found when following all requirements in the given order.
|
|
# Here is the order by increasing priority:
|
|
# 1) The general development constraints (tools/dev_constraints.txt)
|
|
# 2) The general tests constraints (oldest_requirements.txt or
|
|
# certbot-auto's dependency-requirements.txt for the normal processing)
|
|
# 3) The local requirement file, typically local-oldest-requirement in oldest tests
|
|
files = [os.path.join(tools_path, 'dev_constraints.txt'), test_constraints]
|
|
if requirements:
|
|
files.append(requirements)
|
|
merged_requirements = merge_module.main(*files)
|
|
with open(all_constraints, 'w') as fd:
|
|
fd.write(merged_requirements)
|
|
|
|
|
|
def call_with_print(command):
|
|
print(command)
|
|
subprocess.check_call(command, shell=True)
|
|
|
|
|
|
def pip_install_with_print(args_str):
|
|
command = '"{0}" -m pip install --disable-pip-version-check {1}'.format(sys.executable,
|
|
args_str)
|
|
call_with_print(command)
|
|
|
|
|
|
def main(args):
|
|
tools_path = find_tools_path()
|
|
working_dir = tempfile.mkdtemp()
|
|
|
|
if os.environ.get('TRAVIS'):
|
|
# When this script is executed on Travis, the following print will make the log
|
|
# be folded until the end command is printed (see finally section).
|
|
print('travis_fold:start:install_certbot_deps')
|
|
|
|
try:
|
|
test_constraints = os.path.join(working_dir, 'test_constraints.txt')
|
|
all_constraints = os.path.join(working_dir, 'all_constraints.txt')
|
|
|
|
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
|
|
requirements = None
|
|
if os.environ.get('CERTBOT_OLDEST') == '1':
|
|
requirements = certbot_oldest_processing(tools_path, args, test_constraints)
|
|
else:
|
|
certbot_normal_processing(tools_path, test_constraints)
|
|
|
|
merge_requirements(tools_path, requirements, test_constraints, all_constraints)
|
|
if requirements: # This branch is executed during the oldest tests
|
|
# First step, install the transitive dependencies of oldest requirements
|
|
# in respect with oldest constraints.
|
|
pip_install_with_print('--constraint "{0}" --requirement "{1}"'
|
|
.format(all_constraints, requirements))
|
|
# Second step, ensure that oldest requirements themselves are effectively
|
|
# installed using --force-reinstall, and avoid corner cases like the one described
|
|
# in https://github.com/certbot/certbot/issues/7014.
|
|
pip_install_with_print('--force-reinstall --no-deps --requirement "{0}"'
|
|
.format(requirements))
|
|
|
|
pip_install_with_print('--constraint "{0}" {1}'.format(
|
|
all_constraints, ' '.join(args)))
|
|
finally:
|
|
if os.environ.get('TRAVIS'):
|
|
print('travis_fold:end:install_certbot_deps')
|
|
shutil.rmtree(working_dir)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main(sys.argv[1:])
|