Skip to content

Commit 5179471

Browse files
committed
Create initial template for cmd2 plugin
1 parent f5ddeac commit 5179471

File tree

8 files changed

+156
-37
lines changed

8 files changed

+156
-37
lines changed

.gitignore

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,13 @@ wheels/
2525
.installed.cfg
2626
*.egg
2727

28-
# PyInstaller
29-
# Usually these files are written by a python script from a template
30-
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31-
*.manifest
32-
*.spec
33-
3428
# Installer logs
3529
pip-log.txt
3630
pip-delete-this-directory.txt
3731

3832
# Unit test / coverage reports
33+
.tox
34+
.pytest_cache
3935
htmlcov/
4036
.tox/
4137
.coverage
@@ -50,35 +46,12 @@ coverage.xml
5046
*.mo
5147
*.pot
5248

53-
# Django stuff:
54-
*.log
55-
local_settings.py
56-
57-
# Flask stuff:
58-
instance/
59-
.webassets-cache
60-
61-
# Scrapy stuff:
62-
.scrapy
63-
6449
# Sphinx documentation
6550
docs/_build/
6651

67-
# PyBuilder
68-
target/
69-
70-
# Jupyter Notebook
71-
.ipynb_checkpoints
72-
7352
# pyenv
7453
.python-version
7554

76-
# celery beat schedule file
77-
celerybeat-schedule
78-
79-
# SageMath parsed files
80-
*.sage.py
81-
8255
# dotenv
8356
.env
8457

@@ -87,15 +60,8 @@ celerybeat-schedule
8760
venv/
8861
ENV/
8962

90-
# Spyder project settings
91-
.spyderproject
92-
.spyproject
93-
9463
# Rope project settings
9564
.ropeproject
9665

97-
# mkdocs documentation
98-
/site
99-
10066
# mypy
10167
.mypy_cache/

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6+
7+
## Unreleased
8+
### Added
9+
- Created plugin template and initial documentation
10+
11+

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 python-cmd2
3+
Copyright (c) 2018 Jared Crapo
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Creating a plugin for cmd2
2+
3+
## Using this template
4+
5+
This template assumes you are creating a new cmd2 plugin called `myplugin`. I expect you will want
6+
to give your plugin a different name. You will need to rename some of the files and directories
7+
in this template to your own package name. Don't forget to modify the imports and `setup.py`.
8+
9+
You'll probably also want to rewrite the README :)
10+
11+
## Naming
12+
You should prefix the name of your project with `cmd2-`. Within that project, you should have a package with a prefix of `cmd2_`.
13+
14+
## License
15+
16+
Cmd2 uses the very liberal MIT license. We invite plugin authors to
17+
consider doing the same.
18+
19+
## Tests
20+
21+
Make sure you test on all versions of python supported by `cmd2`, and on
22+
all supported platforms. `cmd2` uses a three tiered testing strategy to
23+
accomplish this objective.
24+
25+
- [pytest](https://pytest.org) runs the unit tests
26+
- [tox](https://tox.readthedocs.io/) runs the unit tests on multiple versions
27+
of python
28+
- [AppVeyor](https://www.appveyor.com/) and [TravisCI](https://travis-ci.com)
29+
run the tests on the various supported platforms
30+
31+
AppVeyor and TravisCI offer free plans for open source projects.
32+
33+
34+
## Examples
35+
36+
Include an example or two in the `examples` directory that shows a developer how your plugin
37+
works, and how to utilize it from within their application.
38+
39+
40+
## Distribution and Packaging
41+
42+
When creating your `setup.py` file, keep the following in mind:
43+
44+
- use the keywords `cmd2 plugin` to make it easier for people to find your plugin
45+
- since `cmd2` uses semantic versioning, you should use something like `install_requires=['cmd2 >= 0.9.0, <=2']` to make sure that your plugin doesn't try and run with a future version of `cmd2` with which it may not be compatible
46+
47+

cmd2_myplugin/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# -*- coding: utf-8 -*-
3+
"""Description of myplugin
4+
5+
An overview of what myplugin does.
6+
"""
7+
8+
from .myplugin import myplugin_decorator, MypluginMixin

cmd2_myplugin/myplugin.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# -*- coding: utf-8 -*-
3+
4+
import functools
5+
from typing import Callable
6+
7+
def myplugin_decorator(func: Callable) -> Callable:
8+
"""An empty decorator for myplugin"""
9+
#@functools.wraps(func)
10+
def _myplugin_decorator(self, *args, **kwargs):
11+
self.poutput("in the myplugin decorator")
12+
func(self, *args, **kwargs)
13+
_myplugin_decorator.__doc__ = func.__doc__
14+
return _myplugin_decorator
15+
16+
class MypluginMixin:
17+
"""A mixin class which adds methods to a cmd2 subclass"""
18+
def do_myplugin(self, arg):
19+
"""Add a myplugin command to cmd2"""
20+
self.poutput("just ran my plugin command")

examples/example.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# -*- coding: utf-8 -*-
3+
4+
import cmd2
5+
import cmd2_myplugin
6+
7+
class PluginExample(cmd2.cmd2.Cmd, cmd2_myplugin.MypluginMixin):
8+
"""An class to show how to use a plugin"""
9+
def __init__(self):
10+
super().__init__()
11+
12+
@cmd2_myplugin.myplugin_decorator
13+
def do_something(self, arg):
14+
self.poutput(arg)
15+
16+
if __name__ == '__main__':
17+
app = PluginExample()
18+
app.cmdloop()

setup.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#
2+
# -*- coding: utf-8 -*-
3+
4+
import os
5+
import setuptools
6+
7+
#
8+
# get the long description from the README file
9+
here = os.path.abspath(os.path.dirname(__file__))
10+
with open(os.path.join(here, 'README.md'), encoding='utf-8') as f:
11+
long_description = f.read()
12+
13+
VERSION='0.1.0'
14+
15+
setuptools.setup(
16+
name='cmd2-myplugin',
17+
version=VERSION,
18+
description='A template used to build plugins for cmd2',
19+
long_description=long_description,
20+
keywords='cmd2 plugin',
21+
22+
author='Kotfu',
23+
author_email='[email protected]',
24+
url='https://github.com/python-cmd2/cmd2-plugin-template',
25+
license='MIT',
26+
27+
packages=['cmd2_myplugin'],
28+
29+
python_requires='>=3.4',
30+
install_requires=['cmd2 >= 0.9.0, <=2'],
31+
32+
classifiers=[
33+
'Development Status :: 4 - Beta',
34+
'Environment :: Console',
35+
'Operating System :: OS Independent',
36+
'Topic :: Software Development :: Libraries :: Python Modules',
37+
'Intended Audience :: Developers',
38+
'License :: OSI Approved :: MIT License',
39+
'Programming Language :: Python :: 3.4',
40+
'Programming Language :: Python :: 3.5',
41+
'Programming Language :: Python :: 3.6',
42+
],
43+
44+
# dependencies for development and testing
45+
# $ pip install -e .[dev]
46+
extras_require={
47+
'dev': ['pytest']
48+
},
49+
)

0 commit comments

Comments
 (0)