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
a5dadcf0
Commit
a5dadcf0
authored
Dec 04, 2016
by
idle sign
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
_parse_attr() factored out.
parent
89981722
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
24 deletions
+39
-24
setuptools/config.py
setuptools/config.py
+39
-24
No files found.
setuptools/config.py
View file @
a5dadcf0
...
...
@@ -152,6 +152,37 @@ class ConfigHandler(object):
return
value
@
classmethod
def
_parse_attr
(
cls
,
value
):
"""Represents value as a module attribute.
Examples:
attr: package.attr
attr: package.module.attr
:param str value:
:rtype: str
"""
attr_directive
=
'attr:'
if
not
value
.
startswith
(
attr_directive
):
return
value
attrs_path
=
value
.
replace
(
attr_directive
,
''
).
strip
().
split
(
'.'
)
attr_name
=
attrs_path
.
pop
()
module_name
=
'.'
.
join
(
attrs_path
)
module_name
=
module_name
or
'__init__'
sys
.
path
.
insert
(
0
,
os
.
getcwd
())
try
:
module
=
import_module
(
module_name
)
value
=
getattr
(
module
,
attr_name
)
finally
:
sys
.
path
=
sys
.
path
[
1
:]
return
value
@
classmethod
def
_get_parser_compound
(
cls
,
*
parse_methods
):
"""Returns parser function to represents value as a list.
...
...
@@ -277,32 +308,16 @@ class ConfigMetadataHandler(ConfigHandler):
:rtype: str
"""
attr_directive
=
'attr:'
if
not
value
.
startswith
(
attr_directive
):
return
value
version
=
self
.
_parse_attr
(
value
)
attrs_path
=
value
.
replace
(
attr_directive
,
''
).
strip
().
split
(
'.'
)
attr_name
=
attrs_path
.
pop
()
if
callable
(
version
):
version
=
version
()
module_name
=
'.'
.
join
(
attrs_path
)
module_name
=
module_name
or
'__init__'
sys
.
path
.
insert
(
0
,
os
.
getcwd
())
try
:
module
=
import_module
(
module_name
)
version
=
getattr
(
module
,
attr_name
)
if
callable
(
version
):
version
=
version
()
if
not
isinstance
(
version
,
string_types
):
if
hasattr
(
version
,
'__iter__'
):
version
=
'.'
.
join
(
map
(
str
,
version
))
else
:
version
=
'%s'
%
version
finally
:
sys
.
path
=
sys
.
path
[
1
:]
if
not
isinstance
(
version
,
string_types
):
if
hasattr
(
version
,
'__iter__'
):
version
=
'.'
.
join
(
map
(
str
,
version
))
else
:
version
=
'%s'
%
version
return
version
...
...
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