Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit 7cb8763

Browse files
Fix CI
1 parent f61cfdd commit 7cb8763

12 files changed

+54
-17
lines changed

.github/workflows/run-tox.yml

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ jobs:
2222
tox-env: py311
2323
- python-version: '3.12'
2424
tox-env: py312
25+
- python-version: '3.13'
26+
tox-env: py313
27+
- python-version: '3.12'
28+
tox-env: coverage
2529
codecov: codecov
2630
- python-version: '3.12'
2731
tox-env: lint

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ dist
1212
htmlcov
1313
dask-worker-space
1414
venv
15+
_version.py

.pylintrc

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
[MAIN]
2+
# Files or directories to be skipped. They should be base names, not paths.
3+
ignore=_version.py
4+
15
[MESSAGES CONTROL]
26
disable=fixme,invalid-name,len-as-condition,no-else-return
37

@@ -8,6 +12,8 @@ max-line-length=100
812
[DESIGN]
913
# Maximum number of arguments for function / method
1014
max-args=8
15+
# Maximum number of positional arguments for function / method.
16+
max-positional-arguments=11
1117
# Argument names that match this expression will be ignored. Default to name
1218
# with leading underscore
1319
ignored-argument-names=_.*
@@ -48,3 +54,6 @@ ignore-docstrings=yes
4854
ignored-classes=numpy,list
4955

5056
extension-pkg-whitelist=numpy,lxml
57+
58+
# Files or directories to be skipped. They should be base names, not paths.
59+
ignore=_version.py

connectome_tools/apps/s2f_recipe.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import yaml
1111
from bluepysnap import Circuit
1212

13+
from connectome_tools import __version__
1314
from connectome_tools.s2f_recipe import (
1415
BOUTON_REDUCTION_FACTOR,
1516
CV_SYNS_CONNECTION,
@@ -33,7 +34,6 @@
3334
timed,
3435
validate_config,
3536
)
36-
from connectome_tools.version import __version__
3737

3838
L = logging.getLogger("s2f-recipe")
3939

connectome_tools/equation.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ def evaluate(expression, context=None):
1515
expression(str): math expression.
1616
context: optional dict of variables.
1717
18+
Returns:
19+
the calculated value.
20+
21+
Raises:
22+
NameError: if an unexpected name is present in the given expression.
23+
1824
Examples:
1925
>>> evaluate("1 + 2 * 3")
2026
7
@@ -28,4 +34,11 @@ def evaluate(expression, context=None):
2834
for name in code.co_names:
2935
if name not in allowed_names:
3036
raise NameError(f"The use of '{name}' is not allowed")
31-
return eval(code, {"__builtins__": {}}, allowed_names)
37+
# Add `__import__` to the `__builtins__` dict, because numpy may print a RuntimeWarning,
38+
# and this causes `__import__('warnings')` to be explicitly called in Python >= 3.13,
39+
# raising the exception KeyError: '__import__' if __import__ is not found in globals.
40+
# For example, the following instruction raises with numpy 2.1.3 and Python 3.13.0:
41+
# >>> eval('n ** 0.5', {'__builtins__': {}}, {'n': np.float64(-1)})
42+
return eval( # pylint: disable=eval-used
43+
code, {"__builtins__": {"__import__": __import__}}, allowed_names
44+
)

connectome_tools/merge.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
import submitit
2121
import yaml
2222

23+
from connectome_tools import __version__
2324
from connectome_tools.apps import s2f_recipe
2425
from connectome_tools.utils import DEFAULT_CONFIG_PATH, load_yaml, setup_logging, validate_config
25-
from connectome_tools.version import __version__
2626

2727
L = logging.getLogger(__name__)
2828

connectome_tools/s2f_recipe/estimate_syns_con.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ def _execute(pathway, estimate, formulae, syn_class_map, max_value):
134134
return []
135135
L.info("nsyn estimate for pathway %s: %.3g", pathway, value)
136136
expression = _choose_formula(formulae, pathway, syn_class_map)
137-
value = equation.evaluate(expression, context={"n": value})
137+
# ensure that n is np.float64, to get consistent results
138+
value = equation.evaluate(expression, context={"n": np.float64(value)})
138139
# NSETM-1137 consider nan as 1.0
139140
if value < 1.0 or np.isnan(value):
140141
value = 1.0

pyproject.toml

