Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
checks that a path is not in sys.path for unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Sep 21, 2017
1 parent 64a36f1 commit 4fe2535
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/pymyinstall/packaged/automate_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,26 @@ def reorder_module_list(list_module):
return res


class FileShouldNotBeFound(Exception):
"""
Raised by function @see fn check_sys_path.
"""
pass


def check_sys_path():
"""
An issue is happening during unit test as pymyinstall
could be imported from two locations. We check this is
not the case.
"""
exp = "pymyinstall_ut_skip_pyquickhelper_%d%d_std" % sys.version_info[:2]
for path in sys.path:
if exp in path:
raise FileShouldNotBeFound(
"'{0}' was found in sys.path:\n{1}".format(path, "\n".join(sys.path)))


def update_all(temp_folder=".", fLOG=print, verbose=True,
list_module=None, reorder=True,
skip_module=None, schedule_only=False,
Expand Down Expand Up @@ -148,6 +168,7 @@ def update_all(temp_folder=".", fLOG=print, verbose=True,
It can be due to python keeping in memory an updated module.
Parameters *source*, *download_only* were added.
"""
check_sys_path()
if not os.path.exists(temp_folder):
os.makedirs(temp_folder)
if not has_pip():
Expand All @@ -171,6 +192,7 @@ def update_all(temp_folder=".", fLOG=print, verbose=True,
mod, str) else mod for mod in list_module]

list_module = [_ for _ in list_module if _.name not in skip_module]
check_sys_path()

if reorder:
list_module = reorder_module_list(list_module)
Expand All @@ -186,6 +208,7 @@ def update_all(temp_folder=".", fLOG=print, verbose=True,
errors = []
schedule = []
for mod in modules:
check_sys_path()
is_installed = mod.is_installed_version()
if not is_installed:
continue
Expand Down Expand Up @@ -286,6 +309,7 @@ def install_all(temp_folder=".", fLOG=print, verbose=True,
.. versionadded:: 1.1
"""
check_sys_path()
fLOG("[install_all] begin, exe:", sys.executable)
if _memory is None:
_memory = {}
Expand Down Expand Up @@ -313,6 +337,7 @@ def install_all(temp_folder=".", fLOG=print, verbose=True,
mod, str) else mod for mod in list_module]

list_module = [_ for _ in list_module if _.name not in skip_module]
check_sys_path()

if reorder:
list_module = reorder_module_list(list_module)
Expand All @@ -329,6 +354,7 @@ def install_all(temp_folder=".", fLOG=print, verbose=True,
schedule = []
out_streams_module = {}
for mod in modules:
check_sys_path()
if mod.name in _memory:
# already done
continue
Expand Down Expand Up @@ -450,6 +476,7 @@ def install_module_deps(name, temp_folder=".", fLOG=print, verbose=True, deps=Tr
.. versionadded:: 1.1
"""
check_sys_path()
if _memory is None:
_memory = {}
deps = deps or deep_deps
Expand All @@ -466,6 +493,7 @@ def install_module_deps(name, temp_folder=".", fLOG=print, verbose=True, deps=Tr

stack = [name]
while len(stack) > 0:
check_sys_path()
name = stack[-1]
del stack[-1]
if name in _memory:
Expand Down Expand Up @@ -535,7 +563,7 @@ def update_module(module_name, temp_folder=".", fLOG=print, verbose=True,
reorder=True, skip_module=None, schedule_only=False,
source=None):
"""
Update modules in *list_module*
Updates modules in *list_module*
if None, this list will be returned by @see fn ensae_fullset,
the function starts by updating pip.
Expand All @@ -560,7 +588,7 @@ def download_module(module_name,
unzipFile=True, file_save=None, deps=False,
source=None, fLOG=print):
"""
download the module without installation
Downloads the module without installation.
@param temp_folder destination
@param force force the installation even if already installed
Expand Down

0 comments on commit 4fe2535

Please sign in to comment.