1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
import os
from utils import bin_path, cd, run, virtualenv_enabled
INSTALL_ARGS = (
"--no-build-isolation --no-cache-dir --no-index --prefer-binary "
)
PINNED_PIP_VERSION = '24.0'
SETUP_DEPS = ("setuptools-", "setuptools_scm", "wheel", "hatchling")
class InstallationError(Exception):
pass
def get_package_tarball(package_dir, package_prefix):
package_filenames = sorted(
[p for p in os.listdir(package_dir) if p.startswith(package_prefix)]
)
if len(package_filenames) == 0:
raise InstallationError(
"Unable to find local package starting with %s prefix."
% package_prefix
)
# We only expect a single package from the downloader
return package_filenames[0]
def install_local_package(package_dir, package, pip_script="pip"):
with cd(package_dir):
run(
"%s install %s --find-links file://%s %s"
% (pip_script, INSTALL_ARGS, package_dir, package)
)
def find_and_install_tarball(package_dir, package_prefix, pip_script="pip"):
tarball = get_package_tarball(package_dir, package_prefix)
install_local_package(package_dir, tarball, pip_script)
def pip_install_packages(package_dir):
package_dir = os.path.abspath(package_dir)
# Setup pip to support modern setuptools calls
pip_script = os.path.join(os.environ["VIRTUAL_ENV"], bin_path(), "pip")
local_python = os.path.join(
os.environ["VIRTUAL_ENV"], bin_path(), "python"
)
# Windows can't replace a running pip.exe, so we need to work around
run("%s -m pip install pip==%s" % (local_python, PINNED_PIP_VERSION))
# Install or update prerequisite build packages
setup_requires_dir = os.path.join(package_dir, "setup")
install_setup_deps(pip_script, setup_requires_dir)
find_and_install_tarball(package_dir, "awscli", pip_script)
def install_setup_deps(pip_script, setup_package_dir):
# These packages need to be installed in this order before we
# attempt anything else in order to support PEP517 setup_requires
# specifications.
# We need setuptools >= 37.0.0 for setuptools_scm to work properly
for setup_dep in SETUP_DEPS:
find_and_install_tarball(setup_package_dir, setup_dep, pip_script)
def install_packages(package_dir):
"""Builds setup environment and installs copies of local packages for CLI"""
if not virtualenv_enabled():
raise InstallationError(
"Installation being performed outside of a virtualenv. Please enable before running."
)
else:
pip_install_packages(package_dir)
|