From c013e39d67d3276a3d83960d0bb8aaf997762e37 Mon Sep 17 00:00:00 2001 From: Danylo Ulianych Date: Sun, 21 Jul 2019 09:18:03 +0300 Subject: [PATCH] elephant dir packages are back (#239) * reverted removed imports of elephant's internal packages; download fim during the setup * download fim from tools/fim_manager.py * dummy tools/__init__.py to support py2 * include requirements in MANIFEST back * fixed spade licence typo * included waveform_features module; removed tools; don't donwload fim at setup while macking a tarball with 'sdist' command travis not fixed downloading fim * skip time consuming test_spade_cpp if not HAVE_FIM * travis pip install generated tarball * recursive-include elephant *.py --- .gitignore | 4 ++- .travis.yml | 3 +- MANIFEST.in | 9 +++--- elephant/__init__.py | 27 ++++++++++++++++++ elephant/spade.py | 4 --- elephant/spade_src/fim_manager.py | 41 --------------------------- elephant/test/test_spade.py | 21 ++++---------- setup.py | 47 +++++++++++++++++++++++++++---- 8 files changed, 84 insertions(+), 72 deletions(-) delete mode 100644 elephant/spade_src/fim_manager.py diff --git a/.gitignore b/.gitignore index 926b72a09..acceba13d 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,9 @@ nosetests.xml .pydevproject .settings *.tmp* -.idea +.idea/ +venv/ +env/ .pytest_cache/ # Compiled source # diff --git a/.travis.yml b/.travis.yml index 5c47e59c0..c532810c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -73,7 +73,8 @@ install: - pip -V - pip install coverage coveralls nose - - pip install . + - python setup.py install + - python -c "from elephant.spade import HAVE_FIM; assert HAVE_FIM" - pip list - python --version diff --git a/MANIFEST.in b/MANIFEST.in index 83d750a15..d10c065ef 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,12 +1,13 @@ +recursive-include elephant *.py +include requirements*.txt include README.rst include LICENSE.txt include AUTHORS.txt include elephant/VERSION include elephant/current_source_density_src/README.md include elephant/current_source_density_src/test_data.mat -include elephant/spade_src/LICENCE +include elephant/spade_src/LICENSE +recursive-include elephant/spade_src *.so *.pyd include elephant/test/spike_extraction_test_data.txt recursive-include doc * - -# special care for the files, used in setup.py -include elephant/spade_src/fim_manager.py +prune doc/_build diff --git a/elephant/__init__.py b/elephant/__init__.py index b7cb53d51..d81745346 100644 --- a/elephant/__init__.py +++ b/elephant/__init__.py @@ -6,6 +6,33 @@ :license: Modified BSD, see LICENSE.txt for details. """ +from . import (statistics, + spike_train_generation, + spike_train_correlation, + unitary_event_analysis, + cubic, + spectral, + kernels, + spike_train_dissimilarity, + spike_train_surrogates, + signal_processing, + current_source_density, + change_point_detection, + phase_analysis, + sta, + conversion, + neo_tools, + spade, + cell_assembly_detection, + waveform_features) + +try: + from . import pandas_bridge + from . import asset +except ImportError: + # requirements-extras are missing + pass + def _get_version(): import os diff --git a/elephant/spade.py b/elephant/spade.py index 360f97ccb..6153932fe 100644 --- a/elephant/spade.py +++ b/elephant/spade.py @@ -66,13 +66,9 @@ import quantities as pq import warnings from elephant.spade_src import fast_fca -from elephant.spade_src.fim_manager import download_spade_fim warnings.simplefilter('once', UserWarning) -# if not downloaded during the install, do it now -download_spade_fim() - try: from mpi4py import MPI # for parallelized routines diff --git a/elephant/spade_src/fim_manager.py b/elephant/spade_src/fim_manager.py deleted file mode 100644 index fc70a7d91..000000000 --- a/elephant/spade_src/fim_manager.py +++ /dev/null @@ -1,41 +0,0 @@ -import os -import platform -import struct -import sys - -python_version_major = sys.version_info.major - -if python_version_major == 2: - from urllib import urlretrieve -else: - from urllib.request import urlretrieve - - -def _get_fim_lib_path(): - if platform.system() == "Windows": - fim_filename = "fim.pyd" - else: - # Linux - fim_filename = "fim.so" - fim_lib_path = os.path.join(os.path.dirname(__file__), fim_filename) - return fim_lib_path - - -def download_spade_fim(): - """ - Downloads SPADE specific PyFIM binary file. - """ - fim_lib_path = _get_fim_lib_path() - fim_filename = os.path.basename(fim_lib_path) - if os.path.exists(fim_lib_path): - return - - arch_bits = struct.calcsize("P") * 8 - url_fim = "http://www.borgelt.net/bin{arch}/py{py_ver}/{filename}". \ - format(arch=arch_bits, py_ver=python_version_major, - filename=fim_filename) - try: - urlretrieve(url_fim, filename=fim_lib_path) - print("Successfully downloaded fim lib to {}".format(fim_lib_path)) - except Exception: - print("Unable to download {url} module.".format(url=url_fim)) diff --git a/elephant/test/test_spade.py b/elephant/test/test_spade.py index 05864e3e5..f79827064 100644 --- a/elephant/test/test_spade.py +++ b/elephant/test/test_spade.py @@ -6,7 +6,6 @@ """ from __future__ import division -import os import unittest import neo @@ -18,8 +17,6 @@ import elephant.spade as spade import elephant.spike_train_generation as stg from elephant.spade import HAVE_FIM -from elephant.spade_src.fim_manager import download_spade_fim, \ - _get_fim_lib_path class SpadeTestCase(unittest.TestCase): @@ -110,6 +107,7 @@ def setUp(self): self.patt_psr = self.patt3 + [self.patt3[-1][:3]] # Testing cpp + @unittest.skipUnless(HAVE_FIM, "Time consuming with pythonic FIM") def test_spade_cpp(self): output_cpp = spade.spade(self.cpp, self.binsize, 1, n_subsets=self.n_subset, @@ -243,7 +241,7 @@ def test_parameters(self): # check the lags assert_array_equal([len(lags) < self.max_spikes for lags in lags_msip_max_spikes], [True] * len( - lags_msip_max_spikes)) + lags_msip_max_spikes)) # test max_occ parameter output_msip_max_occ = spade.spade(self.msip, self.binsize, self.winlen, @@ -371,12 +369,11 @@ def test_spectrum(self): self.winlen, report='3d#')[0] assert_array_equal(spectrum_3d, [ [len(self.lags3) + 1, self.n_occ3, max(self.lags3), 1]]) - # test the errors raised def test_spade_raise_error(self): # Test list not using neo.Spiketrain self.assertRaises(TypeError, spade.spade, [ - [1, 2, 3], [3, 4, 5]], 1 * pq.ms, 4) + [1, 2, 3], [3, 4, 5]], 1 * pq.ms, 4) # Test neo.Spiketrain with different t_stop self.assertRaises(AttributeError, spade.spade, [neo.SpikeTrain( [1, 2, 3] * pq.s, t_stop=5 * pq.s), neo.SpikeTrain( @@ -385,7 +382,7 @@ def test_spade_raise_error(self): self.assertRaises(ValueError, spade.spade, [neo.SpikeTrain( [1, 2, 3] * pq.s, t_stop=6 * pq.s), neo.SpikeTrain( [3, 4, 5] * pq.s, t_stop=6 * pq.s)], 1 * pq.ms, 4, n_surr=1, - spectrum='try') + spectrum='try') # Test negative minimum number of spikes self.assertRaises(AttributeError, spade.spade, [neo.SpikeTrain( [1, 2, 3] * pq.s, t_stop=5 * pq.s), neo.SpikeTrain( @@ -394,14 +391,13 @@ def test_spade_raise_error(self): self.assertRaises(AttributeError, spade.pvalue_spectrum, [ neo.SpikeTrain([1, 2, 3] * pq.s, t_stop=5 * pq.s), neo.SpikeTrain( [3, 4, 5] * pq.s, t_stop=5 * pq.s)], 1 * pq.ms, 4, 3 * pq.ms, - n_surr=-3) + n_surr=-3) # Test wrong correction parameter self.assertRaises(AttributeError, spade.test_signature_significance, ( (2, 3, 0.2), (2, 4, 0.1)), 0.01, corr='try') # Test negative number of subset for stability self.assertRaises(AttributeError, spade.approximate_stability, (), np.array([]), n_subsets=-3) - # test psr def test_pattern_set_reduction(self): output_msip = spade.spade(self.patt_psr, self.binsize, self.winlen, @@ -426,13 +422,6 @@ def test_pattern_set_reduction(self): # check the occurrences time of the patters assert_array_equal(len(occ_msip[0]), self.n_occ3) - def test_download_spade_fim(self): - fim_lib_path = _get_fim_lib_path() - if os.path.exists(fim_lib_path): - os.unlink(fim_lib_path) - download_spade_fim() - assert os.path.exists(fim_lib_path) - def suite(): suite = unittest.makeSuite(SpadeTestCase, 'test') diff --git a/setup.py b/setup.py index ebec637a8..050401a41 100644 --- a/setup.py +++ b/setup.py @@ -1,14 +1,23 @@ # -*- coding: utf-8 -*- +import os +import platform +import struct import sys from setuptools import setup -from elephant import __version__ -from elephant.spade_src.fim_manager import download_spade_fim - python_version_major = sys.version_info.major +if python_version_major == 2: + from urllib import urlretrieve +else: + from urllib.request import urlretrieve + +with open(os.path.join(os.path.dirname(__file__), + "elephant", "VERSION")) as version_file: + version = version_file.read().strip() + with open("README.rst") as f: long_description = f.read() with open('requirements.txt') as fp: @@ -18,11 +27,39 @@ with open('requirements-{0}.txt'.format(extra)) as fp: extras_require[extra] = fp.read() -download_spade_fim() + +def download_spade_fim(): + """ + Downloads SPADE specific PyFIM binary file. + """ + if platform.system() == "Windows": + fim_filename = "fim.pyd" + else: + # Linux + fim_filename = "fim.so" + spade_src_dir = os.path.join(os.path.dirname(__file__), "elephant", + "spade_src") + fim_lib_path = os.path.join(spade_src_dir, fim_filename) + if os.path.exists(fim_lib_path): + return + + arch_bits = struct.calcsize("P") * 8 + url_fim = "http://www.borgelt.net/bin{arch}/py{py_ver}/{filename}". \ + format(arch=arch_bits, py_ver=python_version_major, + filename=fim_filename) + try: + urlretrieve(url_fim, filename=fim_lib_path) + print("Successfully downloaded fim lib to {}".format(fim_lib_path)) + except Exception: + print("Unable to download {url} module.".format(url=url_fim)) + + +if len(sys.argv) > 1 and sys.argv[1].lower() != 'sdist': + download_spade_fim() setup( name="elephant", - version=__version__, + version=version, packages=['elephant', 'elephant.test'], include_package_data=True,