Skip to content

Commit

Permalink
Pull in PythonFinder updates
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr authored and techalchemy committed Jul 25, 2018
1 parent 9e2f829 commit 0d2ceb6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
18 changes: 14 additions & 4 deletions pipenv/vendor/pythonfinder/models/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

@attr.s
class SystemPath(object):
global_search = attr.ib(default=True)
paths = attr.ib(default=attr.Factory(defaultdict))
_executables = attr.ib(default=attr.Factory(list))
_python_executables = attr.ib(default=attr.Factory(list))
Expand Down Expand Up @@ -94,7 +95,10 @@ def _setup_pyenv(self):
(p for p in reversed(self.path_order) if PYENV_ROOT.lower() in p.lower()),
None,
)
pyenv_index = self.path_order.index(last_pyenv)
try:
pyenv_index = self.path_order.index(last_pyenv)
except ValueError:
return
self.pyenv_finder = PyenvFinder.create(root=PYENV_ROOT)
# paths = (v.paths.values() for v in self.pyenv_finder.versions.values())
root_paths = (
Expand Down Expand Up @@ -200,7 +204,7 @@ def find_python_version(self, major, minor=None, patch=None, pre=None, dev=None)
)

@classmethod
def create(cls, path=None, system=False, only_python=False):
def create(cls, path=None, system=False, only_python=False, global_search=True):
"""Create a new :class:`pythonfinder.models.SystemPath` instance.
:param path: Search path to prepend when searching, defaults to None
Expand All @@ -214,7 +218,9 @@ def create(cls, path=None, system=False, only_python=False):
"""

path_entries = defaultdict(PathEntry)
paths = os.environ.get("PATH").split(os.pathsep)
paths = []
if global_search:
paths = os.environ.get("PATH").split(os.pathsep)
if path:
paths = [path] + paths
_path_objects = [ensure_path(p.strip('"')) for p in paths]
Expand All @@ -227,7 +233,11 @@ def create(cls, path=None, system=False, only_python=False):
for p in _path_objects
}
)
return cls(paths=path_entries, path_order=paths, only_python=only_python, system=system)
return cls(
paths=path_entries, path_order=paths,
only_python=only_python,
system=system, global_search=global_search,
)


@attr.s
Expand Down
27 changes: 25 additions & 2 deletions pipenv/vendor/pythonfinder/pythonfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,30 @@


class Finder(object):
def __init__(self, path=None, system=False):
def __init__(self, path=None, system=False, global_search=True):
"""Cross-platform Finder for locating python and other executables.
Searches for python and other specified binaries starting in `path`,
if supplied, but searching the bin path of `sys.executable` if
`system=True`, and then searching in the `os.environ['PATH']` if
`global_search=True`.
When `global_search` is `False`, this search operation is restricted to
the allowed locations of `path` and `system`.
:param path: A bin-directory search location, or None to ignore.
:type path: str or None
:param system: Whether to include the bin-dir of `sys.executable`,
defaults to False
:type system: bool
:param global_search: Whether to search the global path from
os.environ, defaults to True.
:type global_search: bool
:returns: a :class:`~pythonfinder.pythonfinder.Finder` object.
"""

self.path_prepend = path
self.global_search = global_search
self.system = system
self._system_path = None
self._windows_finder = None
Expand All @@ -16,7 +38,8 @@ def __init__(self, path=None, system=False):
def system_path(self):
if not self._system_path:
self._system_path = SystemPath.create(
path=self.path_prepend, system=self.system
path=self.path_prepend, system=self.system,
global_search=self.global_search,
)
return self._system_path

Expand Down

0 comments on commit 0d2ceb6

Please sign in to comment.