Replace generated directory modules with simply files

This commit is contained in:
Lonami Exo 2017-09-04 13:51:47 +02:00
parent 7eab28206b
commit e83b250a22

View File

@ -114,37 +114,29 @@ class TLGenerator:
@staticmethod @staticmethod
def _write_init_py(out_dir, depth, namespace_tlobjects, type_constructors): def _write_init_py(out_dir, depth, namespace_tlobjects, type_constructors):
# namespace_tlobjects: {'namespace', [TLObject]} # namespace_tlobjects: {'namespace', [TLObject]}
os.makedirs(out_dir, exist_ok=True)
for ns, tlobjects in namespace_tlobjects.items(): for ns, tlobjects in namespace_tlobjects.items():
# Path depth to perform relative import file = os.path.join(out_dir, ns + '.py' if ns else '__init__.py')
current_depth = depth with open(file, 'w', encoding='utf-8') as f, \
if ns: SourceBuilder(f) as builder:
current_depth += 1 # Add the relative imports to the namespaces,
init_py = os.path.join(out_dir, ns) # unless we already are in a namespace.
else: if not ns:
init_py = out_dir builder.writeln('from . import {}'.format(', '.join(
x for x in namespace_tlobjects.keys() if x
)))
os.makedirs(init_py, exist_ok=True) # Generate the class for every TLObject
init_py = os.path.join(init_py, '__init__.py') for t in tlobjects:
with open(init_py, 'w', encoding='utf-8') as file: # Omit core types, they're embedded in the code
with SourceBuilder(file) as builder: if t.is_core_type():
# Add the relative imports to the namespaces, continue
# unless we already are in a namespace.
if not ns:
builder.writeln('from . import {}'.format(', '.join(
x for x in namespace_tlobjects.keys() if x
)))
# Generate the class for every TLObject TLGenerator._write_source_code(
for t in tlobjects: t, builder, depth, type_constructors
# Omit core types, they're embedded in the code )
if t.is_core_type(): while builder.current_indent != 0:
continue builder.end_block()
TLGenerator._write_source_code(
t, builder, current_depth, type_constructors
)
while builder.current_indent != 0:
builder.end_block()
@staticmethod @staticmethod
def _write_source_code(tlobject, builder, depth, type_constructors): def _write_source_code(tlobject, builder, depth, type_constructors):