Skip to content

Commit

Permalink
Merge pull request #94 from dougransom/pip_pre_option
Browse files Browse the repository at this point in the history
Pip pre option
  • Loading branch information
dougransom authored Nov 29, 2024
2 parents 4a3d6db + 4af6ce8 commit 1504756
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ build-backend = "flit_core.buildapi"
[project]
name = "natlinkcore"
authors = [{name = "Quintijn Hoogenboom (maintainer)", email = "[email protected]"}]
version="5.4.2.dev3"
version="5.4.2.dev5"
dynamic = [ "description"]
requires-python = ">=3.9"
requires-python = ">=3.10"
readme = "readme.md"
dependencies= [

Expand All @@ -22,7 +22,7 @@ dependencies= [
"Environment :: Win32 (MS Windows)",
"Intended Audience :: Developers",
"Operating System :: Microsoft :: Windows",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Multimedia :: Sound/Audio :: Speech",
"Topic :: Software Development :: Libraries :: Python Modules"
Expand Down
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
12 changes: 10 additions & 2 deletions src/natlinkcore/configure/natlinkconfig_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import logging
from platformdirs import user_log_dir
from pathlib import Path
from argparse import ArgumentParser
appname="natlink"
logdir = Path(user_log_dir(appname=appname,ensure_exists=True))
logfilename=logdir/"config_gui_log.txt"
Expand All @@ -28,8 +29,16 @@
pyVersion = platform.python_version()
osVersion = sys.getwindowsversion()

parser=ArgumentParser(description="check for --pre")
parser.add_argument('--pre',action='store_true',help='Enable pre-release mode')
args=parser.parse_args();
prerelease_enabled=args.pre
del parser,args #no longer required
logging.debug(f"prerelease_enabled: {prerelease_enabled} ")
extra_pip_options=['--pre'] if prerelease_enabled else []

# Inlize the NatlinkConfig
Config = NatlinkConfig()
Config = NatlinkConfig(extra_pip_options=extra_pip_options)
Status = natlinkstatus.NatlinkStatus()


Expand Down Expand Up @@ -158,7 +167,6 @@ def OpenNatlinkConfig(values, event):
unimacro_dispatch = {'Set_UserDir_Unimacro': UnimacroUserDir, 'Clear_UserDir_Unimacro': UnimacroUserDir}
autohotkey_dispatch = {'Set_Exe_Ahk': AhkExeDir, 'Clear_Exe_Ahk': AhkExeDir, 'Set_ScriptsDir_Ahk': AhkUserDir,'Clear_ScriptsDir_Ahk': AhkUserDir}


#### Event Loop ####
try:
#we want to set the logger up just before we call window.read()
Expand Down
18 changes: 10 additions & 8 deletions src/natlinkcore/configure/natlinkconfigfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ class NatlinkConfig:
Changes are written in the config file, from which the path is taken from the loader instance.
"""
def __init__(self):
def __init__(self,extra_pip_options=None):
self.extra_pip_options = [] if extra_pip_options is None else extra_pip_options

self.config_path = self.get_check_config_locations()
self.config_dir = str(Path(self.config_path).parent)
self.status = natlinkstatus.NatlinkStatus()
Expand All @@ -70,7 +72,7 @@ def __init__(self):
self.documents_path = str(Path.home()/'Documents')
self.natlinkconfig_path = config.expand_natlink_settingsdir()
pass

def get_check_config_locations(self):

"""check the location/locations as given by the loader
Expand Down Expand Up @@ -340,13 +342,13 @@ def enable_unimacro(self, arg):
if uni_dir:
logging.info('==== instal and/or update unimacro====\n')
try:
do_pip("install", "--upgrade", "unimacro")
do_pip("install", *self.extra_pip_options, "--upgrade", "unimacro")
except subprocess.CalledProcessError:
logging.info('====\ncould not pip install --upgrade unimacro\n====\n')
return
else:
try:
do_pip("install", "unimacro")
do_pip("install",*self.extra_pip_options, "unimacro")
except subprocess.CalledProcessError:
logging.info('====\ncould not pip install unimacro\n====\n')
return
Expand Down Expand Up @@ -385,13 +387,13 @@ def enable_dragonfly(self, arg):
if df_dir:
logging.info('==== instal and/or update dragonfly2====\n')
try:
do_pip( "install", "--upgrade", "dragonfly2")
do_pip( "install", *self.extra_pip_options,"--upgrade", "dragonfly2")
except subprocess.CalledProcessError:
logging.info('====\ncould not pip install --upgrade dragonfly2\n====\n')
return
else:
try:
do_pip( "install", "dragonfly2")
do_pip( "install", *self.extra_pip_options, "dragonfly2")
except subprocess.CalledProcessError:
logging.info('====\ncould not pip install dragonfly2\n====\n')
return
Expand Down Expand Up @@ -424,13 +426,13 @@ def enable_vocola(self, arg):
if voc_dir:
logging.info('==== instal and/or update vocola2====\n')
try:
do_pip("install", "--upgrade", "vocola2")
do_pip("install",*self.extra_pip_options, "--upgrade", "vocola2")
except subprocess.CalledProcessError:
logging.info('====\ncould not pip install --upgrade vocola2\n====\n')
return
else:
try:
do_pip("install", "vocola2")
do_pip("install",*self.extra_pip_options, "vocola2")
except subprocess.CalledProcessError:
logging.info('====\ncould not pip install vocola2\n====\n')
return
Expand Down

0 comments on commit 1504756

Please sign in to comment.