From 847ec0ba8ed52950eafec1b12f0251b776cd3f79 Mon Sep 17 00:00:00 2001 From: Sebastian Spreizer Date: Fri, 7 Mar 2025 11:38:14 +0100 Subject: [PATCH 01/15] Add pyproject.toml --- pyproject.toml | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..20e2d59 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,72 @@ +[project] +name = "nest-client" +description = "NEST Client sends JSON requests to NEST Server." +license = {file = "LICENSE"} +version = "0.1.1" +authors = [ + {name = "Sebastian Spreizer", email = "spreizer@web.de"}, +] +maintainers = [ + {name = "Sebastian Spreizer", email = "spreizer@web.de"}, + {name = "Dennis Terhorst", email = "d.terhorst@fz-juelich.de"} +] +readme = "README.md" +requires-python = ">=3.9" +# keywords = [] +classifiers = [ + # How mature is this project? Common values are + # 3 - Alpha + # 4 - Beta + # 5 - Production/Stable + "Development Status :: 5 - Stable", + + # Indicate who your project is intended for + "Intended Audience :: Science/Research", + + "Topic :: Scientific/Engineering", + + # Pick your license as you wish (see also "license" above) + "License :: OSI Approved :: GNU Public License 3.0 or later", + + # Specify the Python versions you support here. + "Programming Language :: Python :: 3", +] +dynamic = ["dependencies"] + +[project.urls] +repository = "https://github.com/nest/nest_client" + +[project.entry-points.console_scripts] +urlclient = "urlbroker.client:main" + +[tool.setuptools] +package-dir = {"nest_client" = "src"} + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} + +[tool.black] +line-length = 120 + +[tool.flake8] +# This is ignored +# see discussions around https://github.com/PyCQA/flake8/issues/234 + +[tool.isort] +atomic = true +line_length = 120 +multi_line_output = 3 +profile = "black" +skip_gitignore = true + +[tool.pytest.ini_options] +minversion = "6.0" +addopts = "--mypy --pylint --pydocstyle --cov --ignore=conda --ignore=venv --ignore=.git --ignore=__pycache__" +norecursedirs = ".git _build venv tmp*" + +[tool.mypy] +exclude = ".git/, .pytest_cache/, conda/, venv/" + +[tool.pydocstyle] +convention = "numpy" +add-ignore = "D300" From 2576ef0aa5bfb67aadf90b438522832bb3f581d4 Mon Sep 17 00:00:00 2001 From: Sebastian Spreizer Date: Tue, 22 Apr 2025 09:16:33 +0200 Subject: [PATCH 02/15] Rename folder --- pyproject.toml | 14 ++++-------- setup.py | 34 ----------------------------- {nest_client => src}/__init__.py | 6 ++++- {nest_client => src}/nest_client.py | 10 ++++----- 4 files changed, 14 insertions(+), 50 deletions(-) delete mode 100644 setup.py rename {nest_client => src}/__init__.py (83%) rename {nest_client => src}/nest_client.py (84%) diff --git a/pyproject.toml b/pyproject.toml index 20e2d59..d32b519 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,20 +31,14 @@ classifiers = [ # Specify the Python versions you support here. "Programming Language :: Python :: 3", ] -dynamic = ["dependencies"] +dependencies = [ + "requests", + "werkzeug", +] [project.urls] repository = "https://github.com/nest/nest_client" -[project.entry-points.console_scripts] -urlclient = "urlbroker.client:main" - -[tool.setuptools] -package-dir = {"nest_client" = "src"} - -[tool.setuptools.dynamic] -dependencies = {file = ["requirements.txt"]} - [tool.black] line-length = 120 diff --git a/setup.py b/setup.py deleted file mode 100644 index 1cdf933..0000000 --- a/setup.py +++ /dev/null @@ -1,34 +0,0 @@ -# -*- coding: utf-8 -*- -# -# setup.py -# -# This file is part of NEST. -# -# Copyright (C) 2004 The NEST Initiative -# -# NEST is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 2 of the License, or -# (at your option) any later version. -# -# NEST is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with NEST. If not, see . - -# NEST Client -- A client for the NEST Server - -from distutils.core import setup - -setup(name='NEST Client', - version='0.1', - description=('NEST Client sends JSON requests to NEST Server.'), - author='Sebastian Spreizer', - author_email='spreizer@web.de', - url='https://www.nest-simulator.org', - license='GNU Public License v2 or later', - packages=['nest_client'], - ) diff --git a/nest_client/__init__.py b/src/__init__.py similarity index 83% rename from nest_client/__init__.py rename to src/__init__.py index c1d9f38..1caab0b 100644 --- a/nest_client/__init__.py +++ b/src/__init__.py @@ -20,4 +20,8 @@ # along with NEST. If not, see . -from .nest_client import * +from importlib import metadata as _metadata # noqa +from .nest_client import * # noqa + +__version__ = _metadata.version("nest-client") +del _metadata \ No newline at end of file diff --git a/nest_client/nest_client.py b/src/nest_client.py similarity index 84% rename from nest_client/nest_client.py rename to src/nest_client.py index d30cc94..b1d1c96 100644 --- a/nest_client/nest_client.py +++ b/src/nest_client.py @@ -19,8 +19,8 @@ # You should have received a copy of the GNU General Public License # along with NEST. If not, see . -import requests -from werkzeug.exceptions import BadRequest +import requests as _requests # noqa +from werkzeug.exceptions import BadRequest as _BadRequest # noqa __all__ = [ @@ -32,7 +32,7 @@ def encode(response): if response.ok: return response.json() elif response.status_code == 400: - raise BadRequest(response.text) + raise _BadRequest(response.text) class NESTClient: @@ -44,7 +44,7 @@ def __init__(self, host='localhost', port=52425): def __getattr__(self, call): def method(*args, **kwargs): kwargs.update({'args': args}) - response = requests.post(self.url + 'api/' + call, json=kwargs, headers=self.headers) + response = _requests.post(self.url + 'api/' + call, json=kwargs, headers=self.headers) return encode(response) return method @@ -53,7 +53,7 @@ def exec_script(self, source, return_vars=None): 'source': source, 'return': return_vars, } - response = requests.post(self.url + 'exec', json=params, headers=self.headers) + response = _requests.post(self.url + 'exec', json=params, headers=self.headers) return encode(response) def from_file(self, filename, return_vars=None): From cb34b40c81134db7e80167c77977b37b82872b32 Mon Sep 17 00:00:00 2001 From: Sebastian Spreizer Date: Tue, 22 Apr 2025 09:16:46 +0200 Subject: [PATCH 03/15] Update gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f5dca0a..c8b0fa4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__/ build/ -*~ \ No newline at end of file +*~ +*.egg-info \ No newline at end of file From c1ea56695f4a7c243582ef2eed6d0f177def0432 Mon Sep 17 00:00:00 2001 From: Sebastian Spreizer Date: Tue, 22 Apr 2025 09:19:43 +0200 Subject: [PATCH 04/15] Undo import --- src/nest_client.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/nest_client.py b/src/nest_client.py index b1d1c96..925ba80 100644 --- a/src/nest_client.py +++ b/src/nest_client.py @@ -19,8 +19,8 @@ # You should have received a copy of the GNU General Public License # along with NEST. If not, see . -import requests as _requests # noqa -from werkzeug.exceptions import BadRequest as _BadRequest # noqa +import requests # noqa +from werkzeug.exceptions import BadRequest # noqa __all__ = [ @@ -32,7 +32,7 @@ def encode(response): if response.ok: return response.json() elif response.status_code == 400: - raise _BadRequest(response.text) + raise BadRequest(response.text) class NESTClient: @@ -44,7 +44,7 @@ def __init__(self, host='localhost', port=52425): def __getattr__(self, call): def method(*args, **kwargs): kwargs.update({'args': args}) - response = _requests.post(self.url + 'api/' + call, json=kwargs, headers=self.headers) + response = requests.post(self.url + 'api/' + call, json=kwargs, headers=self.headers) return encode(response) return method @@ -53,7 +53,7 @@ def exec_script(self, source, return_vars=None): 'source': source, 'return': return_vars, } - response = _requests.post(self.url + 'exec', json=params, headers=self.headers) + response = requests.post(self.url + 'exec', json=params, headers=self.headers) return encode(response) def from_file(self, filename, return_vars=None): From 2bb0b036a79914088833073a2a2d4a94f63dd520 Mon Sep 17 00:00:00 2001 From: Sebastian Spreizer Date: Tue, 22 Apr 2025 09:20:26 +0200 Subject: [PATCH 05/15] Update gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c8b0fa4..7b414a7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ __pycache__/ build/ *~ -*.egg-info \ No newline at end of file +*.egg-info From ed86a434e9763755e9ec0b82b8e103df2d7ee243 Mon Sep 17 00:00:00 2001 From: Sebastian Spreizer Date: Tue, 22 Apr 2025 09:21:17 +0200 Subject: [PATCH 06/15] Add last empty line --- src/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__init__.py b/src/__init__.py index 1caab0b..05a0bdf 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -24,4 +24,4 @@ from .nest_client import * # noqa __version__ = _metadata.version("nest-client") -del _metadata \ No newline at end of file +del _metadata From 48d342bdc2f15b9b095b720f7c7552e48ddeaf95 Mon Sep 17 00:00:00 2001 From: Sebastian Spreizer Date: Wed, 15 Jan 2025 08:57:54 +0100 Subject: [PATCH 07/15] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index db932d7..6df7325 100644 --- a/README.md +++ b/README.md @@ -9,5 +9,5 @@ The client can either be installed using `python3 setup.py install --user` or, as the client is implemented in a single file, by just copying the file `nest_client/nest_client.py` to your project. -The directory `examples` holds some examples that demostrate the +The directory `examples` holds some examples that demonstrate the usage of the client. From 53d031f0320aca36b37f5ec0cc7399da514fb5d0 Mon Sep 17 00:00:00 2001 From: Sebastian Spreizer Date: Wed, 15 Jan 2025 08:58:15 +0100 Subject: [PATCH 08/15] Fix namespace --- examples/NESTClient_example.py | 42 +++++++++++++++++----------------- examples/__init__.py | 3 --- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/examples/NESTClient_example.py b/examples/NESTClient_example.py index a8b709e..59298e3 100644 --- a/examples/NESTClient_example.py +++ b/examples/NESTClient_example.py @@ -19,46 +19,46 @@ # You should have received a copy of the GNU General Public License # along with NEST. If not, see . -from NESTServerClient import NESTServerClient +from nest_client import NESTClient -print('Running client examples using NEST via NEST Server') +print("Running client examples using NEST via NEST Server") -# Load NEST Server client -nestsc = NESTServerClient() +# Load NEST client +nestc = NESTClient() # # Use NEST Server API # -print('\n') -print('Execute script code with NEST Server API') -print('-' * 20) +print("\n") +print("Execute script code with NEST Server API") +print("-" * 20) # Reset kernel -nestsc.ResetKernel() +nestc.ResetKernel() # Create nodes -pg = nestsc.Create("poisson_generator", params={"rate": 6500.}) -neurons = nestsc.Create("iaf_psc_alpha", 100) -sr = nestsc.Create("spike_recorder") +pg = nestc.Create("poisson_generator", params={"rate": 6500.0}) +neurons = nestc.Create("iaf_psc_alpha", 100) +sr = nestc.Create("spike_recorder") # Connect nodes -nestsc.Connect(pg, neurons, syn_spec={'weight': 10.}) -nestsc.Connect(neurons[::10], sr) +nestc.Connect(pg, neurons, syn_spec={"weight": 10.0}) +nestc.Connect(neurons[::10], sr) # Simulate -nestsc.Simulate(1000.0) +nestc.Simulate(1000.0) # Get events -n_events = nestsc.GetStatus(sr, 'n_events')[0] -print('Number of events:', n_events) +n_events = nestc.GetStatus(sr, "n_events")[0] +print("Number of events:", n_events) # # Use NEST Server exec # -print('\n') -print('Execute script code from file') -print('-' * 20) +print("\n") +print("Execute script code from file") +print("-" * 20) -n_events = nestsc.from_file('NESTClient_script.py', 'n_events')['data'] -print('Number of events:', n_events) +n_events = nestc.from_file("NESTClient_script.py", "n_events")["data"] +print("Number of events:", n_events) diff --git a/examples/__init__.py b/examples/__init__.py index 1a2f534..2f830f2 100644 --- a/examples/__init__.py +++ b/examples/__init__.py @@ -18,6 +18,3 @@ # # You should have received a copy of the GNU General Public License # along with NEST. If not, see . - - -from .NESTServerClient import * From 37a282e088794ace2bb3332050488ce39f2eb2b6 Mon Sep 17 00:00:00 2001 From: Sebastian Spreizer Date: Fri, 7 Mar 2025 11:35:58 +0100 Subject: [PATCH 09/15] Apply suggestions --- examples/NESTClient_example.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/NESTClient_example.py b/examples/NESTClient_example.py index 59298e3..1d6a127 100644 --- a/examples/NESTClient_example.py +++ b/examples/NESTClient_example.py @@ -24,7 +24,7 @@ print("Running client examples using NEST via NEST Server") # Load NEST client -nestc = NESTClient() +nest = NESTClient() # # Use NEST Server API @@ -34,22 +34,22 @@ print("-" * 20) # Reset kernel -nestc.ResetKernel() +nest.ResetKernel() # Create nodes -pg = nestc.Create("poisson_generator", params={"rate": 6500.0}) -neurons = nestc.Create("iaf_psc_alpha", 100) -sr = nestc.Create("spike_recorder") +pg = nest.Create("poisson_generator", params={"rate": 6500.0}) +neurons = nest.Create("iaf_psc_alpha", 100) +sr = nest.Create("spike_recorder") # Connect nodes -nestc.Connect(pg, neurons, syn_spec={"weight": 10.0}) -nestc.Connect(neurons[::10], sr) +nest.Connect(pg, neurons, syn_spec={"weight": 10.0}) +nest.Connect(neurons[::10], sr) # Simulate -nestc.Simulate(1000.0) +nest.Simulate(1000.0) # Get events -n_events = nestc.GetStatus(sr, "n_events")[0] +n_events = nest.GetStatus(sr, "n_events")[0] print("Number of events:", n_events) @@ -60,5 +60,5 @@ print("Execute script code from file") print("-" * 20) -n_events = nestc.from_file("NESTClient_script.py", "n_events")["data"] +n_events = nest.from_file("NESTClient_script.py", "n_events")["data"] print("Number of events:", n_events) From 90cd12f74b64a7ea694db38192fd4cf7f15bfb5e Mon Sep 17 00:00:00 2001 From: Sebastian Spreizer Date: Tue, 6 May 2025 10:46:34 +0200 Subject: [PATCH 10/15] Move src to subfolder `nest_client` --- src/{ => nest_client}/__init__.py | 0 src/{ => nest_client}/nest_client.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/{ => nest_client}/__init__.py (100%) rename src/{ => nest_client}/nest_client.py (100%) diff --git a/src/__init__.py b/src/nest_client/__init__.py similarity index 100% rename from src/__init__.py rename to src/nest_client/__init__.py diff --git a/src/nest_client.py b/src/nest_client/nest_client.py similarity index 100% rename from src/nest_client.py rename to src/nest_client/nest_client.py From b516722d55cdb7ca742a565446d0988ab8585434 Mon Sep 17 00:00:00 2001 From: Sebastian Spreizer Date: Tue, 6 May 2025 11:19:56 +0200 Subject: [PATCH 11/15] Order pyproject --- pyproject.toml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d32b519..512486a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,17 +1,18 @@ [project] name = "nest-client" +version = "0.1.1" description = "NEST Client sends JSON requests to NEST Server." +readme = "README.md" +requires-python = ">=3.9" license = {file = "LICENSE"} -version = "0.1.1" authors = [ {name = "Sebastian Spreizer", email = "spreizer@web.de"}, + {name = "Dennis Terhorst", email = "d.terhorst@fz-juelich.de"} ] maintainers = [ {name = "Sebastian Spreizer", email = "spreizer@web.de"}, {name = "Dennis Terhorst", email = "d.terhorst@fz-juelich.de"} ] -readme = "README.md" -requires-python = ">=3.9" # keywords = [] classifiers = [ # How mature is this project? Common values are @@ -37,7 +38,9 @@ dependencies = [ ] [project.urls] -repository = "https://github.com/nest/nest_client" +homepage = "https://nest-simulator.org" +repository = "https://github.com/nest/nest-client" +documentation = "https://nest-simulator.readthedocs.io" [tool.black] line-length = 120 From ab4f8c8401d50abb671ac87f367746b60f108b51 Mon Sep 17 00:00:00 2001 From: Sebastian Spreizer Date: Tue, 6 May 2025 17:28:25 +0200 Subject: [PATCH 12/15] Clean authors --- pyproject.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 512486a..2158a62 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,11 +6,11 @@ readme = "README.md" requires-python = ">=3.9" license = {file = "LICENSE"} authors = [ - {name = "Sebastian Spreizer", email = "spreizer@web.de"}, - {name = "Dennis Terhorst", email = "d.terhorst@fz-juelich.de"} + {name = "Dennis Terhorst"}, + {name = "Jochen M. Eppler"}, + {name = "Sebastian Spreizer"}, ] maintainers = [ - {name = "Sebastian Spreizer", email = "spreizer@web.de"}, {name = "Dennis Terhorst", email = "d.terhorst@fz-juelich.de"} ] # keywords = [] From d8e74473c9abd3ff1a47d5aacc6a0291e88872b3 Mon Sep 17 00:00:00 2001 From: Sebastian Spreizer Date: Fri, 9 May 2025 17:56:50 +0200 Subject: [PATCH 13/15] Add build-system to pyproject --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2158a62..0d4028e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ version = "0.1.1" description = "NEST Client sends JSON requests to NEST Server." readme = "README.md" requires-python = ">=3.9" -license = {file = "LICENSE"} +license-files = ["LICENSE"] authors = [ {name = "Dennis Terhorst"}, {name = "Jochen M. Eppler"}, From abb7e75460e46b522e20f1921d34269f96760cad Mon Sep 17 00:00:00 2001 From: Sebastian Spreizer Date: Fri, 9 May 2025 17:57:05 +0200 Subject: [PATCH 14/15] Try to import version --- src/nest_client/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/nest_client/__init__.py b/src/nest_client/__init__.py index 05a0bdf..0f62637 100644 --- a/src/nest_client/__init__.py +++ b/src/nest_client/__init__.py @@ -20,8 +20,12 @@ # along with NEST. If not, see . -from importlib import metadata as _metadata # noqa +from importlib import metadata # noqa from .nest_client import * # noqa -__version__ = _metadata.version("nest-client") -del _metadata +try: + __version__ = metadata.version("nest-client") +except metadata.PackageNotFoundError: + pass + +del metadata From d13abaecf637ecebd7f83599722795f981de066d Mon Sep 17 00:00:00 2001 From: Sebastian Spreizer Date: Mon, 12 May 2025 12:28:23 +0200 Subject: [PATCH 15/15] Remove one classifier --- pyproject.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 0d4028e..8465ef0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,9 +26,6 @@ classifiers = [ "Topic :: Scientific/Engineering", - # Pick your license as you wish (see also "license" above) - "License :: OSI Approved :: GNU Public License 3.0 or later", - # Specify the Python versions you support here. "Programming Language :: Python :: 3", ]