Skip to main content

scriptgen

Repo Version PyPI PyPI - Python Version PyPI - Status PyPI - License PyPI - Format Downloads

A collection of script generation helpers and templates.

Installation

pip install scriptgen

Usage

from scriptgen import StringBuilder


if __name__ == "__main__":
    # Create a StringBuilder instance.
    sb = StringBuilder()

    sb.wt("Hello ")  # write text "Hello "
    sb.wl("World!")  # write line "World!\n"

    print(str(sb))
Hello World!


from scriptgen import StringBuilder

from scriptgen.templates.csharp import \
    csharp_usings, \
    csharp_namespace, \
    csharp_class, \
    csharp_method


if __name__ == "__main__":
    # Create a StringBuilder instance.
    sb = StringBuilder()

    # Write using statements.
    sb.wb(csharp_usings(
        "System"
    ))

    # Add a new line after the using statements.
    sb.nl()

    # Create a namespace StringBuilder instance.
    ns = csharp_namespace("Sample")

    # Create a class StringBuilder instance.
    c = csharp_class(
        class_name="Program",
        access_modifier="public"
    )

    # Create a method StringBuilder instance.
    m = csharp_method(
        method_name="Main",
        access_modifier="public static",
        return_type="int"
    )

    # Write the following lines inside the method.
    m.wl('Console.WriteLine("Hello World!");')
    m.wl("return 0;")

    c.wb(m)  # Write the method inside the class.
    ns.wb(c)  # Write the class inside the namespace.
    sb.wb(ns)  # Write the namespace.

    print(str(sb))
using System;

namespace Sample
{
    public class Program
    {
        public static int Main()
        {
            Console.WriteLine("Hello World!");
            return 0;
        }
    }
}

from scriptgen import StringBuilder

from scriptgen.templates.csharp import \
    csharp_autogen, \
    csharp_namespace, \
    csharp_class, \
    csharp_region


if __name__ == "__main__":
    # Get version from arguments..
    # i.e. python script.py -major 0 -minor 0 -patch 1
    major: int = 0
    minor: int = 0
    patch: int = 1

    # Create a StringBuilder instance.
    sb = StringBuilder()

    # Write timestamp.
    sb.wb(csharp_autogen())

    # Add a new line after the using statements.
    sb.nl()

    # Create a namespace StringBuilder instance.
    ns = csharp_namespace("Sample")

    # Create a class StringBuilder instance.
    c = csharp_class(
        class_name="BuildInfo",
        access_modifier="public static partial"
    )

    # Create a "Constants" region StringBuilder instance.
    r = csharp_region("Constants")

    # Write the following lines inside the "Constants" region.
    r.wl(f"public const int MAJOR = {major};")
    r.nl()
    r.wl(f"public const int MINOR = {minor};")
    r.nl()
    r.wl(f"public const int PATCH = {patch};")

    c.wb(r)  # Write the region inside the class.
    ns.wb(c)  # Write the class inside the namespace.
    sb.wb(ns)  # Write the namespace.

    print(str(sb))
// Auto-generated: 2020-03-15T04:20:47.909851

namespace Sample
{
    public static partial class BuildInfo
    {
        #region Constants

        public const int MAJOR = 0;

        public const int MINOR = 0;

        public const int PATCH = 1;

        #endregion Constants
    }
}

Look at this script to see its practical use case.

Contribution

Suggestions and contributions are always welcome. Make sure to read the Contribution Guidelines file for more information before submitting a pull request.

License

scriptgen is released under the MIT License. See the LICENSE file for details.

Changelog

v0.0.5

  • Fixed multiple new lines in Windows.
  • Added more C# templates.

v0.0.4

  • Added XML templates.

v0.0.3

  • Added index parameter in filter_func.
  • Changed from current working path to file directory path in gen_docs.py script.

v0.0.2

  • Added default values for the builder classes.
  • Added optional parameters.
  • Exposed CSharpBlockBuilder class in scriptgen.templates.csharp package.
  • Bug fixes.

v0.0.1

  • Added IndentType, StringBuilder, and BlockBuilder classes.
  • Added diff_lines, diff_text, interpolate_text, timestamp, and write_text_file utility methods.
  • Added C# and Markdown templates.
  • Added tests for the utility methods, C# templates, and Markdown templates.
  • Added gen_docs.py script and template files.

Metadata

Release files for scriptgen 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scriptgen 0.0.5
File Size Uploaded Provenance
scriptgen-0.0.5.tar.gz 12.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for scriptgen 0.0.5
File Interpreter ABI Platform
scriptgen-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 23.7 kB

Release files / scriptgen-0.0.5.tar.gz

Download URL scriptgen-0.0.5.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
efff45ba600d02e9b367aebacf5d3a2e59fd84dc41c5533a7d87ed6322adbecd
BLAKE2b-256 checksum
How to use checksums
b1ac3dd391321e5aeddf19d32a47c4fc7ec432b16c31c3fb43d67134edd0850d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.0

Release files / scriptgen-0.0.5-py3-none-any.whl

Download URL scriptgen-0.0.5-py3-none-any.whl
Size 11.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d4c1832a1065224dfe4d35217bdce7a24525a691c629b8e9392d21a69975f9b8
BLAKE2b-256 checksum
How to use checksums
e08df1240f3681eccd105a4dd50ba3e72de9208fbaaa0e1fe1fc529f516dec17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.0

Security for scriptgen 0.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page