Ignore generated file src/geany_private.res
[geany-mirror.git] / scripts / update-python-identifiers.sh
blob6049c941e872bd0c8559ae5b31f61f0a56e96397
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 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"