This commit is contained in:
Lauréline Guérin 2022-04-29 17:28:51 +02:00
parent fa539105e1
commit 13cdff1e78
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
16 changed files with 322 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*.pyc
*.egg-info
.pytest_cache/
/debian/.debhelper/

18
.pre-commit-config.yaml Normal file
View File

@ -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']

44
Jenkinsfile vendored Normal file
View File

@ -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()
}
}
}

4
MANIFEST.in Normal file
View File

@ -0,0 +1,4 @@
include MANIFEST.in
include COPYING
include README
include VERSION

40
README Normal file
View File

@ -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/>.

5
debian/changelog vendored Normal file
View File

@ -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

13
debian/control vendored Normal file
View File

@ -0,0 +1,13 @@
Source: publik-django-templatetags
Maintainer: Entrouvert <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.

7
debian/rules vendored Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/make -f
export PYBUILD_NAME=publik-django-templatetags
export PYBUILD_DISABLE=test
%:
dh $@ --with python3 --buildsystem=pybuild

1
debian/source/format vendored Normal file
View File

@ -0,0 +1 @@
3.0 (quilt)

View File

2
pytest.ini Normal file
View File

@ -0,0 +1,2 @@
[pytest]
DJANGO_SETTINGS_MODULE = tests.project.settings

114
setup.py Normal file
View File

@ -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,
},
)

0
tests/__init__.py Normal file
View File

View File

45
tests/project/settings.py Normal file
View File

@ -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"

25
tox.ini Normal file
View File

@ -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