Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
setuptools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
setuptools
Commits
42fe2eb1
Commit
42fe2eb1
authored
Oct 28, 2018
by
Jason R. Coombs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract _get_option function for getting an option from getter or attribute.
parent
9ad8e0dd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
9 deletions
+14
-9
setuptools/config.py
setuptools/config.py
+14
-9
No files found.
setuptools/config.py
View file @
42fe2eb1
...
@@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals
...
@@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals
import
io
import
io
import
os
import
os
import
sys
import
sys
import
functools
from
collections
import
defaultdict
from
collections
import
defaultdict
from
functools
import
partial
from
functools
import
partial
from
importlib
import
import_module
from
importlib
import
import_module
...
@@ -61,6 +62,18 @@ def read_configuration(
...
@@ -61,6 +62,18 @@ def read_configuration(
return
configuration_to_dict
(
handlers
)
return
configuration_to_dict
(
handlers
)
def
_get_option
(
target_obj
,
key
):
"""
Given a target object and option key, get that option from
the target object, either through a get_{key} method or
from an attribute directly.
"""
getter_name
=
'get_{key}'
.
format
(
**
locals
())
by_attribute
=
functools
.
partial
(
getattr
,
target_obj
,
key
)
getter
=
getattr
(
target_obj
,
getter_name
,
by_attribute
)
return
getter
()
def
configuration_to_dict
(
handlers
):
def
configuration_to_dict
(
handlers
):
"""Returns configuration data gathered by given handlers as a dict.
"""Returns configuration data gathered by given handlers as a dict.
...
@@ -74,17 +87,9 @@ def configuration_to_dict(handlers):
...
@@ -74,17 +87,9 @@ def configuration_to_dict(handlers):
for
handler
in
handlers
:
for
handler
in
handlers
:
obj_alias
=
handler
.
section_prefix
obj_alias
=
handler
.
section_prefix
target_obj
=
handler
.
target_obj
for
option
in
handler
.
set_options
:
for
option
in
handler
.
set_options
:
getter
=
getattr
(
target_obj
,
'get_%s'
%
option
,
None
)
value
=
_get_option
(
handler
.
target_obj
,
option
)
if
getter
is
None
:
value
=
getattr
(
target_obj
,
option
)
else
:
value
=
getter
()
config_dict
[
obj_alias
][
option
]
=
value
config_dict
[
obj_alias
][
option
]
=
value
return
config_dict
return
config_dict
...
...
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