Skip to content

Commit

Permalink
Add package maintainer information to metadata (#484)
Browse files Browse the repository at this point in the history
Co-authored-by: Jose Luis Rivero <[email protected]>
  • Loading branch information
cottsay and j-rivero authored Mar 31, 2022
1 parent 15fdd96 commit 64f06cf
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
29 changes: 28 additions & 1 deletion colcon_core/package_augmentation/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def augment_package( # noqa: D102

config = get_configuration(setup_cfg)

version = config.get('metadata', {}).get('version')
metadata = config.get('metadata', {})
version = metadata.get('version')
desc.metadata['version'] = version

options = config.get('options', {})
Expand All @@ -59,6 +60,11 @@ def getter(env):

desc.metadata['get_python_setup_options'] = getter

maintainers = _extract_maintainers_with_emails(metadata)
if maintainers:
desc.metadata.setdefault('maintainers', [])
desc.metadata['maintainers'] += maintainers


def extract_dependencies(options):
"""
Expand Down Expand Up @@ -155,3 +161,24 @@ def _next_incompatible_version(version):
if len(version) == 1:
version.append(0)
return '.'.join(map(str, version))


def _extract_maintainers_with_emails(metadata):
if 'maintainer' in metadata:
maintainer = metadata['maintainer']
maintainer_email = metadata.get('maintainer_email')
else:
# If no explicit maintainer is given then it is likely that the
# original author is maintaining the package following python
# recommendations
# https://packaging.python.org/en/latest/specifications/core-metadata/#maintainer
maintainer = metadata.get('author')
maintainer_email = metadata.get('author_email')

# We're only interested in entries with emails
if maintainer and maintainer_email:
maintainers = [
(m[0].strip(), m[1].strip()) for m in zip(
maintainer.split(','),
maintainer_email.split(','))]
return ['{} <{}>'.format(*m) for m in maintainers]
2 changes: 2 additions & 0 deletions test/spell_check.words
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ argparse
asyncio
autouse
basepath
bazqux
blocklist
callables
capsys
Expand Down Expand Up @@ -33,6 +34,7 @@ executables
exitstatus
fdopen
filterwarnings
foobar
fromhex
functools
getcategory
Expand Down
15 changes: 15 additions & 0 deletions test/test_package_identification_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def test_identify():
(basepath / 'setup.cfg').write_text(
'[metadata]\n'
'name = other-name\n'
'maintainer = Foo Bar\n'
'maintainer_email = [email protected]\n'
'[options]\n'
'setup_requires =\n'
" build; sys_platform != 'win32'\n"
Expand Down Expand Up @@ -97,6 +99,19 @@ def test_identify():
options = desc.metadata['get_python_setup_options'](None)
assert 'zip_safe' in options

assert desc.metadata['maintainers'] == ['Foo Bar <[email protected]>']

desc = PackageDescriptor(basepath)
desc.name = 'other-name'
(basepath / 'setup.cfg').write_text(
'[metadata]\n'
'name = other-name\n'
'author = Baz Qux\n'
'author_email = [email protected]\n')
extension.identify(desc)
augmentation_extension.augment_package(desc)
assert desc.metadata['maintainers'] == ['Baz Qux <[email protected]>']


def test_create_dependency_descriptor():
eq_str = 'pkgname==2.2.0'
Expand Down

0 comments on commit 64f06cf

Please sign in to comment.