Add base vars and sudo check

This commit is contained in:
Benjamin Zimmerman 2022-12-13 14:20:23 +00:00
parent c151fd6910
commit 054f5ad80c
8733 changed files with 137813 additions and 15 deletions

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/16/81/e0/95d3b57ae0a95023074a5011e1c109b466bc4b2bf533e58278435ca0e3

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/99/7c/16/0dfb4d2cc29fc15a8a156184feeb8166f1922225042e12e47b2b08b997

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/9e/71/42/bb1acf32000bac80f14a8cbe1fa663e16e1463ad03fae2f5689caad297

View file

@ -0,0 +1,289 @@
"""Build Environment used for isolation during sdist building
"""
import contextlib
import logging
import os
import pathlib
import sys
import textwrap
import zipfile
from collections import OrderedDict
from sysconfig import get_paths
from types import TracebackType
from typing import TYPE_CHECKING, Iterable, Iterator, List, Optional, Set, Tuple, Type
from pip._vendor.certifi import where
from pip._vendor.pkg_resources import Requirement, VersionConflict, WorkingSet
from pip import __file__ as pip_location
from pip._internal.cli.spinners import open_spinner
from pip._internal.locations import get_platlib, get_prefixed_libs, get_purelib
from pip._internal.utils.subprocess import call_subprocess
from pip._internal.utils.temp_dir import TempDirectory, tempdir_kinds
if TYPE_CHECKING:
from pip._internal.index.package_finder import PackageFinder
logger = logging.getLogger(__name__)
class _Prefix:
def __init__(self, path):
# type: (str) -> None
self.path = path
self.setup = False
self.bin_dir = get_paths(
'nt' if os.name == 'nt' else 'posix_prefix',
vars={'base': path, 'platbase': path}
)['scripts']
self.lib_dirs = get_prefixed_libs(path)
@contextlib.contextmanager
def _create_standalone_pip() -> Iterator[str]:
"""Create a "standalone pip" zip file.
The zip file's content is identical to the currently-running pip.
It will be used to install requirements into the build environment.
"""
# Replit mod: the pip binary is a symlink to the content-addressable cache,
# so the original `.resolve()` was causing the zip to have some _very_
# unexpected contents.
source = pathlib.Path(pip_location).parent
# Return the current instance if `source` is not a directory. We can't build
# a zip from this, and it likely means the instance is already standalone.
if not source.is_dir():
yield str(source)
return
with TempDirectory(kind="standalone-pip") as tmp_dir:
pip_zip = os.path.join(tmp_dir.path, "__env_pip__.zip")
kwargs = {}
if sys.version_info >= (3, 8):
kwargs["strict_timestamps"] = False
with zipfile.ZipFile(pip_zip, "w", **kwargs) as zf:
for child in source.rglob("*"):
zf.write(child, child.relative_to(source.parent).as_posix())
yield os.path.join(pip_zip, "pip")
class BuildEnvironment:
"""Creates and manages an isolated environment to install build deps
"""
def __init__(self):
# type: () -> None
temp_dir = TempDirectory(
kind=tempdir_kinds.BUILD_ENV, globally_managed=True
)
self._prefixes = OrderedDict(
(name, _Prefix(os.path.join(temp_dir.path, name)))
for name in ('normal', 'overlay')
)
self._bin_dirs = [] # type: List[str]
self._lib_dirs = [] # type: List[str]
for prefix in reversed(list(self._prefixes.values())):
self._bin_dirs.append(prefix.bin_dir)
self._lib_dirs.extend(prefix.lib_dirs)
# Customize site to:
# - ensure .pth files are honored
# - prevent access to system site packages
system_sites = {
os.path.normcase(site) for site in (get_purelib(), get_platlib())
}
self._site_dir = os.path.join(temp_dir.path, 'site')
if not os.path.exists(self._site_dir):
os.mkdir(self._site_dir)
with open(os.path.join(self._site_dir, 'sitecustomize.py'), 'w') as fp:
fp.write(textwrap.dedent(
'''
import os, site, sys
# First, drop system-sites related paths.
original_sys_path = sys.path[:]
known_paths = set()
for path in {system_sites!r}:
site.addsitedir(path, known_paths=known_paths)
system_paths = set(
os.path.normcase(path)
for path in sys.path[len(original_sys_path):]
)
original_sys_path = [
path for path in original_sys_path
if os.path.normcase(path) not in system_paths
]
sys.path = original_sys_path
# Second, add lib directories.
# ensuring .pth file are processed.
for path in {lib_dirs!r}:
assert not path in sys.path
site.addsitedir(path)
'''
).format(system_sites=system_sites, lib_dirs=self._lib_dirs))
def __enter__(self):
# type: () -> None
self._save_env = {
name: os.environ.get(name, None)
for name in ('PATH', 'PYTHONNOUSERSITE', 'PYTHONPATH')
}
path = self._bin_dirs[:]
old_path = self._save_env['PATH']
if old_path:
path.extend(old_path.split(os.pathsep))
pythonpath = [self._site_dir]
os.environ.update({
'PATH': os.pathsep.join(path),
'PYTHONNOUSERSITE': '1',
'PYTHONPATH': os.pathsep.join(pythonpath),
})
def __exit__(
self,
exc_type, # type: Optional[Type[BaseException]]
exc_val, # type: Optional[BaseException]
exc_tb # type: Optional[TracebackType]
):
# type: (...) -> None
for varname, old_value in self._save_env.items():
if old_value is None:
os.environ.pop(varname, None)
else:
os.environ[varname] = old_value
def check_requirements(self, reqs):
# type: (Iterable[str]) -> Tuple[Set[Tuple[str, str]], Set[str]]
"""Return 2 sets:
- conflicting requirements: set of (installed, wanted) reqs tuples
- missing requirements: set of reqs
"""
missing = set()
conflicting = set()
if reqs:
ws = WorkingSet(self._lib_dirs)
for req in reqs:
try:
if ws.find(Requirement.parse(req)) is None:
missing.add(req)
except VersionConflict as e:
conflicting.add((str(e.args[0].as_requirement()),
str(e.args[1])))
return conflicting, missing
def install_requirements(
self,
finder, # type: PackageFinder
requirements, # type: Iterable[str]
prefix_as_string, # type: str
message # type: str
):
# type: (...) -> None
prefix = self._prefixes[prefix_as_string]
assert not prefix.setup
prefix.setup = True
if not requirements:
return
with contextlib.ExitStack() as ctx:
# TODO: Remove this block when dropping 3.6 support. Python 3.6
# lacks importlib.resources and pep517 has issues loading files in
# a zip, so we fallback to the "old" method by adding the current
# pip directory to the child process's sys.path.
if sys.version_info < (3, 7):
pip_runnable = os.path.dirname(pip_location)
else:
pip_runnable = ctx.enter_context(_create_standalone_pip())
self._install_requirements(
pip_runnable,
finder,
requirements,
prefix,
message,
)
@staticmethod
def _install_requirements(
pip_runnable: str,
finder: "PackageFinder",
requirements: Iterable[str],
prefix: _Prefix,
message: str,
) -> None:
args = [
sys.executable, pip_runnable, 'install',
'--ignore-installed', '--no-user', '--prefix', prefix.path,
'--no-warn-script-location',
] # type: List[str]
if logger.getEffectiveLevel() <= logging.DEBUG:
args.append('-v')
for format_control in ('no_binary', 'only_binary'):
formats = getattr(finder.format_control, format_control)
args.extend(('--' + format_control.replace('_', '-'),
','.join(sorted(formats or {':none:'}))))
index_urls = finder.index_urls
if index_urls:
args.extend(['-i', index_urls[0]])
for extra_index in index_urls[1:]:
args.extend(['--extra-index-url', extra_index])
else:
args.append('--no-index')
for link in finder.find_links:
args.extend(['--find-links', link])
for host in finder.trusted_hosts:
args.extend(['--trusted-host', host])
if finder.allow_all_prereleases:
args.append('--pre')
if finder.prefer_binary:
args.append('--prefer-binary')
args.append('--')
args.extend(requirements)
extra_environ = {"_PIP_STANDALONE_CERT": where()}
with open_spinner(message) as spinner:
call_subprocess(args, spinner=spinner, extra_environ=extra_environ)
class NoOpBuildEnvironment(BuildEnvironment):
"""A no-op drop-in replacement for BuildEnvironment
"""
def __init__(self):
# type: () -> None
pass
def __enter__(self):
# type: () -> None
pass
def __exit__(
self,
exc_type, # type: Optional[Type[BaseException]]
exc_val, # type: Optional[BaseException]
exc_tb # type: Optional[TracebackType]
):
# type: (...) -> None
pass
def cleanup(self):
# type: () -> None
pass
def install_requirements(
self,
finder, # type: PackageFinder
requirements, # type: Iterable[str]
prefix_as_string, # type: str
message # type: str
):
# type: (...) -> None
raise NotImplementedError()

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/e9/53/8d/b6845e1996c177bb2a6359fa87091d582e22cf7b665f05f0663a6364ac

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/16/41/c1/829c716fefe077aaf51639cd85f30ecc0518c97a17289e9a6e28df7055

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/df/3a/e1/e834ead7221d330cdd51677036833fc20e62d85f0b007ee9476d453fdd

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/76/6b/dd/3585dc52fdc12b27f32d565b257ad6a3a19cf8f322d909832fbe75f6f9

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/88/1f/7b/7a89bd625d5de500864492074bfc2c734348a9c9a53bbbc3d62c1b12e7

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/6b/5a/41/06fbc62c3899d4ac3ae3fe2d4fa1e6453c180e8632f091601b90b39fbb

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/8a/82/7c/21595bd8ad6a2cec51fad5e479ef6551185857cf420ccef530a6a0ed86

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/43/d4/e7/cad7ee0b96762528c1156546b447582c5cbbaee90d21bd389a8bc7740a

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/1b/1c/1b/0b60ea216c5910e8762985838271da34ade2ed9d8f614e1c201cf6b8d2

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/13/3f/cf/5d9c03a57bfe5a02024409a5c2127daa3ff4389e52bb6f76f2e0e27bab

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/bf/65/0e/e943a8eef85c5f6e1a767f93e1b825a3f9d5dca119b95f7c01f90314fa

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/11/6f/79/c0c2d5b47bfca911eb58b28c570b2f9eb390e5dec203adbc184c6f3239

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/b0/41/47/51a5096eabfc880acbdc702d733b5666618e157d358537ac4b2b43121d

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/13/61/07/62fe860b0725e29b7549c3b0922e51f0d6c7a65937706df9aa09aa1930

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/54/8e/49/c8110edd4e89fd81783c8961a8faf9a3b95e426e04a7f2f237a8dde190

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/0e/dd/30/ecda85a7ca3fe3927bc37d8642b29ececcf6bf0a3f53c526b070fd60d2

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/53/14/b4/f6cf2b127534f000223778077502235385c64a5bf9489deb209753ca10

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/5f/57/dd/55d120f0c1c5b40ad4fb76cce9604d6b1d44ed9eeab333c47652b5ceaa

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/ca/7b/4e/a65c3ddd56684005410770573cabaa6da9b8993e9312b6acb45c05cb7b

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/ce/ff/12/fc3376fa4e8ad15491df208f2d2acb7a1a18923dc8bf23b51e8f2df15e

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/b4/ee/73/b2565547092deb0e1b337dd08abe141e64dc7d3332fcdf867d77c3d418

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/8a/9e/b8/02c27a105504696283bec6667501e4b35253120ac38c7e5bca5f886327

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/e8/c9/f3/ada93f8fec84de9b030aa8b61b121226a219274e0339b294f50867c4c1

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/c4/5b/5f/1fe0a83eff668fd6c3a1f13c02b17dfd8d90eee3bc129a7a8a23ea1755

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/c0/bf/e4/8d1f4bfa716fdc3cc70933432e9f3ed571b907ec30698319edc93488b1

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/ad/d5/66/58a0d9b51f773ff41c18ef2e92136656b68dd7107d9d499df3ac6bb0aa

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/14/0f/b9/42574440301fbdc3e52e683cd89904d7831b1a5d8a1859d17fd9b9802c

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/b3/3d/af/6f187897b063e232a59031931d80fa23cfddb92a525055715221f8e314

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/10/37/31/ddad3797753cb69676a787df21d9f8e61636605126abdca879c705da8c

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/c0/a1/92/92cb988e38603986bf8c3eae95a2a93d7694ccf8b2cdf44d353e033a2a

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/40/12/df/86ffac6cffa8474f0d1714989effe62c1f9282d34eb165c017db4311c3

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/1e/ae/a4/b7a8170608cd8ade614d358b03378234e2a807e374a46612a9e86b962f

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/1b/29/e5/9d513740bbcdbb826f9f13cee83f08412b3f18094551a6c0e94f86f9e5

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/81/3d/b4/5929e279c3af286300fa70b2abee0370996b223bfc8d3f89116c843a70

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/54/19/9e/d543650ae1ffc08a141d366af67828d8da455905e626a9f051bdd9a539

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/27/b0/cd/42f292e74a577f05ed7ad299b4b36063390473c4806da290e6fe891ed0

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/d8/94/09/492ebca20811fd920e03e8755360d10035116e4427f4d7f8119599f37e

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/be/9b/7e/25e4d979f87c6be142db665e0525c555bb817174868882e141925a3694

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/a0/7e/17/9581ef18c5de3db8cd84a64fa4b23e34b0535f1a4745166043ce6678d9

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/4e/fb/69/644f836327e09c0b2a4ddecba1b7480d50b1f6e8b333d821d51df8c3e6

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/49/5c/8f/8adbf4f3e41a961dbf064e5d88027d18003f77e6bdde4a28b90a1d006d

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/ce/e3/e3/0c2a7085a68b6b6ef0e2ede4c085480941150192226cdf3967cc45f2a6

View file

@ -0,0 +1 @@
/home/runner/.cache/pip/pool/97/e8/69/318acb2ffb24e0fffc6dbbef61255941d9d969f0adf60983efa53bf2e4

Some files were not shown because too many files have changed in this diff Show more