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
2d7b28dc
Commit
2d7b28dc
authored
May 16, 2018
by
Jason R. Coombs
Committed by
GitHub
May 16, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1365 from jmbowman/jmbowman/version_attr_and_package_dir
Fix attr: with package_dirs
parents
1252d1b3
0c2e5c9d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
10 deletions
+79
-10
changelog.d/1365.change.rst
changelog.d/1365.change.rst
+2
-0
setuptools/config.py
setuptools/config.py
+27
-7
setuptools/tests/test_config.py
setuptools/tests/test_config.py
+50
-3
No files found.
changelog.d/1365.change.rst
0 → 100644
View file @
2d7b28dc
Take the package_dir option into account when loading the version from a
module attribute.
setuptools/config.py
View file @
2d7b28dc
...
...
@@ -102,14 +102,14 @@ def parse_configuration(
If False exceptions are propagated as expected.
:rtype: list
"""
meta
=
ConfigMetadataHandler
(
distribution
.
metadata
,
command_options
,
ignore_option_errors
)
meta
.
parse
()
options
=
ConfigOptionsHandler
(
distribution
,
command_options
,
ignore_option_errors
)
options
.
parse
()
meta
=
ConfigMetadataHandler
(
distribution
.
metadata
,
command_options
,
ignore_option_errors
,
distribution
.
package_dir
)
meta
.
parse
()
return
meta
,
options
...
...
@@ -281,7 +281,7 @@ class ConfigHandler(object):
return
f
.
read
()
@
classmethod
def
_parse_attr
(
cls
,
value
):
def
_parse_attr
(
cls
,
value
,
package_dir
=
None
):
"""Represents value as a module attribute.
Examples:
...
...
@@ -301,7 +301,21 @@ class ConfigHandler(object):
module_name
=
'.'
.
join
(
attrs_path
)
module_name
=
module_name
or
'__init__'
sys
.
path
.
insert
(
0
,
os
.
getcwd
())
parent_path
=
os
.
getcwd
()
if
package_dir
:
if
attrs_path
[
0
]
in
package_dir
:
# A custom path was specified for the module we want to import
custom_path
=
package_dir
[
attrs_path
[
0
]]
parts
=
custom_path
.
rsplit
(
'/'
,
1
)
if
len
(
parts
)
>
1
:
parent_path
=
os
.
path
.
join
(
os
.
getcwd
(),
parts
[
0
])
module_name
=
parts
[
1
]
else
:
module_name
=
custom_path
elif
''
in
package_dir
:
# A custom parent directory was specified for all root modules
parent_path
=
os
.
path
.
join
(
os
.
getcwd
(),
package_dir
[
''
])
sys
.
path
.
insert
(
0
,
parent_path
)
try
:
module
=
import_module
(
module_name
)
value
=
getattr
(
module
,
attr_name
)
...
...
@@ -400,6 +414,12 @@ class ConfigMetadataHandler(ConfigHandler):
"""
def
__init__
(
self
,
target_obj
,
options
,
ignore_option_errors
=
False
,
package_dir
=
None
):
super
(
ConfigMetadataHandler
,
self
).
__init__
(
target_obj
,
options
,
ignore_option_errors
)
self
.
package_dir
=
package_dir
@
property
def
parsers
(
self
):
"""Metadata item name to parser function mapping."""
...
...
@@ -440,7 +460,7 @@ class ConfigMetadataHandler(ConfigHandler):
))
return
version
version
=
self
.
_parse_attr
(
value
)
version
=
self
.
_parse_attr
(
value
,
self
.
package_dir
)
if
callable
(
version
):
version
=
version
()
...
...
setuptools/tests/test_config.py
View file @
2d7b28dc
...
...
@@ -10,13 +10,15 @@ class ErrConfigHandler(ConfigHandler):
def
make_package_dir
(
name
,
base_dir
):
dir_package
=
base_dir
.
mkdir
(
name
)
dir_package
=
base_dir
for
dir_name
in
name
.
split
(
'/'
):
dir_package
=
dir_package
.
mkdir
(
dir_name
)
init_file
=
dir_package
.
join
(
'__init__.py'
)
init_file
.
write
(
''
)
return
dir_package
,
init_file
def
fake_env
(
tmpdir
,
setup_cfg
,
setup_py
=
None
):
def
fake_env
(
tmpdir
,
setup_cfg
,
setup_py
=
None
,
package_path
=
'fake_package'
):
if
setup_py
is
None
:
setup_py
=
(
...
...
@@ -28,7 +30,7 @@ def fake_env(tmpdir, setup_cfg, setup_py=None):
config
=
tmpdir
.
join
(
'setup.cfg'
)
config
.
write
(
setup_cfg
)
package_dir
,
init_file
=
make_package_dir
(
'fake_package'
,
tmpdir
)
package_dir
,
init_file
=
make_package_dir
(
package_path
,
tmpdir
)
init_file
.
write
(
'VERSION = (1, 2, 3)
\
n
'
...
...
@@ -285,6 +287,51 @@ class TestMetadata:
with
get_dist
(
tmpdir
)
as
dist
:
_
=
dist
.
metadata
.
version
def
test_version_with_package_dir_simple
(
self
,
tmpdir
):
_
,
config
=
fake_env
(
tmpdir
,
'[metadata]
\
n
'
'version = attr: fake_package_simple.VERSION
\
n
'
'[options]
\
n
'
'package_dir =
\
n
'
' = src
\
n
'
,
package_path
=
'src/fake_package_simple'
)
with
get_dist
(
tmpdir
)
as
dist
:
assert
dist
.
metadata
.
version
==
'1.2.3'
def
test_version_with_package_dir_rename
(
self
,
tmpdir
):
_
,
config
=
fake_env
(
tmpdir
,
'[metadata]
\
n
'
'version = attr: fake_package_rename.VERSION
\
n
'
'[options]
\
n
'
'package_dir =
\
n
'
' fake_package_rename = fake_dir
\
n
'
,
package_path
=
'fake_dir'
)
with
get_dist
(
tmpdir
)
as
dist
:
assert
dist
.
metadata
.
version
==
'1.2.3'
def
test_version_with_package_dir_complex
(
self
,
tmpdir
):
_
,
config
=
fake_env
(
tmpdir
,
'[metadata]
\
n
'
'version = attr: fake_package_complex.VERSION
\
n
'
'[options]
\
n
'
'package_dir =
\
n
'
' fake_package_complex = src/fake_dir
\
n
'
,
package_path
=
'src/fake_dir'
)
with
get_dist
(
tmpdir
)
as
dist
:
assert
dist
.
metadata
.
version
==
'1.2.3'
def
test_unknown_meta_item
(
self
,
tmpdir
):
fake_env
(
...
...
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