Fix bootstrap from sources

#24095 introduced a couple of bugs, which are fixed here:

1. The module path is computed incorrectly for bootstrapped clingo
2. We remove too many paths for `sys.path` in case of failures
This commit is contained in:
Massimiliano Culpo 2021-07-21 14:05:49 +02:00 committed by Todd Gamblin
parent 9237a9f244
commit a68abc15c5

View File

@ -93,15 +93,14 @@ def make_module_available(module, spec=None, install=False):
for ispec in installed_specs: for ispec in installed_specs:
# TODO: make sure run-environment is appropriate # TODO: make sure run-environment is appropriate
module_path = os.path.join(ispec.prefix, module_path = ispec['python'].package.get_python_lib(prefix=ispec.prefix)
ispec['python'].package.site_packages_dir)
try: try:
sys.path.append(module_path) sys.path.append(module_path)
__import__(module) __import__(module)
return return
except ImportError: except ImportError:
tty.warn("Spec %s did not provide module %s" % (ispec, module)) tty.warn("Spec %s did not provide module %s" % (ispec, module))
sys.path = sys.path[:-2] sys.path = sys.path[:-1]
def _raise_error(module_name, module_spec): def _raise_error(module_name, module_spec):
error_msg = 'cannot import module "{0}"'.format(module_name) error_msg = 'cannot import module "{0}"'.format(module_name)
@ -118,14 +117,13 @@ def _raise_error(module_name, module_spec):
spec.concretize() spec.concretize()
spec.package.do_install() spec.package.do_install()
module_path = os.path.join(spec.prefix, module_path = spec['python'].package.get_python_lib(prefix=spec.prefix)
spec['python'].package.site_packages_dir)
try: try:
sys.path.append(module_path) sys.path.append(module_path)
__import__(module) __import__(module)
return return
except ImportError: except ImportError:
sys.path = sys.path[:-2] sys.path = sys.path[:-1]
_raise_error(module, spec) _raise_error(module, spec)