Skip to content

Commit fbf4b2d

Browse files
authored
[enh] Add ./ynh-dev lint PACKAGE command (#87)
* [enh] Add ./ynh-dev lint PACKAGE command * [fix] Bash linter * [fix] Bash linter * [fix] Bash linter
1 parent 07c5259 commit fbf4b2d

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

ynh-dev

Lines changed: 57 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,59 @@ 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+
/ynh-dev/package_linter/venv/bin/pip install -r requirements.txt
488+
popd
489+
fi
490+
}
491+
function run_linters()
492+
{
493+
assert_inside_vm
494+
local PACKAGES=("$@")
495+
for PACKAGE in "${PACKAGES[@]}"; do
496+
case $PACKAGE in
497+
yunohost)
498+
install_tox
499+
pushd /ynh-dev/yunohost
500+
/root/.local/bin/tox run
501+
/root/.local/bin/tox run -e py311-mypy
502+
popd
503+
;;
504+
moulinette)
505+
install_tox
506+
pushd /ynh-dev/moulinette
507+
/root/.local/bin/tox run
508+
/root/.local/bin/tox run -e py311-mypy
509+
popd
510+
;;
511+
ssowat|yunohost-portal|yunohost-admin)
512+
echo "Linter not implemented for $PACKAGE"
513+
;;
514+
*)
515+
install_package_linter
516+
pushd "/ynh-dev/apps/$PACKAGE"
517+
/ynh-dev/package_linter/venv/bin/python3 /ynh-dev/package_linter/package_linter.py "/ynh-dev/apps/$PACKAGE"
518+
popd
519+
;;
520+
521+
esac
522+
done
523+
}
524+
468525
function run_tests()
469526
{
470527
assert_inside_vm

0 commit comments

Comments
 (0)