Skip to content

Commit 4385312

Browse files
authored
Merge pull request #24 from ModECI/development
To v0.2.7
2 parents 4d81b47 + 43a3491 commit 4385312

File tree

9 files changed

+125
-14
lines changed

9 files changed

+125
-14
lines changed

.github/workflows/ci.yml

+5-9
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,23 @@ jobs:
5151
cd examples
5252
python document.py
5353
54+
cd test
55+
python test.py
56+
5457
- name: Run pytest
5558
run: |
5659
pytest tests
5760
5861
- name: Install & test NeuroMLlite
5962
run: |
60-
git clone --branch experimental https://github.com/NeuroML/NeuroMLlite.git
63+
git clone --branch development https://github.com/NeuroML/NeuroMLlite.git
6164
cd NeuroMLlite
62-
pip install .
63-
pip install pyneuroml>=0.5.18
65+
#pip install . # Use versions of neuroml libs as set in setup.py
6466
cd examples
6567
python Example1.py
6668
6769
68-
- name: Install GPy (py3.9)
69-
if: ${{ matrix.python-version == '3.9' }}
70-
run: python -m pip install git+https://github.com/SheffieldML/GPy.git@devel
71-
72-
7370
- name: Install MDF
74-
if: ${{ matrix.python-version != '3.10' }}
7571
run: |
7672
7773
git clone --branch development https://github.com/ModECI/MDF.git

examples/test/test.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## TopClass
2+
A model....
3+
4+
### Allowed parameters
5+
<table>
6+
<tr>
7+
<td><b>id</b></td>
8+
<td>str</td>
9+
<td><i>The unique id of the thing</i></td>
10+
</tr>
11+
12+
13+
<tr>
14+
<td><b>float_like_req</b></td>
15+
<td>int</td>
16+
<td><i>name says it all...</i></td>
17+
</tr>
18+
19+
20+
<tr>
21+
<td><b>float_like_optional</b></td>
22+
<td>int</td>
23+
<td><i>name also says it all...</i></td>
24+
</tr>
25+
26+
27+
</table>

examples/test/test.py

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import modelspec
2+
from modelspec import field, instance_of, optional
3+
from modelspec.base_types import Base
4+
from typing import List
5+
6+
# Example testing multiple options...
7+
8+
from typing import Any
9+
10+
11+
def convert2float(x: Any) -> float:
12+
print("Converting {} ({})".format(x, type(x)))
13+
"""Convert to float if not None"""
14+
if x is not None:
15+
return float(x)
16+
else:
17+
return None
18+
19+
20+
@modelspec.define
21+
class TopClass(Base):
22+
"""
23+
A model....
24+
25+
Args:
26+
id: The unique id of the thing
27+
float_like_req: name says it all...
28+
float_like_optional: name also says it all...
29+
"""
30+
31+
id: str = field(validator=instance_of(str))
32+
float_like_req: int = field(
33+
default=None, validator=instance_of(float), converter=convert2float
34+
)
35+
float_like_optional: int = field(
36+
default=None, validator=optional(instance_of(float)), converter=convert2float
37+
)
38+
39+
40+
tc = TopClass(
41+
id="MyTest", float_like_req="03"
42+
) # a string which can be converted to a float...
43+
44+
# tc.float_like_req = 2.01
45+
tc.float_like_optional = 43
46+
47+
48+
print(tc)
49+
50+
tc.to_yaml_file("test_instance.yaml")
51+
52+
doc_md = tc.generate_documentation(format="markdown")
53+
54+
with open("test.md", "w") as d:
55+
d.write(doc_md)
56+
57+
58+
print("\nGenerating specification in dict form")
59+
doc_dict = tc.generate_documentation(format="dict")
60+
61+
import yaml
62+
63+
print("Generating specification in YAML")
64+
with open("test.specification.yaml", "w") as d:
65+
d.write(yaml.dump(doc_dict, indent=4, sort_keys=False))

examples/test/test.specification.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
TopClass:
2+
definition: A model....
3+
allowed_parameters:
4+
id:
5+
type: str
6+
description: The unique id of the thing
7+
float_like_req:
8+
type: int
9+
description: name says it all...
10+
float_like_optional:
11+
type: int
12+
description: name also says it all...

examples/test/test_instance.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
MyTest:
2+
float_like_req: 3.0
3+
float_like_optional: 43.0

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"pytorch-sphinx-theme==0.0.19",
2424
"sphinxcontrib-versioning",
2525
],
26-
"dev": ["flake8"],
26+
"dev": ["flake8", "pyneuroml>=0.7.2", "NeuroMLlite>=0.5.3"],
2727
}
2828
extras["all"] = sum(extras.values(), [])
2929
extras["dev"] += extras["test"]

src/modelspec/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.2.6"
1+
__version__ = "0.2.7"
22

33
from .base_types import Base, define, has, field, fields, optional, instance_of, in_
44

src/modelspec/base_types.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
MARKDOWN_FORMAT = "markdown"
3434
RST_FORMAT = "rst"
3535
DICT_FORMAT = "dict"
36+
ALL_FORMATS = [MARKDOWN_FORMAT, RST_FORMAT, DICT_FORMAT]
3637

3738

3839
class EvaluableExpression(str):
@@ -572,8 +573,12 @@ def _cls_generate_documentation(cls, format: str = MARKDOWN_FORMAT):
572573

573574
if format == MARKDOWN_FORMAT or format == RST_FORMAT:
574575
doc_string = ""
575-
if format == DICT_FORMAT:
576+
elif format == DICT_FORMAT:
576577
doc_dict = {}
578+
else:
579+
raise ValueError(
580+
f"Unknown format: '{format}', recognised formats: '{ALL_FORMATS}''"
581+
)
577582

578583
definition = cls._parse_definition()
579584
allowed_fields = cls._parse_allowed_fields()

test_all.sh

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ pip install .
66
cd examples
77
python document.py
88

9-
cd ..
9+
cd test
10+
python test.py
1011

11-
pytest tests
12+
cd ../..
13+
14+
pytest tests -v
1215

1316
pre-commit run --all-files

0 commit comments

Comments
 (0)