Skip to content

Commit b5e6997

Browse files
authored
Fix error on inline comments in Python dependencies (#708)
It appears that the distlib parsing function we're using here can't handle inline comments and raises a syntax error. After digging into the setuptools sources, it appears that these comments are dropped between parsing the file and parsing the individual dependencies, so we can do the same.
1 parent 7230e18 commit b5e6997

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

colcon_core/package_augmentation/python.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ def create_dependency_descriptor(requirement_string):
121121
'<': 'version_lt',
122122
}
123123

124+
# Drop inline comments
125+
requirement_string = requirement_string.partition(' #')[0]
126+
124127
requirement = parse_requirement(requirement_string)
125128
metadata = {
126129
'origin': 'python',

test/test_package_identification_python.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,7 @@ def test_create_dependency_descriptor():
161161
dep = create_dependency_descriptor(multi_str)
162162
assert dep.metadata['version_gte'] == '2.2.0'
163163
assert dep.metadata['version_lte'] == '3.2.0'
164+
165+
commented_str = 'pkgname # This is needed for foo'
166+
dep = create_dependency_descriptor(commented_str)
167+
assert dep.name == 'pkgname'

0 commit comments

Comments
 (0)