misc: use nox instead of tox (#81735)
gitea/lingo/pipeline/head This commit looks good Details

This commit is contained in:
Corentin Sechet 2023-09-28 12:15:26 +02:00
parent 71d23268da
commit ffb4754696
5 changed files with 117 additions and 29 deletions

2
Jenkinsfile vendored
View File

@ -9,7 +9,7 @@ pipeline {
stages {
stage('Unit Tests') {
steps {
sh '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

115
noxfile.py Normal file
View File

@ -0,0 +1,115 @@
import os
import shlex
from functools import partial
from pathlib import Path
import nox
nox.options.sessions = ['tests', 'pylint', 'codestyle']
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'):
session.install(
'-e',
'.',
'WebTest',
'django-webtest',
f'django=={django_version}',
'git+https://git.entrouvert.org/entrouvert/debian-django-ckeditor.git',
'git+https://git.entrouvert.org/publik-django-templatetags.git',
'pyquery',
'pytest!=5.3.3',
*packages,
)
get_lasso3(session)
@nox.session()
@nox.parametrize('django', ['3.2'])
def tests(session, django):
setup_venv(
session,
'django-filter>=2.4,<2.5',
'django-mellon>=1.13',
'psycopg2-binary',
'pytest-cov',
'pytest-django',
'pytest-freezegun',
django_version=django,
)
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=lingo/',
'--cov-config',
'.coveragerc',
'-v',
f'--junitxml=junit-coverage.django-{django}.xml',
]
args += session.posargs
session.run(
*args,
env={
'DJANGO_SETTINGS_MODULE': 'lingo.settings',
'LINGO_SETTINGS_FILE': 'tests/settings.py',
'SETUPTOOLS_USE_DISTUTILS': 'stdlib',
'DB_ENGINE': 'django.db.backends.postgresql_psycopg2',
'BRANCH_NAME': os.environ.get('BRANCH_NAME', ''),
},
)
@nox.session
def pylint(session):
setup_venv(session, 'pylint<3', 'pylint-django')
pylint_command = ['pylint', '-f', 'parseable', '--rcfile', 'pylint.rc']
if not session.posargs:
pylint_command += ['lingo/', 'tests/']
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 bandit(session):
session.install('bandit')
session.run('bandit', '-r', 'lingo')

View File

@ -1,5 +0,0 @@
#!/bin/bash
set -e -x
env
pylint -f parseable --rcfile pylint.rc "$@" | tee pylint.out; test $PIPESTATUS -eq 0

View File

@ -24,7 +24,7 @@ class eo_sdist(sdist):
with open('VERSION', 'w') as fd:
fd.write(version)
with open('lingo/version.py', 'w') as fd:
fd.write('VERSION = %r' % version)
fd.write('VERSION = %r\n' % version)
sdist.run(self)
if os.path.exists('VERSION'):
os.remove('VERSION')