Browse Source

Made proper setup

shkolnick-kun 3 years ago
parent
commit
b0e3adea04
8 changed files with 103 additions and 49 deletions
  1. 2 1
      MANIFEST.in
  2. 5 0
      requirements-dev.txt
  3. 3 0
      requirements.txt
  4. 44 0
      setup.cfg
  5. 47 42
      setup.py
  6. 0 2
      src/yaflpy/__init__.py
  7. 0 1
      tests/src/yaflpy_compile.py
  8. 2 3
      tests/src/yaflpy_compile_robust.py

+ 2 - 1
MANIFEST.in

@@ -1 +1,2 @@
-include src/* src/yaflpy/* LICENSE Readme.md
+include src/* src/yaflpy/* requirements.txt requirements-dev.txt
+include LICENSE Readme.md

+ 5 - 0
requirements-dev.txt

@@ -0,0 +1,5 @@
+Cython >= 0.29.21
+numpy >= 1.17
+scipy >= 1.5
+setuptools >= 51.0.0
+wheel >= 0.36.2

+ 3 - 0
requirements.txt

@@ -0,0 +1,3 @@
+Cython >= 0.29.21
+numpy >= 1.17
+scipy >= 1.5

+ 44 - 0
setup.cfg

@@ -0,0 +1,44 @@
+[metadata]
+name = yaflpy
+version = 0.10.0
+
+description = Yet Another Filtering Library
+long_description = file: Readme.md
+long_description_content_type = text/markdown
+
+license = Apache License, Version 2.0
+license_file = LICENSE
+
+author = anonimous
+author_email = shkolnick-kun@gmail.com
+
+url = https://github.com/shkolnick-kun/yafl
+download_urls = https://github.com/shkolnick-kun/yafl
+project_urls =
+	Documentation = https://github.com/shkolnick-kun/yafl
+	Code = https://github.com/shkolnick-kun/yafl
+	Issue tracker = https://github.com/shkolnick-kun/yafl/issues
+
+classifiers =
+	evelopment Status :: 3 - Alpha
+	License :: OSI Approved :: Apache Software License
+	Intended Audience :: Science/Research
+	Topic :: Scientific/Engineering
+	Topic :: Scientific/Engineering :: Mathematics
+	Topic :: Software Development :: Embedded Systems
+	Natural Language :: English
+	Operating System :: OS Independent
+	Programming Language :: C
+	Programming Language :: Cython
+	Programming Language :: Python
+	Programming Language :: Python :: 3
+	Programming Language :: Python :: 3.4
+	Programming Language :: Python :: 3.5
+	Programming Language :: Python :: 3.6
+	Programming Language :: Python :: 3.7
+	Programming Language :: Python :: 3 :: Only
+	Programming Language :: Python :: Implementation :: CPython
+
+[options]
+zip_safe = False
+python_requires = >=3.4

+ 47 - 42
setup.py

@@ -1,55 +1,60 @@
 # -*- coding: utf-8 -*-
 import numpy
-from os.path import join, dirname
+import os
+from os.path import dirname, join, splitext
 from setuptools import Extension, setup
-from Cython.Build import cythonize #must be after setuptools
 
-#------------------------------------------------------------------------------
-EXT_NAME = 'yaflpy'
+try:
+    from Cython.Build import cythonize
+except ImportError:
+    cythonize = None
 
-setup_dir = dirname(__file__)
-src_dir   = join(setup_dir, 'src')
-ext_dir   = join(src_dir, EXT_NAME)
+# https://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html#distributing-cython-modules
+def no_cythonize(extensions, **_ignore):
+    for extension in extensions:
+        sources = []
+        for sfile in extension.sources:
+            path, ext = splitext(sfile)
+            if ext in (".pyx", ".py"):
+                if extension.language == "c++":
+                    ext = ".cpp"
+                else:
+                    ext = ".c"
+                sfile = path + ext
+            sources.append(sfile)
+        extension.sources[:] = sources
+    return extensions
+
+EXT_NAME  = "yaflpy"
+SETUP_DIR = dirname(__file__)
+SRC_DIR   = join(SETUP_DIR, "src")
+EXT_DIR   = join(SRC_DIR, EXT_NAME)
 
 extensions = [
-    Extension(EXT_NAME, [join(ext_dir, EXT_NAME + '.pyx')],
-        include_dirs=[numpy.get_include(), src_dir, ext_dir],
+    Extension(EXT_NAME, [join(EXT_DIR, EXT_NAME + ".pyx")],
+        include_dirs=[numpy.get_include(), SRC_DIR, EXT_DIR],
         define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")])
     ]
 
-#------------------------------------------------------------------------------
-deps = ['Cython', 'numpy', 'scipy', 'setuptools']
+CYTHONIZE = bool(int(os.getenv("CYTHONIZE", 0))) and cythonize is not None
+
+if CYTHONIZE:
+    compiler_directives = {"language_level": 3, "embedsignature": True}
+    extensions = cythonize(extensions, compiler_directives=compiler_directives)
+else:
+    extensions = no_cythonize(extensions)
+
+with open("requirements.txt") as fp:
+    install_requires = fp.read().strip().split("\n")
+
+with open("requirements-dev.txt") as fp:
+    dev_requires = fp.read().strip().split("\n")
 
-#------------------------------------------------------------------------------
 setup(
-      name="yaflpy",
-      version = '0.1.0',
-      description = ['Yet Another Filtering Library'],
-      long_description = open(join(setup_dir, 'Readme.md')).read(),
-      long_description_content_type = 'text/markdown',
-      license = 'Apache License, Version 2.0',
-      license_file = join(setup_dir, 'LICENSE'),
-      author = 'anonimous',
-      author_email = 'shkolnick-kun@gmail.com',
-      url = 'https://github.com/shkolnick-kun/yafl',
-      classifiers = [
-        'Development Status :: 3 - Alpha',
-        'Topic :: Software Development :: Embedded Systems',
-        'Intended Audience :: Science/Research',
-        'License :: OSI Approved :: Apache Software License',
-        'Programming Language :: Python :: 3',
-        'Programming Language :: Python :: 3.3',
-        'Programming Language :: Python :: 3.4',
-        'Programming Language :: Python :: 3.5',
-        'Programming Language :: Python :: 3.6',
-        'Programming Language :: Python :: 3.7',
-        'Programming Language :: Python :: 3.8',
-        'Programming Language :: Python :: 3.9',
-        ],
-      setup_requires=deps,
-      install_requires=deps,
-      python_requires='>=3',
-      platforms = ['any'],
-      ext_modules = cythonize(extensions,
-                              compiler_directives={'language_level' : '3'})
+    ext_modules=extensions,
+    install_requires=install_requires,
+    extras_require={
+        "dev": dev_requires,
+        "docs": ["sphinx", "sphinx-rtd-theme"]
+    },
 )

+ 0 - 2
src/yaflpy/__init__.py

@@ -1,2 +0,0 @@
-# -*- coding: utf-8 -*-
-

+ 0 - 1
tests/src/yaflpy_compile.py

@@ -34,7 +34,6 @@ pyximport.install(
         }
     )
 
-
 #from yaflpy import Bierman as KF
 #from yaflpy import Joseph as KF
 #from yaflpy import AdaptiveBierman as KF

+ 2 - 3
tests/src/yaflpy_compile_robust.py

@@ -22,6 +22,7 @@ import scipy.stats
 import sys
 import time
 
+
 sys.path.insert(0,'../../src/yaflpy')
 
 pyximport.install(
@@ -32,9 +33,7 @@ pyximport.install(
     setup_args={
         'include_dirs': [np.get_include(), '../../src', '../../src/yaflpy'],
         }
-    ))
-
-import yaflpy
+    )
 
 #from yaflpy import RobustJoseph as KF
 #from yaflpy import RobustBierman as KF