import os
import sys
import platform
from setuptools import setup
from setuptools.command.install import install
try:
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
class bdist_wheel(_bdist_wheel):
def finalize_options(self):
_bdist_wheel.finalize_options(self)
self.root_is_pure = False
def get_tag(self):
python, abi, plat = _bdist_wheel.get_tag(self)
cross_compile_target = _get_cross_compile_target()
if cross_compile_target == "armv7-unknown-linux-musleabihf":
plat = "manylinux2014_armv7l"
elif cross_compile_target == "aarch64-unknown-linux-musl":
plat = "manylinux2014_aarch64"
elif cross_compile_target == "i686-unknown-linux-musl":
plat = "manylinux1_i686"
elif cross_compile_target == "x86_64-unknown-linux-musl":
plat = "manylinux1_x86_64"
elif platform.system() == "Darwin" and os.getenv('MACOSX_DEPLOYMENT_TARGET'):
target = os.environ['MACOSX_DEPLOYMENT_TARGET']
plat = "macosx_{}_{}".format(target.replace(".", "_"), platform.machine())
python, abi = "py2.py3", "none"
return python, abi, plat
except ImportError:
bdist_wheel = None
with open("README.md") as f:
long_description = f.read()
executable_name = "py-spy.exe" if sys.platform.startswith("win") else "py-spy"
class PostInstallCommand(install):
def run(self):
source_dir = os.path.dirname(os.path.abspath(__file__))
cross_compile_target = _get_cross_compile_target()
if cross_compile_target:
compile_args = " --target=%s" % cross_compile_target
build_dir = os.path.join(source_dir, "target", cross_compile_target, "release")
else:
compile_args = ""
build_dir = os.path.join(source_dir, "target", "release")
if platform.system() == "Darwin":
os.environ.setdefault("MACOSX_DEPLOYMENT_TARGET", "10.9")
if os.system("cargo build --release %s" % compile_args):
raise ValueError("Failed to compile!")
install.run(self)
if not os.path.isdir(self.install_scripts):
os.makedirs(self.install_scripts)
source = os.path.join(build_dir, executable_name)
target = os.path.join(self.install_scripts, executable_name)
if os.path.isfile(target):
os.remove(target)
self.copy_file(source, target)
def _get_cross_compile_target():
return os.getenv("PYSPY_CROSS_COMPILE_TARGET") or os.getenv("RUST_MUSL_CROSS_TARGET")
setup(
name="py-spy",
author="Ben Frederickson",
author_email="ben@benfrederickson.com",
url="https://github.com/benfred/py-spy",
description="A Sampling Profiler for Python",
long_description=long_description,
long_description_content_type="text/markdown",
version="0.3.6",
license="MIT",
cmdclass={"install": PostInstallCommand, "bdist_wheel": bdist_wheel},
classifiers=[
"Development Status :: 3 - Alpha",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 2",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Topic :: Software Development :: Libraries",
"Topic :: Utilities",
],
zip_safe=False,
)