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

Commit

Permalink
add script to a get a status on the current distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Dec 4, 2016
1 parent b8c1a4c commit 9318159
Show file tree
Hide file tree
Showing 15 changed files with 393 additions and 30 deletions.
2 changes: 1 addition & 1 deletion _unittests/ut_cli/test_pymy_deps_cli.py
Expand Up @@ -57,7 +57,7 @@ def test_install_deps(self):
this = os.path.abspath(os.path.dirname(__file__))
script = os.path.normpath(os.path.join(
this, "..", "..", "src", "pymyinstall", "cli", "pymy_deps.py"))
cmd = "{0} {1} {2}".format(
cmd = "{0} -u {1} {2}".format(
sys.executable, script, "pandas")
try:
out, err = run_cmd(cmd, wait=True, fLOG=fLOG,
Expand Down
4 changes: 2 additions & 2 deletions _unittests/ut_cli/test_pymy_install_cli.py
@@ -1,5 +1,5 @@
"""
@brief test log(time=7s)
@brief test log(time=23s)
"""

import sys
Expand Down Expand Up @@ -58,7 +58,7 @@ def test_install_set_schedule(self):
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(
cmd = "{0} -u {1} {2}".format(
sys.executable, script, "--set=pyquickhelper --schedule")
try:
out, err = run_cmd(cmd, wait=True, fLOG=fLOG,
Expand Down
4 changes: 2 additions & 2 deletions _unittests/ut_cli/test_pymy_install_cli_tool.py
@@ -1,5 +1,5 @@
"""
@brief test log(time=1s)
@brief test log(time=32s)
"""

import sys
Expand Down Expand Up @@ -59,7 +59,7 @@ def test_install_tool(self):
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(
cmd = "{0} -u {1} {2} --force --folder={3}".format(
sys.executable, script, "graphviz --task=tool --source=zip", temp)
out, err = run_cmd(cmd, wait=True)
fLOG("----", cmd)
Expand Down
84 changes: 84 additions & 0 deletions _unittests/ut_cli/test_pymy_status_cli.py
@@ -0,0 +1,84 @@
"""
@brief test log(time=7s)
"""

import sys
import os
import unittest
import warnings


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 is_travis_or_appveyor, get_temp_folder


class TestPyMyStatusCli(unittest.TestCase):

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

if is_travis_or_appveyor() == "travis":
warnings.warn("run_cmd no end on travis")
return
temp = get_temp_folder(__file__, "temp_status")
outfile = os.path.join(temp, "modules.xlsx")
this = os.path.abspath(os.path.dirname(__file__))
script = os.path.normpath(os.path.join(
this, "..", "..", "src", "pymyinstall", "cli", "pymy_status.py"))
cmd = "{0} -u {1} {2}".format(
sys.executable, script, "numpy --out={0}".format(outfile))
fLOG(cmd)
out, err = run_cmd(cmd, wait=True)
if len(out) == 0:
if is_travis_or_appveyor() == "appveyor":
warnings.warn(
"CLI ISSUE cmd:\n{0}\nOUT:\n{1}\nERR\n{2}".format(cmd, out, err))
else:
raise Exception(
"cmd:\n{0}\nOUT:\n{1}\nERR\n{2}".format(cmd, out, err))
if len(err) > 0:
raise Exception(
"cmd:\n{0}\nOUT:\n{1}\nERR\n{2}".format(cmd, out, err))
if not os.path.exists(outfile):
raise Exception(outfile)
fLOG(out)


if __name__ == "__main__":
unittest.main()
4 changes: 2 additions & 2 deletions _unittests/ut_cli/test_pymy_update_cli.py
@@ -1,5 +1,5 @@
"""
@brief test log(time=1s)
@brief test log(time=63s)
"""

import sys
Expand Down Expand Up @@ -59,7 +59,7 @@ def test_update_set_schedule(self):
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(
cmd = "{0} -u {1} {2}".format(
sys.executable, script, "--set=pyquickhelper --schedule")
out, err = run_cmd(cmd, wait=True)
if len(out) == 0:
Expand Down
2 changes: 1 addition & 1 deletion _unittests/ut_cli/test_script_install_cli.py
@@ -1,5 +1,5 @@
"""
@brief test log(time=2s)
@brief test log(time=20s)
skip this test for regular run
"""
Expand Down
70 changes: 70 additions & 0 deletions _unittests/ut_install/test_status_helper.py
@@ -0,0 +1,70 @@
"""
@brief test log(time=20s)
"""

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 import get_installed_modules
from pyquickhelper.loghelper import fLOG


class TestStatusHelper(unittest.TestCase):

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

res = get_installed_modules(
fLOG=fLOG, stop=10, pypi=True, short_list=["numpy"])
for f in res:
fLOG(f)
self.assertEqual(len(res), 1)

res = get_installed_modules(
fLOG=fLOG, stop=10, pypi=True, short_list=["dataspyre"])
fLOG(res)

res = get_installed_modules(fLOG=fLOG, stop=10, pypi=True)
for f in res:
fLOG(f)
self.assertEqual(len(res), 10)


if __name__ == "__main__":
unittest.main()
3 changes: 3 additions & 0 deletions setup.py
Expand Up @@ -213,19 +213,22 @@ def write_version():
'pymy_update3 = pymyinstall.cli.pymy_update:main',
'pymy_install3 = pymyinstall.cli.pymy_install:main',
'pymy_deps3 = pymyinstall.cli.pymy_deps:main',
'pymy_status3 = pymyinstall.cli.pymy_status:main',
]}
if sys.platform.startswith("win"):
entry_points['console_scripts'].extend([
'pymy_update = pymyinstall.cli.pymy_update:main',
'pymy_install = pymyinstall.cli.pymy_install:main',
'pymy_deps = pymyinstall.cli.pymy_deps:main',
'pymy_status = pymyinstall.cli.pymy_status:main',
])
else:
entry_points = {
'console_scripts': [
'pymy_update = pymyinstall.cli.pymy_update:main',
'pymy_install = pymyinstall.cli.pymy_install:main',
'pymy_deps = pymyinstall.cli.pymy_deps:main',
'pymy_status = pymyinstall.cli.pymy_status:main',
]}

setup(
Expand Down
2 changes: 1 addition & 1 deletion src/pymyinstall/cli/pymy_deps.py
Expand Up @@ -22,7 +22,7 @@

def get_parser():
"""
defines the way to parse the magic command ``%head``
defines the way to parse the script ``pymy_deps``
"""
parser = argparse.ArgumentParser(
description='look dependencies for modules')
Expand Down
2 changes: 1 addition & 1 deletion src/pymyinstall/cli/pymy_install.py
Expand Up @@ -12,7 +12,7 @@

def get_parser():
"""
defines the way to parse the magic command ``%head``
defines the way to parse the script ``pymy_install``
"""
typstr = str # unicode#
parser = argparse.ArgumentParser(
Expand Down
104 changes: 104 additions & 0 deletions src/pymyinstall/cli/pymy_status.py
@@ -0,0 +1,104 @@
#!python
"""
script which goes through all installed modules
"""
from __future__ import print_function
import sys
import os
import argparse


def get_parser():
"""
defines the way to parse the script ``pymy_status``
"""
typstr = str # unicode#
parser = argparse.ArgumentParser(
description='information about installed modules')
parser.add_argument(
'-o',
'--out',
default="python_module.xlsx",
type=typstr,
help='output the results into a file (required pandas)')
parser.add_argument(
'-p',
'--pypi',
default=True,
type=bool,
help='checks the version on PyPi')
parser.add_argument(
'module',
nargs="*",
default="all",
help='update only the list of modules included in this list or all modules if not specified or equal to all')
return parser


def do_main(list_module=None, outfile="python_module.xlsx", pypi=True):
"""
calls function @see fn update_all but is meant to be added to scripts folder
@param list_module list of modules to update or None for all
@param outfile output the results into a flat file or an excel file (required pandas)
@param pypi check version on PyPi
"""
try:
from pymyinstall import is_travis_or_appveyor
except ImportError:
def is_travis_or_appveyor():
import sys
if "travis" in sys.executable:
return "travis"
import os
if os.environ.get("USERNAME", os.environ.get("USER", None)) == "appveyor":
return "appveyor"
return None

try:
from pymyinstall.installhelper import get_installed_modules
except ImportError:
pfolder = os.path.normpath(os.path.join(
os.path.abspath(os.path.dirname(__file__)), "..", ".."))
sys.path.append(pfolder)
from pymyinstall.installhelper import get_installed_modules
if len(list_module) == 0:
list_module = None
if outfile:
import pandas
res = get_installed_modules(short_list=list_module, fLOG=print, pypi=True)
if outfile:
df = pandas.DataFrame(res)
cols = list(df.columns)
cols.sort()
df = df[cols]
if ".xls" in os.path.split(outfile)[-1]:
print("Saving into:", outfile)
df.to_excel(outfile, index=False)
else:
print("Saving into (sep=tab, encoding=utf-8):", outfile)
df.to_csv(outfile, seo="\t", encoding="utf-8", index=False)


def main():
"""
calls function @see fn update_all but is meant to be added to scripts folder,
parse command line arguments
"""
parser = get_parser()
try:
res = parser.parse_args()
except SystemExit:
print(parser.format_usage())
res = None

if res is not None:
list_module = None if res.module in [
"all", "", "-", None, []] else res.module
if list_module is None and res.set is not None and len(res.set) > 0 and res.set != "-":
list_module = res.set
do_main(list_module=list_module, outfile=res.out, pypi=res.pypi)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion src/pymyinstall/cli/pymy_update.py
Expand Up @@ -12,7 +12,7 @@

def get_parser():
"""
defines the way to parse the magic command ``%head``
defines the way to parse the script ``pymy_update``
"""
typstr = str # unicode#
parser = argparse.ArgumentParser(
Expand Down
1 change: 1 addition & 0 deletions src/pymyinstall/installhelper/__init__.py
Expand Up @@ -10,6 +10,7 @@
from .module_dependencies import missing_dependencies
from .module_install_version import get_module_dependencies, get_module_version, get_pypi_version, get_module_metadata
from .module_install_version import version_consensus, numeric_version, compare_version, is_installed, get_wheel_version
from .status_helper import get_installed_modules


def module_as_table(list_module, as_df=False):
Expand Down

0 comments on commit 9318159

Please sign in to comment.