Skip to content

Commit

Permalink
Remove pew.lsenvs usage from project
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr committed Jul 4, 2018
1 parent bab691f commit ef0946d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
18 changes: 11 additions & 7 deletions pipenv/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
import sys
import base64
import fnmatch
import hashlib
import contoml
from first import first
Expand Down Expand Up @@ -33,6 +34,7 @@
safe_expandvars,
is_star,
get_workon_home,
is_virtual_environment,
)
from .environments import (
PIPENV_MAX_DEPTH,
Expand Down Expand Up @@ -273,21 +275,23 @@ def get_name(name, location):
clean_name, encoded_hash = get_name(name, self.pipfile_location)
venv_name = "{0}-{1}".format(clean_name, encoded_hash)

# This should work most of the time, for non-WIndows, in-project venv,
# or "proper" path casing (on Windows).
# This should work most of the time for
# Case-sensitive filesystems,
# In-project venv
# "Proper" path casing (on non-case-sensitive filesystems).
if (
os.name != "nt"
fnmatch.fnmatch('A', 'a')
or self.is_venv_in_project()
or self._get_virtualenv_location(venv_name)
):
return clean_name, encoded_hash

# Check for different capitalization of the same project.
from .patched.pew.pew import lsenvs

for env in lsenvs():
for path in get_workon_home().iterdir():
if not is_virtual_environment(path):
continue
try:
env_name, hash_ = env.rsplit("-", 1)
env_name, hash_ = path.name.rsplit("-", 1)
except ValueError:
continue
if len(hash_) != 8 or env_name.lower() != name.lower():
Expand Down
17 changes: 16 additions & 1 deletion pipenv/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,6 @@ def fs_str(string):
_fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding()


# Duplicated from Pew to avoid importing it (performance considerations).
def get_workon_home():
from ._compat import Path

Expand All @@ -1323,3 +1322,19 @@ def get_workon_home():
os.environ.get("XDG_DATA_HOME", "~/.local/share"), "virtualenvs"
)
return Path(os.path.expandvars(workon_home)).expanduser()


def is_virtual_environment(path):
"""Check if a given path is a virtual environment's root.
This is done by checking if the directory contains a Python executable in
its bin/Scripts directory. Not technically correct, but good enough for
general usage.
"""
if not path.is_dir():
return False
for bindir_name in ('bin', 'Scripts'):
for python_like in path.joinpath(bindir_name).glob('python*'):
if python_like.is_file() and os.access(str(python_like), os.X_OK):
return True
return False
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ ignore =
# E231: missing whitespace after ','
# E402: module level import not at top of file
# E501: line too long
E127,E128,E129,E222,E231,E402,E501
# W503: line break before binary operator
E127,E128,E129,E222,E231,E402,E501,W503

0 comments on commit ef0946d

Please sign in to comment.