Commit 21333fe8 authored by idle sign's avatar idle sign

Added `metadata` section aliases.

parent 68c03bee
...@@ -18,6 +18,12 @@ class ConfigHandler(object): ...@@ -18,6 +18,12 @@ class ConfigHandler(object):
""" """
aliases = {}
"""Options aliases.
For compatibility with various packages. E.g.: d2to1 and pbr.
"""
strict_mode = True strict_mode = True
"""Flag. Whether unknown options in config should """Flag. Whether unknown options in config should
raise DistutilsOptionError exception, or pass silently. raise DistutilsOptionError exception, or pass silently.
...@@ -48,6 +54,9 @@ class ConfigHandler(object): ...@@ -48,6 +54,9 @@ class ConfigHandler(object):
unknown = tuple() unknown = tuple()
target_obj = self.target_obj target_obj = self.target_obj
# Translate alias into real name.
option_name = self.aliases.get(option_name, option_name)
current_value = getattr(target_obj, option_name, unknown) current_value = getattr(target_obj, option_name, unknown)
if current_value is unknown: if current_value is unknown:
...@@ -216,9 +225,18 @@ class ConfigHandler(object): ...@@ -216,9 +225,18 @@ class ConfigHandler(object):
class ConfigMetadataHandler(ConfigHandler): class ConfigMetadataHandler(ConfigHandler):
section_prefix = 'metadata' section_prefix = 'metadata'
aliases = {
'author-email': 'author_email',
'home_page': 'url',
'summary': 'description',
'classifier': 'classifiers',
'platform': 'platforms',
}
strict_mode = False strict_mode = False
"""We need to keep it loose, to be compatible with `pbr` package """We need to keep it loose, to be partially compatible with
which also uses `metadata` section. `pbr` and `d2to1` packages which also uses `metadata` section.
""" """
......
...@@ -86,6 +86,31 @@ class TestMetadata: ...@@ -86,6 +86,31 @@ class TestMetadata:
assert metadata.name == 'fake_name' assert metadata.name == 'fake_name'
assert metadata.keywords == ['one', 'two'] assert metadata.keywords == ['one', 'two']
def test_aliases(self, tmpdir):
fake_env(
tmpdir,
'[metadata]\n'
'author-email = test@test.com\n'
'home_page = http://test.test.com/test/\n'
'summary = Short summary\n'
'platform = a, b\n'
'classifier =\n'
' Framework :: Django\n'
' Programming Language :: Python :: 3.5\n'
)
with get_dist(tmpdir) as dist:
metadata = dist.metadata
assert metadata.author_email == 'test@test.com'
assert metadata.url == 'http://test.test.com/test/'
assert metadata.description == 'Short summary'
assert metadata.platforms == ['a', 'b']
assert metadata.classifiers == [
'Framework :: Django',
'Programming Language :: Python :: 3.5',
]
def test_multiline(self, tmpdir): def test_multiline(self, tmpdir):
fake_env( fake_env(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment