diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 87e3d459..04022a37 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -39,8 +39,8 @@ jobs: python-version: ${{ matrix.python }} - name: Install run: | - python -m pip install --upgrade pip setuptools - python -m pip install -e . + python -m pip install --upgrade pip + python -m pip install . python -m pip install -r test_requirements.txt - name: Display Python version run: python -c "import sys; print(sys.version)" diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 5661a827..00000000 --- a/MANIFEST.in +++ /dev/null @@ -1,5 +0,0 @@ -recursive-include src *.h *.c -include src/libbacktrace/* -include LICENSE -recursive-exclude vmprof/test * -recursive-exclude jitlog/test * diff --git a/README.md b/README.md index 390b7856..d8fb61de 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,8 @@ Setting up development can be done using the following commands: $ virtualenv -p /usr/bin/python3 vmprof3 $ source vmprof3/bin/activate - $ python setup.py develop + $ pip install meson-python meson ninja + $ pip install --no-build-isolation --editable . You need to install python development packages. In case of e.g. Debian or Ubuntu the package you need is `python3-dev` and `libunwind-dev`. Now it is time to write a test and implement your feature. If you want diff --git a/docs/development.rst b/docs/development.rst index e01f25bf..685ecec9 100644 --- a/docs/development.rst +++ b/docs/development.rst @@ -65,7 +65,8 @@ An optional stage. It is only necessary if you want to co develop `vmprof-python # install vmprof for development (only needed if you want to co develop vmprof-python) $ cd vmprof-python - $ python setup.py develop + $ pip install meson-python meson ninja + $ pip install --no-build-isolation --editable . Now you are able to change both the python package and the server and see the results. diff --git a/meson.build b/meson.build new file mode 100644 index 00000000..9ef778ce --- /dev/null +++ b/meson.build @@ -0,0 +1,106 @@ +project('vmprof', 'c', + version: '0.5.0', + license: 'MIT', + meson_version: '>=1.1.0', +) + +py = import('python').find_installation(pure: false) +py_dep = py.dependency() +cc = meson.get_compiler('c') + +# PyPy ships _vmprof as a built-in module, so the PyPy wheel is pure python. +is_pypy = run_command(py, '-c', + 'import sys; print("__pypy__" in sys.builtin_module_names)', + check: true, +).stdout().strip() == 'True' + +# The pure python packages. The test packages are not installed. +python_dir = py.get_install_dir(pure: is_pypy) +install_subdir('vmprof', + install_dir: python_dir, + exclude_directories: ['test', '__pycache__'], +) +install_subdir('jitlog', + install_dir: python_dir, + exclude_directories: ['test', '__pycache__'], +) +install_subdir('vmshare', + install_dir: python_dir, + exclude_directories: ['__pycache__'], +) + +if not is_pypy + system = host_machine.system() + + sources = files( + 'src/_vmprof.c', + 'src/machine.c', + 'src/compat.c', + 'src/vmp_stack.c', + 'src/vmprof_common.c', + 'src/vmprof_memory.c', + ) + c_args = [] + deps = [py_dep] + # libbacktrace ships a pre-generated config.h, so it is built as plain + # sources without running its configure script. + inc = include_directories('src', 'src/libbacktrace') + + if system == 'windows' + sources += files('src/vmprof_win.c') + c_args += ['-DVMPROF_WINDOWS=1'] + elif system == 'darwin' + sources += files( + 'src/symboltable.c', + 'src/vmprof_unix.c', + 'src/vmprof_mt.c', + ) + c_args += ['-DVMPROF_APPLE=1', '-DVMPROF_UNIX=1'] + elif system == 'linux' or system == 'freebsd' + sources += files( + 'src/symboltable.c', + 'src/vmprof_unix.c', + 'src/vmprof_mt.c', + 'src/libbacktrace/backtrace.c', + 'src/libbacktrace/state.c', + 'src/libbacktrace/elf.c', + 'src/libbacktrace/dwarf.c', + 'src/libbacktrace/fileline.c', + 'src/libbacktrace/mmap.c', + 'src/libbacktrace/mmapio.c', + 'src/libbacktrace/posix.c', + 'src/libbacktrace/sort.c', + ) + c_args += ['-DVMPROF_UNIX=1'] + unwind_dep = dependency('libunwind', required: false) + if not unwind_dep.found() + unwind_dep = cc.find_library('unwind') + endif + deps += unwind_dep + if system == 'linux' + c_args += ['-DVMPROF_LINUX=1'] + deps += cc.find_library('dl', required: false) + else + c_args += ['-DVMPROF_BSD=1'] + inc = [inc, include_directories('/usr/local/include')] + endif + else + error('platform "' + system + '" is not supported') + endif + + if system != 'windows' + c_args += cc.get_supported_arguments('-Wno-unused') + endif + + if py.language_version().version_compare('>=3.11') + sources += files('src/populate_frames.c') + endif + + py.extension_module('_vmprof', + sources, + c_args: c_args, + include_directories: inc, + dependencies: deps, + install: true, + ) +endif diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..899a1a66 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,37 @@ +[build-system] +build-backend = "mesonpy" +requires = ["meson-python>=0.17"] + +[project] +name = "vmprof" +dynamic = ["version"] +description = "Python's vmprof client" +readme = "README.md" +license = "MIT" +license-files = ["LICENSE"] +authors = [ + {name = "vmprof team", email = "fijal@baroquesoftware.com"}, +] +requires-python = ">=3.9,<3.16" +dependencies = [ + "requests", + "six", + "pytz", + "colorama", +] +classifiers = [ + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", +] + +[project.urls] +Homepage = "https://github.com/vmprof/vmprof-python" +Documentation = "https://vmprof.readthedocs.org/" + +[project.scripts] +vmprofshow = "vmprof.show:main" + +[tool.meson-python.args] +setup = ["--vsenv"] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index b7e47898..00000000 --- a/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[aliases] -test=pytest diff --git a/setup.py b/setup.py deleted file mode 100644 index d36c9f1f..00000000 --- a/setup.py +++ /dev/null @@ -1,158 +0,0 @@ -from setuptools import setup, find_packages, Extension -from setuptools.command.build_py import build_py -from setuptools.command.build_ext import build_ext -import os, sys -import subprocess - -IS_PYPY = '__pypy__' in sys.builtin_module_names - -BASEDIR = os.path.dirname(os.path.abspath(__file__)) - -class vmprof_build(build_py, object): - def run(self): - super(vmprof_build, self).run() - -class vmprof_build_ext(build_ext, object): - """build_ext that runs libbacktrace configure before building. - This is needed because libbacktrace does not have a pre-built library for all platforms. - """ - def run(self): - # configure libbacktrace on Unix systems (not Windows/macOS) - if sys.platform.startswith('linux') or sys.platform.startswith('freebsd'): - libbacktrace_dir = os.path.join(BASEDIR, "src", "libbacktrace") - config_h = os.path.join(libbacktrace_dir, "config.h") - # only run configure if config.h doesn't exist - if not os.path.exists(config_h): - orig_dir = os.getcwd() - os.chdir(libbacktrace_dir) - try: - # generate configure script if it doesn't exist - if not os.path.exists("configure"): - subprocess.check_call(["autoreconf", "-i"]) - subprocess.check_call(["./configure"]) - finally: - os.chdir(orig_dir) - super(vmprof_build_ext, self).run() - -def _supported_unix(): - if sys.platform.startswith('linux'): - return 'linux' - if sys.platform.startswith('freebsd'): - return 'bsd' - return False - -if IS_PYPY: - ext_modules = [] # built-in -else: - extra_compile_args = [] - extra_source_files = [ - 'src/symboltable.c', - ] - if sys.platform == 'win32': - extra_source_files = [ - 'src/vmprof_win.c', - ] # remove the native source files - libraries = [] - extra_compile_args = ['-DVMPROF_WINDOWS=1'] - elif sys.platform == 'darwin': - libraries = [] - extra_compile_args = ['-Wno-unused'] - extra_compile_args += ['-DVMPROF_APPLE=1'] - extra_compile_args += ['-DVMPROF_UNIX=1'] - # overwrite the optimization level, if it is not optimized enough, - # it might use the regiter rbx... - extra_compile_args += ['-g'] - extra_compile_args += ['-O2'] - extra_source_files += ['src/vmprof_unix.c', 'src/vmprof_mt.c'] - elif _supported_unix(): - libraries = ['dl','unwind'] - extra_compile_args = ['-Wno-unused'] - if _supported_unix() == 'linux': - extra_compile_args += ['-DVMPROF_LINUX=1'] - if _supported_unix() == 'bsd': - libraries = ['unwind'] - extra_compile_args += ['-DVMPROF_BSD=1'] - extra_compile_args += ['-I/usr/local/include'] - extra_compile_args += ['-DVMPROF_UNIX=1'] - extra_source_files += [ - 'src/vmprof_mt.c', - 'src/vmprof_unix.c', - 'src/libbacktrace/backtrace.c', - 'src/libbacktrace/state.c', - 'src/libbacktrace/elf.c', - 'src/libbacktrace/dwarf.c', - 'src/libbacktrace/fileline.c', - 'src/libbacktrace/mmap.c', - 'src/libbacktrace/mmapio.c', - 'src/libbacktrace/posix.c', - 'src/libbacktrace/sort.c', - ] - - else: - raise NotImplementedError("platform '%s' is not supported!" % sys.platform) - # use absolute paths for include directories so compilation works from any directory - extra_compile_args.append('-I' + os.path.join(BASEDIR, 'src')) - extra_compile_args.append('-I' + os.path.join(BASEDIR, 'src', 'libbacktrace')) - if sys.version_info[:2] >= (3,11): - extra_source_files += ['src/populate_frames.c'] - ext_modules = [Extension('_vmprof', - sources=[ - 'src/_vmprof.c', - 'src/machine.c', - 'src/compat.c', - 'src/vmp_stack.c', - 'src/vmprof_common.c', - 'src/vmprof_memory.c', - ] + extra_source_files, - depends=[ - 'src/vmprof_unix.h', - 'src/vmprof_mt.h', - 'src/vmprof_common.h', - 'src/vmp_stack.h', - 'src/symboltable.h', - 'src/machine.h', - 'src/vmprof.h', - 'src/vmprof_memory.h', - ], - extra_compile_args=extra_compile_args, - libraries=libraries)] - -if sys.version_info[:2] >= (3, 3): - extra_install_requires = [] -else: - extra_install_requires = ["backports.shutil_which"] - -setup( - name='vmprof', - author='vmprof team', - author_email='fijal@baroquesoftware.com', - version="0.4.19", - packages=find_packages(), - description="Python's vmprof client", - long_description='See https://vmprof.readthedocs.org/', - url='https://github.com/vmprof/vmprof-python', - cmdclass={'build_py': vmprof_build, 'build_ext': vmprof_build_ext}, - install_requires=[ - 'requests', - 'six', - 'pytz', - 'colorama', - ] + extra_install_requires, - python_requires='<3.16', - tests_require=['pytest','cffi','hypothesis'], - entry_points = { - 'console_scripts': [ - 'vmprofshow = vmprof.show:main' - ]}, - classifiers=[ - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: Implementation :: CPython', - 'Programming Language :: Python :: Implementation :: PyPy', - ], - zip_safe=False, - include_package_data=True, - ext_modules=ext_modules, -) diff --git a/test_requirements.txt b/test_requirements.txt index 49a90556..b9400c39 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -3,7 +3,7 @@ requests urllib3==1.26.6 ; python_version < '3.9' backports.shutil_which cffi -setuptools +setuptools>=77 pytest hypothesis colorama