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

Commit

Permalink
update cli, add unit test, add new modules
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Mar 27, 2016
1 parent cccb7b1 commit 6944484
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 20 deletions.
86 changes: 86 additions & 0 deletions _unittests/ut_cli/test_pymy_install_cli.py
@@ -0,0 +1,86 @@
# coding: latin-1
"""
@brief test log(time=1s)
"""

import sys
import os
import unittest

try:
import src
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..")))
if path not in sys.path:
sys.path.append(path)
import src

try:
import pyquickhelper as skip_
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..",
"..",
"pyquickhelper",
"src")))
if path not in sys.path:
sys.path.append(path)
if "PYQUICKHELPER" in os.environ and len(os.environ["PYQUICKHELPER"]) > 0:
sys.path.append(os.environ["PYQUICKHELPER"])
import pyquickhelper as skip_


from src.pymyinstall.installhelper.install_cmd_helper import run_cmd
from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import get_temp_folder


class TestPyMyInstallCli(unittest.TestCase):

def test_install_set_schedule(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")

this = os.path.abspath(os.path.dirname(__file__))
script = os.path.normpath(os.path.join(
this, "..", "..", "src", "pymyinstall", "cli", "pymy_install.py"))
cmd = "{0} {1} {2}".format(
sys.executable, script, "--set=pyquickhelper --schedule")
out, err = run_cmd(cmd, wait=True, do_not_log=True)
assert len(out) > 0

def test_install_download(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")

temp = get_temp_folder(__file__, "temp_install_download")
this = os.path.abspath(os.path.dirname(__file__))
script = os.path.normpath(os.path.join(
this, "..", "..", "src", "pymyinstall", "cli", "pymy_install.py"))
cmd = "{0} {1} {2} --force --folder={3}".format(
sys.executable, script, "colorama xlrd --download", temp)
out, err = run_cmd(cmd, wait=True, do_not_log=True)
fLOG("----", cmd)
fLOG(out.replace("\r", "").replace("\n\n", "\n"))
fLOG("-----")
fLOG(err.replace("\r", "").replace("\n\n", "\n"))
assert "downloaded modules" in out
content = os.listdir(temp)
self.assertEqual(len(content), 2)


if __name__ == "__main__":
unittest.main()
64 changes: 64 additions & 0 deletions _unittests/ut_cli/test_pymy_update_cli.py
@@ -0,0 +1,64 @@
# coding: latin-1
"""
@brief test log(time=1s)
"""

import sys
import os
import unittest

try:
import src
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..")))
if path not in sys.path:
sys.path.append(path)
import src

try:
import pyquickhelper as skip_
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..",
"..",
"pyquickhelper",
"src")))
if path not in sys.path:
sys.path.append(path)
if "PYQUICKHELPER" in os.environ and len(os.environ["PYQUICKHELPER"]) > 0:
sys.path.append(os.environ["PYQUICKHELPER"])
import pyquickhelper as skip_


from src.pymyinstall.installhelper.install_cmd_helper import run_cmd
from pyquickhelper.loghelper import fLOG


class TestPyMyUpdateCli(unittest.TestCase):

