Skip to content

Commit 49d5358

Browse files
committed
[enh] Add ./ynh-dev lint PACKAGE command
1 parent 07c5259 commit 49d5358

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

ynh-dev

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ function show_usage() {
1818
1919
ip Give the ip of the guest container
2020
use-git [PKG] Use Git repositories from dev environment path
21+
lint [PKG] Lint source code from core or app packages.
22+
e.g. ./ynh-dev lint yunohost
23+
e.g. ./ynh-dev lint nextcloud_ynh
2124
test [PKG] Deploy, update and run tests for some packages
2225
Tests for single modules and functions can ran with
2326
e.g. ./ynh-dev test yunohost/appurl:urlavailable
@@ -51,6 +54,7 @@ function main()
5154
ip|--ip) show_vm_ip "${ARGUMENTS[@]}" ;;
5255
use-git|--use-git) use_git "${ARGUMENTS[@]}" ;;
5356
dev|--dev) dev "${ARGUMENTS[@]}" ;;
57+
lint|--lint) run_linters "${ARGUMENTS[@]}" ;;
5458
test|--test) run_tests "${ARGUMENTS[@]}" ;;
5559

5660
catalog|--catalog) catalog "${ARGUMENTS[@]}" ;;
@@ -465,6 +469,61 @@ function dev()
465469

466470
}
467471

472+
function install_tox()
473+
{
474+
if ! type "/root/.local/bin/tox" > /dev/null 2>&1; then
475+
info "> Installing tox ..."
476+
apt-get install pipx -y
477+
pipx install tox
478+
fi
479+
}
480+
function install_package_linter()
481+
{
482+
if [ ! -f /ynh-dev/package_linter/package_linter.py > /dev/null 2>&1 ] ; then
483+
pushd /ynh-dev
484+
git clone https://github.com/YunoHost/package_linter
485+
cd package_linter
486+
python -m venv ./venv
487+
source venv/bin/activate
488+
pip install -r requirements.txt
489+
deactivate
490+
popd
491+
fi
492+
}
493+
function run_linters()
494+
{
495+
assert_inside_vm
496+
local PACKAGES=("$@")
497+
for PACKAGE in "${PACKAGES[@]}"; do
498+
case $PACKAGE in
499+
yunohost)
500+
install_tox
501+
pushd /ynh-dev/yunohost
502+
/root/.local/bin/tox run
503+
/root/.local/bin/tox run -e py311-mypy
504+
popd
505+
;;
506+
moulinette)
507+
install_tox
508+
pushd /ynh-dev/moulinette
509+
/root/.local/bin/tox run
510+
/root/.local/bin/tox run -e py311-mypy
511+
popd
512+
;;
513+
ssowat|yunohost-portal|yunohost-admin)
514+
echo "Linter not implemented for $PACKAGE"
515+
;;
516+
*)
517+
install_package_linter
518+
pushd /ynh-dev/apps/$PACKAGE
519+
/ynh-dev/package_linter/venv/bin/python3 /ynh-dev/package_linter/package_linter.py /ynh-dev/apps/$PACKAGE
520+
popd
521+
;;
522+
523+
esac
524+
done
525+
}
526+
468527
function run_tests()
469528
{
470529
assert_inside_vm

0 commit comments

Comments
 (0)