Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING CHANGE: drop python 2 support #66

Merged
merged 5 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -41,7 +41,7 @@ jobs:
- name: Test with pytest
run: |
pytest
pytest --cov=lems
- name: Test examples
run: |
Expand Down
37 changes: 18 additions & 19 deletions lems/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)