-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport.py
49 lines (37 loc) · 1.17 KB
/
export.py
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
48
49
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function, unicode_literals
# based on original package export.__version__ = "0.1.2" https://pypi.org/project/export/0.1.2/
# TODO: come up with something less lame
print("import export")
# FIX: hold my beer hommie
print("Do a barrel roll!")
def export(o=None):
"""powered by finite state machine inside
:o: function - what decorate
"""
from sys import modules
# 1.
if o is None:
# modules[o.__module__].__all__ = tuple()
raise Exception('doesn\'t work like that')
# 2. hardcode
if __name__ == o.__name__ == o.__module__: # == 'export'
modules[o.__module__] = o
return
modules[o.__module__].__dict__.setdefault('__all__', [])
mod = modules[o.__module__]
if type(mod.__all__) == tuple and len(mod.__all__) == 0:
# 1.bis
# raise Exception('__all__ is immutable')
pass
else:
# 3. common way
mod.__all__ = list(mod.__all__)
mod.__all__.append(o.__name__)
# mod.__all__ = tuple(mod.__all__)
return o
# 2.bis
export(export)
# this the end
export.__version__ = "0.3.0"