Skip to content

Commit 236503d

Browse files
committed
Docs, cleanup, and re-named plugin examples from Printer to PrintIt to prevent accidentally installing a package on PyPI called printer.
1 parent 3449769 commit 236503d

File tree

27 files changed

+169
-146
lines changed

27 files changed

+169
-146
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ python:
99

1010
install:
1111
- pip install coveralls
12-
- pip install -e .[test]
12+
- pip install -e .[dev]
1313

1414
script:
1515
- py.test tests --cov click_plugins --cov-report term-missing

AUTHORS.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Authors
2+
=======
3+
4+
Kevin Wurster <[email protected]>
5+
Sean Gillies <[email protected]>

CHANGES.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
Changelog
22
=========
33

4-
1.0 - ?
5-
-------
4+
5+
1.0 - 2015-07-20
6+
----------------
67

78
Initial release.

MANIFEST.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
include AUTHORS.txt
2+
include CHANGES.txt
13
include LICENSE.txt
24
include MANIFEST.in
3-
include README.md
4-
include setup.py
5+
include README.rst
56
recursive-include tests *.py

README.rst

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,33 @@ click-plugins
88
.. image:: https://coveralls.io/repos/click-contrib/click-plugins/badge.svg?branch=master&service=github
99
:target: https://coveralls.io/github/click-contrib/click-plugins?branch=master
1010

11-
An extension module for `click <https://github.com/mitsuhiko/click>`_ to enable registering
11+
An extension module for `click <https://github.com/mitsuhiko/click>`_ to register
1212
external CLI commands via setuptools entry-points.
1313

1414

1515
Why?
1616
----
1717

1818
Lets say you develop a commandline interface and someone requests a new feature
19-
that is absolutely related to your project but would be very difficult to integrate
20-
into the current codebase, or maybe its just too domain specific to be supported
21-
directly. Rather than developing a separate standalone utility you could offer
22-
up a `setuptools entry point <https://pythonhosted.org/setuptools/setuptools.html#dynamic-discovery-of-services-and-plugins>`_
19+
that is absolutely related to your project but would have negative consequences
20+
like additional dependencies, major refactoring, or maybe its just too domain
21+
specific to be supported directly. Rather than developing a separate standalone
22+
utility you could offer up a `setuptools entry point <https://pythonhosted.org/setuptools/setuptools.html#dynamic-discovery-of-services-and-plugins>`_
2323
that allows others to use your commandline utility as a home for their related
2424
sub-commands. You get to choose where these sub-commands or sub-groups CAN be
25-
registered but the plugin developer gets to choose where it IS registered. You
26-
could have all plugins register alongside the core commands, in a special sub-group,
27-
across multiple sub-groups, or some combination.
25+
registered but the plugin developer gets to choose they ARE registered. You
26+
could have all plugins register alongside the core commands, in a special
27+
sub-group, across multiple sub-groups, or some combination.
2828

2929

3030
Enabling Plugins
3131
----------------
3232

33-
For a more detailed example see the `examples <js/examples>`_ section.
33+
For a more detailed example see the `examples <https://github.com/click-contrib/click-plugins/tree/master/examples>`_ section.
3434

35-
The only requirement is decorating ``click.group()`` with another decorator
36-
that attaches the external ``click.command()`` or ``click.group()``.
35+
The only requirement is decorating ``click.group()`` with ``click_plugins.with_plugins()``
36+
which handles attaching external commands and groups. In this case the core CLI developer
37+
registers CLI plugins from ``core_package.cli_plugins``.
3738

3839
.. code-block:: python
3940
@@ -43,7 +44,7 @@ that attaches the external ``click.command()`` or ``click.group()``.
4344
from click_plugins import with_plugins
4445
4546
46-
@with_plugins(iter_entry_points('yourpackage.cli_plugins'))
47+
@with_plugins(iter_entry_points('core_package.cli_plugins'))
4748
@click.group()
4849
def cli():
4950
"""Commandline interface for yourpackage."""
@@ -57,10 +58,7 @@ Developing Plugins
5758
------------------
5859

5960
Plugin developers need to register their sub-commands or sub-groups to an
60-
entry-point
61-
62-
same entry point
63-
in their ``setup.py``.
61+
entry-point in their ``setup.py`` that is loaded by the core package.
6462

6563
.. code-block:: python
6664
@@ -71,10 +69,10 @@ in their ``setup.py``.
7169
version='0.1',
7270
py_modules=['yourscript'],
7371
install_requires=[
74-
'Click',
72+
'click',
7573
],
7674
entry_points='''
77-
[console_scripts]
75+
[core_package.cli_plugins]
7876
cool_subcommand=yourscript.cli:cool_subcommand
7977
another_subcommand=yourscript.cli:another_subcommand
8078
''',
@@ -98,17 +96,17 @@ and if the sub-command or group is executed the entire traceback is printed.
9896
Best Practices and Extra Credit
9997
-------------------------------
10098

