Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fixed issue #609 - method to detect VCS backend #636

Closed
wants to merge 3 commits into
from

Conversation

Projects
None yet
5 participants

http://stackoverflow.com/questions/11935786/pip-freeze-reports-version-number-instead-of-git-sha-for-certain-package

After I saw this question I tried fix this, I don't know if is the best way, but now works ok.

This pull request fails (merged 3870f51 into 1749343).

Contributor

qwcode commented Aug 15, 2012

this issue is different than #609.
#609 is concerned with why pip freeze doesn't report the vcs url when you leave off the "-e".
in this stackoverflow, piplint is being installed with "-e" but pip freeze is still not reporting the vcs url for whatever reason.

Contributor

qwcode commented Aug 15, 2012

hey @fabiocerqueira, can you help me out and explain what you think the issue is with piplint and why pip freeze fails to do what we expect for it?

@qwcode pip freeze verify if a package is editable through of directory to a VCS(.svn, .git, .hg, .bzr), but the dist.location to piplint doesn't have a directory like this.

The dist.location return: ~/.virtualenvs/pip/src/piplint/src, where doesn't have a .git, the git directory is on parent path.

Contributor

qwcode commented Aug 15, 2012

thanks, so piplint's packages are nested under src and it's using package_dir={'': 'src'} in it's setup.py.
Pip using pkg_resources.distribution.location to try to find the vcs directory is just not good enough here.
so, you've got failures from TravisBot. maybe you can sort that out and come up with a better fix for this.
I'm not sure right off what the best way to handle this is w/o digging deeper.

I'm trying a new approach to solve the problem of VCS backend detection, but when I run the tests return a fail in test_git_works_with_editable_non_origin_repo.

I don't understand what this test is making. Can someone explain?

FAIL: tests.test_vcs_backends.test_git_works_with_editable_non_origin_repo
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/fabiocerqueira/sandbox/pip/nose-1.1.2-py2.7.egg/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/Users/fabiocerqueira/sandbox/pip/tests/test_vcs_backends.py", line 142, in test_git_works_with_editable_non_origin_repo
    assert "Error when trying to get requirement" in result.stderr
AssertionError```

This pull request fails (merged 1067bef into 1749343).

This pull request passes (merged 54ad39f into 1749343).

Contributor

qwcode commented Aug 21, 2012

one thought on another way to handle this w/o resorting to the respective VCS commands.

-- grab one of the egg-info lines out of dist.get_metadata('SOURCES.txt')
e.g. src/piplint.egg-info/PKG-INFO
-- split on dist.project_name, and use the first item to trim down the dist.location.
-- and I think that should leave you with the dir that should contain the VCS dir like .git or .hg

Contributor

mcdonc commented Sep 7, 2012

Random note about the attached patch: in the check_repository methods that were added, the "except Exception" clause (that presumably is meant to catch errors raised by subprocess.Popen or os.chdir, etc) will catch all exceptions. But the logic within the clause doesn't reraise, and "proc" will not be defined when it continues, and that will result in a name error.

@carljm carljm commented on the diff Sep 7, 2012

pip/util.py
@@ -609,3 +609,18 @@ def call_subprocess(cmd, show_stdout=True,
% (command_desc, proc.returncode, cwd))
if stdout is not None:
return ''.join(all_output)
+
+def setup_project_name(setup_py):
+ try:
+ old_cwd = os.getcwd()
+ os.chdir(os.path.abspath(os.path.dirname(setup_py)))
+ cmd = [sys.executable, setup_py, '--name']
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ os.chdir(old_cwd)
+ except Exception:
+ e = sys.exc_info()[1]
+ logger.warn(
+ "Error %s while executing command %s" % (e, ' '.join(cmd)))
+ proc.wait()
@carljm

carljm Sep 7, 2012

Contributor

This has the same issue @mcdonc mentioned in the VCS methods below - if an error is raised before the proc = line in the try block, this line will raise a NameError.

@carljm carljm commented on the diff Sep 7, 2012

pip/util.py
@@ -609,3 +609,18 @@ def call_subprocess(cmd, show_stdout=True,
% (command_desc, proc.returncode, cwd))
if stdout is not None:
return ''.join(all_output)
+
+def setup_project_name(setup_py):
+ try:
+ old_cwd = os.getcwd()
+ os.chdir(os.path.abspath(os.path.dirname(setup_py)))
+ cmd = [sys.executable, setup_py, '--name']
@carljm

carljm Sep 7, 2012

Contributor

This method should just look up the distribution name from the already-built egg-info static metadata. Pip builds this when an editable distribution is first installed, so it should always be there; shouldn't ever be a need to actually run python setup.py --name. The InstallRequirement class contains code that shows how to do this.

Contributor

qwcode commented Feb 10, 2013

@fabiocerqueira, thanks for raising the awareness on this issue.
closing this pull, since I'm inclined to go with a solution like in #717 (although that's currently stalled)
If that falls thru for some reason, I'll keep this pull in mind.

@qwcode qwcode closed this Feb 10, 2013

sbidoul pushed a commit to sbidoul/pip that referenced this pull request Nov 21, 2015

Better check for VCS location
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 #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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment