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
hooks:
- 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
rev: 22.3.0
rev: 23.1.0
hooks:
- 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
rev: 5.12.0
hooks:
- id: isort
args: ['--profile', 'black', '--line-length', '110']
- repo: https://github.com/asottile/pyupgrade
rev: v3.1.0
hooks:
- id: pyupgrade
args: ['--keep-percent-format', '--py37-plus']
- repo: https://github.com/rtts/djhtml
rev: '3.0.5'
hooks:
- id: djhtml
args: ['--tabwidth', '2']
- repo: https://git.entrouvert.org/pre-commit-debian.git
rev: v0.3
hooks:

1
Jenkinsfile vendored
View File

@ -13,7 +13,6 @@ pipeline {
utils = new Utils()
utils.publish_coverage('coverage.xml')
utils.publish_coverage_native('index.html')
utils.publish_pylint('pylint.out')
}
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
#
# 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
@pytest.fixture(autouse=True)
def media(settings, tmpdir):
settings.MEDIA_ROOT = str(tmpdir.mkdir('media'))
return settings.MEDIA_ROOT
@pytest.fixture
def app(request):
wtm = WebTestMixin()

View File

@ -14,22 +14,9 @@
# 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/>.
import os
import tempfile
DEBUG = False
ALLOWED_HOSTS = ['*']
LANGUAGE_CODE = 'en-US'
DATABASES = {
'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')
DATABASES = {'default': {'ENGINE': 'django.db.backends.postgresql', 'NAME': 'fargo'}}

45
tox.ini
View File

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