diff --git a/kibot/dep_downloader.py b/kibot/dep_downloader.py index 89cde6af..982ad54a 100644 --- a/kibot/dep_downloader.py +++ b/kibot/dep_downloader.py @@ -235,10 +235,12 @@ def check_pip(): def pip_install(pip_command, dest=None, name='.'): - cmd = [pip_command, 'install', '-U', '--no-warn-script-location', - # This is what -U (--user) means, but Debian's pip installs to /usr/local when used by root - '--root', os.path.dirname(site.USER_BASE), '--prefix', os.path.basename(site.USER_BASE), - name] + cmd = [pip_command, 'install', '-U', '--no-warn-script-location'] + if name == '.': + # Applied only when installing a downloaded tarball + # This is what -U (--user) means, but Debian's pip installs to /usr/local when used by root + cmd.extend(['--root', os.path.dirname(site.USER_BASE), '--prefix', os.path.basename(site.USER_BASE)]) + cmd.append(name) logger.debug('- Running: {}'.format(cmd)) try: res_run = subprocess.run(cmd, check=True, capture_output=True, cwd=dest) @@ -708,9 +710,10 @@ def check_tool_python(dep, reload=False): return None # Check we can use it try: + importlib.invalidate_caches() mod = importlib.import_module(dep.module_name) res = check_tool_python_version(mod, dep) - if res is not None and reload is not None: + if res is not None and reload: res = importlib.reload(reload) return res except ModuleNotFoundError: diff --git a/tests/test_plot/test_dep_downloader.py b/tests/test_plot/test_dep_downloader.py index 17c0abe5..7803d5f5 100644 --- a/tests/test_plot/test_dep_downloader.py +++ b/tests/test_plot/test_dep_downloader.py @@ -49,6 +49,8 @@ def try_dependency(ctx, caplog, monkeypatch, docstring, name_dep, downloader_nam def try_dependency_module(ctx, caplog, monkeypatch, docstring, name_dep, downloader_name): + # Note: every attempt to install in a chosen dir failed, even when the module was there and in the sys.path the + # importlib call miserably failed. with monkeypatch.context(): # Refresh the module with actual dependencies mod = importlib.reload(downloader) @@ -60,7 +62,7 @@ def try_dependency_module(ctx, caplog, monkeypatch, docstring, name_dep, downloa cov.start() # Python module downloader_func = getattr(mod, downloader_name) - res = downloader_func(dep, False) + res = downloader_func(dep) cov.stop() cov.save() # We should get the following name: