This repository has been archived by the owner on May 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.py
63 lines (50 loc) · 1.99 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
from setuptools import find_packages
import os
import subprocess
import sys
from setuptools import Extension, setup
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)))
if not extdir.endswith(os.path.sep):
extdir += os.path.sep
preset = "linux"
debug = int(os.environ.get("DEBUG", 0)) if self.debug is None else self.debug
cfg = "Debug" if debug else "Release"
cmake_args = [
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}",
f"-DPYTHON_EXECUTABLE={sys.executable}",
f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm
f"-DVERSION_INFO={self.distribution.get_version()}",
]
if self.compiler.compiler_type == "msvc":
cmake_args += [f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={extdir}"]
preset = "windows"
elif self.plat_name.startswith("macosx"):
preset = "macos"
if os.environ.get("CIBUILDWHEEL", "0") == "1":
preset = "ci-" + preset
subprocess.check_call(["cmake", f"--preset {preset}"] + cmake_args)
subprocess.check_call(["cmake", "--build", "--preset", "default"])
setup(
name="pynwn",
version="0.1.dev0",
author="jmd",
author_email="[email protected]",
# packages=find_packages(where="src"),
# package_dir={"": "src"},
include_package_data=True,
description="libnw wrapper",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
ext_modules=[CMakeExtension("src")],
cmdclass={"build_ext": CMakeBuild},
zip_safe=False,
extras_require={"test": ["pytest>=6.0"]},
python_requires=">=3.8",
)