Skip to content

Commit

Permalink
Don't use pyenv shims in search path
Browse files Browse the repository at this point in the history
- Fixes #27

Signed-off-by: Dan Ryan <dan@danryan.co>
  • Loading branch information
techalchemy committed Nov 4, 2018
1 parent 93a1bfd commit b6fb43a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions news/27.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pyenv paths will now be ordered respecting global version settings and pyenv shims will be removed from the search path.
5 changes: 5 additions & 0 deletions src/pythonfinder/models/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ def _setup_pyenv(self):
self.path_order = (
before_path + [p.as_posix() for p in root_paths] + after_path
)
pyenv_shim_path = os.path.join(PYENV_ROOT, "shims")
if pyenv_shim_path in self.path_order:
self.path_order.remove(pyenv_shim_path)
self.paths.update(self.pyenv_finder.roots)
if pyenv_shim_path in self.paths:
del self.paths[pyenv_shim_path]
self._register_finder("pyenv", self.pyenv_finder)

def _setup_windows(self):
Expand Down
17 changes: 14 additions & 3 deletions src/pythonfinder/models/pyenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ def expanded_paths(self):
if path is not None
)

def get_version_order(self):
version_order_file = self.root.joinpath("version").read_text(encoding="utf-8")
version_paths = [
p for p in self.root.glob("versions/*")
if not (p.parent.name == "envs" or p.name == "envs")
]
versions = {v.name: v for v in version_paths}
version_order = [versions[v] for v in version_order_file.splitlines() if v in versions]
for version in version_order:
version_paths.remove(version)
version_order += version_paths
return version_order

@classmethod
def version_from_bin_dir(cls, base_dir, name=None):
py_version = None
Expand All @@ -59,9 +72,7 @@ def version_from_bin_dir(cls, base_dir, name=None):
def get_versions(self):
versions = defaultdict()
bin_ = sysconfig._INSTALL_SCHEMES[sysconfig._get_default_scheme()]["scripts"]
for p in self.root.glob("versions/*"):
if p.parent.name == "envs" or p.name == "envs":
continue
for p in self.get_version_order():
bin_dir = Path(bin_.format(base=p.as_posix()))
version_path = None
if bin_dir.exists():
Expand Down

0 comments on commit b6fb43a

Please sign in to comment.