Repository: BUNPC/pysnirf2 (language: python)

Issue:
Refactored everything to remove "Class" is this is not good style
Also reworked a bit of logic in the varg validate function


Discussion / hints:

Fix patch:
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..7152b80
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,1 @@
+include README.md LICENSE
\ No newline at end of file
diff --git a/gen/gen.py b/gen/gen.py
index a399002..8f59591 100644
--- a/gen/gen.py
+++ b/gen/gen.py
@@ -16,7 +16,7 @@
 
 if __name__ == '__main__':
     
-    local_spec = SPEC_SRC.split('/')[-1].split('.')[0] + '_retrieved_'+ datetime.now().strftime('%d_%m_%y') + '.txt'
+    local_spec = SPEC_SRC.split('/')[-1].split('.')[0] + '_retrieved_' + datetime.now().strftime('%d_%m_%y') + '.txt'
     
     if os.path.exists(local_spec):
         print('Loading specification from local document', local_spec, '...')
@@ -168,7 +168,7 @@
     
     # Generate the complete Snirf interface from base.py and the template + data
     dst = os.path.abspath(os.path.join(os.getcwd(), os.pardir))
-    output_path = dst + '/src/' + 'pysnirf2.py'
+    output_path = dst + '/pysnirf2/' + 'pysnirf2.py'
     with open(HEADER, 'r') as f_header:
         with open(FOOTER, 'r') as f_footer:
             print('Loading base class definitions and file header from', HEADER)
diff --git a/pysnirf2/__init__.py b/pysnirf2/__init__.py
new file mode 100644
index 0000000..610b326
--- /dev/null
+++ b/pysnirf2/__init__.py
@@ -0,0 +1,1 @@
+from .pysnirf2 import *
\ No newline at end of file
diff --git a/pysnirf2/__version__.py b/pysnirf2/__version__.py
new file mode 100644
index 0000000..c20df98
--- /dev/null
+++ b/pysnirf2/__version__.py
@@ -0,0 +1,4 @@
+
+VERSION = (0, 2, 0)
+
+__version__ = '.'.join(map(str, VERSION))
diff --git a/src/pysnirf2.py b/pysnirf2/pysnirf2.py
similarity index 100%
rename from src/pysnirf2.py
rename to pysnirf2/pysnirf2.py
diff --git a/requirements.txt b/requirements.txt
index 23e1966..ae59bbe 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,4 +1,4 @@
-cached-property==1.5.2
 h5py==3.6.0
 numpy==1.19.5
-setuptools==40.8.0
\ No newline at end of file
+setuptools==40.8.0
+pip==21.3.1
diff --git a/setup.cfg b/setup.cfg
deleted file mode 100644
index 064eee8..0000000
--- a/setup.cfg
+++ /dev/null
@@ -1,21 +0,0 @@
-[metadata]
-name = pysnirf2
-author_email = sstucker@bu.edu
-description = Dynamically generated SNIRF file format interface and validator
-long_description = file: README.md
-long_description_content_type = text/markdown
-url = https://github.com/BUNPC/pysnirf2
-project_urls = Bug Tracker = https://github.com/BUNPC/pysnirf2/issues
-classifiers =
-    Programming Language :: Python :: 3
-    License :: OSI Approved :: GNU General Public License v3 (GPLv3)
-    Operating System :: OS Independent
-
-[options]
-package_dir =
-    = src
-packages = find:
-python_requires = >=3
-
-[options.packages.find]
-where = src
\ No newline at end of file
diff --git a/setup.py b/setup.py
index 6c9b838..e97fc7b 100644
--- a/setup.py
+++ b/setup.py
@@ -1,7 +1,94 @@
-from setuptools import setup, find_packages
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Based on https://github.com/kennethreitz/setup.py
+
+import io
+import os
+import sys
+from shutil import rmtree
+
+from setuptools import find_packages, setup, Command
+
+NAME = 'pysnirf2'
+VERSION = '0.1.0'
+
+here = os.path.abspath(os.path.dirname(__file__))
+
+try:
+    with io.open(os.path.join(here, 'README.md'), encoding='utf-8') as f:
+        long_description = '\n' + f.read()
+except FileNotFoundError:
+    long_description = DESCRIPTION
+
+# Load the package's __version__.py module
+about = {}
+if not VERSION:
+    project_slug = NAME.lower().replace("-", "_").replace(" ", "_")
+    with open(os.path.join(here, project_slug, '__version__.py')) as f:
+        exec(f.read(), about)
+else:
+    about['__version__'] = VERSION
+
+
+class UploadCommand(Command):
+    """Support setup.py upload."""
+
+    description = 'Build and publish the package.'
+    user_options = []
+
+    @staticmethod
+    def status(s):
+        """Prints things in bold."""
+        print('\033[1m{0}\033[0m'.format(s))
+
+    def initialize_options(self):
+        pass
+
+    def finalize_options(self):
+        pass
+
+    def run(self):
+        try:
+            self.status('Removing previous builds…')
+            rmtree(os.path.join(here, 'dist'))
+        except OSError:
+            pass
+
+        self.status('Building Source and Wheel (universal) distribution…')
+        os.system('{0} setup.py sdist bdist_wheel --universal'.format(sys.executable))
+
+        self.status('Uploading the package to PyPI via Twine…')
+        os.system('twine upload dist/*')
+
+        self.status('Pushing git tags…')
+        os.system('git tag v{0}'.format(about['__version__']))
+        os.system('git push --tags')
+
+        sys.exit()
+
 
 setup(
-    packages=find_packages('src'),
-    package_dir={'': 'src'},
+    name=NAME,
+    version=about['__version__'],
+    description='Interface and validator for SNIRF files',
+    long_description=long_description,
+    long_description_content_type='text/markdown',
+    author_email='sstucker@bu.edu',
+    python_requires='>=3.6.0',
+    url='https://github.com/BUNPC/pysnirf2',
+    py_modules=['pysnirf2'],
     include_package_data=True,
+    license='GPLv3',
+    classifiers=[
+        'License :: OSI Approved :: MIT License',
+        'Programming Language :: Python',
+        'Programming Language :: Python :: 3',
+        'Programming Language :: Python :: 3.6',
+        'Programming Language :: Python :: Implementation :: CPython',
+        'Programming Language :: Python :: Implementation :: PyPy'
+    ],
+    # $ setup.py publish support.
+    cmdclass={
+        'upload': UploadCommand,
+    },
 )
