Commit 68e47677 by Sébastien Eustace

Add support for file dependencies in the add command

parent 79900178
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
- Added the `cache:clear` command. - Added the `cache:clear` command.
- Added support for `git` dependencies in the `add` command. - Added support for `git` dependencies in the `add` command.
- Added support for `file` dependencies in the `add` command.
### Changed ### Changed
......
...@@ -14,6 +14,7 @@ class AddCommand(VenvCommand): ...@@ -14,6 +14,7 @@ class AddCommand(VenvCommand):
{ name* : Packages to add. } { name* : Packages to add. }
{ --D|dev : Add package as development dependency. } { --D|dev : Add package as development dependency. }
{ --git= : The url of the Git repository. } { --git= : The url of the Git repository. }
{ --path= : The path to a dependency. }
{ --optional : Add as an optional dependency. } { --optional : Add as an optional dependency. }
{ --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
...@@ -36,9 +37,15 @@ If you do not specify a version constraint, poetry will choose a suitable one ba ...@@ -36,9 +37,15 @@ If you do not specify a version constraint, poetry will choose a suitable one ba
packages = self.argument('name') packages = self.argument('name')
is_dev = self.option('dev') is_dev = self.option('dev')
if self.option('git') and len(packages) > 1: if (self.option('git') or self.option('path')) and len(packages) > 1:
raise ValueError( raise ValueError(
'You can only specify one package when using the --git option' 'You can only specify one package '
'when using the --git or --path options'
)
if self.option('git') and self.option('path'):
raise RuntimeError(
'--git and --path cannot be used at the same time'
) )
section = 'dependencies' section = 'dependencies'
...@@ -56,7 +63,7 @@ If you do not specify a version constraint, poetry will choose a suitable one ba ...@@ -56,7 +63,7 @@ If you do not specify a version constraint, poetry will choose a suitable one ba
'Package {} is already present'.format(name) 'Package {} is already present'.format(name)
) )
if self.option('git'): if self.option('git') or self.option('path'):
requirements = { requirements = {
packages[0]: '' packages[0]: ''
} }
...@@ -81,6 +88,10 @@ If you do not specify a version constraint, poetry will choose a suitable one ba ...@@ -81,6 +88,10 @@ If you do not specify a version constraint, poetry will choose a suitable one ba
del constraint['version'] del constraint['version']
constraint['git'] = self.option('git') constraint['git'] = self.option('git')
elif self.option('path'):
del constraint['version']
constraint['path'] = self.option('path')
if self.option('optional'): if self.option('optional'):
constraint['optional'] = True constraint['optional'] = True
......
...@@ -74,7 +74,7 @@ class FileDependency(Dependency): ...@@ -74,7 +74,7 @@ class FileDependency(Dependency):
def hash(self): def hash(self):
h = hashlib.sha256() h = hashlib.sha256()
with self._path.open('rb') as fp: with self._full_path.open('rb') as fp:
for content in iter(lambda: fp.read(io.DEFAULT_BUFFER_SIZE), b''): for content in iter(lambda: fp.read(io.DEFAULT_BUFFER_SIZE), b''):
h.update(content) h.update(content)
......
...@@ -177,3 +177,79 @@ Writing lock file ...@@ -177,3 +177,79 @@ Writing lock file
assert tester.get_display() == expected assert tester.get_display() == expected
assert len(installer.installs) == 2 assert len(installer.installs) == 2
def test_add_file_constraint_wheel(app, repo, installer):
command = app.find('add')
tester = CommandTester(command)
repo.add_package(get_package('pendulum', '1.4.4'))
tester.execute([
('command', command.get_name()),
('name', ['demo']),
('--path', '../distributions/demo-0.1.0-py2.py3-none-any.whl')
])
expected = """\
Updating dependencies
Resolving dependencies
Package operations: 2 installs, 0 updates, 0 removals
Writing lock file
- Installing pendulum (1.4.4)
- Installing demo (0.1.0)
"""
assert tester.get_display() == expected
assert len(installer.installs) == 2
content = app.poetry.file.read(raw=True)['tool']['poetry']
assert 'demo' in content['dependencies']
assert content['dependencies']['demo'] == {
'path': '../distributions/demo-0.1.0-py2.py3-none-any.whl'
}
def test_add_file_constraint_sdist(app, repo, installer):
command = app.find('add')
tester = CommandTester(command)
repo.add_package(get_package('pendulum', '1.4.4'))
tester.execute([
('command', command.get_name()),
('name', ['demo']),
('--path', '../distributions/demo-0.1.0.tar.gz')
])
expected = """\
Updating dependencies
Resolving dependencies
Package operations: 2 installs, 0 updates, 0 removals
Writing lock file
- Installing pendulum (1.4.4)
- Installing demo (0.1.0)
"""
assert tester.get_display() == expected
assert len(installer.installs) == 2
content = app.poetry.file.read(raw=True)['tool']['poetry']
assert 'demo' in content['dependencies']
assert content['dependencies']['demo'] == {
'path': '../distributions/demo-0.1.0.tar.gz'
}
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