mirror of
https://github.com/mkdocs/mkdocs.git
synced 2026-03-27 09:58:31 +07:00
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](8ee94d1eee/setup.py) * [coverage.py](ca875e7390/setup.py) * [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.
This commit is contained in:
@@ -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()
|
||||
6
setup.py
6
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',
|
||||
|
||||
Reference in New Issue
Block a user