From 262293699e583f39e97f8e95e1215f4b257c528b Mon Sep 17 00:00:00 2001 From: Chris Miller Date: Fri, 16 Nov 2018 00:26:35 -0500 Subject: [PATCH 1/6] Fix race condition when installing 2+ editable non-VCS pkgs at once This regression was recently introduced, and only affects non-vcs packages. The effect of the race is that installations of multiple editable non-VCS sourced packages at once may cause some of them to be un-importable. The fix is to make editable package installs Blocking just like VCS installs are. --- pipenv/core.py | 2 +- tests/integration/test_install_twists.py | 53 ++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/pipenv/core.py b/pipenv/core.py index f815e5de9b..f9ffeba38b 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -731,7 +731,7 @@ def batch_install(deps_list, procs, failed_deps_queue, ignore_hashes=any([ignore_hashes, dep.editable, dep.is_vcs]), allow_global=allow_global, no_deps=False if is_artifact else no_deps, - block=any([dep.is_vcs, blocking]), + block=any([dep.editable, dep.is_vcs, blocking]), index=index, requirements_dir=requirements_dir, pypi_mirror=pypi_mirror, diff --git a/tests/integration/test_install_twists.py b/tests/integration/test_install_twists.py index 055c39b2e1..6b202d4d01 100644 --- a/tests/integration/test_install_twists.py +++ b/tests/integration/test_install_twists.py @@ -8,6 +8,7 @@ import pytest from flaky import flaky +import delegator @pytest.mark.extras @@ -333,3 +334,55 @@ def test_install_local_uri_special_character(PipenvInstance, testsroot): c = p.pipenv("install") assert c.return_code == 0 assert "six" in p.lockfile["default"] + + +@pytest.mark.files +@pytest.mark.needs_internet +@pytest.mark.install +@pytest.mark.run +def test_multiple_editable_packages_should_not_race(PipenvInstance, pypi, tmpdir, testsroot): + """Test for a race condition that can occur when installing multiple 'editable' packages at + once, and which causes some of them to not be importable. + + This issue had been fixed for VCS packages already, but not local 'editable' packages. + + So this test locally installs packages from tarballs that have already been committed in + the local `pypi` dir to avoid using VCS packages. + """ + pkgs = { + "requests-2.19.1": "requests/requests-2.19.1.tar.gz", + "flask-0.12.2": "flask/flask-0.12.2.tar.gz", + "six-1.11.0": "six/six-1.11.0.tar.gz", + "jinja2-2.10": "jinja2/jinja2-2.10.tar.gz", + } + + pipfile_string=""" +[packages] +""" + # Unzip tarballs to known location, and update Pipfile template. + for pkg_name, file_name in pkgs.items(): + source_path = os.path.abspath(os.path.join(testsroot, "pypi", file_name)) + unzip_path = os.path.join(tmpdir, pkg_name) + + import tarfile + + with tarfile.open(source_path, "r:gz") as tgz: + tgz.extractall(path=tmpdir) + + pipfile_string += '"{0}" = {{path = "{1}", editable = true}}\n'.format(pkg_name, unzip_path) + + with PipenvInstance(pypi=pypi, chdir=True) as p: + with open(p.pipfile_path, 'w') as f: + f.write(pipfile_string.strip()) + + c = p.pipenv('install') + assert c.return_code == 0 + + c = p.pipenv('run python -c "import requests"') + assert c.return_code == 0 + c = p.pipenv('run python -c "import flask"') + assert c.return_code == 0 + c = p.pipenv('run python -c "import six"') + assert c.return_code == 0 + c = p.pipenv('run python -c "import jinja2"') + assert c.return_code == 0 From a95ce8bb32efea8c73fa8b7e1c4290319444405a Mon Sep 17 00:00:00 2001 From: Chris Miller Date: Fri, 16 Nov 2018 08:14:21 -0500 Subject: [PATCH 2/6] Remove unnecessary test marks and imports. --- tests/integration/test_install_twists.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/integration/test_install_twists.py b/tests/integration/test_install_twists.py index 6b202d4d01..ee11a186f4 100644 --- a/tests/integration/test_install_twists.py +++ b/tests/integration/test_install_twists.py @@ -8,7 +8,6 @@ import pytest from flaky import flaky -import delegator @pytest.mark.extras @@ -337,7 +336,6 @@ def test_install_local_uri_special_character(PipenvInstance, testsroot): @pytest.mark.files -@pytest.mark.needs_internet @pytest.mark.install @pytest.mark.run def test_multiple_editable_packages_should_not_race(PipenvInstance, pypi, tmpdir, testsroot): @@ -351,9 +349,9 @@ def test_multiple_editable_packages_should_not_race(PipenvInstance, pypi, tmpdir """ pkgs = { "requests-2.19.1": "requests/requests-2.19.1.tar.gz", - "flask-0.12.2": "flask/flask-0.12.2.tar.gz", + "Flask-0.12.2": "flask/Flask-0.12.2.tar.gz", "six-1.11.0": "six/six-1.11.0.tar.gz", - "jinja2-2.10": "jinja2/jinja2-2.10.tar.gz", + "Jinja2-2.10": "jinja2/Jinja2-2.10.tar.gz", } pipfile_string=""" From db1eb1bacb9d8fe163f5f6c39304c532b262b5c6 Mon Sep 17 00:00:00 2001 From: Chris Miller Date: Fri, 16 Nov 2018 09:05:58 -0500 Subject: [PATCH 3/6] Use correct Path module to get tests to work. --- tests/integration/test_install_twists.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integration/test_install_twists.py b/tests/integration/test_install_twists.py index ee11a186f4..cef6c34d1e 100644 --- a/tests/integration/test_install_twists.py +++ b/tests/integration/test_install_twists.py @@ -360,14 +360,14 @@ def test_multiple_editable_packages_should_not_race(PipenvInstance, pypi, tmpdir # Unzip tarballs to known location, and update Pipfile template. for pkg_name, file_name in pkgs.items(): source_path = os.path.abspath(os.path.join(testsroot, "pypi", file_name)) - unzip_path = os.path.join(tmpdir, pkg_name) + unzip_path = tmpdir.join(pkg_name) import tarfile with tarfile.open(source_path, "r:gz") as tgz: - tgz.extractall(path=tmpdir) + tgz.extractall(path=tmpdir.strpath) - pipfile_string += '"{0}" = {{path = "{1}", editable = true}}\n'.format(pkg_name, unzip_path) + pipfile_string += '"{0}" = {{path = "{1}", editable = true}}\n'.format(pkg_name, unzip_path.strpath) with PipenvInstance(pypi=pypi, chdir=True) as p: with open(p.pipfile_path, 'w') as f: From 65e49f1bffcdd64db697c911c7723df2f6e794f5 Mon Sep 17 00:00:00 2001 From: Chris Miller Date: Fri, 16 Nov 2018 09:45:59 -0500 Subject: [PATCH 4/6] Print generated Pipfile during test to help debug failures. --- tests/integration/test_install_twists.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integration/test_install_twists.py b/tests/integration/test_install_twists.py index cef6c34d1e..95dc058a8f 100644 --- a/tests/integration/test_install_twists.py +++ b/tests/integration/test_install_twists.py @@ -370,6 +370,7 @@ def test_multiple_editable_packages_should_not_race(PipenvInstance, pypi, tmpdir pipfile_string += '"{0}" = {{path = "{1}", editable = true}}\n'.format(pkg_name, unzip_path.strpath) with PipenvInstance(pypi=pypi, chdir=True) as p: + print(pipfile_string) with open(p.pipfile_path, 'w') as f: f.write(pipfile_string.strip()) From 70f6bec85e65d7b4f02a5c0299fa52b3d2cf75d2 Mon Sep 17 00:00:00 2001 From: Chris Miller Date: Fri, 16 Nov 2018 11:50:25 -0500 Subject: [PATCH 5/6] Use cross platform Path compatibility module in test. --- tests/integration/test_install_twists.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integration/test_install_twists.py b/tests/integration/test_install_twists.py index 95dc058a8f..92dedca861 100644 --- a/tests/integration/test_install_twists.py +++ b/tests/integration/test_install_twists.py @@ -359,15 +359,15 @@ def test_multiple_editable_packages_should_not_race(PipenvInstance, pypi, tmpdir """ # Unzip tarballs to known location, and update Pipfile template. for pkg_name, file_name in pkgs.items(): - source_path = os.path.abspath(os.path.join(testsroot, "pypi", file_name)) - unzip_path = tmpdir.join(pkg_name) + source_path = str(Path(testsroot, "pypi", file_name)) + unzip_path = str(Path(tmpdir.strpath, pkg_name)) import tarfile with tarfile.open(source_path, "r:gz") as tgz: tgz.extractall(path=tmpdir.strpath) - pipfile_string += '"{0}" = {{path = "{1}", editable = true}}\n'.format(pkg_name, unzip_path.strpath) + pipfile_string += "'{0}' = {{path = '{1}', editable = true}}\n".format(pkg_name, unzip_path) with PipenvInstance(pypi=pypi, chdir=True) as p: print(pipfile_string) From cba5a1efc62530aff87558cf0c3aeac7c9896e4f Mon Sep 17 00:00:00 2001 From: Chris Miller Date: Sat, 17 Nov 2018 12:52:12 -0500 Subject: [PATCH 6/6] Remove debug print from test. --- tests/integration/test_install_twists.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration/test_install_twists.py b/tests/integration/test_install_twists.py index 92dedca861..2ad12691f7 100644 --- a/tests/integration/test_install_twists.py +++ b/tests/integration/test_install_twists.py @@ -370,7 +370,6 @@ def test_multiple_editable_packages_should_not_race(PipenvInstance, pypi, tmpdir pipfile_string += "'{0}' = {{path = '{1}', editable = true}}\n".format(pkg_name, unzip_path) with PipenvInstance(pypi=pypi, chdir=True) as p: - print(pipfile_string) with open(p.pipfile_path, 'w') as f: f.write(pipfile_string.strip())