ci: update tox.ini + py311 compatibility (#86371)

* separate codestyle target from test
* remove dead pylint target
* separate test dependencies in requirement file
* update pre-commit hooks
* launch coverage/junit tally when in jenkins
* use tempdir fixture instead of tempfile
This commit is contained in:
Benjamin Dauvergne 2024-01-31 16:12:56 +01:00
parent ee69592cdd
commit 61c10e4f2d
7 changed files with 52 additions and 63 deletions

View File

@ -5,21 +5,31 @@ repos:
rev: v4.4.0 rev: v4.4.0
hooks: hooks:
- id: double-quote-string-fixer - id: double-quote-string-fixer
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: ['--keep-percent-format', '--py39-plus']
- repo: https://github.com/adamchainz/django-upgrade
rev: 1.13.0
hooks:
- id: django-upgrade
args: ['--target-version', '3.2']
- repo: https://github.com/psf/black - repo: https://github.com/psf/black
rev: 22.3.0 rev: 23.1.0
hooks: hooks:
- id: black - id: black
args: ['--target-version', 'py37', '--skip-string-normalization', '--line-length', '110'] args: ['--target-version', 'py39', '--skip-string-normalization', '--line-length', '110']
- repo: https://github.com/PyCQA/isort - repo: https://github.com/PyCQA/isort
rev: 5.12.0 rev: 5.12.0
hooks: hooks:
- id: isort - id: isort
args: ['--profile', 'black', '--line-length', '110'] args: ['--profile', 'black', '--line-length', '110']
- repo: https://github.com/asottile/pyupgrade - repo: https://github.com/rtts/djhtml
rev: v3.1.0 rev: '3.0.5'
hooks: hooks:
- id: pyupgrade - id: djhtml
args: ['--keep-percent-format', '--py37-plus'] args: ['--tabwidth', '2']
- repo: https://git.entrouvert.org/pre-commit-debian.git - repo: https://git.entrouvert.org/pre-commit-debian.git
rev: v0.3 rev: v0.3
hooks: hooks:

1
Jenkinsfile vendored
View File

@ -13,7 +13,6 @@ pipeline {
utils = new Utils() utils = new Utils()
utils.publish_coverage('coverage.xml') utils.publish_coverage('coverage.xml')
utils.publish_coverage_native('index.html') utils.publish_coverage_native('index.html')
utils.publish_pylint('pylint.out')
} }
mergeJunitResults() mergeJunitResults()
} }

View File

@ -1,16 +0,0 @@
#!/bin/sh
set -e -x
env
if [ -f /var/lib/jenkins/pylint.django.rc ]; then
PYLINT_RC=/var/lib/jenkins/pylint.django.rc
elif [ -f pylint.django.rc ]; then
PYLINT_RC=pylint.django.rc
else
echo No pylint RC found
exit 0
fi
test -f pylint.out && cp pylint.out pylint.out.prev
pylint -f parseable --rcfile ${PYLINT_RC} "$@" | tee pylint.out || /bin/true
test -f pylint.out.prev && (diff pylint.out.prev pylint.out | grep '^[><]' | grep .py) || /bin/true

7
test-requirements.txt Normal file
View File

@ -0,0 +1,7 @@
psycopg2-binary
django-webtest
pytest
pytest-cov
pytest-random
pytest-django
pytest-freezer

View File

@ -1,4 +1,3 @@
# fargo - document box
# Copyright (C) 2016-2019 Entr'ouvert # Copyright (C) 2016-2019 Entr'ouvert
# #
# This program is free software: you can redistribute it and/or modify it # This program is free software: you can redistribute it and/or modify it
@ -29,6 +28,12 @@ class WebTestMixin(django_webtest.WebTestMixin):
csrf_checks = False csrf_checks = False
@pytest.fixture(autouse=True)
def media(settings, tmpdir):
settings.MEDIA_ROOT = str(tmpdir.mkdir('media'))
return settings.MEDIA_ROOT
@pytest.fixture @pytest.fixture
def app(request): def app(request):
wtm = WebTestMixin() wtm = WebTestMixin()

View File

@ -14,22 +14,9 @@
# You should have received a copy of the GNU Affero General Public License # 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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import tempfile
DEBUG = False DEBUG = False
ALLOWED_HOSTS = ['*'] ALLOWED_HOSTS = ['*']
LANGUAGE_CODE = 'en-US' LANGUAGE_CODE = 'en-US'
DATABASES = { DATABASES = {'default': {'ENGINE': 'django.db.backends.postgresql', 'NAME': 'fargo'}}
'default': {
'ENGINE': 'django.db.backends.' + os.environ.get('DB_ENGINE', 'sqlite3'),
'NAME': 'fargo.sqlite3',
'TEST': {
'NAME': 'fargo-test-' + os.environ.get('DB_ENGINE', 'sqlite3'),
},
}
}
MEDIA_ROOT = tempfile.mkdtemp('fargo-test')

45
tox.ini
View File

@ -1,39 +1,36 @@
[tox] [tox]
toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/fargo/{env:BRANCH_NAME:} toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/fargo/{env:BRANCH_NAME:}
envlist = envlist = py3,codestyle
py3-dj32-black-coverage-pylint
py3-dj22
[testenv] [testenv]
usedevelop = True usedevelop = True
whitelist_externals = whitelist_externals =
/bin/mv /bin/mv
setenv = setenv =
DB_ENGINE=postgresql_psycopg2
DJANGO_SETTINGS_MODULE=fargo.settings DJANGO_SETTINGS_MODULE=fargo.settings
FARGO_SETTINGS_FILE=tests/settings.py FARGO_SETTINGS_FILE=tests/settings.py
SETUPTOOLS_USE_DISTUTILS=stdlib JUNIT={tty::-o junit_suite_name={envname} --junit-xml=junit-{envname}.xml}
coverage: COVERAGE=--junitxml=junit-{envname}.xml --random --cov-report xml --cov-report html --cov=fargo/ COVERAGE={tty::--cov --cov-append --cov-report xml --cov-report html --cov-context=test --cov-config=tox.ini}
deps = deps =
pytest django>=3.2,<3.3
psycopg2<2.9
pylint<3
astroid<3
pylint-django
dj22: django>=2.2,<2.3
dj32: django>=3.2,<3.3
django-filter>=2.4,<23.2 django-filter>=2.4,<23.2
django-tables2==2.4.1 django-tables2==2.4.1
pytest-cov -r test-requirements.txt
pytest-random commands =
pytest-mock py.test {env:JUNIT:} {env:COVERAGE:} {posargs:tests/}
pytest-django
pytest-freezegun [testenv:codestyle]
django-webtest skip_install = true
WebTest deps =
mock<4
pre-commit pre-commit
commands = commands =
py.test {env:COVERAGE:} {posargs:tests/} pre-commit run --all-files --show-diff-on-failure
pylint: ./pylint.sh fargo/
black: pre-commit run black --all-files --show-diff-on-failure [coverage:run]
source =
fargo
tests
branch = True
[coverage:html]
show_contexts = True