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

Precommit-updates #1515

Merged
merged 4 commits into from
Mar 13, 2024
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
10 changes: 5 additions & 5 deletions .devcontainer/dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ matplotlib >= 2.0
jupyterlab
ipympl
pre-commit == 3.3.*
black == 22.10.0
isort == 5.12.0
pyupgrade == 3.4.0
flake8 == 6.0.0
flake8-bugbear == 23.5.9
black == 24.2.0
isort == 5.13.2
pyupgrade == 3.15.1
flake8 == 7.0.0
flake8-bugbear == 24.2.6
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
28b02c51545298cb9a76d8295e64a5df391b9207
# Fix a number of issues flagged by flake8
0344b005e6ffd232f55e69621630ef01876bc0fb
# Update to black 24.2.0 and isort 5.13.2
0d015a50d641edc7709bd89e0ed389e54f1dcab0
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ repos:
- id: check-hooks-apply
- id: check-useless-excludes
- repo: https://github.com/asottile/pyupgrade
rev: v3.4.0
rev: v3.15.1
hooks:
- id: pyupgrade
args: [--py39-plus]
files: '^brian2/.*\.pyi?$'
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
rev: 7.0.0
hooks:
- id: flake8
# We exclude all __init__.py files, since we use wildcard imports, etc.
exclude: '^brian2/tests/.*$|^brian2/.*__init__[.]py$'
files: '^brian2/.*\.pyi?$'
additional_dependencies: ['flake8-bugbear==23.5.9']
additional_dependencies: ['flake8-bugbear==24.2.6']
- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
files: '^brian2/.*\.pyi?$'
- repo: https://github.com/psf/black
rev: '22.10.0'
rev: '24.2.0'
hooks:
- id: black
files: '^brian2/.*\.pyi?$'
1 change: 1 addition & 0 deletions brian2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Brian 2
"""

import logging


Expand Down
1 change: 1 addition & 0 deletions brian2/codegen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Package providing the code generation framework.
"""

# Import the runtime packages so that they can register their preferences

# isort:skip_file
Expand Down
1 change: 1 addition & 0 deletions brian2/codegen/_prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
-----------
.. document_brian_prefs:: codegen
"""

from brian2.core.preferences import BrianPreference, prefs

from .codeobject import CodeObject
Expand Down
1 change: 1 addition & 0 deletions brian2/codegen/codeobject.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Module providing the base `CodeObject` and related functions.
"""

import collections
import copy
import platform
Expand Down
8 changes: 5 additions & 3 deletions brian2/codegen/cpp_prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.. document_brian_prefs:: codegen.cpp

"""

import distutils
import json
import os
Expand Down Expand Up @@ -266,9 +267,10 @@ def _determine_flag_compatibility(compiler, flagname):
import tempfile
from distutils.errors import CompileError

with tempfile.TemporaryDirectory(
prefix="brian_flag_test_"
) as temp_dir, std_silent():
with (
tempfile.TemporaryDirectory(prefix="brian_flag_test_") as temp_dir,
std_silent(),
):
fname = os.path.join(temp_dir, "flag_test.cpp")
with open(fname, "w") as f:
f.write("int main (int argc, char **argv) { return 0; }")
Expand Down
13 changes: 5 additions & 8 deletions brian2/codegen/generators/GSL_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,9 @@ def to_replace_vector_vars(self, variables_in_vector, ignore=frozenset()):
continue
if isinstance(var_obj, ArrayVariable):
pointer_name = self.get_array_name(var_obj, access_data=True)
to_replace[
pointer_name
] = f"_GSL_dataholder{access_pointer}{pointer_name}"
to_replace[pointer_name] = (
f"_GSL_dataholder{access_pointer}{pointer_name}"
)
else:
to_replace[var] = f"_GSL_dataholder{access_pointer}{var}"

Expand Down Expand Up @@ -933,8 +933,7 @@ def translate(
"well-defined: the outcome may depend on the "
"order of execution. You can ignore this warning if "
"you are sure that the order of operations does not "
"matter. "
+ error_msg
"matter. " + error_msg
)

# save function names because self.generator.translate_statement_sequence
Expand Down Expand Up @@ -1019,9 +1018,7 @@ def translate(
)
# rewrite scalar code, keep variables that are needed in scalar code normal
# and add variables to _dataholder for vector_code
GSL_main_code += (
f"\n{self.translate_scalar_code(scalar_func_code, variables_in_scalar, variables_in_vector)}"
)
GSL_main_code += f"\n{self.translate_scalar_code(scalar_func_code, variables_in_scalar, variables_in_vector)}"
if len(self.variables_to_be_processed) > 0:
raise AssertionError(
"Not all variables that will be used in the vector "
Expand Down
3 changes: 1 addition & 2 deletions brian2/codegen/generators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ def translate(self, code, dtype):
"well-defined: the outcome may depend on the "
"order of execution. You can ignore this warning if "
"you are sure that the order of operations does not "
"matter. "
+ error_msg
"matter. " + error_msg
)

translated = self.translate_statement_sequence(
Expand Down
1 change: 0 additions & 1 deletion brian2/codegen/get_cpu_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
The CPU flags are printed to stdout encoded as JSON.
"""


