File: convert_typecomments.sh

package info (click to toggle)
sardana 3.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 53,360 kB
  • sloc: python: 82,335; makefile: 118; sh: 61; javascript: 24
file content (47 lines) | stat: -rw-r--r-- 1,758 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash

function convert_types {
    # Convert the various styles of typing found in docstrings into
    # actual typing types.
    sed -r -i \
        -e '/# type:/s/`([^`]+)`/\1/g' \
        -e '/# type:/s/~//g' \
        -e '/# type:/s/<>//g' \
        -e '/# type:/s/:obj://g' \
        -e '/# type:/s/:py:obj://g' \
        -e '/# type:/s/:class://g' \
        -e '/# type:/s/:exc://g' \
        -e '/# type:/s/obj://g' \
        -e '/# type:/s/boolean/bool/g' \
        -e '/# type:/s/string/str/g' \
        -e '/# type:/s/:pystr/str/g' \
        -e '/# type:/s/callable/Callable/g' \
        -e '/# type:/s/seq<([^>]+)>/Sequence[\1]/g' \
        -e '/# type:/s/sequence<([^\\>]+)>/Sequence[\1]/g' \
        -e '/# type:/s/list ?<([^\\>]+)\\?>/List[\1]/g' \
        -e '/# type:/s/list\(([^\\>]+)\)/List[\1]/g' \
        -e '/# type:/s/set ?<([^\\>]+)\\?>/Set[\1]/g' \
        -e '/# type:/s/dict ?<([^\\>]+)\\?>/Dict[\1]/g' \
        -e '/# type:/s/dict ?\{([a-z]+): ?([a-z]+)\}/Dict[\1, \2]/g' \
        -e '/# type:/s/dict/Dict/g' \
        -e '/# type:/s/<list>/List/g' \
        -e '/# type:/s/list/List/g' \
        -e '/# type:/s/tuple<([^>]+)\\?>/Tuple[\1]/g' \
        -e '/# type:/s/tuple\(([^>]+)\)/Tuple[\1]/g' \
        -e '/# type:/s/iter ?<([^\\>]+)\\?>/Iterator[\1]/g' \
        -e '/# type:/s/position\(float\?\) ?/float/g' \
        -e '/# type:/s/value\(float\?\) ?/float/g' \
        -e '/# type:/s/([][A-Za-z.]+) or None/Optional[\1]/g' \
        -e '/# type:/s/([][A-Za-z.]+) or ([][A-Za-z.]+)/Union[\1, \2]/g' \
        $1
}

DOCTYPED_MODULES=$(rgrep -Icl "    :r\?type" src/sardana)

for MODULE in ${DOCTYPED_MODULES[@]}
do
    echo $MODULE
    doc484 $MODULE -f rest -w
    convert_types $MODULE
    com2ann $MODULE
done