Skip to content

Commit

Permalink
Bugfix: Do the same transformation to egg-info dirs that pkg_resource…
Browse files Browse the repository at this point in the history
…s does (#1051)

* Add a test for skipsdist=True with hyphenated project names

* Do the same transformation to egg_info dirs that pkg_resources does

To determine whether we should re-install an egg, we look for an .egg-info
directory based on the output of `setup.py --name`, but .egg-info directories
have their dashes transformed into underscores by pkg_resources.to_filename.

When we look for an .egg-info directory, we should apply the same
transformation.

* DRY the test which I WETted
  • Loading branch information
hashbrowncipher authored and gaborbernat committed Oct 11, 2018
1 parent 8944dc1 commit ea53afd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
4 changes: 4 additions & 0 deletions docs/changelog/1051.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Do the same transformation to egg_info dirs that pkg_resources does. This makes
it possible for hyphenated names to use the develop-inst-noop optimization (cf.
#910), which previously only worked with non-hyphenated egg names - by
:user:`hashbrowncipher`.
2 changes: 1 addition & 1 deletion src/tox/_pytestplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def initproj_(nameversion, filedefs=None, src_root=".", add_missing_setup_py=Tru
if not src_root:
src_root = "."
if isinstance(nameversion, six.string_types):
parts = nameversion.split(str("-"))
parts = nameversion.rsplit(str("-"), 1)
if len(parts) == 1:
parts.append("0.1")
name, version = parts
Expand Down
3 changes: 2 additions & 1 deletion src/tox/venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from itertools import chain

import py
from pkg_resources import to_filename

import tox

Expand Down Expand Up @@ -295,7 +296,7 @@ def _needs_reinstall(self, setupdir, action):
sys_path = json.loads(out)
except ValueError:
sys_path = []
egg_info_fname = ".".join((name, "egg-info"))
egg_info_fname = ".".join((to_filename(name), "egg-info"))
for d in reversed(sys_path):
egg_info = py.path.local(d).join(egg_info_fname)
if egg_info.check():
Expand Down
16 changes: 11 additions & 5 deletions tests/unit/test_z_cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,10 +528,12 @@ def test_usedevelop_mixed(initproj, cmd):
assert "sdist-make" in result.out


@pytest.mark.parametrize("skipsdist", [False, True])
@pytest.mark.parametrize("src_root", [".", "src"])
def test_test_usedevelop(cmd, initproj, src_root, monkeypatch):
def test_test_usedevelop(cmd, initproj, src_root, skipsdist, monkeypatch):
name = "example123-spameggs"
base = initproj(
"example123-0.5",
(name, "0.5"),
src_root=src_root,
filedefs={
"tests": {
Expand All @@ -546,8 +548,12 @@ def test_hello(pytestconfig):
changedir=tests
commands=
pytest --basetemp={envtmpdir} --junitxml=junit-{envname}.xml []
deps=pytest
""",
deps=pytest"""
+ """
skipsdist={}
""".format(
skipsdist
),
},
)
result = cmd("-v")
Expand All @@ -567,7 +573,7 @@ def test_hello(pytestconfig):

# see that things work with a different CWD
monkeypatch.chdir(base.dirname)
result = cmd("-c", "example123/tox.ini")
result = cmd("-c", "{}/tox.ini".format(name))
assert not result.ret
assert "develop-inst-noop" in result.out
assert re.match(
Expand Down

0 comments on commit ea53afd

Please sign in to comment.