Skip to content

Commit 1ebd70d

Browse files
committed
copy whole spynnaker.pyNN.__init__.py
1 parent 773ccf9 commit 1ebd70d

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

spynnaker/pyNN/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
# pylint: disable=invalid-name
2222

2323
# common imports
24+
import filecmp
2425
import logging
26+
import os
2527
from typing import (
2628
Any, Callable, Dict, Iterable, List, Optional, Sequence, Tuple, Type,
2729
TypedDict, Union, cast)
@@ -50,6 +52,11 @@
5052
from spinn_front_end_common.utilities.exceptions import (
5153
ConfigurationException)
5254

55+
# Selt import to check if copied into pyNN.spiNNaker
56+
import spynnaker.pyNN as _sim
57+
58+
from spynnaker.pyNN.exceptions import SpynnakerException
59+
5360
from spynnaker.pyNN.random_distribution import RandomDistribution
5461
from spynnaker.pyNN.data import SpynnakerDataView
5562
from spynnaker.pyNN.models.abstract_pynn_model import AbstractPyNNModel
@@ -138,6 +145,8 @@
138145
from spynnaker.pyNN import external_devices
139146
from spynnaker.pyNN import extra_models
140147

148+
from spynnaker.pyNN.setup_pynn import setup_pynn
149+
141150
# big stuff
142151
from spynnaker.pyNN.spinnaker import SpiNNaker
143152

@@ -745,3 +754,13 @@ def get_machine() -> Machine:
745754
"""
746755
SpynnakerDataView.check_user_can_act()
747756
return SpynnakerDataView.get_machine()
757+
758+
759+
# Check copy in case being run from pyNN.spiNNaker
760+
indirect = os.path.abspath(_sim.__file__)
761+
direct = __file__
762+
if direct != indirect:
763+
if not filecmp.cmp(direct, indirect):
764+
setup_pynn()
765+
raise SpynnakerException(
766+
"pyNN.spiNNaker needed updating please restart your script")

spynnaker/pyNN/setup_pynn.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121
"""
2222

2323
import os
24+
import shutil
2425
from types import ModuleType
2526
from packaging.version import Version
2627
import pyNN
28+
import spynnaker.pyNN as sim
29+
2730

2831
# The version of PyNN that we really want
2932
_TARGET_PYNN_VERSION = "0.9"
@@ -54,11 +57,10 @@ def install_spynnaker_into(module: ModuleType) -> None:
5457
if not os.path.exists(spinnaker_dir):
5558
os.mkdir(spinnaker_dir)
5659

57-
spinnaker_init = os.path.join(spinnaker_dir, "__init__.py")
58-
with open(spinnaker_init, "w", encoding="utf-8") as spinn_file:
59-
spinn_file.write("from spynnaker.pyNN import *\n")
60-
61-
print(f"Created {spinnaker_init} to point to spynnaker.pyNN")
60+
pynn_init = os.path.join(spinnaker_dir, "__init__.py")
61+
spynnaker_init = os.path.abspath(sim.__file__)
62+
shutil.copyfile(spynnaker_init, pynn_init)
63+
print(f"Updated {pynn_init} to be the same as spynnaker.pyNN")
6264

6365

6466
def setup_pynn() -> None:

0 commit comments

Comments
 (0)