From e582642f38368e0d13ee72c36a9c2d32c250c1b8 Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Fri, 8 Jun 2018 15:03:52 +0100 Subject: [PATCH] fix(build,#119,#155): use setuptools-entry-points instead of console-script... to fix launching on Windows. Also this is now the officially "blessed" way to generated executables: https://packaging.python.org/guides/distributing-packages-using-setuptools/#scripts --- pycallgraph/__main__.py | 31 +++++++++++++++++++++++++++++++ scripts/pycallgraph | 8 ++++++++ setup.py | 5 ++++- 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 pycallgraph/__main__.py diff --git a/pycallgraph/__main__.py b/pycallgraph/__main__.py new file mode 100644 index 0000000..1011a6f --- /dev/null +++ b/pycallgraph/__main__.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python +""" +pycallgraph +This script is the command line interface to the pycallgraph Python library. + +See http://pycallgraph.slowchop.com/ for more information. +""" +import sys +import os + +def main(): + import pycallgraph + + config = pycallgraph.Config() + config.parse_args() + config.strip_argv() + + globals()['__file__'] = config.command + + file_content = open(config.command).read() + + with pycallgraph.PyCallGraph(config=config): + exec(file_content) + + +if __name__ == '__main__': + ## Pep366 must always be the 1st thing to run. + if not globals().get('__package__'): + __package__ = "polyversion" # noqa: A001 F841 @ReservedAssignment + + main() diff --git a/scripts/pycallgraph b/scripts/pycallgraph index 2577a64..0548e4c 100755 --- a/scripts/pycallgraph +++ b/scripts/pycallgraph @@ -4,6 +4,14 @@ pycallgraph This script is the command line interface to the pycallgraph Python library. See http://pycallgraph.slowchop.com/ for more information. + +.. deprecated:: > 1.0.1 + Code here moved to :func:`pycallgraph.__main__.main()` + and now using setuptools console-script entry-points, + to properly install on Windows. + + - See https://github.com/gak/pycallgraph/issues/119 + - See https://github.com/gak/pycallgraph/issues/155 """ import sys import os diff --git a/setup.py b/setup.py index a2a2380..10e2d7d 100755 --- a/setup.py +++ b/setup.py @@ -6,6 +6,8 @@ from setuptools.command.test import test as TestCommand +## FIXME: importing my-package may fail if dependent projects +# from :mod:`./pycallgraph/__init__.py` are not installed yet at this stage! import pycallgraph # Only install the man page if the correct directory exists @@ -40,7 +42,8 @@ def run_tests(self): license=open('LICENSE').read(), url=pycallgraph.__url__, packages=['pycallgraph', 'pycallgraph.output'], - scripts=['scripts/pycallgraph'], + entry_points={ + 'console_scripts': ['pycallgraph = pycallgraph.__main__:main']}, data_files=data_files, use_2to3=True,