Skip to content

Commit

Permalink
Merge pull request #4982 from f-osorio/4799-extension-template-docume…
Browse files Browse the repository at this point in the history
…ntation

4799 extension template documentation
  • Loading branch information
smotornyuk committed Oct 10, 2019
2 parents 42596a0 + 2e6e3c2 commit f717999
Show file tree
Hide file tree
Showing 34 changed files with 2,066 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -8,7 +8,7 @@ flake8-steps: &flake8-steps
before_script:
- flake8 --version
# stop the build if there are Python syntax errors or undefined names
- flake8 . --count --select=E9,F63,F72,F82 --show-source --statistics --exclude ./ckan/include/rjsmin.py
- flake8 . --count --select=E9,F63,F72,F82 --show-source --statistics --exclude ./ckan/include/rjsmin.py,./contrib/cookiecutter/*
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
- flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
script:
Expand Down
4 changes: 3 additions & 1 deletion ckan/cli/cli.py
Expand Up @@ -15,7 +15,8 @@
notify,
tracking,
minify,
less
less,
generate
)

from ckan.config.middleware import make_app
Expand Down Expand Up @@ -54,3 +55,4 @@ def ckan(ctx, config, *args, **kwargs):
ckan.add_command(tracking.tracking)
ckan.add_command(minify.minify)
ckan.add_command(less.less)
ckan.add_command(generate.generate)
69 changes: 69 additions & 0 deletions ckan/cli/generate.py
@@ -0,0 +1,69 @@
# encoding: utf-8

import os
import sys
import click
from ckan.cli import error_shout
from cookiecutter.main import cookiecutter


@click.group(name=u'generate',
short_help=u"Generate empty extension files to expand CKAN.")
def generate():
pass


@generate.command(name=u'extension', short_help=u"Create empty extension.")
@click.option(u'-o', u'--output-dir', help=u"Location to put the generated "
u"template.",
default=u'.')
def extension(output_dir):
cur_loc = os.path.dirname(os.path.abspath(__file__))
os.chdir(cur_loc)
os.chdir(u'../../contrib/cookiecutter/ckan_extension/')
template_loc = os.getcwd()

# Prompt user for information
click.echo(u"\n")
name = click.prompt(u"Extenion's name", default=u"must begin 'ckanext-'")
author = click.prompt(u"Author's name", default=u"")
email = click.prompt(u"Author's email", default=u"")
github = click.prompt(u"Your Github user or organization name",
default=u"")
description = click.prompt(u"Brief description of the project",
default=u"")
keywords = click.prompt(u"List of keywords (seperated by spaces)",
default=u"CKAN")

# Ensure one instance of 'CKAN' in keywords
keywords = keywords.strip().split()
keywords = [keyword for keyword in keywords
if keyword not in (u'ckan', u'CKAN')]
keywords.insert(0, u'CKAN')
keywords = u' '.join(keywords)

# Set short name and plugin class name
project_short = name[8:].lower().replace(u'-', u'_')
plugin_class_name = project_short.title().replace(u'_', u'') + u'Plugin'

context = {u"project": name,
u"description": description,
u"author": author,
u"author_email": email,
u"keywords": keywords,
u"github_user_name": github,
u"project_shortname": project_short,
u"plugin_class_name": plugin_class_name,
u"_source": u"cli"}

if output_dir == u'.':
os.chdir(u'../../../..')
output_dir = os.getcwd()

if not name.startswith(u"ckanext-"):
print(u"\nERROR: Project name must start with 'ckanext-' > {}"
.format(name))
sys.exit(1)

cookiecutter(template_loc, no_input=True, extra_context=context,
output_dir=output_dir)
8 changes: 8 additions & 0 deletions ckan/tests/legacy/test_coding_standards.py
Expand Up @@ -479,6 +479,14 @@ class TestPep8(object):
'setup.py',
'ckan/tests/legacy/models/test_resource.py',
'ckan/tests/legacy/models/test_revision.py',
'contrib/cookiecutter/ckan_extension/'
'{{cookiecutter.project}}/setup.py',
'contrib/cookiecutter/ckan_extension/hooks/post_gen_project.py',
'contrib/cookiecutter/ckan_extension/'
'{{cookiecutter.project}}/ckanext/{{cookiecutter.project_shortname}}'
'/tests/test_plugin.py',
'contrib/cookiecutter/ckan_extension/{{cookiecutter.project}}'
'/ckanext/{{cookiecutter.project_shortname}}/plugin.py'
]
fails = {}
passes = []
Expand Down
1 change: 1 addition & 0 deletions ckan/tests/test_coding_standards.py
Expand Up @@ -31,6 +31,7 @@
# Directories which are ignored when checking Python source code files
IGNORED_DIRS = [
u'ckan/include',
u'contrib/cookiecutter'
]


Expand Down
3 changes: 3 additions & 0 deletions contrib/cookiecutter/ckan_extension/.travis.yml
@@ -0,0 +1,3 @@
language: python
install: pip install flake8
script: flake8 . --exit-zero

0 comments on commit f717999

Please sign in to comment.