Skip to content

Commit d7a6356

Browse files
committed
validate-input: add python input validator
Signed-off-by: Masatake YAMATO <[email protected]>
1 parent d48558f commit d7a6356

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python

misc/validators/validator-python

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- sh -*-
2+
# validator-python --- validating Python input files
3+
#
4+
# Copyright (c) 2025, Masatake YAMATO
5+
#
6+
# This program is free software; you can redistribute it and/or
7+
# modify it under the terms of the GNU General Public License
8+
# as published by the Free Software Foundation; either version 2
9+
# of the License, or (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program; if not, write to the Free Software
18+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19+
# USA.
20+
PYTHON=${PYTHON:-python}
21+
action=$1
22+
input=$2
23+
24+
case "$action" in
25+
is_runnable)
26+
type ${PYTHON} > /dev/null 2>&1
27+
exit $?
28+
;;
29+
validate)
30+
${PYTHON} -m py_compile "$input"
31+
s=$?
32+
d=$(dirname "$input")
33+
b=$(basename "$input" .py)
34+
rm $d/__pycache__/$b*pyc
35+
rmdir $d/__pycache__
36+
exit $s
37+
;;
38+
esac

0 commit comments

Comments
 (0)