Update to latest ctags main
[geany-mirror.git] / scripts / update-python-identifiers.sh
blob4b3586491e1ff48e4299492fe1cceac25969ca09
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/filedefs/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 keywords=$(py_2_and_3 -c 'from keyword import kwlist; print("\n".join(kwlist))')
30 builtins=$(py_2_and_3 -c 'print("\n".join(dir(__builtins__)))')
32 primary=$(echo "$keywords" | sort_filter)
33 # builtins, but excluding keywords that are already listed in primary=
34 identifiers=$(echo "$builtins" | sort_filter $primary)
36 sed -e "s/^primary=.*$/primary=$primary/" \
37 -e "s/^identifiers=.*$/identifiers=$identifiers/" \
38 -i "$file"