Skip to content

Commit 1e976c3

Browse files
committed
Merge pull request #255 from clamsproject/develop
releasing 1.3.2
2 parents 3d489b3 + af5749d commit 1e976c3

33 files changed

Lines changed: 226 additions & 767 deletions

Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ testcaches = .hypothesis .pytest_cache .pytype coverage.xml htmlcov .coverage
2222

2323
all: version test build
2424

25-
develop: devversion package
25+
develop: devversion package test
2626
python3 setup.py develop --uninstall
2727
python3 setup.py develop
2828

@@ -32,7 +32,9 @@ publish: distclean version package test
3232
@git push origin `cat VERSION`
3333

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

3739
# generating jsonschema depends on mmif-python and pydantic
3840
docs: mmif := $(shell grep mmif-python requirements.txt)
@@ -41,6 +43,7 @@ docs: VERSION $(generatedcode)
4143
pip install --upgrade --no-input "$(mmif)" "$(pydantic)"
4244
rm -rf docs
4345
mkdir -p docs
46+
ls clams/ver
4447
python3 clams/appmetadata/__init__.py > documentation/appmetadata.jsonschema
4548
sphinx-build -a -b html documentation/ docs
4649
mv documentation/appmetadata.jsonschema docs/
@@ -96,5 +99,8 @@ distclean:
9699
@rm -rf dist $(artifact) build/bdist*
97100
clean: distclean
98101
@rm -rf VERSION VERSION.dev $(testcaches) $(buildcaches) $(generatedcode)
102+
@rm -rf docs
103+
@rm -rf .*cache
104+
@rm -rf .hypothesis tests/.hypothesis
99105
cleandocs:
100106
@git checkout -- docs && git clean -fx docs

clams/__init__.py

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1+
import argparse
12
import sys
23

3-
from mmif import __specver__
4-
4+
import mmif
55
from clams import develop
6-
from clams.mmif_utils import source
7-
from clams.mmif_utils import rewind
86
from clams.app import *
97
from clams.app import __all__ as app_all
108
from clams.appmetadata import AppMetadata
@@ -16,34 +14,41 @@
1614

1715

1816
def prep_argparser():
19-
import argparse
2017
parser = argparse.ArgumentParser()
2118
parser.add_argument(
2219
'-v', '--version',
2320
action='version',
24-
version=version_template.format(__version__, __specver__)
21+
version=version_template.format(__version__, mmif.__specver__)
2522
)
2623
subparsers = parser.add_subparsers(title='sub-command', dest='subcmd')
27-
for subcmd_module in [source, rewind, develop]:
28-
subcmd_name = subcmd_module.__name__.rsplit('.')[-1]
29-
subcmd_parser = subcmd_module.prep_argparser(add_help=False)
30-
subparsers.add_parser(subcmd_name, parents=[subcmd_parser],
31-
help=subcmd_module.describe_argparser()[0],
32-
description=subcmd_module.describe_argparser()[1],
33-
formatter_class=argparse.RawDescriptionHelpFormatter,
34-
)
35-
return parser
24+
return parser, subparsers
3625

3726

3827
def cli():
39-
parser = prep_argparser()
28+
parser, subparsers = prep_argparser()
29+
cli_modules = {}
30+
# thinly wrap all `mmif` subcommands
31+
# this is primarily for backward compatibility for `souce` and `rewind` subcmds
32+
to_register = list(mmif.find_all_modules('mmif.utils.cli'))
33+
# then add my own subcommands
34+
to_register.append(develop)
35+
for cli_module in to_register:
36+
cli_module_name = cli_module.__name__.rsplit('.')[-1]
37+
cli_modules[cli_module_name] = cli_module
38+
subcmd_parser = cli_module.prep_argparser(add_help=False)
39+
subparsers.add_parser(cli_module_name, parents=[subcmd_parser],
40+
help=cli_module.describe_argparser()[0],
41+
description=cli_module.describe_argparser()[1],
42+
formatter_class=argparse.RawDescriptionHelpFormatter,
43+
)
4044
if len(sys.argv) == 1:
4145
parser.print_help(sys.stderr)
4246
sys.exit(1)
4347
args = parser.parse_args()
44-
if args.subcmd == 'source':
45-
source.main(args)
46-
if args.subcmd == 'rewind':
47-
rewind.main(args)
48-
if args.subcmd == 'develop':
49-
develop.main(args)
48+
if args.subcmd not in cli_modules:
49+
parser.print_help(sys.stderr)
50+
else:
51+
cli_modules[args.subcmd].main(args)
52+
53+
if __name__ == '__main__':
54+
cli()

clams/app/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,13 @@ def cast(self, args: Dict[str, List[str]]) \
404404
if valuetype == dict:
405405
casted.setdefault(k, {}).update(v)
406406
else:
407-
casted.setdefault(k, []).append(v)
407+
# pytype will complain about the next line, but it is actually correct
408+
# casted.setdefault(k, []).append(v)
409+
# so doing it in a more explicit way
410+
if k in casted and isinstance(casted[k], list):
411+
casted[k].append(v)
412+
else:
413+
casted[k] = [v]
408414
else:
409415
casted[k] = v
410416
# when an empty value is passed (usually as a default value)

0 commit comments

Comments
 (0)