Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract test dependencies from [options.extras_require]test #61

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions colcon_python_setup_py/package_augmentation/python_setup_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,22 @@ def augment_package( # noqa: D102

config = get_setup_information(setup_py)

for dependency_type, option_name in [
mapping = {
('build', 'setup_requires'),
('run', 'install_requires'),
('test', 'tests_require')
]:
desc.dependencies[dependency_type] = {
create_dependency_descriptor(d)
for d in config.get(option_name) or ()}
('test', 'tests_require'),
}
_map_dependencies(config, mapping, desc.dependencies)

extras_mapping = {
('test', 'test'),
('test', 'tests'),
('test', 'testing'),
}
_map_dependencies(
config.get('extras_require') or {},
extras_mapping,
desc.dependencies)

def getter(env):
nonlocal setup_py
Expand All @@ -53,3 +61,11 @@ def getter(env):
desc.metadata['get_python_setup_options'] = getter

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


def _map_dependencies(options, mapping, dependencies):
for dependency_type, option_name in mapping:
dependencies.setdefault(dependency_type, set())
dependencies[dependency_type].update(
create_dependency_descriptor(d)
for d in options.get(option_name) or ())
7 changes: 7 additions & 0 deletions test/test_package_identification_python_setup_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ def test_identify():
" 'runB',\n"
' ],\n'
' zip_safe=False,\n'
' extras_require={\n'
" 'test': ['test2 == 3.0.0'],\n"
" 'tests': ['test3'],\n"
" 'testing': ['test4'],\n"
" 'other': ['not-test'],\n"
' },\n'
')\n')
_setup_information_cache.clear()
assert extension.identify(desc) is None
Expand All @@ -87,3 +93,4 @@ def test_identify():
assert desc.dependencies['run'] == {'runA', 'runB'}
dep = next(x for x in desc.dependencies['run'] if x == 'runA')
assert dep.metadata['version_gt'] == '1.2.3'
assert desc.dependencies['test'] == {'test2', 'test3', 'test4'}
Loading