source code generation library (with overuse with-syntax)
Project description
this is heavily inspired by srcgen .
(todo: gentle introduction)
features
generating code with with-syntax
string injection after writing string
generating code with with-syntax
from prestring.python import PythonModule
m = PythonModule()
with m.class_("Point", metaclass="InterfaceMeta"):
with m.def_("__init__", "self", "value"):
m.stmt("self.value = value")
with m.def_("__str__", "self"):
m.return_("self.value")
output is.
class Point(object, metaclass=InterfaceMeta)
def __init__(self, value):
self.value = value
def __str__(self):
return self.value
string injection after writing string
from prestring.python import PythonModule
m = PythonModule()
with m.def_("setup", "config"):
import_area = m.submodule()
m.sep()
for k in ["a", "b", "c", "d", "e"]:
import_area.stmt("from .plugins import {k}_plugin", k=k)
m.stmt("config.activate({}_plugin)", k)
print(m)
def setup(config):
from .plugins import(
a_plugin,
b_plugin,
c_plugin,
d_plugin,
e_plugin
)
config.activate(a_plugin)
config.activate(b_plugin)
config.activate(c_plugin)
config.activate(d_plugin)
config.activate(e_plugin)
0.3.1
more lazy (go module)
0.3.0
go code output support
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
prestring-0.3.1.tar.gz
(8.3 kB
view hashes)
Built Distribution
Close
Hashes for prestring-0.3.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 735af03aa07d73664de97e107c72a4c384b4825555e5c7fa2b450d427b507fc2 |
|
MD5 | 99c99fb176d664997ffc6f7a2681a67c |
|
BLAKE2b-256 | 82297692c5cef2ff1cef6d9d08081a4c0f4af13ab923c11d1e40fc8d87f403ad |