misc: switch from tox to nox (#84136) #884

Open
csechet wants to merge 1 commits from wip/84136-passage-a-nox into main
5 changed files with 116 additions and 42 deletions

2
Jenkinsfile vendored
View File

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

View File

@ -1,20 +0,0 @@
#!/bin/sh
# Get venv site-packages path
DSTDIR=`python -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 python -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 $SRCDIR/lasso.py $DSTDIR
ln -sv $SRCDIR/_lasso.* $DSTDIR
exit 0

View File

@ -1,17 +0,0 @@
#!/bin/sh
# Get venv site-packages path
DSTDIR=`python3 -c 'import sysconfig; print(sysconfig.get_path("platlib"))'`
# 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
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',
'.',
'pytest>=3.6',
'WebTest',
'responses',
'pyzbar',
'schwifty',
'mechanize',
f'django{django_version}',
*packages,
)
get_lasso3(session)
@nox.session()
@nox.parametrize('django', ['>=3.2,<3.3'])
def tests(session, django):
setup_venv(
session,
'astroid!=2.5.7',
'bleach<5',
'mock',
'pyquery',
'requests',
'pytest-cov',
'pytest-django',
'pytest-freezegun',
'pytest-xdist',
django_version=django,
)
bdauvergne marked this conversation as resolved Outdated

La partie parallélisation n'a pas été reprise :

    py.test {posargs:-v {env:COVERAGE:} --numprocesses={env:NUMPROCESSES:1} --dist loadfile --junitxml=junit-{envname}.xml tests/} 

(la partie --dist loadfile est importante, et le not session.interactive dessous ne semble pas effectif.

La partie parallélisation n'a pas été reprise : ``` py.test {posargs:-v {env:COVERAGE:} --numprocesses={env:NUMPROCESSES:1} --dist loadfile --junitxml=junit-{envname}.xml tests/} ``` (la partie --dist loadfile est importante, et le `not session.interactive` dessous ne semble pas effectif.
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=wcs/',
'--cov-config',
'.coveragerc',
'-v',
f'--junitxml=junit-coverage.django-{django}.xml',
]
if not session.interactive:
args += ['-v', '--numprocesses', '8']
args += session.posargs
session.run(
*args,
env={
'LANG': 'C',
'LC_ALL': 'C',
'LC_TIME': 'C',
'DJANGO_SETTINGS_MODULE': 'wcs.settings',
'WCS_SETTINGS_FILE': 'tests/settings.py',
'SETUPTOOLS_USE_DISTUTILS': 'stdlib',
},
)
@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 += ['wcs/', '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')

View File

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