def test_update_set_schedule(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")

this = os.path.abspath(os.path.dirname(__file__))
script = os.path.normpath(os.path.join(
this, "..", "..", "src", "pymyinstall", "cli", "pymy_update.py"))
cmd = "{0} {1} {2}".format(
sys.executable, script, "--set=pyquickhelper --schedule")
out, err = run_cmd(cmd, wait=True, do_not_log=True)
assert len(out) > 0


if __name__ == "__main__":
unittest.main()
7 changes: 6 additions & 1 deletion _unittests/ut_install/test_download_pycrypto.py
Expand Up @@ -51,8 +51,13 @@ def test_install_pycrypto(self):
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")

if sys.platform.startswith("win") and sys.version_info[0] == 2:
# no pycrypto on Python 2.7 for Windows
return

fold = os.path.abspath(os.path.split(__file__)[0])
temp = os.path.join(fold, "temp_download_lxml")
temp = os.path.join(fold, "temp_download_pycrypto")
if not os.path.exists(temp):
os.mkdir(temp)
for _ in os.listdir(temp):
Expand Down
21 changes: 17 additions & 4 deletions src/pymyinstall/cli/pymy_install.py
Expand Up @@ -49,6 +49,14 @@ def get_parser():
'--schedule',
action='store_true',
help='do not install the modules, returned the list scheduled to be installed')
parser.add_argument(
'--force',
action='store_true',
help='install or download even the module is already installed')
parser.add_argument(
'--download',
action='store_true',
help='do not install the modules but download them')
parser.add_argument(
'-t',
'--task',
Expand All @@ -71,7 +79,8 @@ def do_main(temp_folder="build/update_modules",
skip_module=None, # ["ete", "dataspyre", "pycuda", "cubehelix"],
list_module=None, deps=False, schedule_only=False,
deep_deps=False, checkings=None,
task="install", source=None):
task="install", source=None, download_only=False,
force=False):
"""
calls function @see fn install_all but is meant to be added to scripts folder
Expand All @@ -86,11 +95,13 @@ def do_main(temp_folder="build/update_modules",
``""``, ``matplotlib``, ``100,end``,
option *download* is equivalent to *checkings*
@param source overwrite the source of the wheel
@param download_only only download the modules, no installation
@param force force the download or the installation
If *deps* is True, *list_module* cannot be empty.
.. versionchanged:: 1.1
Parameter *source* was added.
Parameters *source*, *force* were added.
"""
try:
from pymyinstall import is_travis_or_appveyor
Expand Down Expand Up @@ -154,7 +165,8 @@ def to_int(s):
res = install_all(temp_folder=temp_folder, verbose=True,
skip_module=skip_module, list_module=list_module, deps=deps,
schedule_only=schedule_only,
deep_deps=deep_deps, source=source)
deep_deps=deep_deps, source=source,
download_only=download_only, force=force)
if schedule_only:
print("SCHEDULED")
for r in res:
Expand Down Expand Up @@ -198,7 +210,8 @@ def main():
do_main(temp_folder=res.folder, skip_module=skip_module,
list_module=list_module, deps=res.deps, schedule_only=res.schedule,
deep_deps=res.deep_deps, checkings=res.check, task=res.task,
source=res.source if res.source else None)
source=res.source if res.source else None,
download_only=res.download, force=res.force)


