From 9202ffdff8ea6d87ec2ee3170c8b187da5a2ac07 Mon Sep 17 00:00:00 2001 From: Ed Brannin Date: Sun, 17 Aug 2014 00:01:45 -0400 Subject: [PATCH] Updated setup.py to use entry_points['console_scripts'] instead of scripts. This makes a "mkdocs" command on Windows/OSX/Linux without any platform-specific code in setup.py. I think this is the preferred way to install a Python command with setuptools. It is, at least, the method used by: * [flake8](https://bitbucket.org/tarek/flake8/src/8ee94d1eeea36e835583b68c59682bfc3684fab9/setup.py?at=default) * [coverage.py](https://bitbucket.org/ned/coveragepy/src/ca875e739048c3b333e862471b89d55e3c7b7170/setup.py?at=default) * [Fabric](https://github.com/fabric/fabric/blob/master/setup.py) * Many others In the past, I had to change imports willy-nilly or add "from __future__ import absolute_imports" to a bunch of files. This is because I was renaming "mkdocs" to "mkdocs.py" instead of "main.py", and the module-vs-script name clash was confusing imports from other files. --- mkdocs/{mkdocs => main.py} | 11 ++++++++++- setup.py | 6 +++++- 2 files changed, 15 insertions(+), 2 deletions(-) rename mkdocs/{mkdocs => main.py} (87%) diff --git a/mkdocs/mkdocs b/mkdocs/main.py similarity index 87% rename from mkdocs/mkdocs rename to mkdocs/main.py index cc60c980..adc554ae 100755 --- a/mkdocs/mkdocs +++ b/mkdocs/main.py @@ -39,7 +39,16 @@ def main(cmd, args, options=None): else: print('mkdocs [help|new|build|serve|gh-deploy] {options}') -if __name__ == '__main__': +def run_main(): + """ + Invokes main() with the contents of sys.argv + + This is a separate function so it can be invoked + by a setuptools console_script. + """ cmd = sys.argv[1] if len(sys.argv) >= 2 else None opts = [arg_to_option(arg) for arg in sys.argv[2:] if arg.startswith('--')] main(cmd, args=sys.argv[2:], options=dict(opts)) + +if __name__ == '__main__': + run_main() diff --git a/setup.py b/setup.py index 51f4e14e..07ca37f8 100755 --- a/setup.py +++ b/setup.py @@ -80,7 +80,11 @@ setup( packages=get_packages(package), package_data=get_package_data(package), install_requires=install_requires, - scripts=['mkdocs/mkdocs'], + entry_points={ + 'console_scripts': [ + 'mkdocs = mkdocs.main:run_main', + ], + }, classifiers=[ 'Development Status :: 5 - Production/Stable', 'Environment :: Web Environment',