Skip to content

Commit

Permalink
Rename cmd.py to prevent clashes with stdlib
Browse files Browse the repository at this point in the history
Update associated testing file names as well.
  • Loading branch information
Gumnos committed Nov 28, 2012
1 parent 25f4447 commit ca2b89b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions command-line-scripts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ In this case, we'll add a new file and function to support the command line tool
funniest/
funniest/
__init__.py
cmd.py
command_line.py
...
setup.py
...

The ``cmd.py`` submodule exists only to service the command line tool (which is a convenient organization method)::
The ``command_line.py`` submodule exists only to service the command line tool (which is a convenient organization method)::

import funniest

Expand All @@ -70,16 +70,16 @@ The ``cmd.py`` submodule exists only to service the command line tool (which is
You can test the "script" by running it directly, e.g.::

$ python
>>> import funniest.cmd
>>> funniest.cmd.main()
>>> import funniest.command_line
>>> funniest.command_line.main()
...

The ``main()`` function can then be registered like so::

setup(
...
entry_points = {
'console_scripts': ['funniest-joke=funniest.cmd:main'],
'console_scripts': ['funniest-joke=funniest.command_line:main'],
}
...
)
Expand All @@ -89,7 +89,7 @@ Again, once the package has been installed, we can use it in the same way. Setup
This method has the advantage that it's very easily testable. Instead of having to shell out to spawn the script, we can have a test case that just does something like::

from unittest import TestCase
from funniest.cmd import main
from funniest.command_line import main

class TestConsole(TestCase):
def test_basic(self):
Expand Down
12 changes: 6 additions & 6 deletions everything.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ Our whole package, for reference, looks like this::
funniest/
funniest/
__init__.py
cmd.py
command_line.py
tests/
__init__.py
test_joke.py
test_cmd.py
test_command_line.py
MANIFEST.in
README.rst
setup.py
Expand All @@ -22,9 +22,9 @@ Here is the contents of each file:

.. literalinclude:: funniest/funniest/__init__.py

**funniest/cmd.py**
**funniest/command_line.py**

.. literalinclude:: funniest/funniest/cmd.py
.. literalinclude:: funniest/funniest/command_line.py

**funniest/tests/__init__.py**

Expand All @@ -34,9 +34,9 @@ Here is the contents of each file:

.. literalinclude:: funniest/funniest/tests/test_joke.py

**funniest/tests/test_cmd.py**
**funniest/tests/test_command_line.py**

.. literalinclude:: funniest/funniest/tests/test_cmd.py
.. literalinclude:: funniest/funniest/tests/test_command_line.py

**MANIFEST.in**

Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit ca2b89b

Please sign in to comment.