if __name__ == "__main__":
Expand Down
50 changes: 35 additions & 15 deletions src/pymyinstall/packaged/automate_install.py
Expand Up @@ -108,7 +108,7 @@ def reorder_module_list(list_module):
def update_all(temp_folder=".", fLOG=print, verbose=True,
list_module=None, reorder=True,
skip_module=None, schedule_only=False,
source=None):
source=None, download_only=False):
"""
update modules in *list_module*
if None, this list will be returned by @see fn ensae_fullset,
Expand All @@ -122,6 +122,7 @@ def update_all(temp_folder=".", fLOG=print, verbose=True,
@param skip_module module to skip (list of str)
@param schedule_only if True, the function returns the list of modules scheduled to be installed
@param source overwrite the wheels location, see @see me get_exewheel_url_link2
@param download_only only downloads the module, no installation
*list_module* can be a set of modules of a name set.
Name sets can be accesses by function @see fn get_package_set.
Expand All @@ -131,7 +132,7 @@ def update_all(temp_folder=".", fLOG=print, verbose=True,
Catch an exception while updating modules and walk through the end of the list.
The function should be run a second time to make sure an exception remains.
It can be due to python keeping in memory an updated module.
Parameter *source* was added.
Parameters *source*, *download_only* were added.
"""
if not os.path.exists(temp_folder):
os.makedirs(temp_folder)
Expand Down Expand Up @@ -196,8 +197,11 @@ def update_all(temp_folder=".", fLOG=print, verbose=True,
.format(mod.name, inst, ver, mod.kind)
fLOG(m)
try:
b = mod.update(temp_folder=temp_folder,
log=verbose, source=source)
if download_only:
b = mod.download(temp_folder=temp_folder, source=source)
else:
b = mod.update(temp_folder=temp_folder,
log=verbose, source=source)
except (SystemExit, Exception) as e:
b = False
m = " - failed to update module {0} --- {1} --> {2} (kind={3}) due to {4} ({5})" \
Expand Down Expand Up @@ -225,7 +229,8 @@ def install_all(temp_folder=".", fLOG=print, verbose=True,
list_module=None, reorder=True, skip_module=None,
up_pip=True, skip_missing=False, deps=False,
schedule_only=False, deep_deps=False,
_memory=None, source=None):
_memory=None, source=None, download_only=False,
force=False):
"""
install modules in *list_module*
if None, this list will be returned by @see fn ensae_fullset,
Expand All @@ -244,6 +249,8 @@ def install_all(temp_folder=".", fLOG=print, verbose=True,
@param deep_deps check dependencies for dependencies
@param _memory stores installed packages, avoid going into an infinite loop
@param source overwrite the location of the wheels, see @see me get_exewheel_url_link2
@param download_only only downloads the module, no installation
@param force force the installation or the download
*list_module* can be a set of modules of a name set.
Name sets can be accesses by function @see fn get_package_set.
Expand Down Expand Up @@ -306,7 +313,7 @@ def install_all(temp_folder=".", fLOG=print, verbose=True,
continue
if verbose:
fLOG("[loopi] check module: ", mod.name)
if not mod.is_installed_version():
if force or not mod.is_installed_version():
schedule.append(mod)
if not schedule_only:
ver = mod.version
Expand All @@ -317,11 +324,16 @@ def install_all(temp_folder=".", fLOG=print, verbose=True,
fLOG("[loopi] check dependencies: ", mod.name)
install_module_deps(mod.name, temp_folder=temp_folder,
fLOG=fLOG, verbose=verbose, deps=deps, deep_deps=deep_deps,
_memory=_memory, source=source)
_memory=_memory, source=source, download_only=download_only,
force=force)
else:
try:
b = mod.install(temp_folder=temp_folder,
log=verbose, source=source)
if download_only:
b = mod.download(
temp_folder=temp_folder, source=source)
else:
b = mod.install(temp_folder=temp_folder,
log=verbose, source=source)
except (SystemExit, Exception) as e:
b = False
m = " - failed to update module {0} --- {1} --> {2} (kind={3}) due to {4} ({5})" \
Expand All @@ -338,7 +350,7 @@ def install_all(temp_folder=".", fLOG=print, verbose=True,

if verbose:
fLOG("")
fLOG("installed modules")
fLOG("downloaded modules" if download_only else "installed modules")
for m in again:
fLOG(" ", m)
if len(errors) > 0:
Expand All @@ -355,7 +367,8 @@ def install_all(temp_folder=".", fLOG=print, verbose=True,


def install_module_deps(name, temp_folder=".", fLOG=print, verbose=True, deps=True,
deep_deps=False, _memory=None, source=None):
deep_deps=False, _memory=None, source=None,
download_only=False, force=False):
"""
install a module with its dependencies,
if a module is already installed, it installs the missing dependencies
Expand All @@ -368,6 +381,8 @@ def install_module_deps(name, temp_folder=".", fLOG=print, verbose=True, deps=Tr
@param deep_deps check dependencies for dependencies
@param _memory stores installed packages, avoid going into an infinite loop
@param source overwrite the wheels location, see @see me get_exewheel_url_link2
@param download_only only downloads the module, no installation
@param force force the download or the update
@return list of installed modules
The function does not handle properly contraints on versions.
Expand All @@ -386,7 +401,8 @@ def install_module_deps(name, temp_folder=".", fLOG=print, verbose=True, deps=Tr
install_all(temp_folder=temp_folder, fLOG=fLOG, verbose=verbose,
list_module=[name], reorder=True, up_pip=False,
skip_missing=True, _memory=memory2, deps=False,
deep_deps=False, source=source)
deep_deps=False, source=source, download_only=download_only,
force=force)
installed.append(name)

stack = [name]
Expand All @@ -410,7 +426,7 @@ def install_module_deps(name, temp_folder=".", fLOG=print, verbose=True, deps=Tr
install_all(temp_folder=temp_folder, fLOG=fLOG, verbose=verbose,
list_module=inst, reorder=True, up_pip=False,
skip_missing=True, deep_deps=deep_deps,
_memory=_memory, source=source)
_memory=_memory, source=source, download_only=download_only)
stack.extend(inst)
installed.extend(inst)
for i in inst:
Expand All @@ -423,7 +439,8 @@ def install_module(module_name, temp_folder=".", fLOG=print, verbose=True,
reorder=True, skip_module=None,
up_pip=True, skip_missing=False, deps=False,
schedule_only=False, deep_deps=False,
_memory=None, source=None):
_memory=None, source=None, download_only=False,
force=False):
"""
install a module
Expand All @@ -440,6 +457,8 @@ def install_module(module_name, temp_folder=".", fLOG=print, verbose=True,
@param deep_deps check dependencies for dependencies
@param _memory stores installed packages, avoid going into an infinite loop
@param source overwrite the wheels location, see @see me get_exewheel_url_link2
@param download_only only downloads the module, no installation
@param force force the download or the install
.. versionadded:: 1.1
"""
Expand All @@ -449,7 +468,8 @@ def install_module(module_name, temp_folder=".", fLOG=print, verbose=True,
verbose=verbose, reorder=reorder, skip_module=skip_module,
up_pip=up_pip, skip_missing=skip_missing, deps=deps,
schedule_only=schedule_only, deep_deps=deep_deps,
_memory=_memory, source=source)
_memory=_memory, source=source, download_only=download_only,
force=force)


def update_module(module_name, temp_folder=".", fLOG=print, verbose=True,
Expand Down

0 comments on commit 6944484

Please sign in to comment.