Skip to content

Commit 7caab97

Browse files
authored
move Python dependencies and metadata extraction from identification to augmentation module (#40)
* duplicate Python identification module for augmentation * move Python dependencies and metadata extraction from identification to augmentation module
1 parent 7214429 commit 7caab97

File tree

4 files changed

+57
-20
lines changed

4 files changed

+57
-20
lines changed

colcon_python_setup_py/package_augmentation/__init__.py

Whitespace-only changes.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2016-2018 Dirk Thomas
2+
# Licensed under the Apache License, Version 2.0
3+
4+
from colcon_core.package_augmentation \
5+
import PackageAugmentationExtensionPoint
6+
from colcon_core.package_augmentation.python import \
7+
create_dependency_descriptor
8+
from colcon_core.plugin_system import satisfies_version
9+
from colcon_python_setup_py.package_identification.python_setup_py import \
10+
get_setup_information
11+
12+
13+
class PythonPackageAugmentation(PackageAugmentationExtensionPoint):
14+
"""Augment Python packages with information from `setup.py` files."""
15+
16+
# the priority needs to be lower than the extensions augmenting packages
17+
# using the setup.cfg file
18+
PRIORITY = 90
19+
20+
def __init__(self): # noqa: D107
21+
super().__init__()
22+
satisfies_version(
23+
PackageAugmentationExtensionPoint.EXTENSION_POINT_VERSION,
24+
'^1.0')
25+
26+
def augment_package(
27+
self, desc, *, additional_argument_names=None
28+
): # noqa: D102
29+
if desc.type != 'python':
30+
return
31+
if 'get_python_setup_options' in desc.metadata:
32+
return
33+
34+
setup_py = desc.path / 'setup.py'
35+
if not setup_py.is_file():
36+
return
37+
38+
config = get_setup_information(setup_py)
39+
40+
for dependency_type, option_name in [
41+
('build', 'setup_requires'),
42+
('run', 'install_requires'),
43+
('test', 'tests_require')
44+
]:
45+
desc.dependencies[dependency_type] = {
46+
create_dependency_descriptor(d)
47+
for d in config[option_name] or ()}
48+
49+
def getter(env):
50+
nonlocal setup_py
51+
return get_setup_information(setup_py, env=env)
52+
53+
desc.metadata['get_python_setup_options'] = getter
54+
55+
desc.metadata['version'] = config['metadata'].get('version')

colcon_python_setup_py/package_identification/python_setup_py.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ def identify(self, desc): # noqa: D102
4747

4848
config = get_setup_information(setup_py)
4949

50-
if desc.type is not None and desc.type != 'python':
51-
logger.error('Package type already set to different value')
52-
raise RuntimeError('Package type already set to different value')
5350
desc.type = 'python'
5451

5552
name = config['metadata'].get('name')
@@ -65,23 +62,6 @@ def identify(self, desc): # noqa: D102
6562
raise RuntimeError('Package name already set to different value')
6663
desc.name = name
6764

68-
for dependency_type, option_name in [
69-
('build', 'setup_requires'),
70-
('run', 'install_requires'),
71-
('test', 'tests_require')
72-
]:
73-
desc.dependencies[dependency_type] = {
74-
create_dependency_descriptor(d)
75-
for d in config[option_name] or ()}
76-
77-
def getter(env):
78-
nonlocal setup_py
79-
return get_setup_information(setup_py, env=env)
80-
81-
desc.metadata['get_python_setup_options'] = getter
82-
83-
desc.metadata['version'] = config['metadata'].get('version')
84-
8565

8666
cwd_lock = None
8767

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ filterwarnings =
5252
junit_suite_name = colcon-python-setup-py
5353

5454
[options.entry_points]
55+
colcon_core.package_augmentation =
56+
python_setup_py = colcon_python_setup_py.package_augmentation.python_setup_py:PythonPackageAugmentation
5557
colcon_core.package_identification =
5658
python_setup_py = colcon_python_setup_py.package_identification.python_setup_py:PythonPackageIdentification
5759

0 commit comments

Comments
 (0)