Skip to content

Commit

Permalink
Wipe git dependency repositories if they exist on dep install
Browse files Browse the repository at this point in the history
add ``--exists-action w`` to default pip flags to handle better VCS
dependencies, which may prompt question about how to handle it

pip documentation on this
https://pip.pypa.io/en/latest/reference/pip/#exists-action-option

Resolves #503.
  • Loading branch information
gaborbernat committed Sep 13, 2018
1 parent e728692 commit 8c34fab
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
1 change: 1 addition & 0 deletions changelog/503.bugfix.rst
@@ -0,0 +1 @@
add ``--exists-action w`` to default pip flags to handle better VCS dependencies (`pip documentation on this <https://pip.pypa.io/en/latest/reference/pip/#exists-action-option>`_) - by :user:`gaborbernat`
38 changes: 16 additions & 22 deletions src/tox/venv.py
Expand Up @@ -261,38 +261,32 @@ def _needs_reinstall(self, setupdir, action):

return needs_reinstall

def developpkg(self, setupdir, action):
def install_pkg(self, dir, action, name, is_develop=False):
assert action is not None

if getattr(self, "just_created", False):
action.setactivity("develop-inst", setupdir)
action.setactivity(name, dir)
self.finish()
extraopts = []
pip_flags = ["--exists-action", "w"]
else:
if not self._needs_reinstall(setupdir, action):
action.setactivity("develop-inst-noop", setupdir)
if is_develop and not self._needs_reinstall(dir, action):
action.setactivity("{}-noop".format(name), dir)
return
action.setactivity("develop-inst-nodeps", setupdir)
extraopts = ["--no-deps"]
action.setactivity("{}-nodeps".format(name), dir)
pip_flags = ["--no-deps"] + ([] if is_develop else ["-U"])

if action.venv.envconfig.extras:
setupdir += "[{}]".format(",".join(action.venv.envconfig.extras))
dir += "[{}]".format(",".join(action.venv.envconfig.extras))
target = [dir]
if is_develop:
target.insert(0, "-e")
self._install(target, extraopts=pip_flags, action=action)

self._install(["-e", setupdir], extraopts=extraopts, action=action)
def developpkg(self, setupdir, action):
self.install_pkg(setupdir, action, "develop-inst", is_develop=True)

def installpkg(self, sdistpath, action):
assert action is not None
if getattr(self, "just_created", False):
action.setactivity("inst", sdistpath)
self.finish()
extraopts = []
else:
action.setactivity("inst-nodeps", sdistpath)
extraopts = ["-U", "--no-deps"]

if action.venv.envconfig.extras:
sdistpath += "[{}]".format(",".join(action.venv.envconfig.extras))

self._install([sdistpath], extraopts=extraopts, action=action)
self.install_pkg(sdistpath, action, "inst")

def _installopts(self, indexserver):
options = []
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_venv.py
Expand Up @@ -721,7 +721,7 @@ def test_installpkg_no_upgrade(tmpdir, newmocksession):
mocksession.installpkg(venv, pkg)
pcalls = mocksession._pcalls
assert len(pcalls) == 1
assert "-U" not in pcalls[0].args
assert pcalls[0].args[1:-1] == ["-m", "pip", "install", "--exists-action", "w"]


def test_installpkg_upgrade(newmocksession, tmpdir):
Expand Down

0 comments on commit 8c34fab

Please sign in to comment.