From d3d06a0b715d123d403134a067d2d6a41f21442c Mon Sep 17 00:00:00 2001 From: Jack O'Connor Date: Wed, 26 Nov 2014 20:38:26 -0500 Subject: [PATCH] use entry_points instead of a pre-written script Summary: This was the recommendation of https://packaging.python.org/en/latest/distributing.html, but I unwisely ignored it back when I wrote our setup.py. It turns out that getting a launcher script to work properly on Windows is tricky. The `entry_points` field generates a platform-appropriate launcher script at install time, so we get Windows for free. Previously our launcher script checked the version of Python and printed a helpful error if it was too low. Because our main.py has `yield from` syntax in it, printing such an error message isn't possible; we'll crash with a syntax error first. We could create another file within the modile (or maybe an __init__.py) to support this, but for now I'm just dropping the feature. Test Plan: Manually played with peru.sh to make sure it still works. Ran `pip install .` to check that the generated script works. Also tested that on my Windows VM, and it works great. (It generates an exe file, in fact.) Reviewers: sean Differential Revision: https://phabricator.buildinspace.com/D135 --- bin/peru | 11 ----------- peru.sh | 2 +- setup.py | 6 +++++- 3 files changed, 6 insertions(+), 13 deletions(-) delete mode 100755 bin/peru diff --git a/bin/peru b/bin/peru deleted file mode 100755 index cb9299f..0000000 --- a/bin/peru +++ /dev/null @@ -1,11 +0,0 @@ -#! /usr/bin/env python3 - -import sys - -if sys.version_info.major < 3 or sys.version_info.minor < 3: - print("Peru requires Python 3.3 or newer.") - sys.exit(1) - -from peru import main - -main.main() diff --git a/peru.sh b/peru.sh index c6d133b..c6c6b14 100755 --- a/peru.sh +++ b/peru.sh @@ -27,4 +27,4 @@ repo_root=$(dirname $(realpath $BASH_SOURCE)) source "$repo_root/scripts/env.sh" -"$repo_root/bin/peru" "$@" +python3 -c "import peru.main; peru.main.main()" "$@" diff --git a/setup.py b/setup.py index 682b4af..e74e372 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,11 @@ setuptools.setup( license='MIT', packages=['peru'], package_data={'peru': resources_paths}, - scripts=['bin/peru'], + entry_points={ + 'console_scripts': [ + 'peru=peru.main:main', + ] + }, install_requires=[ 'docopt', 'PyYAML',