From ea53afdd353899682b9e1e48d0332006a0ac56a3 Mon Sep 17 00:00:00 2001 From: Josh Snyder Date: Thu, 11 Oct 2018 13:17:07 -0700 Subject: [PATCH] Bugfix: Do the same transformation to egg-info dirs that pkg_resources 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 --- docs/changelog/1051.bugfix.rst | 4 ++++ src/tox/_pytestplugin.py | 2 +- src/tox/venv.py | 3 ++- tests/unit/test_z_cmdline.py | 16 +++++++++++----- 4 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 docs/changelog/1051.bugfix.rst diff --git a/docs/changelog/1051.bugfix.rst b/docs/changelog/1051.bugfix.rst new file mode 100644 index 000000000..398f1cbec --- /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/_pytestplugin.py b/src/tox/_pytestplugin.py index 203debe08..75d986ec5 100644 --- a/src/tox/_pytestplugin.py +++ b/src/tox/_pytestplugin.py @@ -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 diff --git a/src/tox/venv.py b/src/tox/venv.py index 29d5b644f..85da04122 100755 --- a/src/tox/venv.py +++ b/src/tox/venv.py @@ -8,6 +8,7 @@ from itertools import chain import py +from pkg_resources import to_filename import tox @@ -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(): diff --git a/tests/unit/test_z_cmdline.py b/tests/unit/test_z_cmdline.py index 964c71451..ed1ebdb63 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_hello(pytestconfig): 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_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(