summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLauréline Guérin <zebuline@entrouvert.com>2022-04-29 15:28:51 (GMT)
committerLauréline Guérin <zebuline@entrouvert.com>2022-05-03 07:43:09 (GMT)
commit13cdff1e78f523145f3117ba9ddbd05b65cee289 (patch)
tree37379bd50ea320c72ba391fa8226c561cfaf3b95
parentfa539105e1045fa0149830fca592726200f01cdb (diff)
downloadpublik-django-templatetags-13cdff1e78f523145f3117ba9ddbd05b65cee289.zip
publik-django-templatetags-13cdff1e78f523145f3117ba9ddbd05b65cee289.tar.gz
publik-django-templatetags-13cdff1e78f523145f3117ba9ddbd05b65cee289.tar.bz2
init
-rw-r--r--.gitignore4
-rw-r--r--.pre-commit-config.yaml18
-rw-r--r--Jenkinsfile44
-rw-r--r--MANIFEST.in4
-rw-r--r--README40
-rw-r--r--debian/changelog5
-rw-r--r--debian/control13
-rwxr-xr-xdebian/rules7
-rw-r--r--debian/source/format1
-rw-r--r--publik_django_templatetags/__init__.py0
-rw-r--r--pytest.ini2
-rw-r--r--setup.py114
-rw-r--r--tests/__init__.py0
-rw-r--r--tests/project/__init__.py0
-rw-r--r--tests/project/settings.py45
-rw-r--r--tox.ini25
16 files changed, 322 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..2830888
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+*.pyc
+*.egg-info
+.pytest_cache/
+/debian/.debhelper/
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 0000000..7e7f73b
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,18 @@
+# See https://pre-commit.com for more information
+# See https://pre-commit.com/hooks.html for more hooks
+repos:
+- repo: https://github.com/psf/black
+ rev: 22.3.0
+ hooks:
+ - id: black
+ args: ['--target-version', 'py37', '--skip-string-normalization', '--line-length', '110']
+- repo: https://github.com/PyCQA/isort
+ rev: 5.7.0
+ hooks:
+ - id: isort
+ args: ['--profile', 'black', '--line-length', '110']
+- repo: https://github.com/asottile/pyupgrade
+ rev: v2.20.0
+ hooks:
+ - id: pyupgrade
+ args: ['--keep-percent-format', '--py37-plus']
diff --git a/Jenkinsfile b/Jenkinsfile
new file mode 100644
index 0000000..6a44876
--- /dev/null
+++ b/Jenkinsfile
@@ -0,0 +1,44 @@
+@Library('eo-jenkins-lib@main') import eo.Utils
+
+pipeline {
+ agent any
+ options {
+ disableConcurrentBuilds()
+ }
+ stages {
+ stage('Unit Tests') {
+ steps {
+ sh 'tox -rv'
+ }
+ post {
+ always {
+ mergeJunitResults()
+ }
+ }
+ }
+ stage('Packaging') {
+ steps {
+ script {
+ if (env.JOB_NAME == 'publik-django-templatetags' && env.GIT_BRANCH == 'origin/main') {
+ sh 'sudo -H -u eobuilder /usr/local/bin/eobuilder -d buster,bullseye publik-django-templatetags'
+ } else if (env.GIT_BRANCH.startsWith('hotfix/')) {
+ sh "sudo -H -u eobuilder /usr/local/bin/eobuilder -d buster,bullseye --branch ${env.GIT_BRANCH} --hotfix publik-django-templatetags"
+ }
+ }
+ }
+ }
+ }
+ post {
+ always {
+ script {
+ utils = new Utils()
+ utils.mail_notify(currentBuild, env, 'ci+jenkins-publik-django-templatetags@entrouvert.org')
+ }
+ }
+ success {
+ cleanWs()
+ }
+ }
+}
+
+
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..61ad30b
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,4 @@
+include MANIFEST.in
+include COPYING
+include README
+include VERSION
diff --git a/README b/README
new file mode 100644
index 0000000..6d4c6b9
--- /dev/null
+++ b/README
@@ -0,0 +1,40 @@
+publik-django-templatetags
+==========================
+
+Template tags and filters shared between Publik projects.
+
+Code Style
+----------
+
+black is used to format the code, using thoses parameters:
+
+ black --target-version py35 --skip-string-normalization --line-length 110
+
+isort is used to format the imports, using those parameters:
+
+ isort --profile black --line-length 110
+
+pyupgrade is used to automatically upgrade syntax, using those parameters:
+
+ pyupgrade --keep-percent-format --py37-plus
+
+There is .pre-commit-config.yaml to use pre-commit to automatically run black,
+isort and pyupgrade before commits. (execute `pre-commit install` to install
+the git hook.)
+
+
+License
+-------
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU Affero 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 Affero General Public License for more
+details.
+
+You should have received a copy of the GNU Affero General Public License along
+with this program. If not, see <http://www.gnu.org/licenses/>.
diff --git a/debian/changelog b/debian/changelog
new file mode 100644
index 0000000..e18862d
--- /dev/null
+++ b/debian/changelog
@@ -0,0 +1,5 @@
+publik-django-templatetags (0-1) unstable; urgency=low
+
+ * initial release
+
+ -- Frederic Peters <fpeters@entrouvert.com> Tue, 03 May 2022 08:42:40 +0200
diff --git a/debian/control b/debian/control
new file mode 100644
index 0000000..0e88b60
--- /dev/null
+++ b/debian/control
@@ -0,0 +1,13 @@
+Source: publik-django-templatetags
+Maintainer: Entr’ouvert <info@entrouvert.com>
+Section: python
+Priority: optional
+Build-Depends: debhelper-compat (= 12), dh-python, python3-all, python3-setuptools, python3-django
+Standards-Version: 3.9.1
+
+Package: python3-publik-django-templatetags
+Architecture: all
+Depends: ${misc:Depends}, ${python3:Depends}
+Description: Template tags and filters shared between Publik projects
+ Django shared application with custom template tags and filters
+ useful in multiple Publik modules.
diff --git a/debian/rules b/debian/rules
new file mode 100755
index 0000000..b37f7a2
--- /dev/null
+++ b/debian/rules
@@ -0,0 +1,7 @@
+#!/usr/bin/make -f
+
+export PYBUILD_NAME=publik-django-templatetags
+export PYBUILD_DISABLE=test
+
+%:
+ dh $@ --with python3 --buildsystem=pybuild
diff --git a/debian/source/format b/debian/source/format
new file mode 100644
index 0000000..163aaf8
--- /dev/null
+++ b/debian/source/format
@@ -0,0 +1 @@
+3.0 (quilt)
diff --git a/publik_django_templatetags/__init__.py b/publik_django_templatetags/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/publik_django_templatetags/__init__.py
diff --git a/pytest.ini b/pytest.ini
new file mode 100644
index 0000000..c184c0f
--- /dev/null
+++ b/pytest.ini
@@ -0,0 +1,2 @@
+[pytest]
+DJANGO_SETTINGS_MODULE = tests.project.settings
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..2871a66
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,114 @@
+#! /usr/bin/env python
+
+import os
+import subprocess
+import sys
+from distutils.cmd import Command
+from distutils.command.build import build as _build
+from distutils.command.sdist import sdist
+
+from setuptools import find_packages, setup
+from setuptools.command.install_lib import install_lib as _install_lib
+
+
+class eo_sdist(sdist):
+ def run(self):
+ if os.path.exists('VERSION'):
+ os.remove('VERSION')
+ version = get_version()
+ with open('VERSION', 'w') as fd:
+ fd.write(version)
+ sdist.run(self)
+ if os.path.exists('VERSION'):
+ os.remove('VERSION')
+
+
+def get_version():
+ if os.path.exists('VERSION'):
+ with open('VERSION') as v:
+ return v.read()
+ if os.path.exists('.git'):
+ p = subprocess.Popen(
+ ['git', 'describe', '--dirty=.dirty', '--match=v*'],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ )
+ result = p.communicate()[0]
+ if p.returncode == 0:
+ result = result.decode('ascii').strip()[1:] # strip spaces/newlines and initial v
+ if '-' in result: # not a tagged version
+ real_number, commit_count, commit_hash = result.split('-', 2)
+ version = '%s.post%s+%s' % (real_number, commit_count, commit_hash)
+ else:
+ version = result
+ return version
+ else:
+ return '0.0.post%s' % len(subprocess.check_output(['git', 'rev-list', 'HEAD']).splitlines())
+ return '0.0'
+
+
+class compile_translations(Command):
+ description = 'compile message catalogs to MO files via django compilemessages'
+ user_options = []
+
+ def initialize_options(self):
+ pass
+
+ def finalize_options(self):
+ pass
+
+ def run(self):
+ try:
+ from django.core.management import call_command
+
+ for path, dirs, files in os.walk('publik_django_templatetags'):
+ if 'locale' not in dirs:
+ continue
+ curdir = os.getcwd()
+ os.chdir(os.path.realpath(path))
+ call_command('compilemessages')
+ os.chdir(curdir)
+ except ImportError:
+ sys.stderr.write('!!! Please install Django >= 2.2 to build translations\n')
+
+
+class build(_build):
+ sub_commands = [('compile_translations', None)] + _build.sub_commands
+
+
+class install_lib(_install_lib):
+ def run(self):
+ self.run_command('compile_translations')
+ _install_lib.run(self)
+
+
+setup(
+ name='publik_django_templatetags',
+ version=get_version(),
+ description='Publik Django Templatetags',
+ author='Lauréline Guérin',
+ author_email='lguerin@entrouvert.com',
+ packages=find_packages(),
+ include_package_data=True,
+ url='https://dev.entrouvert.org/projects/publik-django-templatetags',
+ classifiers=[
+ 'Development Status :: 2 - Pre-Alpha',
+ 'Environment :: Web Environment',
+ 'Framework :: Django',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
+ 'Operating System :: OS Independent',
+ 'Programming Language :: Python',
+ ],
+ install_requires=[
+ 'django',
+ 'requests',
+ ],
+ zip_safe=False,
+ cmdclass={
+ 'build': build,
+ 'compile_translations': compile_translations,
+ 'install_lib': install_lib,
+ 'sdist': eo_sdist,
+ },
+)
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/__init__.py
diff --git a/tests/project/__init__.py b/tests/project/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/project/__init__.py
diff --git a/tests/project/settings.py b/tests/project/settings.py
new file mode 100644
index 0000000..a820ed6
--- /dev/null
+++ b/tests/project/settings.py
@@ -0,0 +1,45 @@
+import os
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': os.environ.get('DB_ENGINE', 'django.db.backends.postgresql_psycopg2'),
+ 'NAME': 'publik-django-templatetags-test-%s'
+ % os.environ.get("BRANCH_NAME", "").replace('/', '-')[:45],
+ }
+}
+
+KNOWN_SERVICES = {
+ 'wcs': {
+ 'default': {
+ 'title': 'test',
+ 'url': 'http://127.0.0.1:8999/',
+ 'secret': 'combo',
+ 'orig': 'combo',
+ 'backoffice-menu-url': 'http://127.0.0.1:8999/backoffice/',
+ 'secondary': False,
+ },
+ 'other': {
+ 'title': 'test2',
+ 'url': 'http://127.0.0.2:8999/',
+ 'secret': 'combo',
+ 'orig': 'combo',
+ 'backoffice-menu-url': 'http://127.0.0.2:8999/backoffice/',
+ 'secondary': True,
+ },
+ },
+}
+
+REQUESTS_TIMEOUT = 25
+
+DEBUG = True
+USE_TZ = True
+INSTALLED_APPS = [
+ "django.contrib.auth",
+ "django.contrib.contenttypes",
+ "django.contrib.sites",
+]
+STATIC_URL = "/static/"
+SITE_ID = 1
+MIDDLEWARE_CLASSES = ()
+LOGGING = {}
+SECRET_KEY = "yay"
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..a1e6f23
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,25 @@
+[tox]
+envlist = py3-django{22,32}-codestyle-coverage
+toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/publik-django-templatetags/{env:BRANCH_NAME:}
+
+[testenv]
+usedevelop =
+ coverage: True
+ nocoverage: False
+setenv =
+ SETUPTOOLS_USE_DISTUTILS=stdlib
+ JUNIT=--junitxml=junit-{envname}.xml
+ coverage: COVERAGE=--cov-report xml --cov-report html --cov=publik_django_templatetags/
+deps =
+ django22: django>=2.2,<2.3
+ django32: django>=3.2,<3.3
+ pytest
+ pytest-cov
+ pytest-django
+ WebTest
+ psycopg2-binary<2.9
+ psycopg2<2.9
+ pre-commit
+commands =
+ pytest {posargs: {env:JUNIT:} {env:COVERAGE:} tests/}
+ codestyle: pre-commit run --all-files --show-diff-on-failure