Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit a1bc91a

Browse files
author
f-osorio
committed
Add Cookiecutter to Core
Small update to tutorial
1 parent 4b90d44 commit a1bc91a

29 files changed

+1941
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: python
2+
install: pip install flake8
3+
script: flake8 . --exit-zero

contrib/cookiecutter/ckan_extension/LICENSE

+674
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# CKAN Extension Template
2+
3+
[Cookiecutter](https://github.com/audreyr/cookiecutter) for creating a [CKAN](https://github.com/ckan/ckan) extension skeleton.
4+
5+
## Getting Started
6+
7+
Install Cookiecutter:
8+
```sh
9+
$pip install cookiecutter
10+
```
11+
12+
Generate the skeleton:
13+
```sh
14+
$ cookiecutter https://github.com/f-osorio/cookiecutter-ckan-extension.git
15+
```
16+
17+
Cookiecutter will prompt you for the following information to generate the skeleton:
18+
```no-highlight
19+
project: name of the project - MUST begin with "ckanext-"
20+
keywords: associated with the project
21+
description: of the project
22+
author: of the project
23+
author_email:
24+
github_user_name: GitHub user or organization name
25+
```
26+
27+
Additionally, it will display the following which should not be changed:
28+
```no-highlight
29+
project_shortname
30+
plugin_class_name
31+
```
32+
33+
Consult [CKAN documentation](https://docs.ckan.org/en/latest/extensions/tutorial.html) for creating an extension.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"project": "Project's name (must begin with 'ckanext-')",
3+
"keywords": "A space separated list of keywords",
4+
"description": "",
5+
"author": "",
6+
"author_email": "",
7+
"github_user_name": "Github user or organization name",
8+
"project_shortname": "{{ cookiecutter.project[8:].lower().replace('-','_') }}",
9+
"plugin_class_name": "{{ cookiecutter.project_shortname.title().replace('_','') }}Plugin",
10+
"_source": "local"
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import os
2+
import json
3+
import jinja2
4+
import cookiecutter.find as find
5+
import cookiecutter.generate as gen
6+
from cookiecutter.config import DEFAULT_CONFIG as config
7+
from cookiecutter.environment import StrictEnvironment
8+
from cookiecutter.exceptions import NonTemplatedInputDirException
9+
from cookiecutter.main import cookiecutter as c
10+
11+
12+
def recut():
13+
"""
14+
Recreate setup.py so that we can edit keywords
15+
"""
16+
# template location
17+
try:
18+
# cutting cookie from directory with template
19+
temp_dir = find.find_template('..')
20+
except NonTemplatedInputDirException as e:
21+
# template coming from Github
22+
# Hooks are passed through jinja2. raw will
23+
# Make sure `cookiecutter.project` isn't replaced
24+
{% raw %}
25+
temp_dir = os.path.join(config['cookiecutters_dir'],
26+
'cookiecutter-ckan-extension',
27+
'{{cookiecutter.project}}')
28+
{% endraw %}
29+
30+
# Location for resulting file
31+
destination = os.getcwd()
32+
# name of template
33+
setup_template = 'setup.py'
34+
35+
# get context
36+
context = {{ cookiecutter | jsonify }}
37+
38+
# Process keywords
39+
keywords = context['keywords'].strip().split()
40+
keywords = [keyword for keyword in keywords
41+
if keyword not in ('ckan', 'CKAN', 'A','space',
42+
'seperated','list','of','keywords')]
43+
keywords.insert(0, 'CKAN')
44+
keywords = u' '.join(keywords)
45+
context['keywords'] = keywords
46+
47+
# Double check 'project_shortname' and 'plugin_class_name'
48+
short_name = context['project'][8:].replace('-','_')
49+
if context['project_shortname'] != short_name:
50+
context['project_shortname'] = short_name
51+
52+
plugin_class_name = '{}Plugin'.format(context['project_shortname']\
53+
.title().replace('_',''))
54+
if context['plugin_class_name'] != plugin_class_name:
55+
context['plugin_class_name'] = plugin_class_name
56+
57+
# Recut cookie
58+
env = StrictEnvironment()
59+
env.loader = jinja2.FileSystemLoader(temp_dir)
60+
gen.generate_file(project_dir=destination,
61+
infile=setup_template,
62+
context={'cookiecutter': context},
63+
env=env)
64+
65+
66+
if __name__ == '__main__':
67+
context = {{ cookiecutter | jsonify }}
68+
if context['_source'] == 'local':
69+
recut()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import sys
2+
3+
4+
def validate_project_name():
5+
# Check that project name begins with 'ckanext-'
6+
project_name = "{{ cookiecutter.project }}"
7+
if not project_name.startswith('ckanext-'):
8+
print("\nERROR: Project name must start with 'ckanext-' > {}" \
9+
.format(project_name))
10+
sys.exit(1)
11+
12+
13+
if __name__ == '__main__':
14+
validate_project_name()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[report]
2+
omit =
3+
*/site-packages/*
4+
*/python?.?/*
5+
ckan/*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
.ropeproject
2+
node_modules
3+
bower_components
4+
5+
# Byte-compiled / optimized / DLL files
6+
__pycache__/
7+
*.py[cod]
8+
9+
# C extensions
10+
*.so
11+
12+
# Distribution / packaging
13+
.Python
14+
env/
15+
build/
16+
develop-eggs/
17+
dist/
18+
sdist/
19+
*.egg-info/
20+
.installed.cfg
21+
*.egg
22+
23+
# PyInstaller
24+
# Usually these files are written by a python script from a template
25+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
26+
*.manifest
27+
*.spec
28+
29+
# Installer logs
30+
pip-log.txt
31+
pip-delete-this-directory.txt
32+
33+
# Unit test / coverage reports
34+
htmlcov/
35+
.tox/
36+
.coverage
37+
.cache
38+
nosetests.xml
39+
coverage.xml
40+
41+
# Sphinx documentation
42+
docs/_build/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
language: python
2+
sudo: required
3+
4+
# use an older trusty image, because the newer images cause build errors with
5+
# psycopg2 that comes with CKAN<2.8:
6+
#  "Error: could not determine PostgreSQL version from '10.1'"
7+
# see https://github.com/travis-ci/travis-ci/issues/8897
8+
dist: trusty
9+
group: deprecated-2017Q4
10+
11+
# matrix
12+
python:
13+
- 2.7
14+
env:
15+
- CKANVERSION=master
16+
- CKANVERSION=2.7
17+
- CKANVERSION=2.8
18+
19+
# tests
20+
services:
21+
- postgresql
22+
- redis-server
23+
install:
24+
- bash bin/travis-build.bash
25+
- pip install coveralls
26+
script: sh bin/travis-run.sh
27+
after_success:
28+
- coveralls
29+
30+
# additional jobs
31+
matrix:
32+
include:
33+
- name: "Flake8 on Python 3.7"
34+
dist: xenial # required for Python 3.7
35+
cache: pip
36+
install: pip install flake8
37+
script:
38+
- flake8 --version
39+
- flake8 . --count --max-complexity=10 --max-line-length=127 --statistics --exclude ckan,{{ cookiecutter.project }}
40+
python: 3.7
41+
# overwrite matrix
42+
env:
43+
- FLAKE8=true
44+
- CKANVERSION=master

0 commit comments

Comments
 (0)