diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f541de2..794f3cd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [2.7, 3.7, 3.8, 3.9] + python-version: ["3.7", "3.8", "3.9", "3.10"] steps: - uses: actions/checkout@v2 @@ -25,7 +25,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install pytest + python -m pip install pytest pytest-cov if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Checkout NeuroML2 @@ -41,7 +41,7 @@ jobs: - name: Test with pytest run: | - pytest + pytest --cov=lems - name: Test examples run: | diff --git a/lems/model/model.py b/lems/model/model.py index eb5f6ee..281a34e 100644 --- a/lems/model/model.py +++ b/lems/model/model.py @@ -5,16 +5,18 @@ :organization: LEMS (https://github.com/organizations/LEMS) """ +from __future__ import annotations import os from os.path import dirname # For python versions where typing isn't available at all try: - from typing import List, Dict, Union, Tuple + import typing except ImportError: pass import copy +import lems from lems import __schema_location__, __schema_version__ from lems.base.base import LEMSBase from lems.base.util import merge_maps, merge_lists @@ -376,8 +378,7 @@ def export_to_file(self, filepath, level_prefix=" "): f.write(xmlstr) f.close() - def resolve(self): - # type: () -> Model + def resolve(self) -> lems.model.Model: """ Resolves references in this model and returns resolved model. @@ -1036,8 +1037,7 @@ def get_numeric_value(self, value_str, dimension=None): # print("Have converted %s to value: %s, dimension %s"%(value_str, numeric_value, dimension)) return numeric_value - def get_component_list(self, substring=""): - # type: (str) -> Dict[str, Component] + def get_component_list(self, substring: str = "") -> dict[str, Component]: """Get all components whose id matches the given substring. Note that in PyLEMS, if a component does not have an id attribute, @@ -1071,8 +1071,7 @@ def get_component_list(self, substring=""): return ret_list - def get_fattened_component_list(self, substring=""): - # type: (str) -> Map + def get_fattened_component_list(self, substring: str = "") -> Map: """Get a list of fattened components whose ids include the substring. A "fattened component" is one where all elements of the components have @@ -1092,8 +1091,7 @@ def get_fattened_component_list(self, substring=""): return fattened_comp_list - def get_nested_components(self, comp): - # type: (Component) -> Dict[str, Component] + def get_nested_components(self, comp: Component) -> dict[str, Component]: """Get all nested (child/children) components in the comp component :param comp: component to get all nested (child/children) components for @@ -1109,8 +1107,7 @@ def get_nested_components(self, comp): return comp_list - def list_exposures(self, substring=""): - # type: (str) -> Dict[FatComponent, Map] + def list_exposures(self, substring: str = "") -> dict[FatComponent, Map]: """Get exposures from model belonging to components which contain the given substring. @@ -1150,8 +1147,9 @@ def list_exposures(self, substring=""): return exposures - def get_full_comp_paths_with_comp_refs(self, comp, comptext=None): - # type: (FatComponent, Union[None, str]) -> None + def get_full_comp_paths_with_comp_refs( + self, comp: FatComponent, comptext: typing.Optional[str] = None + ): """Get list of component paths with all component references also resolved for the given component `comp`. @@ -1281,8 +1279,9 @@ def get_full_comp_paths_with_comp_refs(self, comp, comptext=None): self.temp_vec.pop() self.path_vec.pop() - def construct_path(self, pathlist, skip=None): - # type: (List[str], str) -> str + def construct_path( + self, pathlist: list[str], skip: typing.Optional[str] = None + ) -> str: """Construct path from a list. :param vec: list of text strings to generate path from @@ -1298,8 +1297,9 @@ def construct_path(self, pathlist, skip=None): pathlist.remove(skip) return "/".join(pathlist) - def list_recording_paths_for_exposures(self, substring="", target=""): - # (str, str) -> List[str] + def list_recording_paths_for_exposures( + self, substring: str = "", target: str = "" + ) -> list[str]: """List recording paths for exposures in the model for components matching the given substring, and for the given simulation target. @@ -1369,8 +1369,7 @@ def list_recording_paths_for_exposures(self, substring="", target=""): print("\n".join(exp_paths)) return exp_paths - def get_comp_ref_map(self): - # type () -> Map[str, List[FatComponent]] + def get_comp_ref_map(self) -> Map: """Get a Map of ComponentReferences in the model. :returns: Map with target -> [source] entries diff --git a/setup.py b/setup.py index 0d5794e..680d0a3 100644 --- a/setup.py +++ b/setup.py @@ -34,11 +34,11 @@ "License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)", "Natural Language :: English", "Operating System :: OS Independent", - "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", "Topic :: Scientific/Engineering", ], )