Repository: tox-dev/tox
Pull request #1051 (2018-10-10 03:35:23)

Bugfix: Do the same transformation to egg-info dirs that pkg_resources does
I noticed that my hyphenated project name is not using the `develop-inst-noop` action, instead using the `develop-inst-nodeps` (cf. #910). This is because it uses a hyphenated project name, and tox was looking at the mtime of a nonexistent `myproject-name.egg-info` directory, when distutils/setuptools instead create a directory called `myproject_name.egg-info`. I don't know why they behave this way.

I've added a test for this behavior, and also made it so that initproj can take hyphenated strings for project names. Then, to fix the failing test, I added a call to `to_filename`, the function which `pkg_resources` uses for the same transformation.

gaborbernat: Interesting that this did not generate a CI run, will need to investigate. Will follow up tomorrow. Thanks for the PR.

Patch:
diff --git a/docs/changelog/1051.bugfix.rst b/docs/changelog/1051.bugfix.rst
new file mode 100644
index 00000000..398f1cbe
--- /dev/null
+++ b/docs/changelog/1051.bugfix.rst
@@ -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`.
diff --git a/src/tox/venv.py b/src/tox/venv.py
index 29d5b644..85da0412 100755
--- a/src/tox/venv.py
+++ b/src/tox/venv.py
@@ -8,6 +8,7 @@ import warnings
 from itertools import chain
 
 import py
+from pkg_resources import to_filename
 
 import tox
 
@@ -295,7 +296,7 @@ class VirtualEnv(object):
             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():


Test patch:
diff --git a/src/tox/_pytestplugin.py b/src/tox/_pytestplugin.py
index 203debe0..75d986ec 100644
--- a/src/tox/_pytestplugin.py
+++ b/src/tox/_pytestplugin.py
@@ -284,7 +284,7 @@ def initproj(tmpdir):
         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
diff --git a/tests/unit/test_z_cmdline.py b/tests/unit/test_z_cmdline.py
index 964c7145..ed1ebdb6 100644
--- a/tests/unit/test_z_cmdline.py
+++ b/tests/unit/test_z_cmdline.py
@@ -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": {
@@ -546,8 +548,12 @@ def test_test_usedevelop(cmd, initproj, src_root, monkeypatch):
             changedir=tests
             commands=
                 pytest --basetemp={envtmpdir} --junitxml=junit-{envname}.xml []
-            deps=pytest
-        """,
+            deps=pytest"""
+            + """
+            skipsdist={}
+        """.format(
+                skipsdist
+            ),
         },
     )
     result = cmd("-v")
@@ -567,7 +573,7 @@ def test_test_usedevelop(cmd, initproj, src_root, monkeypatch):
 
     # 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(