Skip to content

Commit

Permalink
feat: add kinstall option
Browse files Browse the repository at this point in the history
  • Loading branch information
breakthewall committed Sep 23, 2022
1 parent 7f7ddc5 commit 5728dfc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
14 changes: 13 additions & 1 deletion retropath2_wrapper/Args.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@author: Joan Hérisson
"""

from os import path as os_path
from argparse import ArgumentParser
from retropath2_wrapper._version import __version__

Expand All @@ -24,6 +24,10 @@
'OSError': 2,
'InChI': 3
}
__PACKAGE_FOLDER = os_path.dirname(
os_path.realpath(__file__)
)
DEFAULT_KNIME_FOLDER = __PACKAGE_FOLDER


def build_args_parser():
Expand Down Expand Up @@ -81,6 +85,14 @@ def _add_arguments(parser):
downloaded if not already installed or path is \
wrong).'
)
parser.add_argument(
'--kinstall',
type=str,
default=DEFAULT_KNIME_FOLDER,
help='path to KNIME executable file (KNIME will be \
downloaded if not already installed or path is \
wrong).'
)
parser.add_argument(
'--kver',
type=str,
Expand Down
19 changes: 16 additions & 3 deletions retropath2_wrapper/RetroPath2.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
from logging import StreamHandler
from csv import reader
from .Args import (
DEFAULT_KNIME_FOLDER,
DEFAULT_TIMEOUT,
DEFAULT_KNIME_VERSION,
DEFAULT_RP2_VERSION,
Expand All @@ -65,8 +66,10 @@
def set_vars(
kexec: str,
kpkg_install: bool,
kinstall: str = DEFAULT_KNIME_FOLDER,
kver: str = DEFAULT_KNIME_VERSION,
rp2_version: str = DEFAULT_RP2_VERSION
rp2_version: str = DEFAULT_RP2_VERSION,
logger: Logger = getLogger(__name__)
) -> Dict:
"""
Set variables and store them into a dictionary.
Expand All @@ -84,10 +87,16 @@ def set_vars(
"""

logger.debug(f'kexec: {kexec}')
logger.debug(f'kver: {kver}')
logger.debug(f'kpkg_install: {kpkg_install}')
logger.debug(f'kinstall: {kinstall}')
logger.debug(f'rp2_version: {rp2_version}')

# Setting kexec, kpath, kinstall, kver
kexec_install = False
if kexec is None:
kinstall = os_path.join(here, '.knime', sys_platform)
kinstall = os_path.join(kinstall, '.knime', sys_platform)
if sys_platform == 'darwin':
kpath = os_path.join(kinstall, f'KNIME_{kver}.app')
kexec = os_path.join(kpath, 'Contents', 'MacOS', 'knime')
Expand Down Expand Up @@ -125,6 +134,7 @@ def set_vars(
def retropath2(
sink_file: str, source_file: str, rules_file: str,
outdir: str,
kinstall: str = DEFAULT_KNIME_FOLDER,
kexec: str = None, kpkg_install: bool = True, kver: str = DEFAULT_KNIME_VERSION,
rp2_version: str = DEFAULT_RP2_VERSION,
kvars: Dict = None,
Expand All @@ -142,6 +152,7 @@ def retropath2(
logger.debug(f'outdir: {outdir}')
logger.debug(f'kexec: {kexec}')
logger.debug(f'kpkg_install: {kpkg_install}')
logger.debug(f'kinstall: {kinstall}')
logger.debug(f'kver: {kver}')
logger.debug(f'rp2_version: {rp2_version}')
logger.debug(f'kvars: {kvars}')
Expand All @@ -158,7 +169,9 @@ def retropath2(
kexec=kexec,
kver=kver,
kpkg_install=kpkg_install,
rp2_version=rp2_version
rp2_version=rp2_version,
kinstall=kinstall,
logger=logger
)
logger.debug('kvars: ' + str(kvars))
# Store RetroPath2 params into a dictionary
Expand Down
10 changes: 6 additions & 4 deletions retropath2_wrapper/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,23 @@ def _cli():
if args.log.lower() in ['silent', 'quiet'] or args.silent:
args.log = 'CRITICAL'

# Create logger
logger = create_logger(parser.prog, args.log)

# Store KNIME vars into a dictionary
kvars = set_vars(
kexec=args.kexec,
kver=args.kver,
kpkg_install=args.kpkg_install,
rp2_version=args.rp2_version
rp2_version=args.rp2_version,
kinstall=args.kinstall,
logger=logger
)

# Print out configuration
if not args.silent and args.log.lower() not in ['critical', 'error']:
print_conf(kvars, prog = parser.prog)

# Create logger
logger = create_logger(parser.prog, args.log)

logger.debug('args: ' + str(args))
logger.debug('kvars: ' + str(kvars))

Expand Down

0 comments on commit 5728dfc

Please sign in to comment.