Skip to content

Commit

Permalink
Merge pull request #1444 from aleksejleonov/ci/add-isort
Browse files Browse the repository at this point in the history
ci: add isort
  • Loading branch information
mstimberg committed Nov 22, 2022
2 parents dcad1a6 + 4be70b3 commit 761c9c0
Show file tree
Hide file tree
Showing 123 changed files with 643 additions and 583 deletions.
1 change: 1 addition & 0 deletions .devcontainer/dev-requirements.txt
Expand Up @@ -5,3 +5,4 @@ jupyterlab
ipympl
pre-commit == 2.20.*
black == 22.10.0
isort == 5.10.1
14 changes: 10 additions & 4 deletions .devcontainer/devcontainer.json
Expand Up @@ -5,7 +5,7 @@
"build": {
"dockerfile": "Dockerfile",
"context": "..",
"args": {
"args": {
// Update 'VARIANT' to pick a Python version: 3, 3.10, 3.9, 3.8, 3.7, 3.6
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local on arm64/Apple Silicon.
Expand All @@ -16,7 +16,7 @@
},

// Set *default* container specific settings.json values on container create.
"settings": {
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
Expand All @@ -33,13 +33,19 @@
"jupyter.widgetScriptSources": [
"jsdelivr.com",
"unpkg.com"
]
],
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
}
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance"
"ms-python.vscode-pylance",
"ms-python.vscode-isort"
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
Expand Down
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Expand Up @@ -8,3 +8,5 @@
d3ae59251c753ae0737d6ae6242b7e85b60908c4
# Reformatting with black
1e9ea598491444fe7c4ee9ece2ec94ad7c5020ec
# Reformatting with isort
67bf6d3760fa3fb8b3aa121b1b972d6cf36ec048
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Expand Up @@ -3,6 +3,12 @@ repos:
hooks:
- id: check-hooks-apply
- id: check-useless-excludes
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
exclude: '^brian2/_version.py$'
files: '^brian2/.*\.pyi?$'
- repo: https://github.com/psf/black
rev: '22.10.0'
hooks:
Expand Down
11 changes: 8 additions & 3 deletions brian2/__init__.py
Expand Up @@ -77,12 +77,15 @@ def _check_dependencies():
from brian2.only import *
from brian2.only import test


# Check for outdated dependency versions
def _check_dependency_version(name, version):
import sys

from packaging.version import Version

from .core.preferences import prefs
from .utils.logger import get_logger
import sys

logger = get_logger(__name__)

Expand Down Expand Up @@ -194,8 +197,10 @@ def clear_cache(target):


def _check_caches():
from brian2.codegen.runtime.cython_rt.extension_manager import get_cython_cache_dir
from brian2.codegen.runtime.cython_rt.extension_manager import get_cython_extensions
from brian2.codegen.runtime.cython_rt.extension_manager import (
get_cython_cache_dir,
get_cython_extensions,
)

for target, (dirname, extensions) in [
("cython", (get_cython_cache_dir(), get_cython_extensions()))
Expand Down
2 changes: 2 additions & 0 deletions brian2/codegen/__init__.py
Expand Up @@ -3,6 +3,8 @@
"""
# Import the runtime packages so that they can register their preferences

# isort:skip_file

from .runtime import *
from . import _prefs
from . import cpp_prefs as _cpp_prefs
Expand Down
3 changes: 2 additions & 1 deletion brian2/codegen/_prefs.py
Expand Up @@ -5,7 +5,8 @@
-----------
.. document_brian_prefs:: codegen
"""
from brian2.core.preferences import prefs, BrianPreference
from brian2.core.preferences import BrianPreference, prefs

from .codeobject import CodeObject

# Preferences
Expand Down
2 changes: 1 addition & 1 deletion brian2/codegen/codeobject.py
Expand Up @@ -11,7 +11,7 @@
from brian2.core.names import Nameable
from brian2.equations.unitcheck import check_units_statements
from brian2.utils.logger import get_logger
from brian2.utils.stringtools import indent, code_representation
from brian2.utils.stringtools import code_representation, indent

from .translation import analyse_identifiers

Expand Down
9 changes: 5 additions & 4 deletions brian2/codegen/cpp_prefs.py
Expand Up @@ -6,20 +6,21 @@
.. document_brian_prefs:: codegen.cpp
"""
from setuptools import msvc
import distutils
from distutils.ccompiler import get_default_compiler
import json
import os
import re
import platform
import re
import socket
import struct
import subprocess
import sys
import tempfile
from distutils.ccompiler import get_default_compiler

from setuptools import msvc

from brian2.core.preferences import prefs, BrianPreference
from brian2.core.preferences import BrianPreference, prefs
from brian2.utils.filetools import ensure_directory
from brian2.utils.logger import get_logger, std_silent

Expand Down
21 changes: 9 additions & 12 deletions brian2/codegen/generators/GSL_generator.py
Expand Up @@ -7,21 +7,18 @@

import numpy as np

from brian2.units.fundamentalunits import fail_for_dimension_mismatch
from brian2.core.variables import AuxiliaryVariable, ArrayVariable, Constant
from brian2.core.functions import Function
from brian2.codegen.translation import make_statements
from brian2.codegen.generators import c_data_type
from brian2.codegen.permutation_analysis import (
check_for_order_independence,
OrderDependenceError,
check_for_order_independence,
)
from brian2.core.preferences import prefs, BrianPreference
from brian2.utils.stringtools import get_identifiers, word_substitute
from brian2.codegen.translation import make_statements
from brian2.core.functions import Function
from brian2.core.preferences import BrianPreference, PreferenceError, prefs
from brian2.core.variables import ArrayVariable, AuxiliaryVariable, Constant
from brian2.parsing.statements import parse_statement
from brian2.codegen.generators import c_data_type


from brian2.core.preferences import PreferenceError
from brian2.units.fundamentalunits import fail_for_dimension_mismatch
from brian2.utils.stringtools import get_identifiers, word_substitute

__all__ = ["GSLCodeGenerator", "GSLCPPCodeGenerator", "GSLCythonCodeGenerator"]

Expand Down Expand Up @@ -212,8 +209,8 @@ def is_cpp_standalone(self):
is_constant_and_cpp_standalone : uses the returned value
"""
# imports here to avoid circular imports
from brian2.devices.device import get_device
from brian2.devices.cpp_standalone.device import CPPStandaloneDevice
from brian2.devices.device import get_device

device = get_device()
return isinstance(device, CPPStandaloneDevice)
Expand Down
12 changes: 6 additions & 6 deletions brian2/codegen/generators/base.py
Expand Up @@ -3,15 +3,15 @@
methods which should be overridden to implement a new language.
"""

from brian2.core.variables import ArrayVariable
from brian2.core.functions import Function
from brian2.utils.stringtools import get_identifiers
from brian2.utils.logger import get_logger
from brian2.codegen.translation import make_statements
from brian2.codegen.permutation_analysis import (
check_for_order_independence,
OrderDependenceError,
check_for_order_independence,
)
from brian2.codegen.translation import make_statements
from brian2.core.functions import Function
from brian2.core.variables import ArrayVariable
from brian2.utils.logger import get_logger
from brian2.utils.stringtools import get_identifiers

__all__ = ["CodeGenerator"]

Expand Down
10 changes: 5 additions & 5 deletions brian2/codegen/generators/cpp_generator.py
Expand Up @@ -3,16 +3,16 @@
import numpy

from brian2.codegen.cpp_prefs import C99Check
from brian2.core.functions import DEFAULT_FUNCTIONS, Function
from brian2.core.preferences import BrianPreference, prefs
from brian2.core.variables import ArrayVariable
from brian2.parsing.rendering import CPPNodeRenderer
from brian2.utils.logger import get_logger
from brian2.utils.stringtools import (
deindent,
stripped_deindented_lines,
word_substitute,
)
from brian2.utils.logger import get_logger
from brian2.parsing.rendering import CPPNodeRenderer
from brian2.core.functions import Function, DEFAULT_FUNCTIONS
from brian2.core.preferences import prefs, BrianPreference
from brian2.core.variables import ArrayVariable

from .base import CodeGenerator

Expand Down
15 changes: 7 additions & 8 deletions brian2/codegen/generators/cython_generator.py
@@ -1,22 +1,21 @@
import itertools

from brian2.codegen.cpp_prefs import C99Check
from brian2.devices.device import all_devices
from brian2.utils.stringtools import word_substitute, deindent, indent
from brian2.parsing.rendering import NodeRenderer
from brian2.parsing.bast import brian_dtype_from_dtype
from brian2.core.functions import DEFAULT_FUNCTIONS, Function
from brian2.core.variables import (
Constant,
AuxiliaryVariable,
get_dtype_str,
Variable,
Constant,
Subexpression,
Variable,
get_dtype_str,
)
from brian2.devices.device import all_devices
from brian2.parsing.bast import brian_dtype_from_dtype
from brian2.parsing.rendering import NodeRenderer
from brian2.utils.stringtools import deindent, indent, word_substitute

from .base import CodeGenerator


__all__ = ["CythonCodeGenerator"]


Expand Down
6 changes: 3 additions & 3 deletions brian2/codegen/generators/numpy_generator.py
Expand Up @@ -2,12 +2,12 @@

import numpy as np

from brian2.parsing.bast import brian_dtype_from_dtype
from brian2.parsing.rendering import NumpyNodeRenderer
from brian2.core.functions import DEFAULT_FUNCTIONS, timestep
from brian2.core.variables import ArrayVariable
from brian2.utils.stringtools import get_identifiers, word_substitute, indent
from brian2.parsing.bast import brian_dtype_from_dtype
from brian2.parsing.rendering import NumpyNodeRenderer
from brian2.utils.logger import get_logger
from brian2.utils.stringtools import get_identifiers, indent, word_substitute

from .base import CodeGenerator

Expand Down
10 changes: 5 additions & 5 deletions brian2/codegen/optimisation.py
Expand Up @@ -3,22 +3,22 @@
"""

import ast
from collections import OrderedDict
import copy
import itertools
from collections import OrderedDict
from functools import reduce

from brian2.core.functions import DEFAULT_FUNCTIONS, DEFAULT_CONSTANTS
from brian2.core.functions import DEFAULT_CONSTANTS, DEFAULT_FUNCTIONS
from brian2.core.preferences import prefs
from brian2.core.variables import AuxiliaryVariable
from brian2.parsing.bast import (
brian_ast,
BrianASTRenderer,
dtype_hierarchy,
brian_ast,
brian_dtype_from_dtype,
dtype_hierarchy,
)
from brian2.parsing.rendering import NodeRenderer, get_node_value
from brian2.utils.stringtools import get_identifiers, word_substitute
from brian2.core.preferences import prefs

from .statements import Statement

Expand Down
2 changes: 1 addition & 1 deletion brian2/codegen/permutation_analysis.py
Expand Up @@ -2,9 +2,9 @@
Module for analysing synaptic pre and post code for synapse order independence.
"""

from brian2.utils.stringtools import get_identifiers
from brian2.core.functions import Function
from brian2.core.variables import Constant
from brian2.utils.stringtools import get_identifiers

__all__ = ["OrderDependenceError", "check_for_order_independence"]

Expand Down
4 changes: 2 additions & 2 deletions brian2/codegen/runtime/GSLcython_rt/GSLcython_rt.py
Expand Up @@ -8,9 +8,9 @@

from brian2.core.preferences import prefs

from ..cython_rt import CythonCodeObject
from ...generators.GSL_generator import GSLCythonCodeGenerator
from ...generators.cython_generator import CythonCodeGenerator
from ...generators.GSL_generator import GSLCythonCodeGenerator
from ..cython_rt import CythonCodeObject

__all__ = ["GSLCythonCodeObject", "IntegrationError"]

Expand Down
14 changes: 7 additions & 7 deletions brian2/codegen/runtime/cython_rt/cython_rt.py
Expand Up @@ -3,27 +3,27 @@
import numpy

from brian2.core.base import BrianObjectException
from brian2.core.functions import Function
from brian2.core.preferences import BrianPreference, prefs
from brian2.core.variables import (
DynamicArrayVariable,
ArrayVariable,
AuxiliaryVariable,
DynamicArrayVariable,
Subexpression,
)
from brian2.core.functions import Function
from brian2.core.preferences import prefs, BrianPreference
from brian2.utils.logger import get_logger
from brian2.utils.stringtools import get_identifiers

from ...codeobject import constant_or_scalar, check_compiler_kwds
from ..numpy_rt import NumpyCodeObject
from ...templates import Templater
from ...codeobject import check_compiler_kwds, constant_or_scalar
from ...cpp_prefs import get_compiler_and_args
from ...generators.cython_generator import (
CythonCodeGenerator,
get_cpp_dtype,
get_numpy_dtype,
)
from ...targets import codegen_targets
from ...cpp_prefs import get_compiler_and_args
from ...templates import Templater
from ..numpy_rt import NumpyCodeObject
from .extension_manager import cython_extension_manager

__all__ = ["CythonCodeObject"]
Expand Down

0 comments on commit 761c9c0

Please sign in to comment.