Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the ckanext template #1956

Merged
merged 8 commits into from Nov 20, 2014
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 47 additions & 16 deletions ckan/pastertemplates/__init__.py
@@ -1,41 +1,72 @@
"""A Paste template for creating new CKAN extensions.

Usage::

paster --plugin=ckan create -t ckanext

See:

* http://docs.pylonsproject.org/projects/pylons-webframework/en/latest/advanced_pylons/creating_paste_templates.html
* http://pythonpaste.org/script/developer.html#templates

"""
Paste template for new ckanext.plugins projects
"""
import sys

import jinja2
from paste.script.templates import Template, var
from paste.util.template import paste_script_template_renderer
from paste.script.create_distro import Command
import sys

# Horrible hack to change the behaviour of Paste itself
# Since this module is only imported when commands are
# run, this will not affect any other paster commands.
import re
Command._bad_chars_re = re.compile('[^a-zA-Z0-9_-]')


def jinja2_template_renderer(content_as_string, vars_as_dict, filename=None):
return jinja2.Environment().from_string(content_as_string).render(
vars_as_dict)


class CkanextTemplate(Template):
"""A Paste template for a skeleton CKAN extension package.

"""
Template to build a skeleton ckanext.plugins package
"""

_template_dir = 'template/'
summary = 'CKAN extension project template'
template_renderer = staticmethod(paste_script_template_renderer)
use_cheetah = True
template_renderer = staticmethod(jinja2_template_renderer)

vars = [
var('version', 'Version (like 0.1)'),
var('description', 'One-line description of the package'),
var('author', 'Author name'),
var('author_email', 'Author email'),
var('url', 'URL of homepage'),
var('license_name', 'License name'),
var('description', 'a one-line description of the extension, '
'for example: "A simple blog extension for CKAN"'),
var('author', 'for example: "Guybrush Threepwood"'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brilliant.

var('author_email', 'for example: "guybrush@meleeisland.com"'),
var('keywords', 'a space-separated list of keywords, for example: '
'"CKAN blog"'),
var('github_user_name', 'your GitHub user or organization name, for '
'example: "guybrush" or "ckan"'),
]

def check_vars(self, vars, cmd):
vars = Template.check_vars(self, vars, cmd)

if not vars['project'].startswith('ckanext-'):
print "\nError: Expected the project name to start with 'ckanext-'"
print "\nError: Project name must start with 'ckanext-'"
sys.exit(1)
vars['project'] = vars['project'][len('ckanext-'):]

# The project name without the ckanext-.
vars['project_shortname'] = vars['project'][len('ckanext-'):]

# Make sure keywords contains "CKAN" (upper-case) once only.
keywords = vars['keywords'].strip().split()
keywords = [keyword for keyword in keywords
if keyword not in ('ckan', 'CKAN')]
keywords.insert(0, 'CKAN')
vars['keywords'] = ' '.join(keywords)

# For an extension named ckanext-example we want a plugin class
# named ExamplePlugin.
vars['plugin_class_name'] = vars['project_shortname'].title() + 'Plugin'

return vars
5 changes: 5 additions & 0 deletions ckan/pastertemplates/template/+dot+coveragerc_tmpl
@@ -0,0 +1,5 @@
[report]
omit =
*/site-packages/*
*/python?.?/*
ckan/*
42 changes: 42 additions & 0 deletions ckan/pastertemplates/template/+dot+gitignore_tmpl
@@ -0,0 +1,42 @@
.ropeproject
node_modules
bower_components

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
sdist/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Sphinx documentation
docs/_build/
12 changes: 12 additions & 0 deletions ckan/pastertemplates/template/+dot+travis.yml_tmpl
@@ -0,0 +1,12 @@
language: python
python:
- "2.6"
- "2.7"
env: PGVERSION=9.1
install:
- bash bin/travis-build.bash
- pip install coveralls
script: sh bin/travis-run.sh
after_success:
- coveralls