This repository has been archived by the owner on Jan 13, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add script to a get a status on the current distribution
- Loading branch information
Showing
15 changed files
with
393 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
""" | ||
@brief test log(time=2s) | ||
@brief test log(time=20s) | ||
skip this test for regular run | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.