Skip to content

Commit

Permalink
[Draft] setup.py
Browse files Browse the repository at this point in the history
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
ax3l committed Jun 11, 2018
1 parent 376f74e commit 8135502
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cmake>=3.10.0
pybind11>=2.2.1
numpy
133 changes: 133 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
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)

def build_extension(self, ext):
extdir = os.path.abspath(os.path.dirname(
self.get_ext_fullpath(ext.name)
))
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',
]

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
)


# PyPI supports reStructuredText, so try to convert our markdown file
try:
import pypandoc
long_description = pypandoc.convert('./README.md', 'rst')
except (ImportError, RuntimeError):
long_description = open('./README.md').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.1.1',
author='Fabian Koller, Axel Huebl',
author_email='f.koller@hzdr.de, a.huebl@hzdr.de',
maintainer='Axel Huebl',
maintainer_email='a.huebl@hzdr.de',
description='C++ & Python API for Scientific I/O with openPMD',
long_description=long_description,
url='https://github.com/openPMD/openPMD-api.git',
license='LGPL-3.0',
ext_modules=[CMakeExtension('openPMD_api')],
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',
],
)

0 comments on commit 8135502

Please sign in to comment.