diff --git a/setup.py b/setup.py index 4c9b4ae..c5f370b 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from os import cpu_count -from shutil import copy2, copytree, rmtree +from shutil import copy2, copytree from os.path import join -from tempfile import mkdtemp +from tempfile import TemporaryDirectory from subprocess import run as sub_process_run from setuptools import setup from setuptools.command.build_ext import build_ext @@ -10,20 +10,6 @@ from Cython.Distutils import Extension -uring = 'uring-ffi' -tmpdir = mkdtemp() -threads = cpu_count() -lib = join(tmpdir, 'libs/liburing') -libsrc = join(lib, 'src') -libinc = join(libsrc, 'include') - -# compiler options -Options.annotate = False -Options.fast_fail = True -Options.docstrings = True -Options.warning_errors = False - - class BuildExt(build_ext): def initialize_options(self): @@ -41,22 +27,34 @@ def build_extensions(self): 'libs/liburing/Makefile.quiet'): copy2(src, join(tmpdir, src)) - # sub_process_run(['./configure', '--use-libc'], cwd=lib, capture_output=True, check=True) - sub_process_run(['./configure'], cwd=lib, capture_output=True, check=True) - sub_process_run(['make', f'--jobs={threads}'], cwd=lib, capture_output=True) # note: just runs `configure` & `make`, does not `install`. + sub_process_run(['./configure'], cwd=lib, capture_output=False, check=True) + sub_process_run(['make', f'--jobs={threads}'], cwd=lib, capture_output=False) # replace `include` placeholder files with actual content. copytree(libinc, 'src/liburing/include', dirs_exist_ok=True) + # have to replace `include` in `build_lib` e.g.'build/lib.linux-x86_64-cpython-313' + # as well since installer copies over the files before `BuildExt` is called. + copytree(libinc, join(self.build_lib, 'liburing/include'), dirs_exist_ok=True) super().build_extensions() if __name__ == '__main__': - try: + # compiler options + Options.annotate = False + Options.fast_fail = True + Options.docstrings = True + Options.warning_errors = False + + with TemporaryDirectory() as tmpdir: + lib = join(tmpdir, 'libs/liburing') + libsrc = join(lib, 'src') + libinc = join(libsrc, 'include') + threads = cpu_count() extension = [Extension(name='liburing.*', # where the `.so` will be saved. sources=['src/liburing/*.pyx'], language='c', - libraries=[uring], + libraries=['uring-ffi'], library_dirs=[libsrc], include_dirs=[libinc], # optimize & remove debug symbols + data. @@ -65,9 +63,7 @@ def build_extensions(self): setup(cmdclass={'build_ext': BuildExt}, ext_modules=cythonize(extension, nthreads=threads, - compiler_directives={'embedsignature': True, # show `__doc__` + compiler_directives={'language_level': 3, + 'embedsignature': True, # show `__doc__` 'boundscheck': False, - 'wraparound': False, - 'language_level': 3})) - finally: - rmtree(tmpdir) + 'wraparound': False})) diff --git a/src/liburing/__init__.py b/src/liburing/__init__.py index 86b3ab8..f276dd1 100644 --- a/src/liburing/__init__.py +++ b/src/liburing/__init__.py @@ -1,7 +1,7 @@ from dynamic_import import importer -__version__ = '2024.4.22' +__version__ = '2024.4.23' importer(exclude_dir=['lib', 'include'])