Commit 20c87bc0 by Sébastien Eustace

Add support for specifying platform for dependencies

parent 2bfc6f8d
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
- Added a new setting `settings.virtualenvs.in-project` to make `poetry` create the project's virtualenv inside the project's directory. - Added a new setting `settings.virtualenvs.in-project` to make `poetry` create the project's virtualenv inside the project's directory.
- Added the `--extras` and `--python` options to `debug:resolve` to help debug dependency resolution. - Added the `--extras` and `--python` options to `debug:resolve` to help debug dependency resolution.
- Added a `--src` option to new to create an `src` layout. - Added a `--src` option to new to create an `src` layout.
- Added support for specifying the `platform` for dependencies.
- Added the `--python` option to the `add` command.
- Added the `--platform` option to the `add` command.
### Changed ### Changed
......
...@@ -13,6 +13,8 @@ class AddCommand(VenvCommand, InitCommand): ...@@ -13,6 +13,8 @@ class AddCommand(VenvCommand, InitCommand):
{ --path= : The path to a dependency. } { --path= : The path to a dependency. }
{ --E|extras=* : Extras to activate for the dependency. } { --E|extras=* : Extras to activate for the dependency. }
{ --optional : Add as an optional dependency. } { --optional : Add as an optional dependency. }
{ --python= : Python version( for which the dependencies must be installed. }
{ --platform= : Platforms for which the dependencies must be installed. }
{ --allow-prereleases : Accept prereleases. } { --allow-prereleases : Accept prereleases. }
{ --dry-run : Outputs the operations but will not execute anything { --dry-run : Outputs the operations but will not execute anything
(implicitly enables --verbose). } (implicitly enables --verbose). }
...@@ -98,6 +100,12 @@ If you do not specify a version constraint, poetry will choose a suitable one ba ...@@ -98,6 +100,12 @@ If you do not specify a version constraint, poetry will choose a suitable one ba
if self.option('extras'): if self.option('extras'):
constraint['extras'] = self.option('extras') constraint['extras'] = self.option('extras')
if self.option('python'):
constraint['python'] = self.option('python')
if self.option('platform'):
constraint['platform'] = self.option('platform')
if len(constraint) == 1 and 'version' in constraint: if len(constraint) == 1 and 'version' in constraint:
constraint = constraint['version'] constraint = constraint['version']
......
...@@ -182,6 +182,10 @@ ...@@ -182,6 +182,10 @@
"type": "string", "type": "string",
"description": "The python versions for which the dependency should be installed." "description": "The python versions for which the dependency should be installed."
}, },
"platform": {
"type": "string",
"description": "The platform(s) for which the dependency should be installed."
},
"allows-prereleases": { "allows-prereleases": {
"type": "boolean", "type": "boolean",
"description": "Whether the dependency allows prereleases or not." "description": "Whether the dependency allows prereleases or not."
...@@ -225,6 +229,10 @@ ...@@ -225,6 +229,10 @@
"type": "string", "type": "string",
"description": "The python versions for which the dependency should be installed." "description": "The python versions for which the dependency should be installed."
}, },
"platform": {
"type": "string",
"description": "The platform(s) for which the dependency should be installed."
},
"allows-prereleases": { "allows-prereleases": {
"type": "boolean", "type": "boolean",
"description": "Whether the dependency allows prereleases or not." "description": "Whether the dependency allows prereleases or not."
...@@ -255,6 +263,10 @@ ...@@ -255,6 +263,10 @@
"type": "string", "type": "string",
"description": "The python versions for which the dependency should be installed." "description": "The python versions for which the dependency should be installed."
}, },
"platform": {
"type": "string",
"description": "The platform(s) for which the dependency should be installed."
},
"optional": { "optional": {
"type": "boolean", "type": "boolean",
"description": "Whether the dependency is optional or not." "description": "Whether the dependency is optional or not."
...@@ -281,6 +293,10 @@ ...@@ -281,6 +293,10 @@
"type": "string", "type": "string",
"description": "The python versions for which the dependency should be installed." "description": "The python versions for which the dependency should be installed."
}, },
"platform": {
"type": "string",
"description": "The platform(s) for which the dependency should be installed."
},
"optional": { "optional": {
"type": "boolean", "type": "boolean",
"description": "Whether the dependency is optional or not." "description": "Whether the dependency is optional or not."
......
...@@ -151,6 +151,13 @@ class Dependency(object): ...@@ -151,6 +151,13 @@ class Dependency(object):
self._create_nested_marker('python_version', python_constraint) self._create_nested_marker('python_version', python_constraint)
) )
if self.platform != '*':
platform_constraint = self.platform_constraint
markers.append(
self._create_nested_marker('sys_platform', platform_constraint)
)
in_extras = ' || '.join(self._in_extras) in_extras = ' || '.join(self._in_extras)
if in_extras and with_extras: if in_extras and with_extras:
markers.append( markers.append(
......
import sys
from cleo.testers import CommandTester from cleo.testers import CommandTester
from tests.helpers import get_dependency from tests.helpers import get_dependency
...@@ -303,3 +305,86 @@ Writing lock file ...@@ -303,3 +305,86 @@ Writing lock file
'version': '0.2.0', 'version': '0.2.0',
'extras': ['msgpack'] 'extras': ['msgpack']
} }
def test_add_constraint_with_python(app, repo, installer):
command = app.find('add')
tester = CommandTester(command)
cachy2 = get_package('cachy', '0.2.0')
repo.add_package(get_package('cachy', '0.1.0'))
repo.add_package(cachy2)
tester.execute([
('command', command.get_name()),
('name', ['cachy=0.2.0']),
('--python', '>=2.7')
])
expected = """\
Updating dependencies
Resolving dependencies...
Package operations: 1 install, 0 updates, 0 removals
Writing lock file
- Installing cachy (0.2.0)
"""
assert tester.get_display() == expected
assert len(installer.installs) == 1
content = app.poetry.file.read(raw=True)['tool']['poetry']
assert 'cachy' in content['dependencies']
assert content['dependencies']['cachy'] == {
'version': '0.2.0',
'python': '>=2.7'
}
def test_add_constraint_with_platform(app, repo, installer):
platform = sys.platform
command = app.find('add')
tester = CommandTester(command)
cachy2 = get_package('cachy', '0.2.0')
repo.add_package(get_package('cachy', '0.1.0'))
repo.add_package(cachy2)
tester.execute([
('command', command.get_name()),
('name', ['cachy=0.2.0']),
('--platform', platform)
])
expected = """\
Updating dependencies
Resolving dependencies...
Package operations: 1 install, 0 updates, 0 removals
Writing lock file
- Installing cachy (0.2.0)
"""
assert tester.get_display() == expected
assert len(installer.installs) == 1
content = app.poetry.file.read(raw=True)['tool']['poetry']
assert 'cachy' in content['dependencies']
assert content['dependencies']['cachy'] == {
'version': '0.2.0',
'platform': platform
}
...@@ -70,6 +70,21 @@ def test_to_pep_508(): ...@@ -70,6 +70,21 @@ def test_to_pep_508():
'or (python_version >= "3.6" and python_version < "4.0")' 'or (python_version >= "3.6" and python_version < "4.0")'
def test_to_pep_508_with_platform():
dependency = Dependency('Django', '^1.23')
dependency.python_versions = '~2.7 || ^3.6'
dependency.platform = 'linux || linux2'
result = dependency.to_pep_508()
assert result == (
'Django (>=1.23,<2.0); '
'((python_version >= "2.7" and python_version < "2.8") '
'or (python_version >= "3.6" and python_version < "4.0"))'
' and (sys_platform == "linux" or sys_platform == "linux2")'
)
def test_to_pep_508_wilcard(): def test_to_pep_508_wilcard():
dependency = Dependency('Django', '*') dependency = Dependency('Django', '*')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment