clams-python 1.1.4__tar.gz → 1.1.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. {clams-python-1.1.4/clams_python.egg-info → clams-python-1.1.6}/PKG-INFO +2 -2
  2. clams-python-1.1.6/VERSION +1 -0
  3. {clams-python-1.1.4 → clams-python-1.1.6}/clams/app/__init__.py +28 -22
  4. {clams-python-1.1.4 → clams-python-1.1.6}/clams/appmetadata/__init__.py +5 -0
  5. clams-python-1.1.6/clams/ver/__init__.py +1 -0
  6. {clams-python-1.1.4 → clams-python-1.1.6/clams_python.egg-info}/PKG-INFO +2 -2
  7. {clams-python-1.1.4 → clams-python-1.1.6}/clams_python.egg-info/requires.txt +1 -1
  8. {clams-python-1.1.4 → clams-python-1.1.6}/requirements.txt +1 -1
  9. {clams-python-1.1.4 → clams-python-1.1.6}/tests/test_clamsapp.py +10 -12
  10. clams-python-1.1.4/VERSION +0 -1
  11. clams-python-1.1.4/clams/ver/__init__.py +0 -1
  12. {clams-python-1.1.4 → clams-python-1.1.6}/LICENSE +0 -0
  13. {clams-python-1.1.4 → clams-python-1.1.6}/MANIFEST.in +0 -0
  14. {clams-python-1.1.4 → clams-python-1.1.6}/README.md +0 -0
  15. {clams-python-1.1.4 → clams-python-1.1.6}/clams/__init__.py +0 -0
  16. {clams-python-1.1.4 → clams-python-1.1.6}/clams/develop/__init__.py +0 -0
  17. {clams-python-1.1.4 → clams-python-1.1.6}/clams/develop/templates/app/.dockerignore.template +0 -0
  18. {clams-python-1.1.4 → clams-python-1.1.6}/clams/develop/templates/app/.gitignore.template +0 -0
  19. {clams-python-1.1.4 → clams-python-1.1.6}/clams/develop/templates/app/Containerfile.template +0 -0
  20. {clams-python-1.1.4 → clams-python-1.1.6}/clams/develop/templates/app/LICENSE.template +0 -0
  21. {clams-python-1.1.4 → clams-python-1.1.6}/clams/develop/templates/app/README.md.template +0 -0
  22. {clams-python-1.1.4 → clams-python-1.1.6}/clams/develop/templates/app/app.py.template +0 -0
  23. {clams-python-1.1.4 → clams-python-1.1.6}/clams/develop/templates/app/metadata.py.template +0 -0
  24. {clams-python-1.1.4 → clams-python-1.1.6}/clams/develop/templates/app/requirements.txt.template +0 -0
  25. {clams-python-1.1.4 → clams-python-1.1.6}/clams/develop/templates/gha/for-clams-team.md.template +0 -0
  26. {clams-python-1.1.4 → clams-python-1.1.6}/clams/develop/templates/gha/workflows/issue-apps-project.yml.template +0 -0
  27. {clams-python-1.1.4 → clams-python-1.1.6}/clams/develop/templates/gha/workflows/issue-assign.yml.template +0 -0
  28. {clams-python-1.1.4 → clams-python-1.1.6}/clams/develop/templates/gha/workflows/issue-close.yml.template +0 -0
  29. {clams-python-1.1.4 → clams-python-1.1.6}/clams/develop/templates/gha/workflows/publish.yml.template +0 -0
  30. {clams-python-1.1.4 → clams-python-1.1.6}/clams/mmif_utils/__init__.py +0 -0
  31. {clams-python-1.1.4 → clams-python-1.1.6}/clams/mmif_utils/rewind.py +0 -0
  32. {clams-python-1.1.4 → clams-python-1.1.6}/clams/mmif_utils/source.py +0 -0
  33. {clams-python-1.1.4 → clams-python-1.1.6}/clams/restify/__init__.py +0 -0
  34. {clams-python-1.1.4 → clams-python-1.1.6}/clams/serve/__init__.py +0 -0
  35. {clams-python-1.1.4 → clams-python-1.1.6}/clams_python.egg-info/SOURCES.txt +0 -0
  36. {clams-python-1.1.4 → clams-python-1.1.6}/clams_python.egg-info/dependency_links.txt +0 -0
  37. {clams-python-1.1.4 → clams-python-1.1.6}/clams_python.egg-info/entry_points.txt +0 -0
  38. {clams-python-1.1.4 → clams-python-1.1.6}/clams_python.egg-info/top_level.txt +0 -0
  39. {clams-python-1.1.4 → clams-python-1.1.6}/setup.cfg +0 -0
  40. {clams-python-1.1.4 → clams-python-1.1.6}/setup.py +0 -0
  41. {clams-python-1.1.4 → clams-python-1.1.6}/tests/test_clamscli.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: clams-python
3
- Version: 1.1.4
3
+ Version: 1.1.6
4
4
  Summary: A collection of APIs to develop CLAMS app for python
5
5
  Home-page: https://clams.ai
6
6
  Author: Brandeis Lab for Linguistics and Computation
@@ -14,7 +14,7 @@ Classifier: Programming Language :: Python :: 3 :: Only
14
14
  Requires-Python: >=3.8
15
15
  Description-Content-Type: text/markdown
16
16
  License-File: LICENSE
17
- Requires-Dist: mmif-python==1.0.11
17
+ Requires-Dist: mmif-python==1.0.13
18
18
  Requires-Dist: Flask>=2
19
19
  Requires-Dist: Flask-RESTful>=0.3.9
20
20
  Requires-Dist: gunicorn>=20
@@ -0,0 +1 @@
1
+ 1.1.6
@@ -9,10 +9,10 @@ from urllib import parse as urlparser
9
9
 
10
10
  __all__ = ['ClamsApp']
11
11
 
12
- from typing import Union, Any, Optional, Dict, List, Iterable
12
+ from typing import Union, Any, Optional, Dict, List, Tuple
13
13
 
14
14
  from mmif import Mmif, Document, DocumentTypes, View
15
- from clams.appmetadata import AppMetadata, RuntimeParameter, real_valued_primitives
15
+ from clams.appmetadata import AppMetadata, real_valued_primitives, python_type, map_param_kv_delimiter
16
16
 
