Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ testcaches = .hypothesis .pytest_cache .pytype coverage.xml htmlcov .coverage

all: version test build

develop: devversion package
develop: devversion package test
python3 setup.py develop --uninstall
python3 setup.py develop

Expand All @@ -33,7 +33,9 @@ publish: distclean version package test
@git push origin `cat VERSION`

$(generatedcode): VERSION
python3 setup.py donothing
# this will generate the version subpackage inside clams package
python3 setup.py --help 2>/dev/null || echo "Ignore setuptools import error for now"
ls $(generatedcode)*

# generating jsonschema depends on mmif-python and pydantic
docs: mmif := $(shell grep mmif-python requirements.txt)
Expand Down Expand Up @@ -97,5 +99,8 @@ distclean:
@rm -rf dist $(artifact) build/bdist*
clean: distclean
@rm -rf VERSION VERSION.dev $(testcaches) $(buildcaches) $(generatedcode)
@rm -rf docs
@rm -rf .*cache
@rm -rf .hypothesis tests/.hypothesis
cleandocs:
@git checkout -- docs && git clean -fx docs
49 changes: 27 additions & 22 deletions clams/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import argparse
import sys

from mmif import __specver__

import mmif
from clams import develop
from clams.mmif_utils import source
from clams.mmif_utils import rewind
from clams.app import *
from clams.app import __all__ as app_all
from clams.appmetadata import AppMetadata
Expand All @@ -16,34 +14,41 @@


def prep_argparser():
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
'-v', '--version',
action='version',
version=version_template.format(__version__, __specver__)
version=version_template.format(__version__, mmif.__specver__)
)
subparsers = parser.add_subparsers(title='sub-command', dest='subcmd')
for subcmd_module in [source, rewind, develop]:
subcmd_name = subcmd_module.__name__.rsplit('.')[-1]
subcmd_parser = subcmd_module.prep_argparser(add_help=False)
subparsers.add_parser(subcmd_name, parents=[subcmd_parser],
help=subcmd_module.describe_argparser()[0],
description=subcmd_module.describe_argparser()[1],
formatter_class=argparse.RawDescriptionHelpFormatter,
)
return parser
return parser, subparsers


def cli():
parser = prep_argparser()
parser, subparsers = prep_argparser()
cli_modules = {}
# thinly wrap all `mmif` subcommands
# this is primarily for backward compatibility for `souce` and `rewind` subcmds
to_register = list(mmif.find_all_modules('mmif.utils.cli'))
# then add my own subcommands
to_register.append(develop)
for cli_module in to_register:
cli_module_name = cli_module.__name__.rsplit('.')[-1]
cli_modules[cli_module_name] = cli_module
subcmd_parser = cli_module.prep_argparser(add_help=False)
subparsers.add_parser(cli_module_name, parents=[subcmd_parser],
help=cli_module.describe_argparser()[0],
description=cli_module.describe_argparser()[1],
formatter_class=argparse.RawDescriptionHelpFormatter,
)
if len(sys.argv) == 1:
parser.print_help(sys.stderr)
sys.exit(1)
args = parser.parse_args()
if args.subcmd == 'source':
source.main(args)
if args.subcmd == 'rewind':
rewind.main(args)
if args.subcmd == 'develop':
develop.main(args)
if args.subcmd not in cli_modules:
parser.print_help(sys.stderr)
else:
cli_modules[args.subcmd].main(args)

if __name__ == '__main__':
cli()
8 changes: 7 additions & 1 deletion clams/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,13 @@ def cast(self, args: Dict[str, List[str]]) \
if valuetype == dict:
casted.setdefault(k, {}).update(v)
else:
casted.setdefault(k, []).append(v)
# pytype will complain about the next line, but it is actually correct
# casted.setdefault(k, []).append(v)
# so doing it in a more explicit way
if k in casted and isinstance(casted[k], list):
casted[k].append(v)
else:
casted[k] = [v]
else:
casted[k] = v
# when an empty value is passed (usually as a default value)
Expand Down
Loading
Loading