Skip to content

Commit

Permalink
Add support for PEP 508 @ url syntax (#4175)
Browse files Browse the repository at this point in the history
* Add support for PEP 508 @ url syntax

* Add test for install_requires

* Forbid dependencies direct url
  • Loading branch information
xavfernandez authored Feb 5, 2017
1 parent 8abdb25 commit 6ec5597
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
type (:pull:`4194`). To completely suppress (for example in a CI environment)
use ``--progress-bar off```.

* Add support for the new ``@ url`` syntax from PEP 508 (:pull:`4175`)


**9.0.1 (2016-11-06)**

Expand Down
12 changes: 11 additions & 1 deletion pip/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ def __init__(self, req, comes_from, source_dir=None, editable=False,
self.editable = editable

self._wheel_cache = wheel_cache
self.link = self.original_link = link
if link is not None:
self.link = self.original_link = link
else:
from pip.index import Link
self.link = self.original_link = req and req.url and Link(req.url)

self.as_egg = as_egg
if extras:
self.extras = extras
Expand Down Expand Up @@ -159,6 +164,11 @@ def from_req(cls, req, comes_from=None, isolated=False, wheel_cache=None):
req = Requirement(req)
except InvalidRequirement:
raise InstallationError("Invalid requirement: '%s'" % req)
if req.url:
raise InstallationError(
"Direct url requirement (like %s) are not allowed for "
"dependencies" % req
)
return cls(req, comes_from, isolated=isolated, wheel_cache=wheel_cache)

@classmethod
Expand Down
29 changes: 29 additions & 0 deletions tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pip.status_codes import ERROR
from tests.lib import (pyversion, pyversion_tuple,
_create_test_package, _create_svn_repo, path_to_url,
create_test_package_with_setup,
requirements_file)
from tests.lib.local_repos import local_checkout
from tests.lib.path import Path
Expand Down Expand Up @@ -1191,3 +1192,31 @@ def test_install_environment_markers(script, data):
assert ("Ignoring missing-pkg: markers 'python_version == \"1.0\"' don't "
"match your environment") in res.stderr, str(res)
assert "Successfully installed pkga-0.1" in res.stdout, str(res)


@pytest.mark.network
def test_install_pep508_with_url(script):
res = script.pip(
'install', '--no-index',
'packaging@https://files.pythonhosted.org/packages/2f/2b/'
'c681de3e1dbcd469537aefb15186b800209aa1f299d933d23b48d85c9d56/'
'packaging-15.3-py2.py3-none-any.whl#sha256='
'ce1a869fe039fbf7e217df36c4653d1dbe657778b2d41709593a0003584405f4'
)
assert "Successfully installed packaging-15.3" in str(res), str(res)


@pytest.mark.network
def test_install_pep508_with_url_in_install_requires(script):
pkga_path = create_test_package_with_setup(
script, name='pkga', version='1.0',
install_requires=[
'packaging@https://files.pythonhosted.org/packages/2f/2b/'
'c681de3e1dbcd469537aefb15186b800209aa1f299d933d23b48d85c9d56/'
'packaging-15.3-py2.py3-none-any.whl#sha256='
'ce1a869fe039fbf7e217df36c4653d1dbe657778b2d41709593a0003584405f4'
],
)
res = script.pip('install', pkga_path, expect_error=True)
assert "Direct url requirement " in res.stderr, str(res)
assert "are not allowed for dependencies" in res.stderr, str(res)

0 comments on commit 6ec5597

Please sign in to comment.