Skip to content
Myr

Use code-block markup, align snippets, add setup.py

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Peter Bittner · committed by Peter Bittner · parent f4d6ed8 · Browse files · 1 file+28 added−15 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+28 added−15 removed

  • other:+28 added−15 removed

1 file+28 added−15 removed

modified:docs/setuptools.rst+28 added-15 removed
43 unmodified lines
44Python package and a ``setup.py`` file.4546Imagine this directory structure::4748.. code-block:: text4950 yourscript.py51 setup.py5253Contents of ``yourscript.py``:
6 unmodified lines
60 def cli():61 """Example script."""62 click.echo('Hello World!')6362Contents of ``setup.py``::64Contents of ``setup.py``:6566.. code-block:: python6768 from setuptools import setup6970 setup(71 name='yourscript',68 version='0.1',72 version='0.1.0',73 py_modules=['yourscript'],74 install_requires=[75 'Click',76 ],73 entry_points='''74 [console_scripts]75 yourscript=yourscript:cli76 ''',77 entry_points={78 'console_scripts': [79 'yourscript = yourscript:cli',80 ],81 },82 )8384The magic is in the ``entry_points`` parameter. Below85``console_scripts``, each line identifies one console script. The first
6 unmodified lines
92Testing The Script93------------------9495To test the script, you can make a new virtualenv and then install your91package::96package:9798.. code-block:: console99100 $ virtualenv venv101 $ . venv/bin/activate102 $ pip install --editable .103
7 unmodified lines
111-------------------112113If your script is growing and you want to switch over to your script being114contained in a Python package the changes necessary are minimal. Let's108assume your directory structure changed to this::115assume your directory structure changed to this:116110 yourpackage/111 __init__.py112 main.py113 utils.py114 scripts/117.. code-block:: text118119 project/120 yourpackage/121 __init__.py122 main.py123 utils.py124 scripts/125 __init__.py116 yourscript.py126 yourscript.py127 setup.py128129In this case instead of using ``py_modules`` in your ``setup.py`` file you130can use ``packages`` and the automatic package finding support of131setuptools. In addition to that it's also recommended to include other132package data.133123These would be the modified contents of ``setup.py``::134These would be the modified contents of ``setup.py``:135136.. code-block:: python137138 from setuptools import setup, find_packages139140 setup(141 name='yourpackage',
12 unmodified lines