Add a script to update Python filetype's identifiers list
[geany-mirror.git] / scripts / update-python-identifiers.sh
blobade59fab6ea1278accf0ef427556272684a57b98
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 py2_builtins=$(python2 -c 'print("\n".join(dir(__builtins__)))')
16 py3_builtins=$(python3 -c 'print("\n".join(dir(__builtins__)))')
18 # merge Python 2 and 3 keywords but exclude the ones that are already listed primary=
19 identifiers=$( (echo "$py2_builtins" && echo "$py3_builtins") | python -c '\
20 from sys import stdin; \
21 builtins=set(stdin.read().strip().split("\n")); \
22 exclude=["False", "None", "True", "exec"]; \
23 print(" ".join(sorted([i for i in builtins if i not in exclude])))
26 sed -e "s/^identifiers=.*$/identifiers=$identifiers/" -i "$file"