diff --git a/.gitmodules b/.gitmodules index d15e8a54..240d71a6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -16,3 +16,9 @@ [submodule "tests/test_artifacts/git/pyinstaller"] path = tests/test_artifacts/git/pyinstaller url = https://github.com/pyinstaller/pyinstaller.git +[submodule "tests/test_artifacts/git/jinja2"] + path = tests/test_artifacts/git/jinja2 + url = git@github.com:pallets/jinja.git +[submodule "tests/test_artifacts/git/flask"] + path = tests/test_artifacts/git/flask + url = git@github.com:pallets/flask.git diff --git a/pipenv/vendor/requirementslib/models/requirements.py b/pipenv/vendor/requirementslib/models/requirements.py index bfd69b37..af3d07ed 100644 --- a/pipenv/vendor/requirementslib/models/requirements.py +++ b/pipenv/vendor/requirementslib/models/requirements.py @@ -290,7 +290,7 @@ class FileRequirement(object): if self.path and not self.uri: self._uri_scheme = "path" return pip_shims.shims.path_to_url(os.path.abspath(self.path)) - elif self.req and getattr(self.req, "url"): + elif getattr(self, "req", None) and getattr(self.req, "url"): return self.req.url @name.default @@ -321,7 +321,7 @@ class FileRequirement(object): if self.extras: line = "{0}[{1}]".format(line, ",".join(self.extras)) _ireq = pip_shims.shims.install_req_from_line(line) - if self.req: + if getattr(self, "req", None): _ireq.req = copy.deepcopy(self.req) else: if self.extras: @@ -710,7 +710,7 @@ class VCSRequirement(FileRequirement): def get_name(self): return ( self.link.egg_fragment or self.req.name - if self.req + if getattr(self, "req", None) else super(VCSRequirement, self).get_name() ) diff --git a/tests/integration/test_install_twists.py b/tests/integration/test_install_twists.py index 2ad12691..e8fdfd33 100644 --- a/tests/integration/test_install_twists.py +++ b/tests/integration/test_install_twists.py @@ -338,7 +338,7 @@ six = {{path = "./artifacts/{}"}} @pytest.mark.files @pytest.mark.install @pytest.mark.run -def test_multiple_editable_packages_should_not_race(PipenvInstance, pypi, tmpdir, testsroot): +def test_multiple_editable_packages_should_not_race(PipenvInstance, pypi, 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. @@ -347,40 +347,25 @@ def test_multiple_editable_packages_should_not_race(PipenvInstance, pypi, tmpdir 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", - } + pkgs = ["requests", "flask", "six", "jinja2"] + + pipfile_string = """ +[dev-packages] - pipfile_string=""" [packages] """ - # Unzip tarballs to known location, and update Pipfile template. - for pkg_name, file_name in pkgs.items(): - 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) with PipenvInstance(pypi=pypi, chdir=True) as p: + for pkg_name in pkgs: + source_path = p._pipfile.get_fixture_path("git/{0}".format(pkg_name)).as_posix() + + pipfile_string += '"{0}" = {{path = "{1}", editable = true}}\n'.format(pkg_name, source_path) + 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 + c = p.pipenv('run python -c "import requests, flask, six, jinja2"') + assert c.return_code == 0, c.err diff --git a/tests/integration/test_install_uri.py b/tests/integration/test_install_uri.py index 337181fa..2d279001 100644 --- a/tests/integration/test_install_uri.py +++ b/tests/integration/test_install_uri.py @@ -63,9 +63,10 @@ def test_ssh_vcs_install(PipenvInstance, pip_src_dir, pypi): @pytest.mark.needs_internet @flaky def test_urls_work(PipenvInstance, pypi, pip_src_dir): - with PipenvInstance(pypi=pypi) as p: + with PipenvInstance(pypi=pypi, chdir=True) as p: + path = p._pipfile.get_fixture_path("django/3.4.x.zip") c = p.pipenv( - "install https://github.com/divio/django-cms/archive/release/3.4.x.zip" + "install {0}".format(path.as_uri()) ) assert c.return_code == 0 @@ -187,27 +188,14 @@ six = "*" @pytest.mark.needs_internet def test_install_local_vcs_not_in_lockfile(PipenvInstance, pip_src_dir): with PipenvInstance(chdir=True) as p: - six_path = os.path.join(p.path, "six") - c = delegator.run( - "git clone https://github.com/benjaminp/six.git {0}".format(six_path) - ) - assert c.return_code == 0 - c = p.pipenv("install -e ./six") + # six_path = os.path.join(p.path, "six") + six_path = p._pipfile.get_fixture_path("git/six").as_posix() + requests_uri = p._pipfile.get_fixture_path("git/requests").as_uri() + c = p.pipenv("install -e {0}".format(six_path)) assert c.return_code == 0 six_key = list(p.pipfile["packages"].keys())[0] - c = p.pipenv( - "install -e git+https://github.com/requests/requests.git#egg=requests" - ) - assert c.return_code == 0 - c = p.pipenv("lock") - assert c.return_code == 0 - assert "requests" in p.pipfile["packages"] - assert "requests" in p.lockfile["default"] - # This is the hash of ./six - assert six_key in p.pipfile["packages"] - assert six_key in p.lockfile["default"] - # The hash isn't a hash anymore, its actually the name of the package (we now resolve this) - assert "six" in p.pipfile["packages"] + # we don't need the rest of the test anymore, this just works on its own + assert six_key == "six" @pytest.mark.vcs @@ -247,6 +235,7 @@ def test_vcs_entry_supersedes_non_vcs(PipenvInstance, pip_src_dir): the resolution graph of non-editable vcs dependencies. """ with PipenvInstance(chdir=True) as p: + pyinstaller_path = p._pipfile.get_fixture_path("git/pyinstaller") with open(p.pipfile_path, "w") as f: f.write( """ @@ -257,8 +246,8 @@ name = "pypi" [packages] PyUpdater = "*" -PyInstaller = {ref = "develop", git = "https://github.com/pyinstaller/pyinstaller.git"} - """.strip() +PyInstaller = {{ref = "develop", git = "{0}"}} + """.format(pyinstaller_path.as_uri()).strip() ) p.pipenv("install") installed_packages = ["PyUpdater", "PyInstaller"] @@ -268,7 +257,7 @@ PyInstaller = {ref = "develop", git = "https://github.com/pyinstaller/pyinstalle assert p.lockfile["default"]["pyinstaller"].get("ref") is not None assert ( p.lockfile["default"]["pyinstaller"]["git"] - == "https://github.com/pyinstaller/pyinstaller.git" + == pyinstaller_path.as_uri() ) diff --git a/tests/test_artifacts/django/3.4.x.zip b/tests/test_artifacts/django/3.4.x.zip new file mode 100644 index 00000000..6c2ae5f6 Binary files /dev/null and b/tests/test_artifacts/django/3.4.x.zip differ diff --git a/tests/test_artifacts/git/flask b/tests/test_artifacts/git/flask new file mode 160000 index 00000000..dcc02d6e --- /dev/null +++ b/tests/test_artifacts/git/flask @@ -0,0 +1 @@ +Subproject commit dcc02d6e7d4bf486e64aa5b6e55a75501c2ba2e5 diff --git a/tests/test_artifacts/git/jinja2 b/tests/test_artifacts/git/jinja2 new file mode 160000 index 00000000..a7f1f528 --- /dev/null +++ b/tests/test_artifacts/git/jinja2 @@ -0,0 +1 @@ +Subproject commit a7f1f528f5e77d5401a96aa326885508245f7c6f