Skip to content

pip freeze fails to properly return hg URL if virtualenv is under Git controlled project #3988

@ruiwen

Description

@ruiwen
  • Pip version: 8.1.2
  • Python version: 2.7.12
  • Operating System: Ubuntu 16.04.1

Description:

I've got my virtulenv directory (venv) under my project folder

acme-server/
├── bin
├── acme
├── manage.py
├── Procfile
├── requirements
├── requirements.txt
├── venv
└── web

One of my requirements is installed via -e hg+https://, which ends up getting cloned to venv/src.

I'd like to automatically update my requirements.txt via pip freeze, but pip keeps returning my hg repo as a git URL instead.

I'd expect

-e hg+https://bitbucket.org/somedev/some-project@<some_projects_hash>#egg=some_project

but I keep getting this instead

-e git+git@github.com:Acme/acme-server.git@<my_projects_hash>#egg=some_project&subdirectory=venv/src/some_project

which isn't very helpful for my requirements.txt.

What I've run:

I dug into pip's source, and narrowed it down to controls_location() in pip/vcs/git.py.


   @classmethod
   def controls_location(cls, location):
       if super(Git, cls).controls_location(location):
           return True
       try:
           r = cls().run_command(['rev-parse'],
                                 cwd=location,
                                 show_stdout=False,
                                 on_returncode='ignore')
           return not r
       except BadCommand:
           logger.debug("could not determine if %s is under git control "
                        "because git is not available", location)
           return False

Turns out, running git rev-parse in the hg-cloned copy of some_project does not raise an error, because git traverses the tree upwards, eventually reaching the top level of my own project and finding the .git there instead. That would seem why <my_projects_hash> appears in the pip freeze output.

In pip/vcs::VcsSupport.get_backend_name(), it would appear the the git module is running first, and because git rev-parse is not raising an error from within the hg-cloned directory under venv/src, is claiming the hg-cloned project as a git repo instead (even before the hg module has a chance to run).

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: freeze'pip freeze' relatedC: vcspip's interaction with version control systems like git, svn and bzrauto-lockedOutdated issues that have been locked by automationstate: awaiting PRFeature discussed, PR is neededtype: bugA confirmed bug or unintended behavior

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions