-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a draft of a `setup.py`. I am not sure it it does more harm than good to expose this to the user or if I should hide a perfectly tailored, `PyPI` distribution building only one deep in the source tree.
- Loading branch information
Showing
3 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
include README.md COPYING COPYING.LESSER | ||
include requirements.txt | ||
global-include CMakeLists.txt *.cmake *.cmake.in | ||
recursive-include include * | ||
recursive-include src * | ||
recursive-include share * | ||
recursive-include test * | ||
recursive-include examples * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
cmake>=3.10.0 | ||
pybind11>=2.2.1 | ||
numpy>=1.15.0 | ||
setuptools>=38.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import os | ||
import re | ||
import sys | ||
import platform | ||
import subprocess | ||
|
||
from setuptools import setup, Extension | ||
from setuptools.command.build_ext import build_ext | ||
from distutils.version import LooseVersion | ||
|
||
|
||
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 3.10.0+ must be installed to build the following " + | ||
"extensions: " + | ||
", ".join(e.name for e in self.extensions)) | ||
|
||
cmake_version = LooseVersion(re.search( | ||
r'version\s*([\d.]+)', | ||
out.decode() | ||
).group(1)) | ||
if cmake_version < '3.10.0': | ||
raise RuntimeError("CMake >= 3.10.0 is required") | ||
|
||
for ext in self.extensions: | ||
self.build_extension(ext) | ||
|
||
# find extra shared ("native") libs | ||
# for o in os.listdir(self.extdir): | ||
# full_path = os.path.join(self.extdir, o) | ||
# self.shlibs.append(full_path) | ||
|
||
# remove python libs from shared ("native") libs | ||
# for o in self.get_outputs(): | ||
# abs_path = os.path.abspath(o) | ||
# if abs_path in self.shlibs: | ||
# self.shlibs.remove(abs_path) | ||
|
||
def build_extension(self, ext): | ||
extdir = os.path.abspath(os.path.dirname( | ||
self.get_ext_fullpath(ext.name) | ||
)) | ||
# required for auto-detection of auxiliary "native" libs | ||
if not extdir.endswith(os.path.sep): | ||
extdir += os.path.sep | ||
|
||
cmake_args = [ | ||
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir, | ||
'-DCMAKE_PYTHON_OUTPUT_DIRECTORY=' + extdir, | ||
'-DPYTHON_EXECUTABLE=' + sys.executable, | ||
# skip building tests & examples | ||
'-DBUILD_TESTING:BOOL=OFF', | ||
'-DBUILD_EXAMPLES:BOOL=OFF', | ||
# Unix: rpath to current dir when packaged | ||
'-DCMAKE_INSTALL_RPATH=$ORIGIN', | ||
'-DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON', | ||
'-DCMAKE_INSTALL_RPATH_USE_LINK_PATH:BOOL=OFF', | ||
# Windows: will already have %PATH% in package dir | ||
] | ||
|
||
cfg = 'Debug' if self.debug else 'Release' | ||
build_args = ['--config', cfg] | ||
|
||
if platform.system() == "Windows": | ||
cmake_args += [ | ||
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format( | ||
cfg.upper(), | ||
extdir | ||
) | ||
] | ||
if sys.maxsize > 2**32: | ||
cmake_args += ['-A', 'x64'] | ||
build_args += ['--', '/m'] | ||
else: | ||
cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg] | ||
build_args += ['--', '-j2'] | ||
|
||
env = os.environ.copy() | ||
env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format( | ||
env.get('CXXFLAGS', ''), | ||
self.distribution.get_version() | ||
) | ||
if not os.path.exists(self.build_temp): | ||
os.makedirs(self.build_temp) | ||
subprocess.check_call( | ||
['cmake', ext.sourcedir] + cmake_args, | ||
cwd=self.build_temp, | ||
env=env | ||
) | ||
subprocess.check_call( | ||
['cmake', '--build', '.'] + build_args, | ||
cwd=self.build_temp | ||
) | ||
|
||
with open('./README.md', encoding='utf-8') as f: | ||
long_description = f.read() | ||
|
||
# Get the package requirements from the requirements.txt file | ||
with open('./requirements.txt') as f: | ||
install_requires = [line.strip('\n') for line in f.readlines()] | ||
|
||
setup( | ||
name='openPMD-api', | ||
version='0.6.2a', | ||
author='Fabian Koller, Axel Huebl', | ||
author_email='f.koller@hzdr.de, a.huebl@hzdr.de', | ||
maintainer='Fabian Koller, Axel Huebl', | ||
maintainer_email='f.koller@hzdr.de, a.huebl@hzdr.de', | ||
description='C++ & Python API for Scientific I/O with openPMD', | ||
long_description=long_description, | ||
long_description_content_type='text/markdown', | ||
url='https://github.com/openPMD/openPMD-api.git', | ||
license='LGPL-3.0', | ||
ext_modules=[CMakeExtension('openPMD')], | ||
cmdclass=dict(build_ext=CMakeBuild), | ||
zip_safe=False, | ||
# tests_require=['pytest'], | ||
install_requires=install_requires, | ||
# extras_require = { | ||
# 'GUI': ["ipywidgets", "matplotlib", "cython"], | ||
# 'plot': ["matplotlib", "cython"], | ||
# 'tutorials': ["ipywidgets", "matplotlib", "wget", "cython"] | ||
# }, | ||
# cmdclass={'test': PyTest}, | ||
# platforms='any', | ||
classifiers=[ | ||
'Development Status :: 3 - Alpha', | ||
'Natural Language :: English', | ||
'Environment :: Console', | ||
'Intended Audience :: Science/Research', | ||
'Operating System :: OS Independent', | ||
'Topic :: Scientific/Engineering', | ||
'Topic :: Database :: Front-Ends', | ||
'Programming Language :: C++', | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 3.5', | ||
'Programming Language :: Python :: 3.6', | ||
], | ||
) |