101-
Opening a CLI to external plugins encourages other developers to independently
102-
extend functionality on their own but their is no guarantee that their own
103-
features will be "on brand". Plugin developers are almost certainly already
104-
using features in the core package the CLI belongs to so defining commonly used
105-
arguments and options in one place lets plugin developers reuse these flags to
106-
produce a more cohesive CLI. If the CLI is simple maybe just define them at
107-
the top of ``yourpackage/cli.py`` or for more complex packages ``yourpackage/cli/options.py``.
108-
These common options need to be easy to find and be well documented so that
109-
plugin developers know what variable to give to their sub-command's function
110-
and what object they can expect to receive. Don't forget to document non-obvious
111-
callbacks.
99+
Opening a CLI to plugins encourages other developers to independently extend
100+
functionality independently but their is no guarantee these new features will
101+
be "on brand". Plugin developers are almost certainly already using features
102+
in the core package the CLI belongs to so defining commonly used arguments and
103+
options in one place lets plugin developers reuse these flags to produce a more
104+
cohesive CLI. If the CLI is simple maybe just define them at the top of
105+
``yourpackage/cli.py`` or for more complex packages something like
106+
``yourpackage/cli/options.py``. These common options need to be easy to find
107+
and be well documented so that plugin developers know what variable to give to
108+
their sub-command's function and what object they can expect to receive. Don't
109+
forget to document non-obvious callbacks.
112110

113111
Keep in mind that plugin developers also have access to the parent group's
114112
``ctx.obj``, which is very useful for passing things like verbosity levels or
@@ -167,11 +165,23 @@ Developing
167165
$ git clone https://github.com/click-contrib/click-plugins.git
168166
$ cd click-plugins
169167
$ virtualenv venv && source venv/bin/activate
170-
$ pip install -e .[test]
168+
$ pip install -e .[dev]
171169
$ py.test tests --cov click_plugins --cov-report term-missing
172170
173171
172+
Changelog
173+
---------
174+
175+
See ``CHANGES.txt``
176+
177+
178+
Authors
179+
-------
180+
181+
See ``AUTHORS.txt``
182+
183+
174184
License
175185
-------
176186

177-
See ``LICENSE.txt``.
187+
See ``LICENSE.txt``

click_plugins/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ def subcommand(arg):
2626

2727
__version__ = '1.0'
2828
__author__ = 'Kevin Wurster, Sean Gillies'
29-
__email__ = '[email protected]'
30-
__source__ = 'https://github.com/geowurster/click_plugins'
29+
30+
__source__ = 'https://github.com/click-contrib/click-plugins'
3131
__license__ = '''
3232
New BSD License
3333

example/PrintIt/README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
PrintIt
2+
=======
3+
4+
This represents a core package with a CLI that registers external plugins. All
5+
it does is print stuff.
File renamed without changes.

example/printer/cli.py renamed to example/PrintIt/printit/cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Commandline interface for printer
2+
Commandline interface for PrintIt
33
"""
44

55

@@ -9,7 +9,7 @@
99
from click_plugins import with_plugins
1010

1111

12-
@with_plugins(iter_entry_points('printer.plugins'))
12+
@with_plugins(iter_entry_points('printit.plugins'))
1313
@click.group()
1414
def cli():
1515

@@ -19,7 +19,7 @@ def cli():
1919
\b
2020
For example:
2121
\b
22-
$ cat README.rst | printer lower
22+
$ cat README.rst | printit lower
2323
"""
2424

2525

File renamed without changes.

example/setup.py renamed to example/PrintIt/setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33

44
"""
5-
Setup script for `printer`
5+
Setup script for `PrintIt`
66
"""
77

88

99
from setuptools import setup
1010

1111

1212
setup(
13-
name='printer',
13+
name='PrintIt',
1414
version='0.1dev0',
15-
packages=['printer'],
15+
packages=['printit'],
1616
entry_points='''
1717
[console_scripts]
18-
printer=printer.cli:cli
18+
printit=printit.cli:cli
1919
'''
2020
)

example/PrintItBold/README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
PrintItBold
2+
===========
3+
4+
This plugin should add bold styling to ``PrintIt`` but there is a typo in the
5+
entry point section of the ``setup.py`` that prevents the plugin from loading.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""
2+
A CLI plugin for `PrintIt` that adds bold text.
3+
"""

example/PrinterBold/printer_bold/core.py renamed to example/PrintItBold/printit_bold/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Add bold styling to `printer`
2+
Add bold styling to `printit`
33
"""
44

55

example/PrintItBold/setup.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python
2+
3+
4+
"""
5+
Setup script for `PrintItBold`
6+
"""
7+
8+
9+
from setuptools import setup
10+
11+
12+
setup(
13+
name='PrintItBold',
14+
version='0.1dev0',
15+
packages=['printit_bold'],
16+
entry_points='''
17+
[printit.plugins]
18+
bold=printit_bold.core:bolddddddddddd
19+
'''
20+
)

example/PrintItStyle/README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
PrintItStyle
2+
============
3+
4+
A plugin for ``PrintIt`` that adds commands for text styling.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""
2+
A CLI plugin for `PrintIt` that adds styling options.
3+
"""

example/PrinterStyle/printer_style/core.py renamed to example/PrintItStyle/printit_style/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Core components for printer_style
2+
Core components for `PrintItStyle`
33
"""
44

55

example/PrintItStyle/setup.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python
2+
3+
4+
"""
5+
Setup script for `PrintItStyle`
6+
"""
7+
8+
9+
from setuptools import setup
10+
11+
12+
setup(
13+
name='PrintItStyle',
14+
version='0.1dev0',
15+
packages=['printit_style'],
16+
entry_points='''
17+
[printit.plugins]
18+
background=printit_style.core:background
19+
color=printit_style.core:color
20+
'''
21+
)

example/PrinterBold/README.rst

Lines changed: 0 additions & 5 deletions
This file was deleted.

example/PrinterBold/printer_bold/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

example/PrinterBold/setup.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

example/PrinterStyle/README.rst

Lines changed: 0 additions & 12 deletions
This file was deleted.

example/PrinterStyle/printer_style/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

example/PrinterStyle/setup.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)