17
17
  logging.basicConfig(
18
18
  level=logging.WARNING,
@@ -28,12 +28,14 @@ class ClamsApp(ABC):
28
28
  """
29
29
  # A set of "universal runtime parameters that can be used for both GET and POST anytime".
30
30
  # The behavioral changes based on these parameters must be implemented on the SDK level.
31
+ # This needs to stay as a list of dicts for compatibility with the metadata.py file (templated).
31
32
  universal_parameters = [
32
- RuntimeParameter(**{
33
+ {
33
34
  'name': 'pretty', 'type': 'boolean', 'choices': None, 'default': False, 'multivalued': False,
34
35
  'description': 'The JSON body of the HTTP response will be re-formatted with 2-space indentation',
35
- }),
36
+ },
36
37
  ]
38
+
37
39
  # this key is used to store users' raw input params in the parameter dict
38
40
  # even after "refinement" (i.e., casting to proper data types)
39
41
  _RAW_PARAMS_KEY = "#RAW#"
@@ -41,12 +43,19 @@ class ClamsApp(ABC):
41
43
  def __init__(self):
42
44
  self.metadata: AppMetadata = self._load_appmetadata()
43
45
  super().__init__()
44
- # data type specification for common parameters
45
-
46
+
47
+ # data type spec to be used in type caster
48
+ self.metadata_param_spec = {}
49
+ self.annotate_param_spec = {}
46
50
  for param in ClamsApp.universal_parameters:
47
- self.metadata.parameters.append(param)
48
- self.metadata_param_caster = ParameterCaster(ClamsApp.universal_parameters) # pytype: disable=wrong-arg-types
49
- self.annotate_param_caster = ParameterCaster(self.metadata.parameters) # pytype: disable=wrong-arg-types
51
+ # in addition to building the param spec, add them as regular params, so they are serialized in metadata
52
+ self.metadata.add_parameter(**param)
53
+ self.metadata_param_spec[param['name']] = (param['type'], param.get('multivalued', False))
54
+ for param_spec in self.metadata.parameters:
55
+ self.annotate_param_spec[param_spec.name] = (param_spec.type, param_spec.multivalued)
56
+
57
+ self.metadata_param_caster = ParameterCaster(self.metadata_param_spec)
58
+ self.annotate_param_caster = ParameterCaster(self.annotate_param_spec)
50
59
  self.logger = logging.getLogger(self.metadata.identifier)
51
60
 
52
61
  def appmetadata(self, **kwargs: List[str]) -> str:
@@ -110,7 +119,7 @@ class ClamsApp(ABC):
110
119
  mmif = Mmif(mmif)
111
120
  issued_warnings = []
112
121
  for key in runtime_params:
113
- if key not in self.annotate_param_caster.param_spec:
122
+ if key not in self.annotate_param_spec:
114
123
  issued_warnings.append(UserWarning(f'An undefined parameter "{key}" (value: "{runtime_params[key]}") is passed'))
115
124
  # this will do casting + refinement altogether
116
125
  refined = self._refine_params(**runtime_params)
@@ -297,19 +306,16 @@ class ClamsApp(ABC):
297
306
 
298
307
 
299
308
  class ParameterCaster(object):
300
- KV_DELIMITER = ':'
301
- python_type = {"boolean": bool, "number": float, "integer": int, "string": str, "map": dict}
302
309
 
303
- """
304
- A helper class to convert parameters passed by HTTP query strings to
305
- proper python data types.
310
+ def __init__(self, param_spec: Dict[str, Tuple[str, bool]]):
311
+ """
312
+ A helper class to convert parameters passed by HTTP query strings to
313
+ proper python data types.
306
314
 
307
- :param param_spec: A specification of a data types of parameters
308
- """
309
- def __init__(self, params: Iterable[RuntimeParameter]):
310
- self.param_spec = {}
311
- for param in params:
312
- self.param_spec[param.name] = (self.python_type[param.type], param.multivalued)
315
+ :param param_spec: A specification of a data types of parameters
316
+ """
317
+ self.param_spec = {pname: (python_type[ptype_str], pmultivalued)
318
+ for pname, (ptype_str, pmultivalued) in param_spec.items()}
313
319
 
314
320
  def cast(self, args: Dict[str, List[str]]) \
315
321
  -> Dict[str, Union[real_valued_primitives, List[real_valued_primitives], Dict[str, str]]]:
@@ -395,4 +401,4 @@ class ParameterCaster(object):
395
401
  """
396
402
  Helper function to convert string values to key-value pair type.
397
403
  """
398
- return dict([value.split(ParameterCaster.KV_DELIMITER, 1)])
404
+ return dict([value.split(map_param_kv_delimiter, 1)])
@@ -15,6 +15,11 @@ app_version_envvar_key = 'CLAMS_APP_VERSION'
15
15
  real_valued_primitives = Union[int, float, bool, str]
16
16
  # these names are taken from the JSON schema data types
17
17
  param_value_types = Literal['integer', 'number', 'string', 'boolean', 'map']
18
+ # and the specific delimiter for the map type
19
+ map_param_kv_delimiter = ':'
20
+
21
+ # dict to map app parameter data types to Python data types
22
+ python_type = {"boolean": bool, "number": float, "integer": int, "string": str, "map": dict}
18
23
 
19
24
  param_value_types_values = param_value_types.__args__ # pytype: disable=attribute-error
20
25
  app_directory_baseurl = "http://apps.clams.ai"
@@ -0,0 +1 @@
1
+ __version__ = "1.1.6"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: clams-python
3
- Version: 1.1.4
3
+ Version: 1.1.6
4
4
  Summary: A collection of APIs to develop CLAMS app for python
5
5
  Home-page: https://clams.ai
6
6
  Author: Brandeis Lab for Linguistics and Computation
@@ -14,7 +14,7 @@ Classifier: Programming Language :: Python :: 3 :: Only
14
14
  Requires-Python: >=3.8
15
15
  Description-Content-Type: text/markdown
16
16
  License-File: LICENSE
17
- Requires-Dist: mmif-python==1.0.11
17
+ Requires-Dist: mmif-python==1.0.13
18
18
  Requires-Dist: Flask>=2
19
19
  Requires-Dist: Flask-RESTful>=0.3.9
20
20
  Requires-Dist: gunicorn>=20
@@ -1,4 +1,4 @@
1
- mmif-python==1.0.11
1
+ mmif-python==1.0.13
2
2
  Flask>=2
3
3
  Flask-RESTful>=0.3.9
4
4
  gunicorn>=20
@@ -1,4 +1,4 @@
1
- mmif-python==1.0.11
1
+ mmif-python==1.0.13
2
2
 
3
3
  Flask>=2
4
4
  Flask-RESTful>=0.3.9
@@ -14,7 +14,7 @@ from mmif import Mmif, Document, DocumentTypes, AnnotationTypes, View, __specver
14
14
  import clams.app
15
15
  import clams.restify
16
16
  from clams.app import ParameterCaster
17
- from clams.appmetadata import AppMetadata, Input, RuntimeParameter
17
+ from clams.appmetadata import AppMetadata, Input
18
18
 
19
19
 
20
20
  class ExampleInputMMIF(object):
@@ -420,19 +420,16 @@ class TestRestifier(unittest.TestCase):
420
420
  class TestParameterCaster(unittest.TestCase):
421
421
 
422
422
  def setUp(self) -> None:
423
- self.params = []
424
- specs = {'str_param': ('string', False),
425
- 'number_param': ('number', False),
426
- 'int_param': ('integer', False),
427
- 'bool_param': ('boolean', False),
428
- 'str_multi_param': ('string', True),
429
- 'map_param': ('map', True),
430
- }
431
- for name, (t, mv) in specs.items():
432
- self.params.append(RuntimeParameter(**{'name': name, 'type': t, 'multivalued': mv, 'description': ""}))
423
+ self.param_spec = {'str_param': ('string', False),
424
+ 'number_param': ('number', False),
425
+ 'int_param': ('integer', False),
426
+ 'bool_param': ('boolean', False),
427
+ 'str_multi_param': ('string', True),
428
+ 'map_param': ('map', True),
429
+ }
433
430
 
434
431
  def test_cast(self):
435
- caster = ParameterCaster(self.params)
432
+ caster = ParameterCaster(self.param_spec)
436
433
  params = {
437
434
  'str_param': ["a_string"],
438
435
  'number_param': ["1.11"],
@@ -443,6 +440,7 @@ class TestParameterCaster(unittest.TestCase):
443
440
  'undefined_param_multi': ['undefined_value1', 'undefined_value2'],
444
441
  'map_param': ['key1:val1', 'key2:val2', 'key3:val3', 'key1:val4']
445
442
  }
443
+ # all "RAW" parameter values are assumed to be strings
446
444
  self.assertTrue(all(map(lambda x: isinstance(x, str), itertools.chain.from_iterable(params.values()))))
447
445
  casted = caster.cast(params)
448
446
  # must push out to the list
@@ -1 +0,0 @@
1
- 1.1.4
@@ -1 +0,0 @@
1
- __version__ = "1.1.4"
File without changes
File without changes
File without changes
File without changes
File without changes