Skip to content

Commit

Permalink
Merge branch 'update-vendor' into feature/improved-async-installer
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Ryan <[email protected]>
  • Loading branch information
techalchemy committed Nov 13, 2018
2 parents e62b800 + 6b3c9a7 commit 4370281
Show file tree
Hide file tree
Showing 8 changed files with 339 additions and 93 deletions.
32 changes: 0 additions & 32 deletions pipenv/test_script.py

This file was deleted.

60 changes: 29 additions & 31 deletions pipenv/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,36 +362,6 @@ def get_resolver(self, clear=False, pre=False):
clear_caches=clear, prereleases=pre,
)

def populate_file_hashes(self):
from pipenv.vendor.vistir.compat import Path, to_native_string
from pipenv.vendor.vistir.path import url_to_path

def _should_include(ireq):
# We can only hash artifacts.
try:
if not ireq.link.is_artifact:
return False
except AttributeError:
return False

# But we don't want normal pypi artifcats since the normal resolver
# handles those
if is_pypi_url(ireq.link.url):
return False

# We also don't want to try to hash directories as this will fail
# as these are editable deps and are not hashable.
if (ireq.link.scheme == "file" and
Path(to_native_string(url_to_path(ireq.link.url))).is_dir()):
return False
return True

self.hashes.update({
ireq: self.resolver._hash_cache.get_hash(ireq.link)
for ireq in self.parsed_constraints
if _should_include(ireq)
})

@property
def resolver(self):
if self._resolver is None:
Expand Down Expand Up @@ -422,11 +392,39 @@ def resolve(self):
return self.resolved_tree

def resolve_hashes(self):
def _should_include_hash(ireq):
from pipenv.vendor.vistir.compat import Path, to_native_string
from pipenv.vendor.vistir.path import url_to_path

# We can only hash artifacts.
try:
if not ireq.link.is_artifact:
return False
except AttributeError:
return False

# But we don't want normal pypi artifcats since the normal resolver
# handles those
if is_pypi_url(ireq.link.url):
return False

# We also don't want to try to hash directories as this will fail
# as these are editable deps and are not hashable.
if (ireq.link.scheme == "file" and
Path(to_native_string(url_to_path(ireq.link.url))).is_dir()):
return False
return True

if self.results is not None:
resolved_hashes = self.resolver.resolve_hashes(self.results)
for ireq, ireq_hashes in resolved_hashes.items():
if ireq not in self.hashes:
self.hashes[ireq] = ireq_hashes
if _should_include_hash(ireq):
self.hashes[ireq] = [
self.resolver.repository._hash_cache.get_hash(ireq.link)
]
else:
self.hashes[ireq] = ireq_hashes
return self.hashes


Expand Down
68 changes: 56 additions & 12 deletions pipenv/vendor/pythonfinder/models/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
optional_instance_of,
path_is_known_executable,
unnest,
normalize_path,
parse_pyenv_version_order,
parse_asdf_version_order
)
from .python import PythonVersion

Expand Down Expand Up @@ -128,9 +131,10 @@ def __attrs_post_init__(self):
)

def _get_last_instance(self, path):
last_instance = next(iter(
(p for p in reversed(self.path_order) if path.lower() in p.lower())),
None,
paths = [normalize_path(p) for p in reversed(self.path_order)]
normalized_target = normalize_path(path)
last_instance = next(
iter(p for p in paths if normalized_target in p), None
)
try:
path_index = self.path_order.index(last_instance)
Expand All @@ -148,36 +152,47 @@ def _slice_in_paths(self, start_idx, paths):
def _remove_path(self, path):
path_copy = reversed(self.path_order[:])
new_order = []
target = os.path.normcase(os.path.normpath(os.path.abspath(path)))
target = normalize_path(path)
path_map = {
os.path.normcase(os.path.normpath(os.path.abspath(pth))): pth
normalize_path(pth): pth
for pth in self.paths.keys()
}
if target in path_map:
del self.paths[path_map.get(target)]
for current_path in path_copy:
normalized = os.path.normcase(os.path.normpath(os.path.abspath(current_path)))
normalized = normalize_path(current_path)
if normalized != target:
new_order.append(normalized)
new_order = reversed(new_order)
self.path_order = new_order

def _setup_asdf(self):
from .asdf import AsdfFinder
from .python import PythonFinder
asdf_index = self._get_last_instance(ASDF_DATA_DIR)
self.asdf_finder = AsdfFinder.create(root=ASDF_DATA_DIR, ignore_unsupported=True)
if not asdf_index:
# we are in a virtualenv without global pyenv on the path, so we should
# not write pyenv to the path here
return
self.asdf_finder = PythonFinder.create(
root=ASDF_DATA_DIR, ignore_unsupported=True,
sort_function=parse_asdf_version_order, version_glob_path="installs/python/*")
root_paths = [p for p in self.asdf_finder.roots]
self._slice_in_paths(asdf_index, root_paths)
self.paths.update(self.asdf_finder.roots)
self._register_finder("asdf", self.asdf_finder)

def _setup_pyenv(self):
from .pyenv import PyenvFinder
from .python import PythonFinder

pyenv_index = self._get_last_instance(PYENV_ROOT)
self.pyenv_finder = PyenvFinder.create(
root=PYENV_ROOT, ignore_unsupported=self.ignore_unsupported
self.pyenv_finder = PythonFinder.create(
root=PYENV_ROOT, sort_function=parse_pyenv_version_order,
version_glob_path="versions/*", ignore_unsupported=self.ignore_unsupported
)
pyenv_index = self._get_last_instance(PYENV_ROOT)
if not pyenv_index:
# we are in a virtualenv without global pyenv on the path, so we should
# not write pyenv to the path here
return
root_paths = [p for p in self.pyenv_finder.roots]
self._slice_in_paths(pyenv_index, root_paths)

Expand Down Expand Up @@ -485,6 +500,9 @@ def get_py_version(self):
py_version = PythonVersion.from_path(path=self, name=self.name)
except InvalidPythonVersion:
py_version = None
except Exception:
if not IGNORE_UNSUPPORTED:
raise
return py_version
return

Expand Down Expand Up @@ -572,3 +590,29 @@ def is_python(self):
return self.is_executable and (
looks_like_python(self.path.name)
)


@attr.s
class VersionPath(SystemPath):
base = attr.ib(default=None, validator=optional_instance_of(Path))
name = attr.ib(default=None)

@classmethod
def create(cls, path, only_python=True, pythons=None, name=None):
"""Accepts a path to a base python version directory.
Generates the version listings for it"""
from .path import PathEntry
path = ensure_path(path)
path_entries = defaultdict(PathEntry)
bin_ = "{base}/bin"
if path.as_posix().endswith(Path(bin_).name):
path = path.parent
bin_dir = ensure_path(bin_.format(base=path.as_posix()))
if not name:
name = path.name
current_entry = PathEntry.create(
bin_dir, is_root=True, only_python=True, pythons=pythons, name=name
)
path_entries[bin_dir.as_posix()] = current_entry
return cls(name=name, base=bin_dir, paths=path_entries)
2 changes: 0 additions & 2 deletions pipenv/vendor/pythonfinder/models/pyenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
from ..utils import (
ensure_path,
optional_instance_of,
get_python_version,
filter_pythons,
unnest,
)
from .mixins import BaseFinder, BasePath
Expand Down
Loading

0 comments on commit 4370281

Please sign in to comment.