Skip to main content

A utility for generating variations of source code for docmentation

Project description

pear

A utility for generating variations source code for docmentation.

In documentation you might want to show the growth of a file over time. However, if you want to keep only one copy of the source code. Consider the following file:

class Foo:
    def __init__(self, name):
        self.name = name

    def reverse_name(self):
        return self.name.reverse()

If we can to incrementally build the file, we might write the constructor first and reverse_name second. That means we would want two versions of the file:

class Foo:
    def __init__(self, name):
        self.name = name
class Foo:
    # constructor

    def reverse_name(self):
        return self.name.reverse()

Using pear you can accomplush this.

Usage

Include a pear.json file in your root directory with the necessary configurations. For our above example, we would have:

{
    "out": "out",
    "files": [
        {
            "path": "foo.py",
            "tag": "without_reverse_name",
            "layers": [
                {
                    "type": "remove",
                    "start": 4,
                    "end": 6
                }
            ]
        },
        {
            "path": "foo.py",
            "tag": "constructor_comment",
            "layers": [
                {
                    "type": "replace",
                    "start": 2,
                    "end": 3,
                    "replacement": [
                        "    # constructor"
                    ]
                }
            ]
        }
    ]
}

Then call pear from the same directory. This will generate foo.py_without_reverse_name and foo.py_constructor_comment files in out/.

Project details


Download files

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

Source Distribution

pear-cli-0.1.0.tar.gz (5.5 kB view hashes)

Uploaded Source

Built Distribution

pear_cli-0.1.0-py3-none-any.whl (5.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page