import os
import sys
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):
if not sys.platform.startswith("win"):
return _bdist_wheel.get_tag(self)
python, abi, plat = _bdist_wheel.get_tag(self)
python, abi = 'py2.py3', 'none'
return python, abi, plat
except ImportError:
bdist_wheel = None
try:
import pypandoc
long_description = pypandoc.convert_file("README.md", "rst")
except ImportError:
long_description = ''
executable_name = "py-spy.exe" if sys.platform.startswith("win") else "py-spy"
class PostInstallCommand(install):
def run(self):
install.run(self)
source_dir = os.path.dirname(os.path.abspath(__file__))
if os.getenv("PYSPY_MUSL_64"):
compile_args = " --target=x86_64-unknown-linux-musl"
build_dir = os.path.join(source_dir, "target", "x86_64-unknown-linux-musl", "release")
elif os.getenv("PYSPY_MUSL_32"):
compile_args = " --target=i686-unknown-linux-musl"
build_dir = os.path.join(source_dir, "target", "i686-unknown-linux-musl", "release")
else:
compile_args = ""
build_dir = os.path.join(source_dir, "target", "release")
if os.system("cargo build --release %s" % compile_args):
raise ValueError("Failed to compile!")
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.move_file(source, 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,
version="0.1.8",
license="GPL",
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 :: GNU General Public License v3 (GPLv3)",
"Topic :: Software Development :: Libraries",
"Topic :: Utilities"],
zip_safe=False)