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
0f0558f9
Unverified
Commit
0f0558f9
authored
Jun 27, 2018
by
Sébastien Eustace
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
List all settings with config —list
parent
9434580d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
138 additions
and
30 deletions
+138
-30
CHANGELOG.md
+1
-0
poetry/console/commands/config.py
+84
-30
tests/console/commands/test_config.py
+53
-0
No files found.
CHANGELOG.md
View file @
0f0558f9
...
...
@@ -13,6 +13,7 @@
-
Changed the dependency installation order, deepest dependencies are now installed first.
-
Improved solver error messages.
-
`poetry`
now always reads/writes the
`pyproject.toml`
file with the
`utf-8`
encoding.
-
`config --list`
now lists all available settings.
### Fixed
...
...
poetry/console/commands/config.py
View file @
0f0558f9
...
...
@@ -43,6 +43,26 @@ To remove a repository (repo is a short alias for repositories):
self
.
_config
=
Config
.
create
(
"config.toml"
)
self
.
_auth_config
=
Config
.
create
(
"auth.toml"
)
@property
def
unique_config_values
(
self
):
boolean_validator
=
lambda
val
:
val
in
{
"true"
,
"false"
,
"1"
,
"0"
}
boolean_normalizer
=
lambda
val
:
True
if
val
in
[
"true"
,
"1"
]
else
False
unique_config_values
=
{
"settings.virtualenvs.create"
:
(
boolean_validator
,
boolean_normalizer
,
True
,
),
"settings.virtualenvs.in-project"
:
(
boolean_validator
,
boolean_normalizer
,
False
,
),
}
return
unique_config_values
def
initialize
(
self
,
i
,
o
):
super
(
ConfigCommand
,
self
)
.
initialize
(
i
,
o
)
...
...
@@ -93,15 +113,7 @@ To remove a repository (repo is a short alias for repositories):
values
=
self
.
argument
(
"value"
)
boolean_validator
=
lambda
val
:
val
in
{
"true"
,
"false"
,
"1"
,
"0"
}
boolean_normalizer
=
lambda
val
:
True
if
val
in
[
"true"
,
"1"
]
else
False
unique_config_values
=
{
"settings.virtualenvs.create"
:
(
boolean_validator
,
boolean_normalizer
),
"settings.virtualenvs.in-project"
:
(
boolean_validator
,
boolean_normalizer
),
"settings.pypi.fallback"
:
(
boolean_validator
,
boolean_normalizer
),
}
unique_config_values
=
self
.
unique_config_values
if
setting_key
in
unique_config_values
:
if
self
.
option
(
"unset"
):
return
self
.
_remove_single_value
(
setting_key
)
...
...
@@ -180,7 +192,7 @@ To remove a repository (repo is a short alias for repositories):
raise
ValueError
(
"Setting {} does not exist"
.
format
(
self
.
argument
(
"key"
)))
def
_handle_single_value
(
self
,
key
,
callbacks
,
values
):
validator
,
normalizer
=
callbacks
validator
,
normalizer
,
_
=
callbacks
if
len
(
values
)
>
1
:
raise
RuntimeError
(
"You can only pass one value."
)
...
...
@@ -198,32 +210,74 @@ To remove a repository (repo is a short alias for repositories):
return
0
def
_list_configuration
(
self
,
contents
,
k
=
None
):
def
_list_configuration
(
self
,
contents
):
settings
=
contents
.
get
(
"settings"
,
{})
for
setting_key
,
value
in
sorted
(
self
.
unique_config_values
.
items
()):
self
.
_list_setting
(
settings
,
setting_key
.
replace
(
"settings."
,
""
),
"settings."
,
default
=
value
[
-
1
],
)
repositories
=
contents
.
get
(
"repositories"
)
if
not
repositories
:
self
.
line
(
"<comment>repositories</comment> = <info>{}</info>"
)
else
:
self
.
_list_setting
(
repositories
,
k
=
"repositories."
)
def
_list_setting
(
self
,
contents
,
setting
=
None
,
k
=
None
,
default
=
None
):
orig_k
=
k
for
key
,
value
in
contents
.
items
():
if
k
is
None
and
key
not
in
[
"config"
,
"repositories"
,
"settings"
]:
continue
if
setting
and
setting
.
split
(
"."
)[
0
]
not
in
contents
:
value
=
json
.
dumps
(
default
)
if
isinstance
(
value
,
dict
)
or
key
==
"repositories"
and
k
is
None
:
if
k
is
None
:
k
=
""
self
.
line
(
"<comment>{}</comment> = <info>{}</info>"
.
format
(
(
k
or
""
)
+
setting
,
value
)
)
else
:
for
key
,
value
in
contents
.
items
():
if
k
is
None
and
key
not
in
[
"config"
,
"repositories"
,
"settings"
]:
continue
k
+=
re
.
sub
(
"^config
\
."
,
""
,
key
+
"."
)
self
.
_list_configuration
(
value
,
k
=
k
)
k
=
orig_k
if
setting
and
key
!=
setting
.
split
(
"."
)[
0
]:
continue
continue
if
isinstance
(
value
,
dict
)
or
key
==
"repositories"
and
k
is
None
:
if
k
is
None
:
k
=
""
if
isinstance
(
value
,
list
):
value
=
[
json
.
dumps
(
val
)
if
isinstance
(
val
,
list
)
else
val
for
val
in
value
]
k
+=
re
.
sub
(
"^config
\
."
,
""
,
key
+
"."
)
if
setting
and
len
(
setting
)
>
1
:
setting
=
"."
.
join
(
setting
.
split
(
"."
)[
1
:])
value
=
"[{}]"
.
format
(
", "
.
join
(
value
))
self
.
_list_setting
(
value
,
k
=
k
,
setting
=
setting
,
default
=
default
)
k
=
orig_k
value
=
json
.
dumps
(
value
)
continue
self
.
line
(
"[<comment>{}</comment>] <info>{}</info>"
.
format
((
k
or
""
)
+
key
,
value
)
)
if
isinstance
(
value
,
list
):
value
=
[
json
.
dumps
(
val
)
if
isinstance
(
val
,
list
)
else
val
for
val
in
value
]
value
=
"[{}]"
.
format
(
", "
.
join
(
value
))
value
=
json
.
dumps
(
value
)
self
.
line
(
"<comment>{}</comment> = <info>{}</info>"
.
format
(
(
k
or
""
)
+
key
,
value
)
)
def
_get_formatted_value
(
self
,
value
):
if
isinstance
(
value
,
list
):
value
=
[
json
.
dumps
(
val
)
if
isinstance
(
val
,
list
)
else
val
for
val
in
value
]
value
=
"[{}]"
.
format
(
", "
.
join
(
value
))
return
json
.
dumps
(
value
)
tests/console/commands/test_config.py
0 → 100644
View file @
0f0558f9
import
pytest
import
tempfile
from
cleo.testers
import
CommandTester
from
poetry.config
import
Config
from
poetry.utils._compat
import
Path
from
poetry.utils.toml_file
import
TomlFile
@pytest.fixture
def
config
():
with
tempfile
.
NamedTemporaryFile
()
as
f
:
return
Config
(
TomlFile
(
f
.
name
))
def
test_list_displays_default_value_if_not_set
(
app
,
config
):
command
=
app
.
find
(
"config"
)
command
.
_config
=
config
tester
=
CommandTester
(
command
)
tester
.
execute
([(
"command"
,
command
.
get_name
()),
(
"--list"
,
True
)])
expected
=
"""settings.virtualenvs.create = true
settings.virtualenvs.in-project = false
repositories = {}
"""
assert
tester
.
get_display
(
True
)
==
expected
def
test_list_displays_set_get_setting
(
app
,
config
):
command
=
app
.
find
(
"config"
)
command
.
_config
=
config
tester
=
CommandTester
(
command
)
tester
.
execute
(
[
(
"command"
,
command
.
get_name
()),
(
"key"
,
"settings.virtualenvs.create"
),
(
"value"
,
[
"false"
]),
]
)
command
.
_config
=
Config
(
config
.
file
)
tester
.
execute
([(
"command"
,
command
.
get_name
()),
(
"--list"
,
True
)])
expected
=
"""settings.virtualenvs.create = false
settings.virtualenvs.in-project = false
repositories = {}
"""
assert
tester
.
get_display
(
True
)
==
expected
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