Skip to main content
Help improve PyPI by participating in a 5-minute user interface survey!

source code generation library (with overuse with-syntax)

Project Description

https://travis-ci.org/podhmo/prestring.svg?branch=master

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.4.7

  • add prestring.output.SeparatedOutput
  • LazyKeywords is sorted

0.4.3

  • clear if empty (e.g. go-module’s import_group)

0.4.2

  • bug fix LazyArgumentsAndKeywords

0.4

  • more lazy (python module)
  • lazy object is cached

0.3.3

  • goname function

0.3.1

  • more lazy (go module)

0.3.0

  • go code output support

Release history Release notifications

This version
History Node

0.4.9.2

History Node

0.4.9.1

History Node

0.4.9

History Node

0.4.8

History Node

0.4.7.2

History Node

0.4.7.1

History Node

0.4.7

History Node

0.4.6

History Node

0.4.5

History Node

0.4.4

History Node

0.4.3

History Node

0.4.2

History Node

0.4.1

History Node

0.4

History Node

0.3.3

History Node

0.3.2

History Node

0.3.1

History Node

0.3.0

History Node

0.2.5

History Node

0.2.4

History Node

0.2.3

History Node

0.2.2

History Node

0.2.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
prestring-0.4.9.2-py2.py3-none-any.whl (11.9 kB) Copy SHA256 hash SHA256 Wheel py2.py3 Sep 9, 2017
prestring-0.4.9.2.tar.gz (9.3 kB) Copy SHA256 hash SHA256 Source None Sep 9, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page