Skip to content

Commit 1107364

Browse files
committed
Disable export to xml on py3.7 or less
1 parent d7b69f8 commit 1107364

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

docs/sphinx/source/api/examples/document.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from modelspec import field, instance_of, optional
33
from modelspec.base_types import Base
44
from typing import List
5+
import sys
56

67
# Example showing how to create a model of a document and use it to create/serialize instances
78

@@ -69,13 +70,16 @@ class Document(Base):
6970

7071
doc.to_json_file("document.json")
7172
doc.to_yaml_file("document.yaml")
73+
print(" >> Full document details in YAML format:\n")
74+
print(doc.to_yaml())
75+
7276
doc.to_bson_file("document.bson")
73-
doc.to_xml_file("document.xml")
7477

75-
print(" >> Full document details in YAML format:\n")
78+
if sys.version_info >= (3, 8):
79+
doc.to_xml_file("document.xml")
80+
print(" >> Full document details in XML format:\n")
81+
print(doc.to_xml())
7682

77-
print(doc.to_yaml())
78-
print(doc.to_xml())
7983

8084
doc_md = doc.generate_documentation(format="markdown")
8185

examples/document.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from modelspec import field, instance_of, optional
33
from modelspec.base_types import Base
44
from typing import List
5+
import sys
56

67
# Example showing how to create a model of a document and use it to create/serialize instances
78

@@ -69,13 +70,16 @@ class Document(Base):
6970

7071
doc.to_json_file("document.json")
7172
doc.to_yaml_file("document.yaml")
73+
print(" >> Full document details in YAML format:\n")
74+
print(doc.to_yaml())
75+
7276
doc.to_bson_file("document.bson")
73-
doc.to_xml_file("document.xml")
7477

75-
print(" >> Full document details in YAML format:\n")
78+
if sys.version_info >= (3, 8):
79+
doc.to_xml_file("document.xml")
80+
print(" >> Full document details in XML format:\n")
81+
print(doc.to_xml())
7682

77-
print(doc.to_yaml())
78-
print(doc.to_xml())
7983

8084
doc_md = doc.generate_documentation(format="markdown")
8185

examples/neuroml2/neuroml2_spec.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from modelspec import field, instance_of, optional
33
from modelspec.base_types import Base
44
from typing import List
5+
import sys
56

67
# Example showing ...
78

@@ -147,13 +148,15 @@ class neuroML(Base):
147148

148149
nml_doc.to_json_file("%s.json" % nml_doc.id)
149150
nml_doc.to_yaml_file("%s.yaml" % nml_doc.id)
150-
nml_doc.to_bson_file("%s.bson" % nml_doc.id)
151-
nml_doc.to_xml_file("%s.xml" % nml_doc.id)
152-
153151
print(" >> Full document details in YAML format:\n")
154-
155152
print(nml_doc.to_yaml())
156-
print(nml_doc.to_xml())
153+
154+
nml_doc.to_bson_file("%s.bson" % nml_doc.id)
155+
156+
if sys.version_info >= (3, 8):
157+
nml_doc.to_xml_file("%s.xml" % nml_doc.id)
158+
print(" >> Full document details in XML format:\n")
159+
print(nml_doc.to_xml())
157160

158161
print("Generating documentation...")
159162

src/modelspec/base_types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ def to_xml(self) -> str:
119119
"""
120120
Convert the data dictionary to an XML string representation using the ElementTree library.
121121
"""
122+
if sys.version_info < (3, 8):
123+
raise Exception(
124+
"XML export functionality is not available in Python 3.7 or lower"
125+
)
122126
from modelspec.utils import build_xml_element
123127

124128
# root = ET.Element("modelspec")

0 commit comments

Comments
 (0)