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
3ec2e98c
Unverified
Commit
3ec2e98c
authored
Sep 24, 2020
by
finswimmer
Committed by
GitHub
Sep 24, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support dependency parameters for interactive init
Resolves: #711
parent
dfbe55a8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
194 additions
and
4 deletions
+194
-4
poetry/console/commands/init.py
+12
-4
tests/console/commands/test_init.py
+182
-0
No files found.
poetry/console/commands/init.py
View file @
3ec2e98c
...
...
@@ -144,6 +144,10 @@ The <c1>init</c1> command creates a basic <comment>pyproject.toml</> file in the
self
.
line
(
""
)
requirements
=
{}
if
self
.
option
(
"dependency"
):
requirements
=
self
.
_format_requirements
(
self
.
_determine_requirements
(
self
.
option
(
"dependency"
))
)
question
=
"Would you like to define your main dependencies interactively?"
help_message
=
(
...
...
@@ -160,12 +164,16 @@ The <c1>init</c1> command creates a basic <comment>pyproject.toml</> file in the
if
self
.
confirm
(
question
,
True
):
self
.
line
(
help_message
)
help_displayed
=
True
requirements
=
self
.
_format_requirements
(
self
.
_
determine_requirements
(
self
.
option
(
"dependency"
))
requirements
.
update
(
self
.
_
format_requirements
(
self
.
_determine_requirements
([]
))
)
self
.
line
(
""
)
dev_requirements
=
{}
if
self
.
option
(
"dev-dependency"
):
dev_requirements
=
self
.
_format_requirements
(
self
.
_determine_requirements
(
self
.
option
(
"dev-dependency"
))
)
question
=
(
"Would you like to define your development dependencies interactively?"
...
...
@@ -174,8 +182,8 @@ The <c1>init</c1> command creates a basic <comment>pyproject.toml</> file in the
if
not
help_displayed
:
self
.
line
(
help_message
)
dev_requirements
=
self
.
_format_requirements
(
self
.
_
determine_requirements
(
self
.
option
(
"dev-dependency"
))
dev_requirements
.
update
(
self
.
_
format_requirements
(
self
.
_determine_requirements
([]
))
)
self
.
line
(
""
)
...
...
tests/console/commands/test_init.py
View file @
3ec2e98c
...
...
@@ -484,3 +484,185 @@ python = "~2.7 || ^3.6"
"""
assert
expected
in
tester
.
io
.
fetch_output
()
def
test_predefined_dependency
(
app
,
repo
,
mocker
,
poetry
):
repo
.
add_package
(
get_package
(
"pendulum"
,
"2.0.0"
))
command
=
app
.
find
(
"init"
)
command
.
_pool
=
poetry
.
pool
mocker
.
patch
(
"poetry.utils._compat.Path.open"
)
p
=
mocker
.
patch
(
"poetry.utils._compat.Path.cwd"
)
p
.
return_value
=
Path
(
__file__
)
tester
=
CommandTester
(
command
)
inputs
=
[
"my-package"
,
# Package name
"1.2.3"
,
# Version
"This is a description"
,
# Description
"n"
,
# Author
"MIT"
,
# License
"~2.7 || ^3.6"
,
# Python
"n"
,
# Interactive packages
"n"
,
# Interactive dev packages
"
\n
"
,
# Generate
]
tester
.
execute
(
"--dependency pendulum"
,
inputs
=
"
\n
"
.
join
(
inputs
))
expected
=
"""
\
[tool.poetry]
name = "my-package"
version = "1.2.3"
description = "This is a description"
authors = ["Your Name <you@example.com>"]
license = "MIT"
[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
pendulum = "^2.0.0"
[tool.poetry.dev-dependencies]
"""
assert
expected
in
tester
.
io
.
fetch_output
()
def
test_predefined_and_interactive_dependencies
(
app
,
repo
,
mocker
,
poetry
):
repo
.
add_package
(
get_package
(
"pendulum"
,
"2.0.0"
))
repo
.
add_package
(
get_package
(
"pyramid"
,
"1.10"
))
command
=
app
.
find
(
"init"
)
command
.
_pool
=
poetry
.
pool
mocker
.
patch
(
"poetry.utils._compat.Path.open"
)
p
=
mocker
.
patch
(
"poetry.utils._compat.Path.cwd"
)
p
.
return_value
=
Path
(
__file__
)
tester
=
CommandTester
(
command
)
inputs
=
[
"my-package"
,
# Package name
"1.2.3"
,
# Version
"This is a description"
,
# Description
"n"
,
# Author
"MIT"
,
# License
"~2.7 || ^3.6"
,
# Python
""
,
# Interactive packages
"pyramid"
,
# Search for package
"0"
,
# First option
""
,
# Do not set constraint
""
,
# Stop searching for packages
"n"
,
# Interactive dev packages
"
\n
"
,
# Generate
]
tester
.
execute
(
"--dependency pendulum"
,
inputs
=
"
\n
"
.
join
(
inputs
))
expected
=
"""
\
[tool.poetry]
name = "my-package"
version = "1.2.3"
description = "This is a description"
authors = ["Your Name <you@example.com>"]
license = "MIT"
[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
"""
output
=
tester
.
io
.
fetch_output
()
assert
expected
in
output
assert
'pendulum = "^2.0.0"'
in
output
assert
'pyramid = "^1.10"'
in
output
def
test_predefined_dev_dependency
(
app
,
repo
,
mocker
,
poetry
):
repo
.
add_package
(
get_package
(
"pytest"
,
"3.6.0"
))
command
=
app
.
find
(
"init"
)
command
.
_pool
=
poetry
.
pool
mocker
.
patch
(
"poetry.utils._compat.Path.open"
)
p
=
mocker
.
patch
(
"poetry.utils._compat.Path.cwd"
)
p
.
return_value
=
Path
(
__file__
)
tester
=
CommandTester
(
command
)
inputs
=
[
"my-package"
,
# Package name
"1.2.3"
,
# Version
"This is a description"
,
# Description
"n"
,
# Author
"MIT"
,
# License
"~2.7 || ^3.6"
,
# Python
"n"
,
# Interactive packages
"n"
,
# Interactive dev packages
"
\n
"
,
# Generate
]
tester
.
execute
(
"--dev-dependency pytest"
,
inputs
=
"
\n
"
.
join
(
inputs
))
expected
=
"""
\
[tool.poetry]
name = "my-package"
version = "1.2.3"
description = "This is a description"
authors = ["Your Name <you@example.com>"]
license = "MIT"
[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
[tool.poetry.dev-dependencies]
pytest = "^3.6.0"
"""
assert
expected
in
tester
.
io
.
fetch_output
()
def
test_predefined_and_interactive_dev_dependencies
(
app
,
repo
,
mocker
,
poetry
):
repo
.
add_package
(
get_package
(
"pytest"
,
"3.6.0"
))
repo
.
add_package
(
get_package
(
"pytest-requests"
,
"0.2.0"
))
command
=
app
.
find
(
"init"
)
command
.
_pool
=
poetry
.
pool
mocker
.
patch
(
"poetry.utils._compat.Path.open"
)
p
=
mocker
.
patch
(
"poetry.utils._compat.Path.cwd"
)
p
.
return_value
=
Path
(
__file__
)
tester
=
CommandTester
(
command
)
inputs
=
[
"my-package"
,
# Package name
"1.2.3"
,
# Version
"This is a description"
,
# Description
"n"
,
# Author
"MIT"
,
# License
"~2.7 || ^3.6"
,
# Python
"n"
,
# Interactive packages
""
,
# Interactive dev packages
"pytest-requests"
,
# Search for package
"0"
,
# Select first option
""
,
# Do not set constraint
""
,
# Stop searching for dev packages
"
\n
"
,
# Generate
]
tester
.
execute
(
"--dev-dependency pytest"
,
inputs
=
"
\n
"
.
join
(
inputs
))
expected
=
"""
\
[tool.poetry]
name = "my-package"
version = "1.2.3"
description = "This is a description"
authors = ["Your Name <you@example.com>"]
license = "MIT"
[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
[tool.poetry.dev-dependencies]
"""
output
=
tester
.
io
.
fetch_output
()
assert
expected
in
output
assert
'pytest-requests = "^0.2.0"'
in
output
assert
'pytest = "^3.6.0"'
in
output
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