11from setuptools import setup , find_packages , Extension
2- from distutils .command .build_py import build_py
2+ from setuptools .command .build_py import build_py
3+ from setuptools .command .build_ext import build_ext
34import os , sys
45import subprocess
5- import platform
66
77IS_PYPY = '__pypy__' in sys .builtin_module_names
88
9+ BASEDIR = os .path .dirname (os .path .abspath (__file__ ))
10+
911class vmprof_build (build_py , object ):
1012 def run (self ):
1113 super (vmprof_build , self ).run ()
1214
13- BASEDIR = os .path .dirname (os .path .abspath (__file__ ))
15+ class vmprof_build_ext (build_ext , object ):
16+ """build_ext that runs libbacktrace configure before building.
17+ This is needed because libbacktrace does not have a pre-built library for all platforms.
18+ """
19+ def run (self ):
20+ # configure libbacktrace on Unix systems (not Windows/macOS)
21+ if sys .platform .startswith ('linux' ) or sys .platform .startswith ('freebsd' ):
22+ libbacktrace_dir = os .path .join (BASEDIR , "src" , "libbacktrace" )
23+ config_h = os .path .join (libbacktrace_dir , "config.h" )
24+ # only run configure if config.h doesn't exist
25+ if not os .path .exists (config_h ):
26+ orig_dir = os .getcwd ()
27+ os .chdir (libbacktrace_dir )
28+ try :
29+ # generate configure script if it doesn't exist
30+ if not os .path .exists ("configure" ):
31+ subprocess .check_call (["autoreconf" , "-i" ])
32+ subprocess .check_call (["./configure" ])
33+ finally :
34+ os .chdir (orig_dir )
35+ super (vmprof_build_ext , self ).run ()
1436
1537def _supported_unix ():
1638 if sys .platform .startswith ('linux' ):
@@ -65,20 +87,13 @@ def _supported_unix():
6587 'src/libbacktrace/posix.c' ,
6688 'src/libbacktrace/sort.c' ,
6789 ]
68- # configure libbacktrace!!
69- class vmprof_build (build_py , object ):
70- def run (self ):
71- orig_dir = os .getcwd ()
72- os .chdir (os .path .join (BASEDIR , "src" , "libbacktrace" ))
73- subprocess .check_call (["./configure" ])
74- os .chdir (orig_dir )
75- super (vmprof_build , self ).run ()
7690
7791 else :
7892 raise NotImplementedError ("platform '%s' is not supported!" % sys .platform )
79- extra_compile_args .append ('-I src/' )
80- extra_compile_args .append ('-I src/libbacktrace' )
81- if sys .version_info [:2 ] == (3 ,11 ):
93+ # use absolute paths for include directories so compilation works from any directory
94+ extra_compile_args .append ('-I' + os .path .join (BASEDIR , 'src' ))
95+ extra_compile_args .append ('-I' + os .path .join (BASEDIR , 'src' , 'libbacktrace' ))
96+ if sys .version_info [:2 ] >= (3 ,11 ):
8297 extra_source_files += ['src/populate_frames.c' ]
8398 ext_modules = [Extension ('_vmprof' ,
8499 sources = [
@@ -116,14 +131,14 @@ def run(self):
116131 description = "Python's vmprof client" ,
117132 long_description = 'See https://vmprof.readthedocs.org/' ,
118133 url = 'https://github.com/vmprof/vmprof-python' ,
119- cmdclass = {'build_py' : vmprof_build },
134+ cmdclass = {'build_py' : vmprof_build , 'build_ext' : vmprof_build_ext },
120135 install_requires = [
121136 'requests' ,
122137 'six' ,
123138 'pytz' ,
124139 'colorama' ,
125140 ] + extra_install_requires ,
126- python_requires = '<3.12 ' ,
141+ python_requires = '<3.15 ' ,
127142 tests_require = ['pytest' ,'cffi' ,'hypothesis' ],
128143 entry_points = {
129144 'console_scripts' : [
@@ -140,4 +155,4 @@ def run(self):
140155 zip_safe = False ,
141156 include_package_data = True ,
142157 ext_modules = ext_modules ,
143- )
158+ )
0 commit comments