import json

if __name__ == "__main__":
Expand Down
1 change: 0 additions & 1 deletion brian2/codegen/runtime/cython_rt/extension_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
https://github.com/ipython/ipython/blob/master/IPython/extensions/cythonmagic.py
"""


import glob
import hashlib
import importlib.util
Expand Down
1 change: 1 addition & 0 deletions brian2/codegen/templates.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Handles loading templates from a directory.
"""

import re
from collections.abc import Mapping

Expand Down
1 change: 1 addition & 0 deletions brian2/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Module containing fixtures and hooks used by the pytest test suite.
"""

import re

import numpy as np
Expand Down
4 changes: 2 additions & 2 deletions brian2/core/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
All Brian objects should derive from `BrianObject`.
"""

import functools
import os
import sys
Expand Down Expand Up @@ -81,8 +82,7 @@ def __init__(
#: A string indicating where this object was created (traceback with any parts of Brian code removed)
self._creation_stack = (
"Object was created here (most recent call only, full details in "
"debug log):\n"
+ creation_stack[-1]
"debug log):\n" + creation_stack[-1]
)
self._full_creation_stack = "Object was created here:\n" + "\n".join(
creation_stack
Expand Down
1 change: 0 additions & 1 deletion brian2/core/clocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Clocks for the simulator.
"""


__docformat__ = "restructuredtext en"

import numpy as np
Expand Down
32 changes: 20 additions & 12 deletions brian2/core/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,18 @@ def __repr__(self):
[
[
f"{entry.name} ({entry.type})",
f"{entry.owner_name} ({entry.owner_type})"
if entry.owner_name is not None
else "--",
(
f"{entry.owner_name} ({entry.owner_type})"
if entry.owner_name is not None
else "--"
),
"{} (every {})".format(
str(entry.dt),
"step"
if self.steps[float(entry.dt)] == 1
else f"{self.steps[float(entry.dt)]} steps",
(
"step"
if self.steps[float(entry.dt)] == 1
else f"{self.steps[float(entry.dt)]} steps"
),
),
entry.when,
entry.order,
Expand All @@ -248,14 +252,18 @@ def _repr_html_(self):
</tr>
""".format(
f"<b>{entry.name}</b> (<em>{entry.type}</em>)",
f"{entry.owner_name} (<em>{entry.owner_type}</em>)"
if entry.owner_name is not None
else "&ndash;",
(
f"{entry.owner_name} (<em>{entry.owner_type}</em>)"
if entry.owner_name is not None
else "&ndash;"
),
"{} (every {})".format(
str(entry.dt),
"step"
if self.steps[float(entry.dt)] == 1
else f"{self.steps[float(entry.dt)]} steps",
(
"step"
if self.steps[float(entry.dt)] == 1
else f"{self.steps[float(entry.dt)]} steps"
),
),
entry.when,
entry.order,
Expand Down
1 change: 1 addition & 0 deletions brian2/core/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def f():

NetworkOperation, Network, BrianObject
"""

# Notes on this decorator:
# Normally, a decorator comes in two types, with or without arguments. If
# it has no arguments, e.g.
Expand Down
3 changes: 1 addition & 2 deletions brian2/core/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,7 @@ def check_all_validated(self):
"The following preferences values have been set but "
"are not registered preferences:\n%s\nThis is usually "
"because of a spelling mistake or missing library "
"import."
% ", ".join(self.prefs_unvalidated),
"import." % ", ".join(self.prefs_unvalidated),
once=True,
)

Expand Down
1 change: 1 addition & 0 deletions brian2/core/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Classes used to specify the type of a function, variable or common
sub-expression.
"""

import collections
import functools
import numbers
Expand Down
1 change: 1 addition & 0 deletions brian2/devices/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Package providing the "devices" infrastructure.
"""

from . import device as device_module
from .device import *
11 changes: 5 additions & 6 deletions brian2/devices/cpp_standalone/device.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Module implementing the C++ "standalone" device.
"""

import inspect
import itertools
import numbers
Expand Down Expand Up @@ -233,9 +234,7 @@ def __init__(self):
self.run_environment_variables = {}
if sys.platform.startswith("darwin"):
if "DYLD_LIBRARY_PATH" in os.environ:
dyld_library_path = (
f"{os.environ['DYLD_LIBRARY_PATH']}:{os.path.join(sys.prefix, 'lib')}"
)
dyld_library_path = f"{os.environ['DYLD_LIBRARY_PATH']}:{os.path.join(sys.prefix, 'lib')}"
else:
dyld_library_path = os.path.join(sys.prefix, "lib")
self.run_environment_variables["DYLD_LIBRARY_PATH"] = dyld_library_path
Expand Down Expand Up @@ -387,9 +386,9 @@ def add_array(self, var):
# use the same name in the two dictionaries, not for example
# ``_dynamic_array_source_name_2`` and ``_array_source_name_1``
# (this would work fine, but it would make the code harder to read).
orig_dynamic_name = (
dynamic_name
) = f"_dynamic_array_{var.owner.name}_{var.name}"
orig_dynamic_name = dynamic_name = (
f"_dynamic_array_{var.owner.name}_{var.name}"
)
orig_array_name = array_name = f"_array_{var.owner.name}_{var.name}"
suffix = 0

Expand Down
1 change: 1 addition & 0 deletions brian2/equations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Module handling equations and "code strings", expressions or statements, used
for example for the reset and threshold definition of a neuron.
"""

from .codestrings import Expression, Statements
from .equations import Equations

Expand Down
1 change: 1 addition & 0 deletions brian2/equations/equations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Differential equations for Brian models.
"""

import keyword
import re
import string
Expand Down
1 change: 0 additions & 1 deletion brian2/equations/refractory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Module implementing Brian's refractory mechanism.
"""


from brian2.units.allunits import second
from brian2.units.fundamentalunits import DIMENSIONLESS

Expand Down
1 change: 1 addition & 0 deletions brian2/groups/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
objects such as `NeuronGroup` or `StateMonitor` but not `Clock`, and finally
`CodeRunner`, a class to run code in the context of a `Group`.
"""

import inspect
import numbers
import weakref
Expand Down
1 change: 1 addition & 0 deletions brian2/groups/neurongroup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This model defines the `NeuronGroup`, the core of most simulations.
"""

import numbers
import string
from collections.abc import MutableMapping, Sequence
Expand Down
1 change: 0 additions & 1 deletion brian2/hears.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* time_varying_filter1 (care with units)
"""


try:
import brian as b1
import brian.hears as b1h
Expand Down
3 changes: 1 addition & 2 deletions brian2/importexport/dictlike.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ def export_data(group, variables, units=True, level=0):
except ImportError as ex:
raise ImportError(
"Exporting to pandas needs a working installation"
" of pandas. Importing pandas failed: "
+ str(ex)
" of pandas. Importing pandas failed: " + str(ex)
)
if units:
raise NotImplementedError(
Expand Down
1 change: 1 addition & 0 deletions brian2/input/poissongroup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Implementation of `PoissonGroup`.
"""

import numpy as np

from brian2.core.spikesource import SpikeSource
Expand Down
1 change: 1 addition & 0 deletions brian2/input/poissoninput.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Implementation of `PoissonInput`.
"""

from brian2.core.variables import Variables
from brian2.groups.group import CodeRunner
from brian2.units.fundamentalunits import (
Expand Down
Loading
Loading