Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pip for resolving and building distributions. #788

Merged
merged 11 commits into from
Nov 14, 2019
269 changes: 95 additions & 174 deletions pex/bin/pex.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pex/commands/bdist_pex.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def parse_entry_point_name(entry_point):
return ()

def run(self):
parser, options_builder = configure_clp()
parser = configure_clp()
options, reqs = parser.parse_args(self.pex_args)

if options.entry_point or options.script or options.pex_name:
Expand Down
10 changes: 10 additions & 0 deletions pex/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ def open_zip(path, *args, **kwargs):
yield zip


@contextlib.contextmanager
def temporary_dir(cleanup=True):
td = tempfile.mkdtemp()
try:
yield td
finally:
if cleanup:
safe_rmtree(td)


def safe_mkdtemp(**kw):
"""Create a temporary directory that is cleaned up on process exit.

Expand Down
24 changes: 1 addition & 23 deletions pex/compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

import os
from abc import ABCMeta
from io import BytesIO, StringIO
from numbers import Integral, Real
from io import StringIO
from sys import version_info as sys_version_info

try:
Expand All @@ -23,9 +22,6 @@
PY2 = sys_version_info[0] == 2
PY3 = sys_version_info[0] == 3

integer = (Integral,)
real = (Real,)
numeric = integer + real
string = (str,) if PY3 else (str, unicode)
unicode_string = (str,) if PY3 else (unicode,)
bytes = (bytes,)
Expand Down Expand Up @@ -107,21 +103,3 @@ def nested(*context_managers):


WINDOWS = os.name == 'nt'


__all__ = (
'AbstractClass',
'BytesIO',
'ConfigParser',
'PY2',
'PY3',
'StringIO',
'WINDOWS',
'bytes',
'exec_function',
'nested',
'pathname2url',
'string',
'to_bytes',
'url2pathname',
)
10 changes: 2 additions & 8 deletions pex/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ def _write_zipped_internal_cache(cls, pex, pex_info):
prefix_length = len(pex_info.internal_cache) + 1
existing_cached_distributions = []
newly_cached_distributions = []
zip_safe_distributions = []
with open_zip(pex) as zf:
# Distribution names are the first element after ".deps/" and before the next "/"
distribution_names = set(filter(None, (filename[prefix_length:].split('/')[0]
Expand All @@ -184,18 +183,13 @@ def _write_zipped_internal_cache(cls, pex, pex_info):
if dist is not None:
existing_cached_distributions.append(dist)
continue
else:
dist = DistributionHelper.distribution_from_path(os.path.join(pex, internal_dist_path))
if dist is not None:
if DistributionHelper.zipsafe(dist) and not pex_info.always_write_cache:
zip_safe_distributions.append(dist)
continue

dist = DistributionHelper.distribution_from_path(os.path.join(pex, internal_dist_path))
with TRACER.timed('Caching %s' % dist):
newly_cached_distributions.append(
CacheHelper.cache_distribution(zf, internal_dist_path, cached_location))

return existing_cached_distributions, newly_cached_distributions, zip_safe_distributions
return existing_cached_distributions, newly_cached_distributions

@classmethod
def _load_internal_cache(cls, pex, pex_info):
Expand Down
16 changes: 1 addition & 15 deletions pex/finders.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,6 @@ def unregister_finders():
__PREVIOUS_FINDER = None


def get_script_from_egg(name, dist):
"""Returns location, content of script in distribution or (None, None) if not there."""
if dist.metadata_isdir('scripts') and name in dist.metadata_listdir('scripts'):
return (
os.path.join(dist.egg_info, 'scripts', name),
dist.get_metadata('scripts/%s' % name).replace('\r\n', '\n').replace('\r', '\n'))
return None, None


def get_script_from_whl(name, dist):
# This can get called in different contexts; in some, it looks for files in the
# wheel archives being used to produce a pex; in others, it looks for files in the
Expand All @@ -256,18 +247,13 @@ def get_script_from_whl(name, dist):
def get_script_from_distribution(name, dist):
# PathMetadata: exploded distribution on disk.
if isinstance(dist._provider, pkg_resources.PathMetadata):
if dist.egg_info.endswith('EGG-INFO'):
return get_script_from_egg(name, dist)
elif dist.egg_info.endswith('.dist-info'):
if dist.egg_info.endswith('.dist-info'):
return get_script_from_whl(name, dist)
else:
return None, None
# WheelMetadata: Zipped whl (in theory should not experience this at runtime.)
elif isinstance(dist._provider, WheelMetadata):
return get_script_from_whl(name, dist)
# EggMetadata: Zipped egg
elif isinstance(dist._provider, pkg_resources.EggMetadata):
return get_script_from_egg(name, dist)
return None, None


Expand Down
Loading