Skip to content

WIP: better way to get python package metadata#21

Closed
rotu wants to merge 3 commits intocolcon:masterfrom
RoverRobotics-forks:better_metadata
Closed

WIP: better way to get python package metadata#21
rotu wants to merge 3 commits intocolcon:masterfrom
RoverRobotics-forks:better_metadata

Conversation

@rotu
Copy link
Copy Markdown
Contributor

@rotu rotu commented Aug 27, 2019

Instead of monkey-patching setup.py to harvest the args, use distutils.core.run_setup which returns the actual metadata, inclusive of cfg files.

@dirk-thomas
Copy link
Copy Markdown
Member

dirk-thomas commented Aug 27, 2019

Interesting, I didn't know about distutils.core.run_setup.

I tried using the function on some of the existing packages but it seems it has trouble even parsing some of the existing setup.cfg files: e.g. https://github.com/ros2/ros2cli/blob/9f2854465ee704ee9b6c58c91c286fef5939f411/ros2multicast/setup.cfg

If this approach works it might be better to replace the Python identification in colcon_core and get rid of this package altogether.

@rotu
Copy link
Copy Markdown
Contributor Author

rotu commented Aug 27, 2019

That package seems to work just fine for me. There are some gotchas:

  1. Some of the properties of the distribution object seem like they should work but don't (e.g. you need to use .get_name() or .metadata.name or dist.command_options['metadata']['name'][1] -- .name will seemingly always be 0).
  2. It only properly finds setuptools.cfg if it's in the cwd.
>>> os.chdir('/Users/dan/Downloads/ros2cli-9f2854465ee704ee9b6c58c91c286fef5939f411/ros2multicast')
>>> dist=run_setup('setup.py')
>>> dist.dump_option_dicts()
option dict for 'build_ext' command:
  {'include_dirs': ('/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/distutils.cfg',
                    '/usr/local/include:/usr/local/opt/openssl/include:/usr/local/opt/sqlite/include'),
   'library_dirs': ('/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/distutils.cfg',
                    '/usr/local/lib:/usr/local/opt/openssl/lib:/usr/local/opt/sqlite/lib')}
option dict for 'install' command:
  {'prefix': ('/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/distutils.cfg',
              '/usr/local')}
option dict for 'metadata' command:
  {'author': ('setup.cfg', 'Dirk Thomas'),
   'author_email': ('setup.cfg', 'dthomas@osrfoundation.org'),
   'classifiers': ('setup.cfg',
                   '\n'
                   'Environment :: Console\n'
                   'Intended Audience :: Developers\n'
                   'License :: OSI Approved :: Apache Software License\n'
                   'Programming Language :: Python'),
   'description': ('setup.cfg',
                   'The multicast command for ROS 2 command line tools.'),
   'keywords': ('setup.cfg', 'ros2cli'),
   'license': ('setup.cfg', 'Apache License, Version 2.0'),
   'long_description': ('setup.cfg', 'file: README.rst'),
   'maintainer': ('setup.cfg', 'Dirk Thomas'),
   'maintainer_email': ('setup.cfg', 'dthomas@osrfoundation.org'),
   'name': ('setup.cfg', 'ros2multicast'),
   'project_urls': ('setup.cfg',
                    '\n'
                    'GitHub = '
                    'https://github.com/ros2/ros2cli/tree/master/ros2multicast'),
   'version': ('setup.cfg', "'0.6.3'")}
option dict for 'options' command:
  {'install_requires': ('setup.cfg', '\nros2cli'),
   'packages': ('setup.cfg', 'find:'),
   'tests_require': ('setup.cfg', '\npytest\npytest-cov'),
   'zip_safe': ('setup.cfg', 'true')}
option dict for 'options.entry_points' command:
  {'ros2cli.command': ('setup.cfg',
                       '\n'
                       'multicast = '
                       'ros2multicast.command.multicast:MulticastCommand'),
   'ros2cli.extension_point': ('setup.cfg',
                               '\n'
                               'ros2multicast.verb = '
                               'ros2multicast.verb:VerbExtension'),
   'ros2multicast.verb': ('setup.cfg',
                          '\n'
                          'receive = ros2multicast.verb.receive:ReceiveVerb\n'
                          'send = ros2multicast.verb.send:SendVerb')}

@dirk-thomas

This comment has been minimized.

@rotu

This comment has been minimized.

@rotu

This comment has been minimized.

@dirk-thomas
Copy link
Copy Markdown
Member

I think you may have accidentally typed run_setup('setup.cfg') instead of run_setup('setup.py')

🤐 indeed, sorry for the noise...

If this approach works it might be better to replace the Python identification in colcon_core and get rid of this package altogether.

How about proceeding with this instead? Would you like to create a PR against colcon-core with a similar change or do you want me to do it?

@rotu
Copy link
Copy Markdown
Contributor Author

rotu commented Aug 27, 2019

How about proceeding with this instead? Would you like to create a PR against colcon-core with a similar change or do you want me to do it?

I'm working on it right now. Closing this PR in preference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants