-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·55 lines (42 loc) · 2.01 KB
/
setup.py
File metadata and controls
executable file
·55 lines (42 loc) · 2.01 KB
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
# Copyright (c) 2025-2026. The FSMod Team. All rights reserved.
# This program is free software; you can redistribute it and/or modify it
# under the terms of the license (GNU LGPL-2.1-only) which comes with this package.
# python3 setup.py sdist # Build a source distrib (building binary distribs is complex on linux)
# python3 -m build --sdist # Build a source distrib (building binary distribs is complex on linux)
# twine upload --repository-url https://test.pypi.org/legacy/ dist/dtlmod-*.tar.gz # Upload to test
# pip3 install --extra-index-url https://test.pypi.org/simple dtlmod
# Once it works, upload to the real infra. /!\ you cannot modify a file once uploaded
# twine upload dist/dtlmod-*.tar.gz
import os
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=""):
super().__init__(name, sources=[])
self.sourcedir = os.path.abspath(sourcedir)
class CMakeBuild(build_ext):
def run(self):
try:
subprocess.check_output(["/usr/bin/cmake", "--version"])
except OSError:
raise RuntimeError("CMake must be installed to build the file-system-module")
for ext in self.extensions:
self.build_extension(ext)
def build_extension(self, ext):
from pybind11 import get_cmake_dir
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
cmake_args = [
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}",
f"-DPYTHON_EXECUTABLE={sys.executable}",
"-Denable_python=ON",
f"-Dpybind11_DIR={get_cmake_dir()}",
]
os.makedirs(self.build_temp, exist_ok=True)
subprocess.check_call(["cmake", ext.sourcedir] + cmake_args, cwd=self.build_temp)
subprocess.check_call(["/usr/bin/cmake", "--build", "."], cwd=self.build_temp)
setup(
ext_modules=[CMakeExtension("fsmod")],
cmdclass={"build_ext": CMakeBuild},
)