Skip to content

Commit e17f0ff

Browse files
committed
Expose errors encountered by the setup script
1 parent 11d9c77 commit e17f0ff

File tree

1 file changed

+52
-33
lines changed

1 file changed

+52
-33
lines changed

colcon_core/package_identification/python.py

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Copyright 2019 Rover RObotics
12
# Copyright 2016-2019 Dirk Thomas
23
# Licensed under the Apache License, Version 2.0
34

@@ -29,7 +30,11 @@ def identify(self, desc): # noqa: D102
2930
if not setup_py.is_file():
3031
return
3132

32-
config = get_setup_result(setup_py)
33+
try:
34+
config = get_setup_result(setup_py)
35+
except Exception as e:
36+
logger.warning(e)
37+
return
3338

3439
if 'metadata' not in config:
3540
return
@@ -78,13 +83,19 @@ def get_setup_result(setup_py, env=None):
7883
)
7984
p.start()
8085
p.join()
81-
if p.exitcode:
82-
logger.warning("Python setup script '%s' terminated with exit code %d",
83-
setup_py, p.exitcode)
8486

8587
if not conn_recv.poll():
86-
raise RuntimeError('No results available from Python setup script')
87-
return conn_recv.recv()
88+
raise RuntimeError('Python setup script "%s" did not return any data',
89+
setup_py)
90+
91+
result_or_error = conn_recv.recv()
92+
conn_recv.close()
93+
94+
if isinstance(result_or_error, dict):
95+
return result_or_error
96+
else:
97+
raise RuntimeError('Python setup script "%s" failed"',
98+
setup_py) from result_or_error
8899

89100

90101
def _get_setup_result_target(setup_py, env, conn_send):
@@ -95,35 +106,43 @@ def _get_setup_result_target(setup_py, env, conn_send):
95106
96107
:param setup_py: path to a setup.py script
97108
:param env: environment variables to set before running setup.py
98-
:param conn_send: Connection to send the results dictionary
109+
:param conn_send: Connection to send the result as either a dict or
110+
an Exception.
99111
:return: None. Results are transmitted via conn_send.
100112
"""
101-
import os
102-
import distutils.core
103-
104-
# need to be in setup.py's parent dir to detect any setup.cfg
105-
os.chdir(os.path.dirname(setup_py))
106-
107-
# don't worry - the environments of functions called with
108-
# subprocess.Process don't leak into each other
109-
if env is not None:
110-
os.environ.update(env)
111-
112-
result = distutils.core.run_setup(str(setup_py), stop_after='commandline')
113-
114-
# could just return all attrs in result.__dict__, but we take this
115-
# opportunity to filter a few things that don't need to be there
116-
conn_send.send({
117-
attr: value for attr, value in result.__dict__.items()
118-
if (
119-
# These *seem* useful but always have the value 0.
120-
# Look for their values in the 'metadata' object instead.
121-
attr not in result.display_option_names
122-
# Getter methods
123-
and not callable(value)
124-
# Private properties
125-
and not attr.startswith('_')
126-
)})
113+
try:
114+
import os
115+
import distutils.core
116+
117+
# need to be in setup.py's parent dir to detect any setup.cfg
118+
os.chdir(os.path.dirname(setup_py))
119+
120+
# don't worry - the environments of functions called with
121+
# subprocess.Process don't leak into each other
122+
if env is not None:
123+
os.environ.update(env)
124+
125+
result = distutils.core.run_setup(
126+
str(setup_py),
127+
stop_after='commandline')
128+
129+
# could just return all attrs in result.__dict__, but we take this
130+
# opportunity to filter a few things that don't need to be there
131+
conn_send.send({
132+
attr: value for attr, value in result.__dict__.items()
133+
if (
134+
# These *seem* useful but always have the value 0.
135+
# Look for their values in the 'metadata' object instead.
136+
attr not in result.display_option_names
137+
# Getter methods
138+
and not callable(value)
139+
# Private properties
140+
and not attr.startswith('_')
141+
)})
142+
except Exception as e:
143+
conn_send.send(e)
144+
finally:
145+
conn_send.close()
127146

128147

129148
def create_dependency_descriptor(requirement_string):

0 commit comments

Comments
 (0)