+11-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ dependencies = [
2626
"morphio>=3.0.1,<4.0.0",
2727
"voxcell>=3.0,<4.0",
2828
# setuptools needed because of https://github.com/facebookincubator/submitit/issues/1765
29-
'setuptools;python_version>="3.12"',
29+
"setuptools",
30+
# pynrrd>=1.1.0 needed because of https://github.com/mhe/pynrrd/issues/152
31+
# this dependency can be removed after pynrrd 1.1.0 is released
32+
"pynrrd @ git+https://github.com/mhe/pynrrd.git@e92a82dd12b6fa99405dc655c4374415367cb778",
3033
]
3134
license = {text = "Apache-2.0"}
3235
classifiers=[
@@ -63,7 +66,8 @@ s2f-recipe = "connectome_tools.apps.s2f_recipe:app"
6366
s2f-recipe-merge = "connectome_tools.apps.s2f_recipe_merge:cli"
6467

6568
[tool.setuptools.packages.find]
66-
include = ["connectome_tools"]
69+
include = ["connectome_tools*"]
70+
namespaces = true
6771

6872
[tool.setuptools_scm]
6973
version_file = "connectome_tools/_version.py"
@@ -91,3 +95,8 @@ pythonpath = [
9195
filterwarnings = [
9296
"ignore::DeprecationWarning:nptyping",
9397
]
98+
99+
[tool.coverage.run]
100+
omit = [
101+
"connectome_tools/_version.py",
102+
]

tests/test_dataset.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
mtypes=None,
1818
expected=pd.DataFrame(
1919
[
20-
["*", 42.0, np.NaN, np.NaN, np.NaN],
21-
["L1_DAC", 10.0, 0.0, 1.0, np.NaN],
22-
["L23_MC", 30.0, 0.0, 1.0, np.NaN],
23-
["SO_OLM", 50.0, 0.0, 1.0, np.NaN],
20+
["*", 42.0, np.nan, np.nan, np.nan],
21+
["L1_DAC", 10.0, 0.0, 1.0, np.nan],
22+
["L23_MC", 30.0, 0.0, 1.0, np.nan],
23+
["SO_OLM", 50.0, 0.0, 1.0, np.nan],
2424
],
2525
columns=["mtype", "mean", "std", "size", "sample"],
2626
),
@@ -29,7 +29,7 @@
2929
_="filter_mtypes",
3030
mtypes={"L1_DAC"},
3131
expected=pd.DataFrame(
32-
[["L1_DAC", 10.0, 0.0, 1.0, np.NaN]],
32+
[["L1_DAC", 10.0, 0.0, 1.0, np.nan]],
3333
columns=["mtype", "mean", "std", "size", "sample"],
3434
),
3535
),
@@ -51,7 +51,7 @@ def test_read_bouton_density(_, mtypes, expected):
5151
expected=pd.DataFrame(
5252
[
5353
["SLM_PPA", "SLM_PPA", 16.2, 8.77, 5.0, "1,16,16,20,28"],
54-
["SLM_PPA", "SO_BP", np.NaN, np.NaN, np.NaN, np.NaN],
54+
["SLM_PPA", "SO_BP", np.nan, np.nan, np.nan, np.nan],
5555
["SLM_PPA", "SP_AA", 3.0, 1.63, 3.0, "1,3,5"],
5656
],
5757
columns=["from", "to", "mean", "std", "size", "sample"],

tests/test_equation.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
("sin(n * pi)", {"n": 0.5}, 1.0),
1414
("n * 3", {"n": np.nan}, np.nan),
1515
("1 / n", {"n": np.nan}, np.nan),
16+
("6 * ((n - 2) ** 0.5) - 1", {"n": 1.5}, (-1 + 4.242640687119286j)), # float -> complex
17+
("6 * ((n - 2) ** 0.5) - 1", {"n": np.float64(1.5)}, np.nan), # np.float64 -> np.nan
1618
],
1719
)
1820
def test_evaluate(expression, context, expected):
@@ -23,9 +25,9 @@ def test_evaluate(expression, context, expected):
2325
@pytest.mark.parametrize(
2426
("expression", "error", "match"),
2527
[
26-
("1 + 2 *", SyntaxError, "invalid syntax"),
28+
("1 + 2 *", SyntaxError, "invalid syntax|unexpected EOF while parsing"),
2729
("sqrt(-1)", ValueError, "math domain error"),
28-
("1 / 0", ValueError, "math domain error"),
30+
("1 / 0", ZeroDivisionError, "division by zero"),
2931
("sum([1, 2])", NameError, "The use of 'sum' is not allowed"),
3032
("open('/etc/passwd')", NameError, "The use of 'open' is not allowed"),
3133
(

tests/test_merge.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
from utils import TEST_DATA_DIR, canonicalize_xml, tmp_cwd, xml_to_regular_dict
77

88
import connectome_tools.merge as test_module
9+
from connectome_tools import __version__
910
from connectome_tools.merge import RECIPES_DIR, SLURM_DIR, WORKDIR
1011
from connectome_tools.utils import load_yaml
11-
from connectome_tools.version import __version__
1212

1313

1414
def test_execute_pending_tasks_success():

tox.ini

-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ ignore_basepython_conflict = true
2222
basepython=python3.11
2323
deps = {[base]testdeps}
2424
commands = pytest -v tests {posargs}
25-
setenv =
26-
PIP_INDEX_URL = https://bbpteam.epfl.ch/repository/devpi/simple
2725

2826
[testenv:check-version]
2927
skip_install = true

0 commit comments

Comments
 (0)