Commit 883fa6d7 authored by Cédric Krier's avatar Cédric Krier
Browse files

Add cookiecutter template for module

parent a22c4cd5d9b2
Pipeline #61627 passed with stages
in 7 minutes and 55 seconds
[flake8]
ignore=E123,E124,E126,E128,E741,W503
extend-exclude=cookiecutter-module
......@@ -90,8 +90,8 @@
check-flake8:
extends: .check-code
script:
- flake8
- flake8 --exclude 'cookiecutter*'
check-isort:
extends: .check-code
script:
......@@ -94,8 +94,8 @@
check-isort:
extends: .check-code
script:
- isort -m VERTICAL_GRID -c .
- isort -m VERTICAL_GRID -c --skip-glob 'cookiecutter*' .
check-dist:
stage: check
......@@ -111,6 +111,21 @@
- python .gitlab-scripts/generate-ci.py $TMPDIR/gitab-ci-modules.yml
- cmp .gitlab-ci-modules.yml $TMPDIR/gitab-ci-modules.yml
check-cookiecutter-module:
extends: .check
cache:
paths:
- .cache/pip/http
before_script:
- pip install cookiecutter
script:
- cookiecutter --no-input cookiecutter-module -o /tmp
- flake8 /tmp/my_module
- isort -m VERTICAL_GRID -c /tmp/my_module
rules:
- changes:
- cookiecutter-module/**/*
.test:
stage: test
rules:
......
......@@ -4,7 +4,7 @@
OUTPUTDIR=`realpath "${1}"`
mkdir -p "${OUTPUTDIR}"
find . -path '*/doc/conf.py' | while read path; do
find . -name 'cookiecutter*' -prune -o -path '*/doc/conf.py' -print | while read path; do
path=`dirname "${path}"`
path=`dirname "${path}"`
package=`basename "${path}"`
......
......@@ -4,6 +4,6 @@
PACKAGES=`realpath "${1}"`
mkdir -p "${PACKAGES}"
find . -name setup.py | while read path; do
find . -name 'cookiecutter*' -prune -o -name setup.py -print | while read path; do
(cd "`dirname ${path}`" && python setup.py sdist && cp dist/* "${PACKAGES}")
done
===================
cookiecutter-module
===================
Cookiecutter_ template for a Tryton module
(requires cookiecutter >= 1.4.0)
Features
--------
* Ready to use setup.py
* Vanilla testing setup with `unittest`
* Tox_: Setup to easily test for Python, PyPy, SQlite and PostgreSQL
* Documentation folder with standard layout
Quickstart
----------
Generate a Tryton module project::
cookiecutter --output-dir modules cookiecutter-module
.. _Cookiecutter: https://github.com/cookiecutter/cookiecutter
.. _Tox: https://tox.wiki/
{
"module_name": "my_module",
"prefix": "",
"package_name": "{% if not cookiecutter.prefix %}trytond_{{ cookiecutter.module_name }}{% else %}{{ cookiecutter.prefix }}_{{ cookiecutter.module_name }}{% endif %}",
"version": "{{ version }}",
"description": "",
"author": "Tryton",
"author_email": "foundation@tryton.org",
"fullname": "",
"url": "http://www.tryton.org/",
"keywords": "",
"test_with_scenario": "",
"_extensions": ["extensions.Version"]
}
import io
import os
import re
from jinja2.ext import Extension
def read(fname):
return io.open(
os.path.join(os.path.dirname(__file__), fname),
'r', encoding='utf-8').read()
def get_version():
init = read(os.path.join(
os.path.dirname(__file__), '../trytond/trytond/__init__.py'))
version = re.search('__version__ = "([0-9.]*)"', init).group(1)
return '.'.join(version.split('.')[:2] + ['0'])
class Version(Extension):
def __init__(self, environment):
super().__init__(environment)
environment.globals.update(version=get_version())
import os
import shutil
try:
os.symlink('doc/index.rst', 'README.rst')
except (AttributeError, OSError):
shutil.copyfile('doc/index.rst', 'README.rst')
Copyright (C) {% now 'local', '%Y' %} {{ cookiecutter.fullname }}
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
This diff is collapsed.
include CHANGELOG
include COPYRIGHT
include LICENSE
include README.rst
include icons/LICENSE
graft doc
{% if not cookiecutter.prefix -%}
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
{% endif -%}
from trytond.pool import Pool
__all__ = ['register']
def register():
Pool.register(
module='{{ cookiecutter.module_name }}', type_='model')
Pool.register(
module='{{ cookiecutter.module_name }}', type_='wizard')
Pool.register(
module='{{ cookiecutter.module_name }}', type_='report')
{% if not cookiecutter.prefix -%}
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
{% endif -%}
import os
base_url = os.environ.get('DOC_BASE_URL')
if base_url:
modules_url = base_url + '/modules-{module}/'
trytond_url = base_url + '/server/'
else:
modules_url = (
'https://docs.tryton.org/projects/modules-{module}/en/{series}/')
trytond_url = 'https://docs.tryton.org/projects/server/en/{series}/'
def get_info():
import configparser
import subprocess
import sys
module_dir = os.path.dirname(os.path.dirname(__file__))
config = configparser.ConfigParser()
config.read_file(open(os.path.join(module_dir, 'tryton.cfg')))
info = dict(config.items('tryton'))
result = subprocess.run(
[sys.executable, 'setup.py', '--name'],
stdout=subprocess.PIPE, check=True, cwd=module_dir)
info['name'] = result.stdout.decode('utf-8').strip()
result = subprocess.run(
[sys.executable, 'setup.py', '--version'],
stdout=subprocess.PIPE, check=True, cwd=module_dir)
version = result.stdout.decode('utf-8').strip()
major_version, minor_version, _ = version.split('.', 2)
major_version = int(major_version)
minor_version = int(minor_version)
if minor_version % 2:
info['series'] = 'latest'
else:
info['series'] = '.'.join(version.split('.', 2)[:2])
for key in {'depends', 'extras_depend'}:
info[key] = info.get(key, '').strip().splitlines()
info['modules'] = set(info['depends'] + info['extras_depend'])
info['modules'] -= {'ir', 'res'}
return info
info = get_info()
master_doc = 'index'
project = info['name']
release = version = info['series']
default_role = 'ref'
highlight_language = 'none'
extensions = [
'sphinx.ext.intersphinx',
]
intersphinx_mapping = {
'trytond': (trytond_url.format(series=version), None),
}
intersphinx_mapping.update({
m: (modules_url.format(
module=m.replace('_', '-'), series=version), None)
for m in info['modules']
})
linkcheck_ignore = [r'/.*', r'https://demo.tryton.org/*']
del get_info, info, base_url, modules_url, trytond_url
*************
Configuration
*************
.. to remove, see https://www.tryton.org/develop/guidelines/documentation#configuration.rst
******
Design
******
.. to remove, see https://www.tryton.org/develop/guidelines/documentation#design.rst
{{ '#' * (cookiecutter.module_name|replace('_', ' ')|title|length + 7) }}
{{ cookiecutter.module_name.replace('_', ' ').title() }} Module
{{ '#' * (cookiecutter.module_name|replace('_', ' ')|title|length + 7) }}
.. to remove, see https://www.tryton.org/develop/guidelines/documentation#index.rst
.. toctree::
:maxdepth: 2
usage
design
releases
*************
API Reference
*************
.. to remove, see https://www.tryton.org/develop/guidelines/documentation#reference.rst
.. _releases-index:
=============
Release notes
=============
.. include:: ../CHANGELOG
.. to remove, see https://www.tryton.org/develop/guidelines/documentation#setup.rst
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment