From f90f3ee9e7b1d504c04599628bbb263187bd0bd3 Mon Sep 17 00:00:00 2001
From: pgleeson
Date: Thu, 25 Apr 2024 08:55:46 +0100
Subject: [PATCH 1/3] Format update
---
.github/workflows/ci.yml | 2 +-
docs/sphinx/source/api/Contributors.md | 2 +-
examples/neuroml2/neuroml2_spec.py | 1 -
examples/sbml/sbml32spec.py | 1 -
examples/sbml/sbml_validators.py | 1 -
src/modelspec/base_types.py | 5 -----
src/modelspec/utils.py | 9 ---------
tests/test_utils.py | 1 -
8 files changed, 2 insertions(+), 20 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index e90604ad..bbdc85cf 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -112,7 +112,7 @@ jobs:
python contributors.py
cd sphinx
make clean
- make html
+ make html
- name: Install and test with OMV
if: ${{ matrix.runs-on != 'windows-latest' }}
diff --git a/docs/sphinx/source/api/Contributors.md b/docs/sphinx/source/api/Contributors.md
index 20ab4a5c..ab26a9f3 100644
--- a/docs/sphinx/source/api/Contributors.md
+++ b/docs/sphinx/source/api/Contributors.md
@@ -3,7 +3,7 @@
# Modelspec contributors
This page list names and Github profiles of contributors to Modelspec, listed in no particular order.
-This page is generated periodically, most recently on 2024-04-12.
+This page is generated periodically, most recently on 2024-04-25.
- Padraig Gleeson ([@pgleeson](https://github.com/pgleeson))
- Manifest Chakalov ([@mqnifestkelvin](https://github.com/mqnifestkelvin))
diff --git a/examples/neuroml2/neuroml2_spec.py b/examples/neuroml2/neuroml2_spec.py
index 36422ab5..5b9be78c 100644
--- a/examples/neuroml2/neuroml2_spec.py
+++ b/examples/neuroml2/neuroml2_spec.py
@@ -128,7 +128,6 @@ class neuroml(Base):
if __name__ == "__main__":
-
nml_doc = neuroml(id="TestNeuroML")
izh = izhikevich2007Cell(
diff --git a/examples/sbml/sbml32spec.py b/examples/sbml/sbml32spec.py
index c6372a91..6abebf2c 100644
--- a/examples/sbml/sbml32spec.py
+++ b/examples/sbml/sbml32spec.py
@@ -82,7 +82,6 @@ class SBase(Base):
@modelspec.define
class SBaseWithId(SBase):
-
id: str = field(default=None, validator=optional([instance_of(str), valid_sid]))
diff --git a/examples/sbml/sbml_validators.py b/examples/sbml/sbml_validators.py
index 5ab66a5b..b1bb44a5 100644
--- a/examples/sbml/sbml_validators.py
+++ b/examples/sbml/sbml_validators.py
@@ -168,7 +168,6 @@ def validate_sbml(doc, units_consistency: bool = False) -> None:
if __name__ == "__main__":
-
import libsbml
sbml_file = sys.argv[1]
diff --git a/src/modelspec/base_types.py b/src/modelspec/base_types.py
index f9459a37..23f8f2f5 100644
--- a/src/modelspec/base_types.py
+++ b/src/modelspec/base_types.py
@@ -147,7 +147,6 @@ def from_dict(cls, d: Dict[str, Any]) -> "Base":
# If this object has an id attribute, it may have been serialized within a dict with the id as the key, even if
# it is a single object.
if "id" in [f.name for f in attr.fields(cls)] and "id" not in d.keys():
-
keys = list(d.keys())
if len(keys) == 0:
raise ValueError(
@@ -297,7 +296,6 @@ def to_yaml_file(
filename = f"{self.id}.yaml"
with open(filename, "w") as outfile:
-
# We need to setup another
yaml.dump(
yaml_converter.unstructure(self.to_dict()),
@@ -313,7 +311,6 @@ def to_xml_file(
filename: Optional[str] = None,
include_metadata: bool = True,
) -> str:
-
if filename is None:
filename = f"{self.id}.xml"
@@ -636,7 +633,6 @@ def _is_base_type(
can_be_none=False,
can_be_eval_expr=False,
):
-
import numpy
if verbose:
@@ -730,7 +726,6 @@ def _cls_generate_documentation(cls, format: str = MARKDOWN_FORMAT):
rst_url_format = "`%s <%s>`__"
def insert_links(text, format=MARKDOWN_FORMAT):
-
code_ref = ":code:`"
# print(" > Converting: %s" % text)
text2 = text
diff --git a/src/modelspec/utils.py b/src/modelspec/utils.py
index af2ca292..2d4a65c6 100644
--- a/src/modelspec/utils.py
+++ b/src/modelspec/utils.py
@@ -192,14 +192,12 @@ def convert_xml_dict_values(value):
def save_to_json_file(info_dict, filename, indent=4):
-
strj = json.dumps(info_dict, indent=indent)
with open(filename, "w") as fp:
fp.write(strj)
def save_to_yaml_file(info_dict, filename, indent=4):
-
if sys.version_info[0] == 2:
stry = yaml.dump(info_dict, indent=indent, default_flow_style=False)
else:
@@ -251,7 +249,6 @@ def build_xml_element(data, parent=None):
attrs = attr.fields(data.__class__)
for aattr in attrs:
-
print_(" == Looking at: {} ({})".format(aattr, type(aattr)), verbose)
if isinstance(aattr.default, attr.Factory):
children = data.__getattribute__(aattr.name)
@@ -280,7 +277,6 @@ def build_xml_element(data, parent=None):
):
parent.set(attribute_name, str(attribute_value))
elif type(attribute_value) == dict:
-
"""for k, v in attribute_value.items():
child_element = build_xml_element(v)"""
else:
@@ -309,7 +305,6 @@ def ascii_encode_dict(data):
def _parse_element(dict_format, to_build):
-
print_("Parse for element: [%s]" % dict_format, verbose)
for k in dict_format.keys():
print_(
@@ -323,7 +318,6 @@ def _parse_element(dict_format, to_build):
def _parse_attributes(dict_format, to_build):
-
for key in dict_format:
value = dict_format[key]
new_format = True
@@ -489,7 +483,6 @@ def evaluate(
else:
expr = int(expr)
except:
-
try:
if array_format == FORMAT_TENSORFLOW:
expr = tf.constant(float(expr))
@@ -557,7 +550,6 @@ def evaluate(
)
if (type(v) is float or type(v) is str) and int(v) == v:
-
print_(" Returning int: %s" % int(v), verbose)
if array_format == FORMAT_TENSORFLOW:
@@ -576,7 +568,6 @@ def evaluate(
def parse_list_like(list_str):
-
if isinstance(list_str, int):
return [list_str]
elif isinstance(list_str, float):
diff --git a/tests/test_utils.py b/tests/test_utils.py
index f3927865..80fc991d 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -12,7 +12,6 @@
class TestUtils(unittest.TestCase):
def test_evaluate(self):
-
assert evaluate("33") == 33.0
assert evaluate("33") == 33
assert evaluate(33) == 33
From 1a048fc4fe30bc891352c7b03396948bf97c8470 Mon Sep 17 00:00:00 2001
From: pgleeson
Date: Thu, 25 Apr 2024 09:07:37 +0100
Subject: [PATCH 2/3] Exclude maclatest py3.8/9
---
.github/workflows/ci.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index bbdc85cf..1c255654 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -29,9 +29,9 @@ jobs:
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
runs-on: [ubuntu-latest, macos-latest, windows-latest]
exclude:
- - runs-on: macos-14
+ - runs-on: macos-latest
python-version: "3.8"
- - runs-on: macos-14
+ - runs-on: macos-latest
python-version: "3.9"
steps:
From 73b57613ec2ec03eedde27ac9721eb3b5b34b38d Mon Sep 17 00:00:00 2001
From: pgleeson
Date: Thu, 25 Apr 2024 09:49:18 +0100
Subject: [PATCH 3/3] More flake highlighted code tweaks
---
.gitignore | 1 +
docs/contributors.py | 1 -
examples/sbml/sbml_validators.py | 2 +-
examples/sbml/test_sbml3.py | 1 -
src/modelspec/base_types.py | 5 -----
src/modelspec/utils.py | 36 ++++++++++++++++++--------------
6 files changed, 22 insertions(+), 24 deletions(-)
diff --git a/.gitignore b/.gitignore
index e7c235dc..dd50990e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -164,3 +164,4 @@ cython_debug/
/examples/document.specification.bson
/examples/neuroml2/hello_world.v.dat
/examples/sbml/example_sbml_test.xml
+/updatelibs.sh
diff --git a/docs/contributors.py b/docs/contributors.py
index f472f3b9..78b61bc3 100644
--- a/docs/contributors.py
+++ b/docs/contributors.py
@@ -1,6 +1,5 @@
import requests
import pandas as pd
-import json
import textwrap
from datetime import date
diff --git a/examples/sbml/sbml_validators.py b/examples/sbml/sbml_validators.py
index b1bb44a5..9d2a5663 100644
--- a/examples/sbml/sbml_validators.py
+++ b/examples/sbml/sbml_validators.py
@@ -19,7 +19,7 @@
def valid_kind(instance, attribute, value):
- if not value in sbml_si_units:
+ if value not in sbml_si_units:
raise ValueError(
f"kind {value} must be one of the standard SI units: {sbml_si_units}"
)
diff --git a/examples/sbml/test_sbml3.py b/examples/sbml/test_sbml3.py
index 6b1c717b..1ee32097 100755
--- a/examples/sbml/test_sbml3.py
+++ b/examples/sbml/test_sbml3.py
@@ -7,7 +7,6 @@
import json
import yaml
-import os
from sbml32spec import *
diff --git a/src/modelspec/base_types.py b/src/modelspec/base_types.py
index 23f8f2f5..4f152abc 100644
--- a/src/modelspec/base_types.py
+++ b/src/modelspec/base_types.py
@@ -165,11 +165,6 @@ def from_yaml(cls, yaml_str: str) -> "Base":
"""Instantiate an modelspec object from a YAML string"""
return cls.from_dict(yaml.load(yaml_str, Loader=yaml.SafeLoader))
- @classmethod
- def from_yaml_file(cls, yaml_file: str) -> "Base":
- """Instantiate an modelspec object from a file containing YAML"""
- return cls.from_dict(yaml.load(yaml_file, Loader=yaml.SafeLoader))
-
@classmethod
def from_json(cls, json_str: str) -> "Base":
"""Instantiate an modelspec object from a JSON string"""
diff --git a/src/modelspec/utils.py b/src/modelspec/utils.py
index 2d4a65c6..4eca4fb7 100644
--- a/src/modelspec/utils.py
+++ b/src/modelspec/utils.py
@@ -269,14 +269,14 @@ def build_xml_element(data, parent=None):
)
if attribute_value is not None:
if (
- type(attribute_value) is int
- or type(attribute_value) is float
- or type(attribute_value) is str
- or type(attribute_value) is bool
- or type(attribute_value) is list
+ isinstance(attribute_value, int)
+ or isinstance(attribute_value, float)
+ or isinstance(attribute_value, str)
+ or isinstance(attribute_value, bool)
+ or isinstance(attribute_value, list)
):
parent.set(attribute_name, str(attribute_value))
- elif type(attribute_value) == dict:
+ elif isinstance(attribute_value, dict):
"""for k, v in attribute_value.items():
child_element = build_xml_element(v)"""
else:
@@ -327,7 +327,7 @@ def _parse_attributes(dict_format, to_build):
)
if new_format:
- if type(to_build) == dict:
+ if isinstance(to_build, dict):
to_build[key] = value
elif key in to_build.allowed_children:
@@ -339,11 +339,11 @@ def _parse_attributes(dict_format, to_build):
exec("to_build.%s.append(ff)" % key)
else:
if (
- type(value) == str
- or type(value) == int
- or type(value) == float
- or type(value) == bool
- or type(value) == list
+ isinstance(value, str)
+ or isinstance(value, int)
+ or isinstance(value, float)
+ or isinstance(value, bool)
+ or isinstance(value, list)
or value is None
):
to_build.__setattr__(key, value)
@@ -364,11 +364,15 @@ def _parse_attributes(dict_format, to_build):
exec("to_build.%s = ff" % key)
else:
- if type(to_build) == dict:
+ if isinstance(to_build, dict):
to_build[key] = value
- elif type(value) == str or type(value) == int or type(value) == float:
+ elif (
+ isinstance(value, str)
+ or isinstance(value, int)
+ or isinstance(value, float)
+ ):
to_build.__setattr__(key, value)
- elif type(value) == list:
+ elif isinstance(value, list):
type_to_use = to_build.allowed_children[key][1]
for vl in value:
@@ -397,7 +401,7 @@ def locate_file(f, base_dir):
def _val_info(param_val):
- if type(param_val) == np.ndarray:
+ if isinstance(param_val, np.ndarray):
pp = "%s" % (np.array2string(param_val, threshold=4, edgeitems=1))
pp = pp.replace("\n", "")
pp += f" (NP {param_val.shape} {param_val.dtype})"