Skip to content

Commit

Permalink
Merge pull request #63 from dls-controls/fix_python2_main
Browse files Browse the repository at this point in the history
Fix main for Python2, and make script optional.
  • Loading branch information
AlexanderWells-diamond authored Nov 25, 2021
2 parents dfc3971 + 5c39790 commit 8c8fb1f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions softioc/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@
from argparse import ArgumentParser
import subprocess

from softioc import __version__
from . import __version__


def main(args=None):
parser = ArgumentParser()
parser.add_argument("--version", action="version", version=__version__)
parser.add_argument("script", help="The python script to run")
parser.add_argument(
"script", help="The python script to run", nargs="?", default=None)
parser.add_argument(
"arg", help="Any arguments to pass to the script", nargs="*")
parsed_args = parser.parse_args(args)
# Execute as subprocess
cmd = [sys.executable, parsed_args.script, *parsed_args.arg]
parsed_args, unknown = parser.parse_known_args(args)

# Execute as subprocess.
cmd = [sys.executable] + parsed_args.arg + unknown
if parsed_args.script:
cmd.insert(1, parsed_args.script)

subprocess.Popen(cmd).communicate()


Expand Down

0 comments on commit 8c8fb1f

Please sign in to comment.