Refactor the Python identifiers update script for better flexibility
[geany-mirror.git] / scripts / update-python-identifiers.sh
blob37d84347e7165a4473f38d6e6d20acfb03ea3912
1 #!/bin/sh
3 # Author: Colomban Wendling <colomban@geany.org>
4 # License: GPL v2 or later
6 # Updates the `identifiers` entry in data/filetypes.python.
7 # Requires both Python 2 and 3.
9 set -e
11 file=data/filetypes.python
13 [ -f "$file" ]
15 py_2_and_3() {
16 python2 "$@" && python3 "$@"
19 # sort_filter [exclude...]
20 sort_filter() {
21 python -c '\
22 from sys import stdin; \
23 items=set(stdin.read().strip().split("\n")); \
24 exclude=['"$(for a in "$@"; do printf "'%s', " "$a"; done)"']; \
25 print(" ".join(sorted([i for i in items if i not in exclude])))
29 builtins=$(py_2_and_3 -c 'print("\n".join(dir(__builtins__)))')
31 # builtins, but excluding keywords that are already listed in primary=
32 identifiers=$(echo "$builtins" | sort_filter False None True exec)
34 sed -e "s/^identifiers=.*$/identifiers=$identifiers/" -i "$file"