Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python-poetry
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
python-poetry
Commits
68e47677
Unverified
Commit
68e47677
authored
May 01, 2018
by
Sébastien Eustace
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for file dependencies in the add command
parent
79900178
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
92 additions
and
4 deletions
+92
-4
CHANGELOG.md
+1
-0
poetry/console/commands/add.py
+14
-3
poetry/packages/file_dependency.py
+1
-1
tests/console/commands/test_add.py
+76
-0
No files found.
CHANGELOG.md
View file @
68e47677
...
@@ -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
...
...
poetry/console/commands/add.py
View file @
68e47677
...
@@ -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
...
...
poetry/packages/file_dependency.py
View file @
68e47677
...
@@ -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
)
...
...
tests/console/commands/test_add.py
View file @
68e47677
...
@@ -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'
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment