setuptools.rst
This file
Path
docs/setuptools.rst
81 lines · 2.0 KiB
Last changed by
Merge pull request #153 from iKevinY/click-renameArmin Ronacherbefore adoption327cfde
History of this fileTake it
The walk stopped after 200 commits: lines older than 002c38d point at it.
Added basic bash complete support.Armin Ronacherbefore adoption4fa40cf
lines 1–2why, one step back1.. _setuptools-integration:2Improved stream support and added it to public API.Armin Ronacherbefore adoption002c38d
lines 3–5why, one step back3Usage with Setuptools4=====================5Documentation fixesKevin Yapbefore adoption67523af
line 6why, one step back6When writing command line utilities, it's recommended to write them asMerge pull request #113 from iKevinY/doc-fixesArmin Ronacherbefore adoptione0ea94a
line 7why, one step back7modules that are distributed with setuptools instead of using UnixDocumentation fixesKevin Yapbefore adoption67523af
line 8why, one step back8shebangs. There are many reasons for this.Improved stream support and added it to public API.Armin Ronacherbefore adoption002c38d
lines 9–12why, one step back910The first one is that setuptools automatically generates executable11wrappers for Windows so your command line utilities work on Windows too.12Merge pull request #113 from iKevinY/doc-fixesArmin Ronacherbefore adoptione0ea94a
line 13why, one step back13The second reason is that setuptools scripts work with virtualenv on UnixImproved stream support and added it to public API.Armin Ronacherbefore adoption002c38d
lines 14–20why, one step back14without the virtualenv having to be activated. This is a very useful15concept which allows you to bundle your scripts with all requirements into16a virtualenv.1718Introduction19------------20Documentation fixesKevin Yapbefore adoption67523af
lines 21–22why, one step back21To bundle your script with setuptools, all you need is the script in a Python22package and a ``setup.py`` file.Improved stream support and added it to public API.Armin Ronacherbefore adoption002c38d
line 23why, one step back23Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69
line 24why, one step back24Imagine this directory structure::Improved stream support and added it to public API.Armin Ronacherbefore adoption002c38d
lines 25–58why, one step back2526 yourpackage/27 cli.py28 setup.py2930Contents of ``cli.py``:3132.. click:example::3334 import click3536 @click.command()37 def cli():38 """Example script."""39 click.echo('Hello World!')4041Contents of ``setup.py``::4243 from setuptools import setup, find_packages4445 setup(46 name='yourpackage',47 version='0.1',48 packages=find_packages(),49 include_package_data=True,50 install_requires=[51 'Click',52 ],53 entry_points='''54 [console_scripts]55 yourscript=yourpackage.cli:cli56 ''',57 )58Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69
line 59why, one step back59The magic is in the ``entry_points`` parameter. Below ``console_scripts``,Improved stream support and added it to public API.Armin Ronacherbefore adoption002c38d
lines 60–61why, one step back60each line identifies one console script. The first part before the equals61sign (``=``) is the name of the script that should be generated, the secondMerge pull request #153 from iKevinY/click-renameArmin Ronacherbefore adoption327cfde
line 62why, one step back62part is the import path followed by a colon (``:``) with the ClickImproved stream support and added it to public API.Armin Ronacherbefore adoption002c38d
lines 63–69why, one step back63command.6465That's it.6667Testing The Script68------------------69Merge pull request #125 from iKevinY/doc-fixesArmin Ronacherbefore adoption1d25afd
line 70why, one step back70To test the script, you can make a new virtualenv and then install yourImproved stream support and added it to public API.Armin Ronacherbefore adoption002c38d
lines 71–76why, one step back71package::7273 $ virtualenv venv74 $ . venv/bin/activate75 $ pip install --editable .76Merge pull request #125 from iKevinY/doc-fixesArmin Ronacherbefore adoption1d25afd
line 77why, one step back77Afterwards, your command should be available:Improved stream support and added it to public API.Armin Ronacherbefore adoption002c38d
lines 78–81why, one step back7879.. click:run::8081 invoke(cli, prog_name='yourscript', prog_prefix='')