Skip to content

Commit

Permalink
Better check for VCS location
Browse files Browse the repository at this point in the history
Identify the likely root directory to pass to the vcs.get_backend_name instead of simply using dist.location. This is necessary to support version control systems such as git and mercurial where the VCS metadata directory only exists off of the root directory.

This is a fix for pypa#713, where "pip freeze" outputs the wrong value for a repository checked out from git if the package puts files in the "src"  directory.

This change is based on @qwcode's comments at pypa#636 (comment).
  • Loading branch information
Lorin Hochstein committed Nov 4, 2012
1 parent fad6532 commit 1956ebe
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion pip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,35 @@ def __init__(self, name, req, editable, comments=()):
_rev_re = re.compile(r'-r(\d+)$')
_date_re = re.compile(r'-(20\d\d\d\d\d\d)$')

@staticmethod
def get_expected_vcs_root(dist):
"""Return the expected location of the VCS root directory.
This is the directory that would have the .git or .hg subdirectory
if the package was installed from git or mercurial"""
try:
egginfo_lines = dist.get_metadata("SOURCES.txt").split()
except KeyError:
# No SOURCES.txt in metadata, just return location
return os.path.normcase(os.path.abspath(dist.location))

line_with_egginfo = (x for x in egginfo_lines if ".egg-info" in x).next()
path_to_trim_from_location = line_with_egginfo.split(dist.project_name)[0]
# Remove trailing slash if it exists
if path_to_trim_from_location.endswith('/'):
path_to_trim_from_location = path_to_trim_from_location[:-1]
rind = dist.location.rfind(path_to_trim_from_location)

location = dist.location
if rind >= 0:
location = location[:rind]
return os.path.normcase(os.path.abspath(location))



@classmethod
def from_dist(cls, dist, dependency_links, find_tags=False):
location = os.path.normcase(os.path.abspath(dist.location))
location = cls.get_expected_vcs_root(dist)
comments = []
from pip.vcs import vcs, get_src_requirement
if vcs.get_backend_name(location):
Expand Down

0 comments on commit 1956ebe

Please sign in to comment.