Skip to content

Commit 5cce53d

Browse files
authored
Merge pull request nest#2883 from nicolossus/sort_imports
Sort and format Python imports and enable `isort` check in CI
2 parents a2e2287 + d8724c9 commit 5cce53d

File tree

295 files changed

+583
-508
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

295 files changed

+583
-508
lines changed

.github/workflows/nestbuildmatrix.yml

+17-3
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,19 @@ jobs:
290290
- name: "Run pylint..."
291291
run: |
292292
pylint --jobs=$(nproc) pynest/ testsuite/pytests/*.py testsuite/regressiontests/*.py
293+
294+
isort:
295+
runs-on: "ubuntu-20.04"
296+
steps:
297+
- name: "Checkout repository content"
298+
uses: actions/checkout@v3
299+
with:
300+
fetch-depth: 0
301+
302+
- name: "Run isort..."
303+
uses: isort/isort-action@f14e57e1d457956c45a19c05a89cccdf087846e5 # 1.1.0
304+
with:
305+
configuration: --profile=black --thirdparty="nest" --check-only --diff
293306

294307
black:
295308
runs-on: "ubuntu-20.04"
@@ -298,8 +311,9 @@ jobs:
298311
uses: actions/checkout@v3
299312
with:
300313
fetch-depth: 0
314+
301315
- name: "Run black..."
302-
uses: psf/black@bf7a16254ec96b084a6caf3d435ec18f0f245cc7 # 23.3.0
316+
uses: psf/black@193ee766ca496871f93621d6b58d57a6564ff81b # 23.7.0
303317
with:
304318
jupyter: true
305319

@@ -405,7 +419,7 @@ jobs:
405419
build_linux:
406420
if: ${{ !contains(github.event.head_commit.message, 'ci skip') }}
407421
runs-on: ${{ matrix.os }}
408-
needs: [clang-format, mypy, copyright_headers, unused_names, forbidden_types, pylint, black, flake8]
422+
needs: [clang-format, mypy, copyright_headers, unused_names, forbidden_types, pylint, isort, black, flake8]
409423
env:
410424
CXX_FLAGS: "-pedantic -Wextra -Woverloaded-virtual -Wno-unknown-pragmas"
411425
NEST_VPATH: "build"
@@ -607,7 +621,7 @@ jobs:
607621
build_macos:
608622
if: ${{ !contains(github.event.head_commit.message, 'ci skip') }}
609623
runs-on: ${{ matrix.os }}
610-
needs: [clang-format, mypy, copyright_headers, unused_names, forbidden_types, pylint, black, flake8]
624+
needs: [clang-format, mypy, copyright_headers, unused_names, forbidden_types, pylint, isort, black, flake8]
611625
env:
612626
CXX_FLAGS: "-pedantic -Wextra -Woverloaded-virtual -Wno-unknown-pragmas"
613627
NEST_VPATH: "build"

.pre-commit-config.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
repos:
2+
- repo: https://github.com/pycqa/isort
3+
rev: 5.12.0
4+
hooks:
5+
- id: isort
6+
args: ["--profile", "black", "--thirdparty", "nest", "--diff"]
27
- repo: https://github.com/psf/black
3-
rev: 23.3.0
8+
rev: 23.7.0
49
hooks:
510
- id: black
611
language_version: python3

bin/nest-server-mpi

+11-13
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@ Options:
1616
from docopt import docopt
1717
from mpi4py import MPI
1818

19-
if __name__ == '__main__':
19+
if __name__ == "__main__":
2020
opt = docopt(__doc__)
2121

22-
import time
22+
import os
2323
import sys
24+
import time
2425

2526
import nest
2627
import nest.server
2728

28-
import os
29-
3029
HOST = os.getenv("NEST_SERVER_HOST", "127.0.0.1")
3130
PORT = os.getenv("NEST_SERVER_PORT", "52425")
3231

@@ -35,34 +34,33 @@ rank = comm.Get_rank()
3534

3635

3736
def log(call_name, msg):
38-
msg = f'==> WORKER {rank}/{time.time():.7f} ({call_name}): {msg}'
37+
msg = f"==> WORKER {rank}/{time.time():.7f} ({call_name}): {msg}"
3938
print(msg, flush=True)
4039

4140

4241
if rank == 0:
4342
print("==> Starting NEST Server Master on rank 0", flush=True)
4443
nest.server.set_mpi_comm(comm)
45-
nest.server.run_mpi_app(host=opt.get('--host', HOST), port=opt.get('--port', PORT))
44+
nest.server.run_mpi_app(host=opt.get("--host", HOST), port=opt.get("--port", PORT))
4645

4746
else:
4847
print(f"==> Starting NEST Server Worker on rank {rank}", flush=True)
4948
nest.server.set_mpi_comm(comm)
5049
while True:
51-
52-
log('spinwait', 'waiting for call bcast')
50+
log("spinwait", "waiting for call bcast")
5351
call_name = comm.bcast(None, root=0)
5452

55-
log(call_name, 'received call bcast, waiting for data bcast')
53+
log(call_name, "received call bcast, waiting for data bcast")
5654
data = comm.bcast(None, root=0)
5755

58-
log(call_name, f'received data bcast, data={data}')
56+
log(call_name, f"received data bcast, data={data}")
5957
args, kwargs = data
6058

61-
if call_name == 'exec':
59+
if call_name == "exec":
6260
response = nest.server.do_exec(args, kwargs)
6361
else:
6462
call, args, kwargs = nest.server.nestify(call_name, args, kwargs)
65-
log(call_name, f'local call, args={args}, kwargs={kwargs}')
63+
log(call_name, f"local call, args={args}, kwargs={kwargs}")
6664

6765
# The following exception handler is useful if an error
6866
# occurs simulataneously on all processes. If only a
@@ -74,5 +72,5 @@ else:
7472
except Exception:
7573
continue
7674

77-
log(call_name, f'sending reponse gather, data={response}')
75+
log(call_name, f"sending reponse gather, data={response}")
7876
comm.gather(nest.serializable(response), root=0)

build_support/check_copyright_headers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040

4141

4242
import os
43-
import sys
4443
import re
44+
import sys
4545

4646

4747
def eprint(*args, **kwargs):

build_support/check_unused_names.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
"""
4141

4242
import os
43-
import sys
4443
import re
44+
import sys
4545
from subprocess import check_output
4646

4747

build_support/format_all_c_c++_files.sh

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
# With this script you can easily format all C/C++ files contained in
44
# any (sub)directory of NEST. Internally it uses clang-format to do
5-
# the actual formatting. You can give a different clang-format command,
6-
# e.g. by executing `CLANG_FORMAT=clang-format-14 ./format_all_c_c++_files.sh`.
5+
# the actual formatting.
6+
#
7+
# NEST C/C++ code should be formatted according to clang-format version 13.0.0.
8+
# If you would like to see how the code will be formatted with a different
9+
# clang-format version, execute e.g. `CLANG_FORMAT=clang-format-14 ./format_all_c_c++_files.sh`.
10+
#
711
# By default the script starts at the current working directory ($PWD), but
812
# supply a different starting directory as the first argument to the command.
13+
914
CLANG_FORMAT=${CLANG_FORMAT:-clang-format}
1015
CLANG_FORMAT_FILE=${CLANG_FORMAT_FILE:-.clang-format}
1116

build_support/generate_modelsmodule.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@
2626
compiled by CMake.
2727
"""
2828

29+
import argparse
2930
import os
3031
import sys
31-
import argparse
32-
3332
from pathlib import Path
3433
from textwrap import dedent
3534

doc/htmldoc/_ext/HoverXTooltip.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
# You should have received a copy of the GNU General Public License
2020
# along with NEST. If not, see <http://www.gnu.org/licenses/>.
2121

22-
import re
2322
import os
23+
import re
2424
import sys
25+
2526
from docutils import nodes
2627
from docutils.parsers.rst import Directive, directives
2728

doc/htmldoc/_ext/VersionSyncRole.py

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import json
2323
from pathlib import Path
24+
2425
from docutils import nodes
2526

2627

doc/htmldoc/_ext/add_button_notebook.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
import glob
2323
import os
2424
import sys
25-
from sphinx.application import Sphinx
2625
from pathlib import Path
2726

27+
from sphinx.application import Sphinx
28+
2829

2930
def add_button_to_examples(app, env, docnames):
3031
"""Find all examples and include a link to launch notebook.

doc/htmldoc/_ext/extract_api_functions.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
#
1919
# You should have received a copy of the GNU General Public License
2020
# along with NEST. If not, see <http://www.gnu.org/licenses/>.
21-
import os
2221
import ast
22+
import glob
2323
import json
24+
import os
2425
import re
25-
import glob
26-
2726

2827
"""
2928
Generate a JSON dictionary that stores the module name as key and corresponding

doc/htmldoc/_ext/extractor_userdocs.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,17 @@
1919
# You should have received a copy of the GNU General Public License
2020
# along with NEST. If not, see <http://www.gnu.org/licenses/>.
2121

22-
import re
23-
from tqdm import tqdm
24-
from pprint import pformat
25-
from math import comb
26-
27-
import os
2822
import glob
2923
import json
30-
from itertools import chain, combinations
3124
import logging
25+
import os
26+
import re
3227
from collections import Counter
28+
from itertools import chain, combinations
29+
from math import comb
30+
from pprint import pformat
3331

32+
from tqdm import tqdm
3433

3534
logging.basicConfig(level=logging.WARNING)
3635
log = logging.getLogger(__name__)

doc/htmldoc/_ext/list_examples.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@
1919
# You should have received a copy of the GNU General Public License
2020
# along with NEST. If not, see <http://www.gnu.org/licenses/>.
2121

22+
import glob
23+
import logging
24+
import os
25+
2226
from docutils import nodes
2327
from docutils.parsers.rst import Directive, Parser
24-
2528
from sphinx.application import Sphinx
2629
from sphinx.util.docutils import SphinxDirective
27-
import os
28-
import glob
29-
30-
import logging
3130

3231
logging.basicConfig(level=logging.WARNING)
3332
log = logging.getLogger(__name__)

doc/htmldoc/clean_source_dirs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
# You should have received a copy of the GNU General Public License
2020
# along with NEST. If not, see <http://www.gnu.org/licenses/>.
2121
import os
22-
import shutil
2322
import pathlib
23+
import shutil
2424
from glob import glob
2525

2626
for dir_ in ("auto_examples", "models"):

doc/htmldoc/conf.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,20 @@
2020
# along with NEST. If not, see <http://www.gnu.org/licenses/>.
2121

2222

23-
import sys
24-
import os
2523
import json
24+
import os
2625
import subprocess
27-
28-
from urllib.request import urlretrieve
29-
26+
import sys
3027
from pathlib import Path
3128
from shutil import copyfile
29+
from urllib.request import urlretrieve
3230

3331
# Add the extension modules to the path
3432
extension_module_dir = os.path.abspath("./_ext")
3533
sys.path.append(extension_module_dir)
3634

37-
from extractor_userdocs import ExtractUserDocs, relative_glob # noqa
3835
from extract_api_functions import ExtractPyNESTAPIS # noqa
36+
from extractor_userdocs import ExtractUserDocs, relative_glob # noqa
3937

4038
repo_root_dir = os.path.abspath("../..")
4139
pynest_dir = os.path.join(repo_root_dir, "pynest")

0 commit comments

Comments
 (0)