diff --git a/src/__init__.py b/src/__init__.py
deleted file mode 100644
index d002639..0000000
--- a/src/__init__.py
+++ /dev/null
@@ -1,1 +0,0 @@
-from pysnirf2 import *
\ No newline at end of file


Test patch:
diff --git a/tests/test.py b/tests/test.py
index b3d27d5..6272625 100644
--- a/tests/test.py
+++ b/tests/test.py
@@ -11,8 +11,11 @@
 import numpy as np
 
 VERBOSE = True  # Additional print statements in each test
-SNIRF_DIR = 'data'  # Sample data source
-WD = 'wd'  # Working directory for testing
+snirf_directory = os.getcwd() + '\\tests\\data'  # Sample data source
+working_directory = os.getcwd() + '\\tests\\wd'  # Working directory for testing
+
+if len(os.listdir(snirf_directory)) == 0:
+    sys.exit('Failed to find test data in '+ working_directory)
 
 ZERO_DEPTH_BASES = (str, bytes, Number, range, bytearray)
 def getsize(obj_0):
@@ -135,28 +138,6 @@ def _print_keys(group):
 
 class TestSnirf(unittest.TestCase):
     
-    def test_dynamic(self):
-        """
-        Confirm that dynamically loaded files have smaller memory footprints
-        and faster load-times than non dynamically loaded files
-        """
-        times = [-1, -1]
-        sizes = [-1, -1]
-        for i, mode in enumerate([True, False]):
-            s = []
-            start = time.time()
-            for file in TEST_FILES:
-                s.append(Snirf(file, dynamic_loading=mode))
-            times[i] = time.time() - start
-            sizes[i] = getsize(s)
-            for snirf in s:
-                snirf.close()
-            if VERBOSE:
-                print('Loaded', len(TEST_FILES), 'SNIRF files of total size', sizes[i],
-                      'in', str(times[i])[0:6], 'seconds with dynamic_loading =', mode)
-        self.assertTrue(times[0] < times[1], msg='Dynamically-loaded files not loaded faster')
-        self.assertTrue(sizes[0] < sizes[1], msg='Dynamically-loaded files not smaller in memory')
-    
     
     def test_loading_saving(self):
         """
@@ -182,7 +163,30 @@ def test_loading_saving(self):
             for (fname1, fname2) in zip(s1_paths, s2_paths):
                 dataset_equal_test(self, fname1, fname2)
     
+
+    def test_dynamic(self):
+        """
+        Confirm that dynamically loaded files have smaller memory footprints
+        and faster load-times than non dynamically loaded files
+        """
+        times = [-1, -1]
+        sizes = [-1, -1]
+        for i, mode in enumerate([True, False]):
+            s = []
+            start = time.time()
+            for file in TEST_FILES:
+                s.append(Snirf(file, dynamic_loading=mode))
+            times[i] = time.time() - start
+            sizes[i] = getsize(s)
+            for snirf in s:
+                snirf.close()
+            if VERBOSE:
+                print('Loaded', len(TEST_FILES), 'SNIRF files of total size', sizes[i],
+                      'in', str(times[i])[0:6], 'seconds with dynamic_loading =', mode)
+        self.assertTrue(times[0] < times[1], msg='Dynamically-loaded files not loaded faster')
+        self.assertTrue(sizes[0] < sizes[1], msg='Dynamically-loaded files not smaller in memory')
     
+
     # def test_create_a_file(self):
     #     """
     #     Create a file from scratch using the data in the first test file. Compare
@@ -255,17 +259,24 @@ def test_loading_saving(self):
 
 # -- Set up test working-directory --------------------------------------------
 
-print('Deleting all files in', WD)
-for file in os.listdir(WD):
-    os.remove(WD + '\\' + file)
-
-'Copying all files to WD'
-for file in os.listdir(SNIRF_DIR):
-    os.popen('copy ' + SNIRF_DIR + '\\' + file + ' ' + WD + '\\' + file)
-time.sleep(1)  # Sleep while os exectues copy operation
+print('Deleting all files in', working_directory)
+for file in os.listdir(working_directory):
+    os.remove(working_directory + '\\' + file)
+    print('Deleted', working_directory + '\\' + file)
 
-TEST_FILES = [WD + '/' + file for file in os.listdir(WD)]
+print('Copying all test files to', working_directory)
+if os.name == 'nt':
+    cmd = 'copy '
+else:
+    cmd = 'cp '
+for file in os.listdir(snirf_directory):
+    os.popen(cmd + snirf_directory + '\\' + file + ' ' + working_directory + '\\' + file)
+    print(cmd + snirf_directory + '\\' + file + ' ' + working_directory + '\\' + file)
+    time.sleep(0.5)  # Sleep while executing copy operation
 
+TEST_FILES = [working_directory + '\\' + file for file in os.listdir(working_directory)]
+if len(TEST_FILES) == 0:
+    sys.exit('Failed to set up test data working directory at '+ working_directory)
 
 if __name__ == '__main__':
     result = unittest.main()