diff --git a/docs/basics.rst b/docs/basics.rst index ee2e6621..00f4c7d9 100644 --- a/docs/basics.rst +++ b/docs/basics.rst @@ -367,18 +367,18 @@ The only optional section is the ``@`` section. When using git o Note that it is **strongly recommended** that you install any version-controlled dependencies in editable mode, using ``pipenv install -e``, in order to ensure that dependency resolution can be performed with an up to date copy of the repository each time it is performed, and that it includes all known dependencies. -Below is an example usage which installs the git repository located at ``https://github.com/requests/requests.git`` from tag ``v2.19.1`` as package name ``requests``:: +Below is an example usage which installs the git repository located at ``https://github.com/requests/requests.git`` from tag ``v2.20.1`` as package name ``requests``:: - $ pipenv install -e git+https://github.com/requests/requests.git@v2.19#egg=requests + $ pipenv install -e git+https://github.com/requests/requests.git@v2.20.1#egg=requests Creating a Pipfile for this project... - Installing -e git+https://github.com/requests/requests.git@v2.19.1#egg=requests... + Installing -e git+https://github.com/requests/requests.git@v2.20.1#egg=requests... [...snipped...] - Adding -e git+https://github.com/requests/requests.git@v2.19.1#egg=requests to Pipfile's [packages]... + Adding -e git+https://github.com/requests/requests.git@v2.20.1#egg=requests to Pipfile's [packages]... [...] $ cat Pipfile [packages] - requests = {git = "https://github.com/requests/requests.git", editable = true, ref = "2.19.1"} + requests = {git = "https://github.com/requests/requests.git", editable = true, ref = "v2.20.1"} Valid values for ```` include ``git``, ``bzr``, ``svn``, and ``hg``. Valid values for ```` include ``http``, ``https``, ``ssh``, and ``file``. In specific cases you also have access to other schemes: ``svn`` may be combined with ``svn`` as a scheme, and ``bzr`` can be combined with ``sftp`` and ``lp``. diff --git a/pipenv/core.py b/pipenv/core.py index 3b304625..159424c1 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -732,7 +732,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/pipenv/project.py b/pipenv/project.py index 590fafe5..0067348c 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -727,6 +727,18 @@ class Project(object): data[u"requires"] = {"python_version": version[: len("2.7")]} self.write_toml(data) + @classmethod + def populate_source(cls, source): + """Derive missing values of source from the existing fields.""" + # Only URL pararemter is mandatory, let the KeyError be thrown. + if "name" not in source: + source["name"] = get_url_name(source["url"]) + if "verify_ssl" not in source: + source["verify_ssl"] = "https://" in source["url"] + if not isinstance(source["verify_ssl"], bool): + source["verify_ssl"] = source["verify_ssl"].lower() == "true" + return source + def get_or_create_lockfile(self): from pipenv.vendor.requirementslib.models.lockfile import Lockfile as Req_Lockfile lockfile = None @@ -747,15 +759,7 @@ class Project(object): elif not isinstance(sources, list): sources = [sources,] lockfile_dict["_meta"]["sources"] = [ - { - "name": s.get("name", get_url_name(s.get("url"))), - "url": s["url"], - "verify_ssl": ( - s["verify_ssl"] if isinstance(s["verify_ssl"], bool) else ( - True if s["verify_ssl"].lower() == "true" else False - ) - ) - } for s in sources + self.populate_source(s) for s in sources ] _created_lockfile = Req_Lockfile.from_data( path=self.lockfile_location, data=lockfile_dict, meta_from_project=False diff --git a/tests/integration/test_install_twists.py b/tests/integration/test_install_twists.py index 055c39b2..2ad12691 100644 --- a/tests/integration/test_install_twists.py +++ b/tests/integration/test_install_twists.py @@ -333,3 +333,54 @@ six = {{path = "./artifacts/{}"}} c = p.pipenv("install") assert c.return_code == 0 assert "six" in p.lockfile["default"] + + +@pytest.mark.files +@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 = 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: + 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 diff --git a/tests/integration/test_lock.py b/tests/integration/test_lock.py index 2b520808..f2f0ac76 100644 --- a/tests/integration/test_lock.py +++ b/tests/integration/test_lock.py @@ -486,3 +486,20 @@ def test_lockfile_with_empty_dict(PipenvInstance): assert c.return_code == 0 assert 'Pipfile.lock is corrupted' in c.err assert p.lockfile['_meta'] + + +@pytest.mark.lock +@pytest.mark.install +def test_lock_with_incomplete_source(PipenvInstance, pypi): + with PipenvInstance(pypi=pypi, chdir=True) as p: + with open(p.pipfile_path, 'w') as f: + f.write(""" +[[source]] +url = "https://test.pypi.org/simple" + +[packages] +requests = "*" + """) + c = p.pipenv('install') + assert c.return_code == 0 + assert p.lockfile['_meta']['sources']