jacobian

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 251f3c93db3c6c304e99adf455555ac57120209a
parent b25230feccf35bc45913fc40482784754d572152
Author: David Freifeld <freifeld.david@gmail.com>
Date:   Sun,  9 Aug 2020 16:06:01 -0700

Wow setuptools can be annoying

Diffstat:
Djacobian/setup.py | 22----------------------
Msetup.py | 54++++++++++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 50 insertions(+), 26 deletions(-)

diff --git a/jacobian/setup.py b/jacobian/setup.py @@ -1,22 +0,0 @@ -# -# setup.py -# Jacobian -# - -from distutils.core import setup - -import sys -if sys.version_info < (3,0): - sys.exit('Sorry, Python < 3.0 is not supported') - -setup( - name = 'cmake_cpp_pybind11', - version = '${PACKAGE_VERSION}', - packages = [ 'jacobian' ], - package_dir = { - '': '${CMAKE_CURRENT_BINARY_DIR}' - }, - package_data = { - '': ['jacobian.cpython-38-darwin.so'] - } -) diff --git a/setup.py b/setup.py @@ -1,5 +1,40 @@ +import os +import re +import sys +import sysconfig +import platform +import subprocess + from subprocess import CalledProcessError +from distutils.version import LooseVersion +from setuptools import setup, Extension +from setuptools.command.build_ext import build_ext + +class CMakeExtension(Extension): + def __init__(self, name, sourcedir=''): + Extension.__init__(self, name, sources=[]) + self.sourcedir = os.path.abspath(sourcedir) + +class CMakeBuild(build_ext): + def run(self): + try: + out = subprocess.check_output(['cmake', '--version']) + except OSError: + raise RuntimeError( + "CMake must be installed to build the following extensions: " + + ", ".join(e.name for e in self.extensions)) + + if platform.system() == "Windows": + cmake_version = LooseVersion(re.search(r'version\s*([\d.]+)', + out.decode()).group(1)) + if cmake_version < '3.1.0': + raise RuntimeError("CMake >= 3.1.0 is required on Windows") + for ext in self.extensions: + if ext is None: + continue + self.build_extension(ext) + kwargs = dict( name='Jacobian', version='0.8', @@ -7,15 +42,26 @@ kwargs = dict( author_email='freifeld.david@gmail.com', description='A Python library for neural networks.', long_description='', - ext_modules=[CMakeExtension('jacobian._jacobian')], + ext_modules=[CMakeExtension('_jacobian')], cmdclass=dict(build_ext=CMakeBuild), - zip_safe=False, - packages=['cmake_example'] + zip_safe=True, + packages=['jacobian'] ) # likely there are more exceptions, take a look at yarl example try: - setup(**kwargs) + setup(**kwargs + # name='Jacobian', + # version='0.8', + # author='David Freifeld', + # author_email='freifeld.david@gmail.com', + # description='A Python library for neural networks.', + # long_description='', + # ext_modules=[CMakeExtension('_jacobian')], + # cmdclass=dict(build_ext=CMakeBuild), + # zip_safe=True, + # package=['jacobian'] + ) except CalledProcessError: print('Failed to build extension!') del kwargs['ext_modules']