def run(inpath, tmpldict, outpath=None, execute=None, runargs=None): """Handles logic for `run` command.""" if not outpath: outpath = op.join(os.getcwd(), "__temp-poppage-" + _getrands(6)) make(inpath, tmpldict, outpath=outpath) qprompt.hrule() if not execute: execute = outpath tmpldict.update({'outpath': outpath}) tmpldict.update({'runargs': " ".join(runargs or [])}) execute = render_str(execute, tmpldict) for line in execute.splitlines(): sh.call(line.strip()) fsys.delete(outpath)
def readme_excerpt(): tempxml = "temp.xml" shell.call(f"asciidoctor -b docbook -o {tempxml} README.adoc") e = ElementTree.parse(tempxml).getroot() fsys.delete(tempxml) ns = {'db': 'http://docbook.org/ns/docbook', 'xml': 'http://www.w3.org/XML/1998/namespace'} rst = "" for sect in ["_introduction", "_status", "_requirements", "_installation"]: xml = ElementTree.tostring(e.find(f".//db:section[@xml:id='{sect}']", ns)).decode("utf-8") fsys.File(tempxml).write(xml) rst += shell.strout(f"pandoc -r docbook -w rst --base-header-level=2 {tempxml}") rst += "\n\n" fsys.File(r"doc\source\readme_excerpt.rst").write(rst) fsys.delete(tempxml) print("Readme excerpt generated.")
def readme_excerpt(): tempxml = "temp.xml" shell.call(f"asciidoctor -b docbook -o {tempxml} README.adoc") e = ElementTree.parse(tempxml).getroot() fsys.delete(tempxml) ns = { 'db': 'http://docbook.org/ns/docbook', 'xml': 'http://www.w3.org/XML/1998/namespace' } rst = "" for sect in ["_introduction", "_status", "_requirements", "_installation"]: xml = ElementTree.tostring( e.find(f".//db:section[@xml:id='{sect}']", ns)).decode("utf-8") fsys.File(tempxml).write(xml) rst += shell.strout( f"pandoc -r docbook -w rst --base-header-level=2 {tempxml}") rst += "\n\n" fsys.File(r"doc\source\readme_excerpt.rst").write(rst) fsys.delete(tempxml) print("Readme excerpt generated.")
def install_package_locally(): with fsys.Cwd("lib", __file__): shell.call("_Install_Package.py")
def run_tests(): with fsys.Cwd("tests", __file__): shell.call("_Run_Tests.py")
def check_version(): with fsys.Cwd(".", __file__): shell.call("_Check_Versions.py")
def cleanup(): with fsys.Cwd("lib"): shell.call("_Cleanup.bat") with fsys.Cwd("doc"): shell.call("make clean")
import qprompt sys.path.append("..") sys.dont_write_bytecode = True from _Check_Versions import VERCHK from _Install_Package import generate_readme, cleanup_readme ##==============================================================# ## SECTION: Main Body # ##==============================================================# if __name__ == '__main__': pause = True if len(sys.argv) > 1 and "nopause" == sys.argv[1]: pause = False ver = VERCHK.run() if not ver: qprompt.alert("Issue with version info!") sys.exit(1) if 0 != qprompt.status("Running tests...", sh.silent, [r"..\tests\_Run_Tests.py nopause"]): qprompt.alert("Issue running tests!") sys.exit(1) if qprompt.ask_yesno("Upload version `%s`?" % (ver)): generate_readme() sh.call("python setup.py sdist upload") cleanup_readme() if pause: qprompt.pause() sys.exit(0)
def all_docs(): readme_excerpt() with fsys.Cwd("doc", __file__): shell.call("make html")
def install_package_locally(): with fsys.Cwd("app", __file__): shell.call("_Install_Package.py")
def cleanup(): with fsys.Cwd("app"): shell.call("_Cleanup.py")
def upload_to_pypi(): with fsys.Cwd("lib", __file__): shell.call("_Upload_PyPI.py")
def upload_to_pypi(): with fsys.Cwd("app", __file__): shell.call("_Upload_PyPI.py")
def call(args, app_path="../app"): """Call PopPage as a CLI utility.""" cmd = "python %s/poppage.py " % (app_path) + args print(cmd) return sh.call(cmd)