ci: migrate tox to nox (#89962)
gitea/combo/pipeline/head This commit looks good Details

This commit is contained in:
Corentin Sechet 2024-04-24 10:35:19 +02:00 committed by Corentin Sechet
parent af473d684e
commit 20ab0b42d6
5 changed files with 130 additions and 122 deletions

2
Jenkinsfile vendored
View File

@ -9,7 +9,7 @@ pipeline {
stages {
stage('Unit Tests') {
steps {
sh 'NUMPROCESSES=6 tox -rv'
sh 'nox'
}
post {
always {

View File

@ -1,22 +0,0 @@
#!/bin/sh
# Get venv site-packages path
DSTDIR=`python3 -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())'`
# Get not venv site-packages path
# Remove first path (assuming that is the venv path)
NONPATH=`echo $PATH | sed 's/^[^:]*://'`
SRCDIR=`PATH=$NONPATH python3 -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())'`
# Clean up
rm -f $DSTDIR/lasso.*
rm -f $DSTDIR/_lasso.*
# Link
ln -sv /usr/lib/python3/dist-packages/lasso.py $DSTDIR/
for SOFILE in /usr/lib/python3/dist-packages/_lasso.cpython-*.so
do
ln -sv $SOFILE $DSTDIR/
done
exit 0

129
noxfile.py Normal file
View File

@ -0,0 +1,129 @@
import shlex
from pathlib import Path
import nox
def get_lasso3(session):
src_dir = Path('/usr/lib/python3/dist-packages/')
venv_dir = Path(session.virtualenv.location)
for dst_dir in venv_dir.glob('lib/**/site-packages'):
files_to_link = [src_dir / 'lasso.py'] + list(src_dir.glob('_lasso.cpython-*.so'))
for src_file in files_to_link:
dst_file = dst_dir / src_file.name
if dst_file.exists():
dst_file.unlink()
session.log('%s => %s', dst_file, src_file)
dst_file.symlink_to(src_file)
def setup_venv(session, *packages, django_version='>=3.2,<3.3'):
session.install(
'-e',
'.',
f'django{django_version}',
'WebTest',
'django-mellon>=1.13',
'django-webtest',
'git+https://git.entrouvert.org/entrouvert/publik-django-templatetags.git',
'httmock',
'pytest!=5.3.3',
'responses',
'uwsgidecorators',
'git+https://git.entrouvert.org/entrouvert/debian-django-ckeditor.git',
*packages,
)
get_lasso3(session)
@nox.session()
@nox.parametrize('django', ['>=3.2,<3.3'])
def tests(session, django):
setup_venv(
session,
'pytest-cov',
'pytest-django',
'pytest-freezegun',
'pytest-xdist',
'mock<4',
'astroid<3',
'pyquery',
'psycopg2-binary',
'django-ratelimit<3',
'djangorestframework>=3.12,<3.13 ', # matching debian bullseye,
django_version=django,
)
session.run('python', 'manage.py', 'compilemessages')
args = ['py.test']
if '--coverage' in session.posargs or not session.interactive:
while '--coverage' in session.posargs:
session.posargs.remove('--coverage')
args += [
'--cov-report',
'xml',
'--cov-report',
'html',
'--cov=combo/',
'--cov-config',
'.coveragerc',
'-v',
f'--junitxml=junit-coverage.django-{django}.xml',
]
if not session.interactive:
args += ['-v', '--numprocesses', '6']
args += session.posargs + ['tests/']
session.run(
*args,
env={
'DJANGO_SETTINGS_MODULE': 'combo.settings',
'COMBO_SETTINGS_FILE': 'tests/settings.py',
'SETUPTOOLS_USE_DISTUTILS': 'stdlib',
'DB_ENGINE': 'django.db.backends.postgresql_psycopg2',
},
)
@nox.session
def pylint(session):
setup_venv(session, 'pylint<3', 'pylint-django', 'nox')
pylint_command = ['pylint', '--jobs', '6', '-f', 'parseable', '--rcfile', 'pylint.rc']
if not session.posargs:
pylint_command += ['combo/', 'tests/', 'noxfile.py']
else:
pylint_command += session.posargs
if not session.interactive:
session.run(
'bash',
'-c',
f'{shlex.join(pylint_command)} | tee pylint.out ; test $PIPESTATUS -eq 0',
external=True,
)
else:
session.run(*pylint_command)
@nox.session
def codestyle(session):
session.install('pre-commit')
session.run('pre-commit', 'run', '--all-files', '--show-diff-on-failure')
@nox.session
def js_tests(session):
session.install('nodeenv')
session.run('nodeenv', '--prebuilt', '--python-virtualenv')
session.run('npm', 'install', 'vite', 'vitest', 'happy-dom', '@vitest/coverage-v8')
session.run(
'npx',
'vitest',
'--run',
'--coverage',
)

View File

@ -1,6 +0,0 @@
#!/bin/bash
pip install $*
nodeenv --prebuilt --python-virtualenv
source $VIRTUAL_ENV/bin/activate # source again to activate npm from env
npm install vite vitest happy-dom @vitest/coverage-v8

93
tox.ini
View File

@ -1,93 +0,0 @@
[tox]
toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/combo/{env:BRANCH_NAME:}
envlist = coverage-py3-django32-codestyle, pylint, vitest
[testenv]
usedevelop = True
setenv =
DJANGO_SETTINGS_MODULE=combo.settings
COMBO_SETTINGS_FILE=tests/settings.py
TOX_WORK_DIR={toxworkdir}
SETUPTOOLS_USE_DISTUTILS=stdlib
NUMPROCESSES={env:NUMPROCESSES:1}
coverage: COVERAGE=--cov-report xml --cov-report html --cov=combo/ --cov-config .coveragerc -v
DB_ENGINE=django.db.backends.postgresql_psycopg2
passenv =
BRANCH_NAME
deps =
django32: django>=3.2,<3.3
pywebpush
pytest-cov
pytest-django
pytest-freezegun
pytest-xdist
pytest!=5.3.3
WebTest
mock<4
httmock
pylint<3
astroid<3
pylint-django
django32: django-webtest
pyquery
django32: psycopg2-binary
django-mellon>=1.13
vobject
django-ratelimit<3
djangorestframework>=3.12,<3.13 # matching debian bullseye
git+https://git.entrouvert.org/entrouvert/debian-django-ckeditor.git
git+https://git.entrouvert.org/entrouvert/publik-django-templatetags.git
pre-commit
uwsgidecorators
responses
allowlist_externals =
./getlasso3.sh
commands =
./getlasso3.sh
python manage.py compilemessages
py.test {env:COVERAGE:} {posargs: --numprocesses {env:NUMPROCESSES:1} --junitxml=junit-{envname}.xml tests/}
codestyle: pre-commit run --all-files --show-diff-on-failure
[testenv:pylint]
setenv =
DJANGO_SETTINGS_MODULE=combo.settings
COMBO_SETTINGS_FILE=tests/settings.py
TOX_WORK_DIR={toxworkdir}
SETUPTOOLS_USE_DISTUTILS=stdlib
DB_ENGINE=django.db.backends.postgresql_psycopg2
NUMPROCESSES={env:NUMPROCESSES:1}
deps =
pytest-django
pytest-freezegun
pytest!=5.3.3
WebTest
mock<4
httmock
django-mellon>=1.13
pylint<3
astroid<3
pylint-django
django-webtest
pyquery
psycopg2-binary
lxml
git+https://git.entrouvert.org/debian/django-ckeditor.git
git+https://git.entrouvert.org/publik-django-templatetags.git
uwsgidecorators
responses
allowlist_externals =
./getlasso3.sh
./pylint.sh
commands =
./getlasso3.sh
./pylint.sh combo/ tests/
[testenv:vitest]
deps = nodeenv
allowlist_externals =
bash
npx
install_command = bash setup-vitest.sh {packages}
setenv =
NODE_PATH={envdir}/lib/node_modules
commands = npx vitest --run --coverage