diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/__init__.py @@ -0,0 +1 @@ + diff --git a/__main__.py b/__main__.py new file mode 100644 index 0000000..21f8383 --- /dev/null +++ b/__main__.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python3 +# Tries to run_as_subprocess.py as an absolute and relative import. (for script or module) +import sys + +try: + from .run_as_subprocess import main +except (ImportError, ModuleNotFoundError): + from run_as_subprocess import main + +main(sys.argv) diff --git a/pesterchum b/pesterchum new file mode 100755 index 0000000..ed347c1 --- /dev/null +++ b/pesterchum @@ -0,0 +1,13 @@ +#!/bin/sh +# Run pesterchum either locally or when installed as library/module. +# If installed as library/module can be excecuted from anywhere. +#echo $@ + +if [ -f "pesterchum.py" ]; +then +python3 pesterchum.py $@ + +else +python3 -m pesterchum_alt $@ + +fi diff --git a/run_as_subprocess.py b/run_as_subprocess.py new file mode 100644 index 0000000..24c96d5 --- /dev/null +++ b/run_as_subprocess.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +# Wrapper script to run Pesterchum from an import independently of the current working directory. (useful for wheel) +# Running MainProgram() from an import would be better, but I think it requires making **all** imports relative depending on __main__, +# and probably other stuff too- + +import os +import sys +from subprocess import call + +#print(sys.argv) +def main(argv): + arguments = '' + for x in argv[1:]: + arguments += x + ' ' + #print(arguments) + + directory_path = os.getcwd() + print("Working directory: " + directory_path) + os.chdir(os.path.dirname(__file__)) + print("Working directory set to: " + directory_path) + print("Running Pesterchum as subprocess, this is not ideal.") + retcode = call("python3 pesterchum.py " + " " + str(arguments), shell=True) + print(retcode) + +if __name__ == "__main__": + main(sys.argv)