Skip to content

Commit

Permalink
--pre for natlinkconfig_cli (works) and natlinkconfig_gui(doesn't).
Browse files Browse the repository at this point in the history
  • Loading branch information
dougransom committed Nov 29, 2024
1 parent bc53016 commit 932d6f0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
31 changes: 23 additions & 8 deletions src/natlinkcore/configure/natlinkconfig_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
from natlinkcore.configure import extensions_and_folders
from natlinkcore.configure import natlinkconfigfunctions
from platformdirs import user_log_dir
from argparse import ArgumentParser


extra_pip_options=[]
appname="natlink"
logdir = Path(user_log_dir(appname=appname,ensure_exists=True))
logfilename=logdir/"cli_log.txt"
Expand All @@ -28,19 +29,19 @@
logfile_logger.addHandler(file_handler)
logfile_logger.setLevel(logging.DEBUG)


def _main(Options=None):
"""Catch the options and perform the resulting command line functions
options: -i, --info: give status info
--pre enable prerelease options
-I, --reginfo: give the info in the registry about Natlink
etc., usage above...
"""


cli = CLI()
cli.Config = natlinkconfigfunctions.NatlinkConfig()
shortOptions = "DVNOHKaAiIxXbBuqe"
shortArgOptions = "d:v:n:o:h:k:"
if Options:
Expand All @@ -51,14 +52,23 @@ def _main(Options=None):
Options = sys.argv[1:]

try:
options, args = getopt.getopt(Options, shortOptions+shortArgOptions)
options, args = getopt.getopt(Options, shortOptions+shortArgOptions,["pre"])
except getopt.GetoptError:
print(f'invalid option: {Options}')
cli.usage()
return

if args:
print(f'should not have extraneous arguments: {args}')

if "--pre" in options:
extra_pip_options.append("--pre")
logging.info("pip extra option --pre")
options.remove("--pre")
cli = CLI(extra_pip_options=extra_pip_options)

cli.Config = natlinkconfigfunctions.NatlinkConfig(cli.extra_pip_options)

for o, v in options:
o = o.lstrip('-')
funcName = f'do_{o}'
Expand All @@ -80,8 +90,9 @@ def _main(Options=None):
class CLI(cmd.Cmd):
"""provide interactive shell control for the different options.
"""
def __init__(self, Config=None):
def __init__(self, Config=None,extra_pip_options=[]):
cmd.Cmd.__init__(self)
self.extra_pip_options=extra_pip_options
self.prompt = '\nNatlink config> '
self.info = "type 'u' for usage"
self.Config = None
Expand Down Expand Up @@ -467,9 +478,13 @@ def help_u(self):


def main_cli():
if len(sys.argv) == 1:
Cli = CLI()
Cli.Config = natlinkconfigfunctions.NatlinkConfig()
#a hack until we switch to ArgParse from getopt, check for --pre
if len(sys.argv) == 2 and sys.argv[1]=="--pre":
extra_pip_options.append("--pre")

if len(sys.argv) == 1 or ( len(sys.argv) == 2 and sys.argv[1]=="--pre"):
Cli = CLI(extra_pip_options=extra_pip_options)
Cli.Config = natlinkconfigfunctions.NatlinkConfig(extra_pip_options=extra_pip_options)
Cli.info = ""
print('\nWelcome to the NatlinkConfig Command Line Interface\n')
print('Type "I" for manual editing the "natlink.ini" config file\n')
Expand Down
2 changes: 1 addition & 1 deletion src/natlinkcore/configure/natlinkconfig_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
args=parser.parse_args();
prerelease_enabled=args.pre
del parser,args #no longer required
logging.debug(f"prerelease_enabled {prerelease_enabled} ")
logging.debug(f"prerelease_enabled: {prerelease_enabled} ")
extra_pip_options=['--pre'] if prerelease_enabled else []

# Inlize the NatlinkConfig
Expand Down
2 changes: 1 addition & 1 deletion src/natlinkcore/configure/natlinkconfigfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def enable_unimacro(self, arg):
return
else:
try:
self.do_pip("install",*self.extra_pip_options, "unimacro")
do_pip("install",*self.extra_pip_options, "unimacro")
except subprocess.CalledProcessError:
logging.info('====\ncould not pip install unimacro\n====\n')
return
Expand Down

0 comments on commit 932d6f0

Please sign in to comment.