1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Demo of Python codegen for simpler imports and API
|
4 | # With backward compatibility
|
5 | #
|
6 | # Usage:
|
7 | # asdl/demo.sh <function name>
|
8 |
|
9 | set -o nounset
|
10 | set -o pipefail
|
11 | set -o errexit
|
12 |
|
13 | py-api() {
|
14 | local pkg=_tmp/runtime_asdl
|
15 |
|
16 | mkdir -v -p $pkg
|
17 |
|
18 | touch _tmp/__init__.py
|
19 |
|
20 | cat >$pkg/__init__.py <<EOF
|
21 | class value_t(object):
|
22 | pass
|
23 |
|
24 | class value_e(object):
|
25 | pass
|
26 |
|
27 | class value(object):
|
28 | class Str(value_t):
|
29 | pass
|
30 |
|
31 | # Do all the aliases LAST
|
32 | #from .value import Str as value__Str
|
33 |
|
34 | EOF
|
35 |
|
36 | cat >$pkg/value.py <<EOF
|
37 |
|
38 | #from . import value_t
|
39 | #
|
40 | #class Str(value_t):
|
41 | # pass
|
42 | EOF
|
43 |
|
44 |
|
45 | PYTHONPATH=_tmp python2 -c '
|
46 | #from _tmp.runtime_asdl import value, value_e, value_t
|
47 | #from _tmp.runtime_asdl import value__Str
|
48 |
|
49 | from _tmp.runtime_asdl import value, value_e, value_t
|
50 |
|
51 |
|
52 | print(value)
|
53 |
|
54 | print(value.Str)
|
55 | #print(value.Str.__bases__)
|
56 |
|
57 | #print(value__Str)
|
58 |
|
59 | print()
|
60 |
|
61 | print(value_e)
|
62 | print(value_t)
|
63 | '
|
64 |
|
65 | python3 -m mypy _tmp/runtime_asdl/{__init__,value}.py
|
66 | }
|
67 |
|
68 | "$@"
|