-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsetup.py
118 lines (93 loc) · 3.96 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# -*- coding: utf-8 -*-
import os
import re
import sys
import subprocess
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 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
cfg = "Debug" if self.debug else "Release"
# CMake lets you override the generator - we need to check this.
# Can be set with Conda-Build, for example.
cmake_generator = os.environ.get("CMAKE_GENERATOR", "")
cmake_args = [
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={}".format(extdir),
"-DPYTHON_EXECUTABLE={}".format(sys.executable),
"-DCMAKE_BUILD_TYPE={}".format(cfg)
]
if "CMAKE_ARGS" in os.environ:
cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item]
build_args = []
if self.compiler.compiler_type != "msvc":
if not cmake_generator:
cmake_args += ["-GNinja"]
else:
cmake_args += [
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}".format(cfg.upper(), extdir)
]
build_args += ["--config", cfg]
if sys.platform.startswith("darwin"):
# Cross-compile support for macOS - respect ARCHFLAGS if set
archs = re.findall(r"-arch (\S+)", os.environ.get("ARCHFLAGS", ""))
if archs:
cmake_args += ["-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))]
# Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
# across all generators.
if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
# self.parallel is a Python 3 only way to set parallel jobs by hand
# using -j in the build_ext call, not supported by pip or PyPA-build.
if hasattr(self, "parallel") and self.parallel:
# CMake 3.12+ only.
build_args += ["-j{}".format(self.parallel)]
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
)
subprocess.check_call(
["cmake", "--build", "."] + build_args, cwd=self.build_temp
)
python_path = extdir
if "PYTHONPATH" in os.environ:
python_path += os.pathsep + os.environ["PYTHONPATH"]
if not "SKIP_PYBIND11_STUBGEN" in os.environ:
# Automatically generate stubs
subprocess.check_call(
["pybind11-stubgen", "-o", extdir, "--ignore-all-errors", "geant4_pybind"],
env=dict(os.environ, PYTHONPATH=python_path)
)
with open("README.md", "r") as readme:
long_desc = readme.read()
# Amalgamate 3rd party licenses
with open("pybind11/LICENSE", "r") as license_file:
licenses = license_file.read()
if os.path.isfile('EXTRA_LICENSES'):
with open("EXTRA_LICENSES", "r") as license_file:
licenses += "\n\n\n" + license_file.read()
with open("LICENSE-3RD-PARTY", "w") as license_file:
license_file.write(licenses)
setup(
name="geant4_pybind",
version="0.1.0",
author="Benjamin H.",
author_email="haarigerharald@gmx.at",
description="Alternative python bindings for Geant4 via pybind11",
long_description=long_desc,
long_description_content_type="text/markdown",
url="https://github.com/HaarigerHarald/geant4_pybind",
license="Public Domain",
python_requires=">=3.7, <4",
ext_modules=[CMakeExtension("geant4_pybind")],
cmdclass={"build_ext": CMakeBuild},
zip_safe=False
)