Skip to content

chiptopher/pear

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 accomplish 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/.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors