Skip to content

Commit d993521

Browse files
Merge pull request #386 from NeuroML/feat/coverage
Feat/coverage
2 parents 357ec2c + 57f609b commit d993521

File tree

14 files changed

+61
-53
lines changed

14 files changed

+61
-53
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,3 @@ jobs:
5050
pynml -h
5151
5252
./test-ghactions.sh -neuron
53-
54-
- name: Lint with ruff
55-
run: |
56-
pip install ruff
57-
ruff . --exit-zero --show-source

.github/workflows/ruff.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Ruff
2+
on:
3+
pull_request:
4+
branches:
5+
- master
6+
- development
7+
- experimental
8+
- 'test*'
9+
jobs:
10+
ruff:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: chartboost/ruff-action@v1
15+
with:
16+
changed-files: 'true'

pyneuroml/channelml/__init__.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@
1313
Copyright 2023 NeuroML contributors
1414
"""
1515

16-
1716
import argparse
1817
import logging
19-
import typing
2018
import pathlib
21-
from lxml.etree import parse, XSLT, tostring
19+
import typing
20+
from typing import Optional
2221

22+
from lxml.etree import XSLT, parse, tostring
2323

2424
from pyneuroml.utils.cli import build_namespace
25-
from typing import Optional
26-
2725

2826
logger = logging.getLogger(__name__)
2927
logger.setLevel(logging.INFO)
@@ -53,7 +51,7 @@ def channelml2nml(
5351
"""
5452
try:
5553
dom = parse(channelmlfile)
56-
except:
54+
except Exception:
5755
logger.error(f"Cannot parse channelml file: {channelmlfile}")
5856
return None
5957
if not xsltfile:
@@ -62,7 +60,7 @@ def channelml2nml(
6260

6361
try:
6462
xslt = parse(xsltfile)
65-
except:
63+
except Exception:
6664
logger.error(f"Cannot parse XSL: {xsltfile}")
6765
return None
6866

pyneuroml/lems/LEMSSimulation.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,25 @@
33
Helper class for generating LEMS xml files for simulations
44
"""
55

6-
import os.path
76
import logging
8-
import typing
9-
import random
107
import os
8+
import os.path
9+
import random
10+
import typing
11+
from typing import Optional
1112

1213
import airspeed
13-
from pyneuroml import __version__ as pynml_ver
1414
from neuroml import __version__ as libnml_ver
15-
from pyneuroml.pynml import read_neuroml2_file
16-
from pyneuroml.pynml import read_lems_file
15+
16+
from pyneuroml import __version__ as pynml_ver
17+
from pyneuroml.pynml import read_lems_file, read_neuroml2_file
1718
from pyneuroml.utils.plot import get_next_hex_color
1819
from pyneuroml.utils.units import convert_to_units
19-
from typing import Optional
2020

2121
logger = logging.getLogger(__name__)
2222

2323

2424
class LEMSSimulation:
25-
2625
"""
2726
Helper class for creating LEMS Simulations for running NeuroML2 models.
2827
"""
@@ -88,7 +87,7 @@ def __init__(
8887
:type meta: dict
8988
"""
9089

91-
if type(duration) is str:
90+
if isinstance(duration, str):
9291
# is this just the magnitude in the string?
9392
try:
9493
duration_mag_ms = float(duration)
@@ -97,7 +96,7 @@ def __init__(
9796
else:
9897
duration_mag_ms = float(duration)
9998

100-
if type(dt) is str:
99+
if isinstance(dt, str):
101100
# is this just the magnitude in the string?
102101
try:
103102
dt_mag_ms = float(dt)

pyneuroml/neuron/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818
import airspeed
1919
import yaml
2020

21-
try:
22-
from yaml import CDumper as Dumper
23-
except ImportError:
24-
from yaml import Dumper
25-
2621
from pyneuroml.pynml import validate_neuroml1, validate_neuroml2
2722

2823
pp = pprint.PrettyPrinter(depth=4)

pyneuroml/plot/PlotTimeSeries.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
import typing
1414

1515
import numpy
16-
import pyneuroml.lems as pynmll
17-
import pyneuroml.plot.Plot as pynmlplt
1816
from matplotlib import pyplot as plt
1917
from matplotlib_scalebar.scalebar import ScaleBar
18+
19+
import pyneuroml.lems as pynmll
20+
import pyneuroml.plot.Plot as pynmlplt
2021
from pyneuroml.utils.cli import build_namespace
2122

2223
logger = logging.getLogger(__name__)
@@ -77,7 +78,7 @@ def plot_time_series(
7778
:raises ValueError: if a 't' (time) key is not found in the traces data
7879
7980
"""
80-
if type(trace_data) is dict:
81+
if isinstance(trace_data, dict):
8182
trace_data = [trace_data]
8283

8384
num_traces = 0
@@ -217,7 +218,7 @@ def plot_time_series_from_data_files(
217218
218219
"""
219220
all_traces = []
220-
if type(data_file_names) is str:
221+
if isinstance(data_file_names, str):
221222
data_file_names = [data_file_names]
222223

223224
for f in data_file_names:

pyneuroml/runners.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
Copyright 2024 NeuroML contributors
88
"""
99

10-
1110
import inspect
1211
import logging
1312
import math
@@ -107,9 +106,12 @@ def run_lems_with_jneuroml(
107106
return False
108107

109108
if load_saved_data:
110-
if verbose: logger.info(
111-
"Reloading data generated by: {}, plotting: {}".format(lems_file_name, plot)
112-
)
109+
if verbose:
110+
logger.info(
111+
"Reloading data generated by: {}, plotting: {}".format(
112+
lems_file_name, plot
113+
)
114+
)
113115
return reload_saved_data(
114116
lems_file_name,
115117
base_dir=exec_in_dir,
@@ -676,15 +678,15 @@ def _gui_string(nogui: bool) -> str:
676678

677679

678680
def _include_string(
679-
paths_to_include: typing.Union[str, typing.Tuple[str], typing.List[str]]
681+
paths_to_include: typing.Union[str, typing.Tuple[str], typing.List[str]],
680682
) -> str:
681683
"""Convert a path or list of paths into an include string to be used by jnml.
682684
:param paths_to_include: path or list or tuple of paths to be included
683685
:type paths_to_include: str or list(str) or tuple(str)
684686
:returns: include string to be used with jnml.
685687
"""
686688
if paths_to_include:
687-
if type(paths_to_include) is str:
689+
if isinstance(paths_to_include, str):
688690
paths_to_include = [paths_to_include]
689691
if type(paths_to_include) in (tuple, list):
690692
result = " -I '%s'" % ":".join(paths_to_include)
@@ -847,7 +849,7 @@ def run_jneuroml_with_realtime_output(
847849

848850
except KeyboardInterrupt as e:
849851
raise e
850-
except:
852+
except Exception:
851853
logger.error("*** Execution of jnml has failed! ***")
852854
logger.error("*** Command: %s ***" % command)
853855
if exit_on_fail:

pyneuroml/tellurium/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
run a model using the tellurium engine
33
"""
44

5-
import os
65
import logging
7-
from pyneuroml.sedml import validate_sedml_files
6+
import os
87

8+
from pyneuroml.sedml import validate_sedml_files
99

1010
logger = logging.getLogger(__name__)
1111
logger.setLevel(logging.INFO)
@@ -51,7 +51,7 @@ def run_from_sedml_file(input_files, args):
5151
if "-outputdir" in args:
5252
try:
5353
outputdir = args[args.index("-outputdir") + 1]
54-
except:
54+
except Exception:
5555
raise ValueError("Incorrectly specified outputdir")
5656

5757
if outputdir == "none":

pyneuroml/tune/NeuroMLTuner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ def _run_optimisation(a: argparse.Namespace) -> typing.Optional[dict]:
646646
added = []
647647
# print("Plotting saved data from %s which are relevant for targets: %s"%(best_candidate_v.keys(), a.target_data.keys()))
648648

649-
fig = plt.figure()
649+
plt.figure()
650650
plt.get_current_fig_manager().set_window_title(
651651
"Simulation of fittest individual from run: %s" % ref
652652
)

pyneuroml/utils/plot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from matplotlib.lines import Line2D
1919
from matplotlib.patches import Rectangle
2020
from matplotlib_scalebar.scalebar import ScaleBar
21-
from neuroml import Cell, NeuroMLDocument
21+
from neuroml import Cell, NeuroMLDocument, Segment
2222
from neuroml.loaders import read_neuroml2_file
2323

2424
logger = logging.getLogger(__name__)
@@ -317,9 +317,9 @@ def get_cell_bound_box(cell: Cell):
317317
:returns: tuple (min view, max view)
318318
319319
"""
320-
seg0 = cell.morphology.segments[0] # type: Segment
320+
seg0: Segment = cell.morphology.segments[0]
321321
ex1 = numpy.array([seg0.distal.x, seg0.distal.y, seg0.distal.z])
322-
seg1 = cell.morphology.segments[-1] # type: Segment
322+
seg1: Segment = cell.morphology.segments[-1]
323323
ex2 = numpy.array([seg1.distal.x, seg1.distal.y, seg1.distal.z])
324324
center = (ex1 + ex2) / 2
325325
diff = numpy.linalg.norm(ex2 - ex1)

0 commit comments

Comments
 (0)