snipinator


Namesnipinator JSON
Version 1.3.1 PyPI version JSON
download
home_pageNone
SummaryPython code snippets for markdown files, e.g READMEs, from actual (testable) code.
upload_time2024-04-22 15:34:30
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License Copyright (c) 2024 Azriel Fasten. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords github testing markdown readme snippets documentation jinja2 templates preprocessor documentation-tool include readme-template readme-md dynamic-documentation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <!--

WARNING: This file is auto-generated by snipinator. Do not edit directly.
SOURCE: `README.md.jinja2`.

-->
<!--




-->

# <div align="center">![Snipinator][22]</div>

<div align="center">

<!-- Icons from https://lucide.dev/icons/users -->
<!-- Icons from https://lucide.dev/icons/laptop-minimal -->

![**Audience:** Developers][19] ![**Platform:** Linux][20]

</div>

<p align="center">
  <strong>
    <a href="#-features">๐ŸŽ‡Features</a> &nbsp;&bull;&nbsp;
    <a href="#-installation">๐Ÿ› ๏ธInstallation</a> &nbsp;&bull;&nbsp;
    <a href="#-usage">๐Ÿ”งUsage</a> &nbsp;&bull;&nbsp;
    <a href="#-command-line-options">๐Ÿ’ปCLI</a> &nbsp;&bull;&nbsp;
    <a href="#-examples">๐Ÿ’กExamples</a> &nbsp;&bull;&nbsp;
    <a href="#-api">๐Ÿค–API</a> &nbsp;&bull;&nbsp;
    <a href="#-requirements">โœ…Requirements</a> &nbsp;&bull;&nbsp;
    <a href="#-gotchas-and-limitations">๐ŸšธGotchas</a>
  </strong>
</p>

<div align="center">

![Top language][9] [![GitHub License][3]][21] [![PyPI - Version][4]][5]
[![Python Version][8]][5]

**CLI to embed (testable) snippets from your codebase into your README**

</div>

---

<div align="center">

|                   | Status                     | Stable                    | Unstable                  |                    |
| ----------------- | -------------------------- | ------------------------- | ------------------------- | ------------------ |
| **[Master][17]**  | [![Build and Test][1]][2]  | [![since tagged][6]][10]  |                           | ![last commit][7]  |
| **[Develop][18]** | [![Build and Test][11]][2] | [![since tagged][12]][13] | [![since tagged][15]][16] | ![last commit][14] |

</div>

<img src=".github/demo.gif" alt="Demo" width="100%">

## โ” What

What it does: **Snipinator** lets you take a `EXAMPLE.md` template and include
snippets from your (working and tested) codebase.

Turn this ([./snipinator/examples/EXAMPLE.md.jinja2](./snipinator/examples/EXAMPLE.md.jinja2)):

<!---->
```md
# A README

Here is a code snippet:

<!--{{ pysnippet(path='snipinator/examples/code.py', symbol='MyClass', backtickify='py', decomentify='nl') }}-->

Note that `code.py` has a test:
{{path('./snipinator/examples/code_test.py', link='md')}}.

```
<!---->

Into this ([./snipinator/examples/EXAMPLE.generated.md](./snipinator/examples/EXAMPLE.generated.md)):

<!---->
````md
<!--

WARNING: This file is auto-generated by snipinator. Do not edit directly.
SOURCE: `snipinator/examples/EXAMPLE.md.jinja2`.

-->
# A README

Here is a code snippet:

<!---->
```py
class MyClass:
  """This is a global class"""

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

  def MyClassMethod(self):
    """This is a method of MyClass"""
    print(self.name)
```
<!---->

Note that `code.py` has a test:
[./snipinator/examples/code_test.py](./snipinator/examples/code_test.py).

````
<!---->

## ๐ŸŽ‡ Features

- ๐Ÿ“ฆโœ…๐Ÿช„ Supports anything **[Jinja2](https://github.com/pallets/jinja)**
  supports.
- ๐Ÿฅ‡๐Ÿ๐Ÿ“œ First-class support for **python** source code.
  - Can include python function signatures, docstrings, entire function source
    code, classes.
- โœ‚๐ŸŒ๐Ÿ—‚๏ธ Snip from **any source code language**.
  - Put delimiter markers into the code (e.g `# START_SNIPPET`,
    `# END_TEMPLATE`), and use [snippet()](#snippet).
- ๐Ÿฅ‡๐Ÿ”–๐Ÿ“œ First-class support for **Markdown** templates (with `backtickify`,
  `decomentify`).
- ๐Ÿ“ฆ๐Ÿš๐Ÿ–จ๏ธ Can include **[shell](#shell) output**.
  - Supports ANSI colors :heart: :green_heart: :blue_heart: with SVG output
    :camera:.
- โš™๏ธ๐Ÿ”—๐Ÿ—ƒ๏ธ More robust **references/links** to local files using [path()](#path).

## ๐Ÿ› ๏ธ Installation

```bash
# Install from pypi (https://pypi.org/project/snipinator/)
pip install snipinator

# Install from git (https://github.com/realazthat/snipinator)
pip install git+https://github.com/realazthat/snipinator.git@v1.3.1
```

## ๐Ÿ”ง Usage

Example template README:
([./snipinator/examples/EXAMPLE.md.jinja2](./snipinator/examples/EXAMPLE.md.jinja2)):

<!---->
```md
# A README

Here is a code snippet:

<!--{{ pysnippet(path='snipinator/examples/code.py', symbol='MyClass', backtickify='py', decomentify='nl') }}-->

Note that `code.py` has a test:
{{path('./snipinator/examples/code_test.py', link='md')}}.

```
<!---->

Generating the README:

<!---->
````bash
$ python -m snipinator.cli -t snipinator/examples/EXAMPLE.md.jinja2
<!--

WARNING: This file is auto-generated by snipinator. Do not edit directly.
SOURCE: `snipinator/examples/EXAMPLE.md.jinja2`.

-->
# A README

Here is a code snippet:

<!---->
```py
class MyClass:
  """This is a global class"""

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

  def MyClassMethod(self):
    """This is a method of MyClass"""
    print(self.name)
```
<!---->

Note that `code.py` has a test:
[./snipinator/examples/code_test.py](./snipinator/examples/code_test.py).

````
<!---->

## ๐Ÿ’ป Command Line Options

<!---->
<img src="README.help.generated.svg" alt="Output of `python -m snipinator.cli --help`" />
<!---->

## ๐Ÿ’ก Examples

- Snipinator's own `README`:
  - Template: [./README.md.jinja2](./README.md.jinja2).
  - Generated: [./README.md](./README.md).
  - Generation script: [./scripts/generate-readme.sh](./scripts/generate-readme.sh).
- Example:
  - Template: [./snipinator/examples/EXAMPLE.md.jinja2](./snipinator/examples/EXAMPLE.md.jinja2).
  - Generated:
    [./snipinator/examples/EXAMPLE.generated.md](./snipinator/examples/EXAMPLE.generated.md).
  - Generation script: [./snipinator/examples/example.sh](./snipinator/examples/example.sh).
- Long example of many features:
  - Template:
    [./snipinator/examples/LONG-EXAMPLE.md.jinja2](./snipinator/examples/LONG-EXAMPLE.md.jinja2).
  - Generated:
    [./snipinator/examples/LONG-EXAMPLE.generated.md](./snipinator/examples/LONG-EXAMPLE.generated.md).
  - Generation script:
    [./snipinator/examples/long-example.sh](./snipinator/examples/long-example.sh).
- Projects using Snipinator:
  - [github.com/realazthat/snipinator](https://github.com/realazthat/snipinator),
    See
    [snipinator/README.md.jinja2](https://github.com/realazthat/snipinator/blob/61cb88593baa099dc375cf5fd40679e4be673fc5/README.md.jinja2).
  - [github.com/realazthat/changeguard](https://github.com/realazthat/changeguard),
    See
    [changeguard/README.md.jinja2](https://github.com/realazthat/changeguard/blob/87d5104b52e651bb9195a3d46dd7f050acbcb534/README.md.jinja2).
  - [github.com/realazthat/comfy-catapult](https://github.com/realazthat/comfy-catapult),
    See
    [comfy-catapult/README.md.jinja2](https://github.com/realazthat/comfy-catapult/blob/ff353d48b25fa7b9c35fa11b31d5f2b3039c41c8/README.md.jinja2).
  - [github.com/realazthat/comfylowda](https://github.com/realazthat/comfylowda),
    See
    [comfylowda/README.md.jinja2](https://github.com/realazthat/comfylowda/blob/e01a32c38107aa0b89ccea21c4678d193a186a78/README.md.jinja2).
  - [github.com/realazthat/excalidraw-brute-export-cli](https://github.com/realazthat/excalidraw-brute-export-cli),
    See
    [excalidraw-brute-export-cli/README.md.jinja2](https://github.com/realazthat/excalidraw-brute-export-cli/blob/54a3b5b08b644e61c721ab565c576094234c5cc7/README.md.jinja2).

## ๐Ÿค– API

(Jinja2) Functions made available:

### pysnippet

Used several times in
[./snipinator/examples/LONG-EXAMPLE.md.jinja2](./snipinator/examples/LONG-EXAMPLE.md.jinja2).

Documentation:

<!---->
```py
def pysnippet(path: str,
              symbol: Optional[str],
              *,
              escape: bool = False,
              indent: Union[str, int, None] = None,
              backtickify: Union[bool, str] = False,
              decomentify: Union[bool, Literal['nl']] = False,
              _ctx: _Context) -> Union[str, markupsafe.Markup]:
  """Return a python snippet, allowing you to specify a class or function.

  Args:
      path (str): The path to the file.
      symbol (Optional[str]): The symbol to extract. If None, the entire file is
        returned. Defaults to None.
      escape (bool, optional): Should use HTML entities escaping? Defaults to
        False.
      indent (Union[str, int, None], optional): Should indent? By how much, or
        with what prefix? Defaults to None.
      backtickify (Union[bool, str], optional): Should surround with backticks?
        With what language? Defaults to False.
      decomentify (Union[bool, Literal['nl']]): Assuming that you will be using
        HTML comments around this call, setting this to true will add
        correspondingcomments to uncomment the output. This allows you to have
        the Jinja2 call unmolested by markdown formatters, because they will be
        inside of a comment section. "nl" adds additional newlines after the
        newline delimiters. Defaults to False.
      _ctx (_Context): This is used by the system and is not available as an
        argument.

  Returns:
      Union[str, markupsafe.Markup]: The snippet.
  """
```
<!---->

### pysignature

Used several times in [./README.md.jinja2](./README.md.jinja2).

Documentation:

<!---->
```py
def pysignature(path: str,
                symbol: str,
                *,
                escape: bool = False,
                indent: Union[str, int, None] = None,
                backtickify: Union[bool, str] = False,
                decomentify: Union[bool, Literal['nl']] = False,
                _ctx: _Context) -> str:
  """Return the signature of a class or function in a python file.

  Returns the {class,function} signature and the docstring.

  Args:
      path (str): The path to the file.
      symbol (str): The symbol to extract.
      escape (bool, optional): Should use HTML entities escaping? Defaults to
        False.
      indent (Union[str, int, None], optional): Should indent? By how much, or
        with what prefix? Defaults to None.
      backtickify (Union[bool, str], optional): Should surround with backticks?
        With what language? Defaults to False.
      decomentify (Union[bool, Literal['nl']]): Assuming that you will be using
        HTML comments around this call, setting this to true will add
        correspondingcomments to uncomment the output. This allows you to have
        the Jinja2 call unmolested by markdown formatters, because they will be
        inside of a comment section. "nl" adds additional newlines after the
        newline delimiters. Defaults to False.
      _ctx (_Context): This is used by the system and is not available as an
        argument.

  Returns:
      str: The signature and docstring.
  """
```
<!---->

### rawsnippet

Used several times in [./README.md.jinja2](./README.md.jinja2).

Documentation:

<!---->
```py
def rawsnippet(path: str,
               *,
               escape: bool = False,
               indent: Union[str, int, None] = None,
               backtickify: Union[bool, str] = False,
               decomentify: Union[bool, Literal['nl']] = False,
               _ctx: _Context) -> Union[str, markupsafe.Markup]:
  """Return an entire file as a snippet.

  Args:
      path (str): The path to the file.
      escape (bool, optional): Should use HTML entities escaping? Defaults to
        False.
      indent (Union[str, int, None], optional): Should indent? By how much, or
        with what prefix? Defaults to None.
      backtickify (Union[bool, str], optional): Should surround with backticks?
        With what language? Defaults to False.
      decomentify (Union[bool, Literal['nl']]): Assuming that you will be using
        HTML comments around this call, setting this to true will add
        correspondingcomments to uncomment the output. This allows you to have
        the Jinja2 call unmolested by markdown formatters, because they will be
        inside of a comment section. "nl" adds additional newlines after the
        newline delimiters. Defaults to False.
      _ctx (_Context): This is used by the system and is not available as an
        argument.

  Returns:
      Union[str, markupsafe.Markup]: The snippet.
  """

```
<!---->

### snippet

Example in [./snipinator/examples/LONG-EXAMPLE.md.jinja2](./snipinator/examples/LONG-EXAMPLE.md.jinja2).

Documentation:

<!---->
```py
def snippet(path: str,
            start: str,
            end: str,
            *,
            escape: bool = False,
            indent: Union[str, int, None] = None,
            backtickify: Union[bool, str] = False,
            decomentify: Union[bool, Literal['nl']] = False,
            _ctx: _Context) -> Union[str, markupsafe.Markup]:
  """Returns a _delimited_ snippet from a file.

  Does not return the delimiters themselves.

  Args:
      path (str): The path to the file.
      start (str): A string that indicates the start of the snippet.
      end (str): A string that indicates the end of the snippet.
      escape (bool, optional): Should use HTML entities escaping? Defaults to
        False.
      indent (Union[str, int, None], optional): Should indent? By how much, or
        with what prefix? Defaults to None.
      backtickify (Union[bool, str], optional): Should surround with backticks?
        With what language? Defaults to False.
      decomentify (Union[bool, Literal['nl']]): Assuming that you will be using
        HTML comments around this call, setting this to true will add
        correspondingcomments to uncomment the output. This allows you to have
        the Jinja2 call unmolested by markdown formatters, because they will be
        inside of a comment section. "nl" adds additional newlines after the
        newline delimiters. Defaults to False.
      _ctx (_Context): This is used by the system and is not available as an
        argument.

  Returns:
      Union[str, markupsafe.Markup]: The snippet.
  """

```
<!---->

### shell

Used several times in [./README.md.jinja2](./README.md.jinja2).

Documentation:

<!---->
```py
def shell(args: str,
          *,
          escape: bool = False,
          indent: Union[str, int, None] = None,
          backtickify: Union[bool, str] = False,
          decomentify: Union[bool, Literal['nl']] = False,
          rich: Union[Literal['svg'], Literal['img+b64+svg'], Literal['raw'],
                      str] = 'raw',
          rich_alt: Optional[str] = None,
          rich_bg_color: Optional[str] = None,
          rich_term: Optional[str] = None,
          rich_rows: int = 24,
          rich_cols: int = 80,
          include_args: bool = True,
          _ctx: _Context) -> Union[str, markupsafe.Markup]:
  """Run a shell command and return the output.

  Use at your own risk, this can potentially introduce security vulnerabilities.
  Only use if you know what you are doing. Ensure that no untrusted input can
  be injected into the `args` parameter, or, into anything the command might
  access. If an adversary can control the `args` parameter, they can execute
  arbitrary commands on your system.

  Args:
      args (str): The command to run.
      escape (bool, optional): Should use HTML entities escaping? Defaults to
        False.
      indent (Union[str, int, None], optional): Should indent? By how much, or with
        what prefix? Defaults to None.
      backtickify (Union[bool, str], optional): Should surround with backticks? With
        what language? Defaults to False.
      decomentify (bool, optional): Assuming that you will be using HTML
        comments around this call, setting this to true will add corresponding
        uncomments to uncomment the output. This allows you to have the Jinja2
        call unmolested by markdown formatters, because they will be inside of
        a comment section. Defaults to False.
      rich (Union[Literal['svg'], Literal['img+b64+svg'], Literal['raw'], str], optional):
        Optionally outputs colored terminal output as an image.
        * If `rich` is a relative file path that ends with ".svg", the svg will
          be saved to that location and an img tag will be emitted. The path
          will be relative to the template file, which is specified on the
          command line. If the template is from stdin, the path will be relative
          to the current working directory (cwd) which is also specified on the
          command line.
        * If 'svg' a raw svg tag will be dumped into the markdown with the
          colored terminal output. Note that your markdown renderer may not
          support this.
        * If 'img+svg' a base64 encoded image will be dumped into the markdown
          with the colored terminal output.
        * If 'raw' the raw (uncolored) terminal output will be dumped into the
          markdown directly.
        * Defaults to 'raw.
      rich_alt (Optional[str], optional): The alt text for the img tag. Defaults
        to None.
      rich_bg_color (Optional[str], optional): The background color for the terminal
        output. Valid colors include anything valid for SVG colors. See
        <https://developer.mozilla.org/en-US/docs/Web/CSS/color>. Defaults to
        None (fully transparent).
      rich_term: (Optional[str], optional): Sets the TERM env var. Defaults to
        None, which uses whatever the env vars already have.
      rich_rows (int, optional): The number of rows to use for the terminal
        output. Doesn't seem to have much effect. Defaults to 24.
      rich_cols (int, optional): The number of columns to use for the terminal
        output. Defaults to 80.
      include_args (bool, optional): Should include the command that was run in
        the output? Defaults to True.
      _ctx (_Context): This is used by the system and is not available as an
        argument.

  Returns:
      Union[str, markupsafe.Markup]: Returns the output of the command.
  """
```
<!---->

### path

Used several times in [./README.md.jinja2](./README.md.jinja2).

Documentation:

<!---->
```py
def path(path: str,
         *,
         escape: bool = False,
         indent: Union[str, int, None] = None,
         backtickify: Union[bool, str] = False,
         decomentify: Union[bool, Literal['nl']] = False,
         link: Optional[Literal['md', 'html']] = None,
         text: Optional[str] = None,
         _ctx: _Context) -> Union[str, markupsafe.Markup]:
  """Verifies that `path` exists, and just returns `path`.

  Unfortunately, I don't know how to use this inside a link, because the
  formatters will destroy it, and it cannot be put into a code block (as the url
  section of a link in markdown does not allow code blocks).

  Args:
      path (str): The path to verify.
      escape (bool, optional): Should use HTML entities escaping? Defaults to
        False.
      indent (Union[str, int, None], optional): Should indent? By how much, or
        with what prefix? Defaults to None.
      backtickify (Union[bool, str], optional): Should surround with backticks?
        With what language? Defaults to False.
      decomentify (Union[bool, Literal['nl']]): Assuming that you will be using
        HTML comments around this call, setting this to true will add
        correspondingcomments to uncomment the output. This allows you to have
        the Jinja2 call unmolested by markdown formatters, because they will be
        inside of a comment section. "nl" adds additional newlines after the
        newline delimiters. Defaults to False.
      link (Optional[Literal['md', 'html']], optional): If specified, will
        return a markdown or html link to the path. Defaults to None.
      text (Optional[str], optional): If specified, will use this text as the
        return value instead of the path. If used with link, will return this
        text as the link text instead of the path. Defaults to None.
      _ctx (_Context): This is used by the system and is not available as an
        argument.

  Returns:
      Union[str, markupsafe.Markup]: Just returns the path. If the path doesn't exist,
        it will raise an error.
  """
```
<!---->

Also see Jinja2 v3
[Template Designer Documentation](https://jinja.palletsprojects.com/en/3.1.x/templates/).

## โœ… Requirements

- Linux-like environment
  - Why: Uses pexpect.spawn().
- Python 3.8+
  - Why: Some dev dependencies require Python 3.8+.

### Tested on

- WSL2 Ubuntu 20.04, Python 3.8.0
- Ubuntu 20.04, Python 3.8.0, 3.9.0, 3.10.0, 3.11.0, 3.12.0, tested in GitHub
  Actions workflow
  ([build-and-test.yml](./.github/workflows/build-and-test.yml)).

## ๐Ÿšธ Gotchas and Limitations

- **Security:** This tool is NOT designed to be used with untrusted input. It is
  designed to be used with your own codebase. Even when using your own input, be
  careful that your own code won't be doing anything that might inadvertently
  include untrusted input.
- Be careful to escape `{{` and `}}`,
  or `{%` and `%}` or anything jinja2
  is sensitive to, in the templates. You'll have to escape it properly for
  jinja2, which involves using `{% raw %}` and
  `{% endraw %}` tags.
- Recursion: Snipinator doesn't directly support recursive inclusion of
  generated content. You can generate the contents of one file first, and
  include that generated content into another template. This would mean that you
  have to worry about order of generation.
- Embedded Backticks: If there are backticks in the included snippet, it might
  ruin the backticks you have in your markdown. This is why `backtickify`
  parameter exists in the API, so that Snipinator provides the backticks, and it
  will detect if there are backticks in the snippet and use a different number
  of backticks on the entire snippet. So if the snippet contains
  ` ```My Snippet``` `, Snipinator will use
  ` ````language ```My Snippet``` ```` ` and this is a method that Markdown uses
  to allow embedded backticks inside a code block.
- Formatting: The `{{` `}}` used to
  surround the snippet calls will unfortunately be formatted by a Markdown
  formatter and make the call invalid. Workarounds:
  - **Decommentify**: Put the snippet call inside a HTML comment, then use
    `decommentify` parameter. See
    [./snipinator/examples/LONG-EXAMPLE.md.jinja2](./snipinator/examples/LONG-EXAMPLE.md.jinja2) for
    examples.
  - [prettier](https://prettier.io/) formatter is pretty good at leaving the
    Jinja2 calls alone, especially if you don't have any spaces. This especially
    helps for markdown "reference-style links" that have Jinja2 calls in them
    generating part of the URL, mdformat will URL encode the Jinja2 calls,
    and/or split them on spaces, which is not what we want. prettier will leave
    them alone.
  - For code blocks: If you embed the snippet call in a code block, it will not
    be formatted. However, because of **Embedded Backticks** gotcha, (see
    above), this is not recommended, unless you know for sure that there are no
    embedded backticks.
  - If your formatter supports a comment that disabled formatting, you can
    surround the snippet call with that comment.
- Editing the wrong file: When you have a template and a generated file, it is
  easy to edit the wrong file. To combat this:
  - Snipinator provides a warning at the top of the generated file to remind you
    that it is auto-generated.
  - Snipinator will optionally chmod the file for you to make it read-only.
- Newlines: This program assumes LF newlines. I don't know if it will work for
  anything else.
- Combining `backtickify` and `indent`: Doesn't make much sense, but if you do
  it, it will run backtickify first, then indent everything including the
  backticks.

## Versioning

We use SemVer for versioning. For the versions available, see the tags on this
repository.

## ๐Ÿ”‘ License

This project is licensed under the MIT License - see the
[./LICENSE.md](./LICENSE.md) file for details.

## ๐Ÿ™ Thanks

Main libraries used in Snipinator are:

- Templating: [Jinja2](https://github.com/pallets/jinja).
- Snippet inclusion: Python's AST library.
- Colorful CLI help: [rich-argparse](https://github.com/hamdanal/rich-argparse).
- ANSI coloring shell output:
  {[pexpect](https://pexpect.readthedocs.io/en/stable/),
  [rich](https://github.com/Textualize/rich)}.

## Related Projects

- [markdown-code-example-inserter](https://github.com/electrovir/markdown-code-example-inserter)
  "Syncs code examples with markdown documentation."
- [ARMmbed/snippet](https://github.com/ARMmbed/snippet) "A Python3 tool to
  extract code snippets from source files".
- [SimonCropp/MarkdownSnippets](https://github.com/SimonCropp/MarkdownSnippets)
  "Extracts snippets from code files and merges them into markdown documents".
- [shiftkey/scribble](https://github.com/shiftkey/scribble) "Making
  documentation for .NET projects easy and fun".

## ๐Ÿซก Contributions

### Development environment: Linux-like

- For running `pre.sh` (Linux-like environment).
  - Requires `pyenv`, or an exact matching version of python as in
    `.python-version` (which is currently
    `3.8.0
`).
  - `jq`, ([installation](https://jqlang.github.io/jq/)) required for
    [yq](https://github.com/kislyuk/yq), which is itself required for our
    `./README.md` generation, which uses `tomlq` (from the
    [yq](https://github.com/kislyuk/yq) package) to include version strings from
    `./pyproject.toml`.
  - `bash`, `grep`, `awk`, `sed` `xxd`, `git`, `xxhash` (for tests/workflows).
  - Requires nodejs (for act).
  - Requires Go (to run act).
  - docker (for act).

### Commit Process

1. (Optionally) Fork the `develop` branch.
2. Stage your files: `git add path/to/file.py`.
3. `bash scripts/pre.sh`, this will format, lint, and test the code.
4. `git status` check if anything changed (generated `./README.md`
   for example), if so, `git add` the changes, and go back to the previous step.
5. `git commit -m "..."`.
6. Make a PR to `develop` (or push to develop if you have the rights).

## โ›™ Release Process

These instructions are for maintainers of the project.

1. In the `develop` branch, run `bash ./scripts/pre.sh` to ensure
   everything is in order.
2. In the `develop` branch, bump the version in `./pyproject.toml`,
   following semantic versioning principles. Also modify the
   `last_unstable_release` and `last_stable_release` in the
   `[tool.changeguard-project-metadata]` table as appropriate. Run
   `bash scripts/pre.sh` to ensure everything is in order.
3. In the `develop` branch, commit these changes with a message like
   `"Prepare release X.Y.Z"`. (See the contributions section
   [above](#commit-process)).
4. Merge the `develop` branch into the `master` branch:
   `git checkout master && git merge develop --no-ff`.
5. `master` branch: Tag the release: Create a git tag for the release with
   `git tag -a vX.Y.Z -m "Version X.Y.Z"`.
6. Publish to PyPI: Publish the release to PyPI with
   `bash scripts/deploy-to-pypi.sh`.
7. Push to GitHub: Push the commit and tags to GitHub with
   `git push && git push --tags`.
8. The `--no-ff` option adds a commit to the master branch for the merge, so
   refork the develop branch from the master branch:
   `git checkout develop && git merge master`.
9. Push the develop branch to GitHub: `git push origin develop`.

[1]:
  https://img.shields.io/github/actions/workflow/status/realazthat/snipinator/build-and-test.yml?branch=master&style=plastic
[2]:
  https://github.com/realazthat/snipinator/actions/workflows/build-and-test.yml
[3]:
  https://img.shields.io/github/license/realazthat/snipinator?style=plastic&color=0A1E1E
[4]:
  https://img.shields.io/pypi/v/snipinator?style=plastic&color=0A1E1E
[5]: https://pypi.org/project/snipinator/
[6]:
  https://img.shields.io/github/commits-since/realazthat/snipinator/v1.3.1/master?style=plastic
[7]:
  https://img.shields.io/github/last-commit/realazthat/snipinator/master?style=plastic
[8]:
  https://img.shields.io/pypi/pyversions/snipinator?style=plastic&color=0A1E1E
[9]:
  https://img.shields.io/github/languages/top/realazthat/snipinator.svg?&cacheSeconds=28800&style=plastic&color=0A1E1E
[10]:
  https://github.com/realazthat/snipinator/compare/v1.3.1...master
[11]:
  https://img.shields.io/github/actions/workflow/status/realazthat/snipinator/build-and-test.yml?branch=develop&style=plastic
[12]:
  https://img.shields.io/github/commits-since/realazthat/snipinator/v1.3.1/develop?style=plastic
[13]:
  https://github.com/realazthat/snipinator/compare/v1.3.1...develop
[14]:
  https://img.shields.io/github/last-commit/realazthat/snipinator/develop?style=plastic
[15]:
  https://img.shields.io/github/commits-since/realazthat/snipinator/v1.3.1/develop?style=plastic
[16]:
  https://github.com/realazthat/snipinator/compare/v1.3.1...develop
[17]: https://github.com/realazthat/snipinator/tree/master
[18]: https://github.com/realazthat/snipinator/tree/develop

<!-- Logo from https://lucide.dev/icons/users -->

[19]:
  https://img.shields.io/badge/Audience-Developers-0A1E1E?style=plastic&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJsdWNpZGUgbHVjaWRlLXVzZXJzIj48cGF0aCBkPSJNMTYgMjF2LTJhNCA0IDAgMCAwLTQtNEg2YTQgNCAwIDAgMC00IDR2MiIvPjxjaXJjbGUgY3g9IjkiIGN5PSI3IiByPSI0Ii8+PHBhdGggZD0iTTIyIDIxdi0yYTQgNCAwIDAgMC0zLTMuODciLz48cGF0aCBkPSJNMTYgMy4xM2E0IDQgMCAwIDEgMCA3Ljc1Ii8+PC9zdmc+

<!-- Logo from https://lucide.dev/icons/laptop-minimal -->

[20]:
  https://img.shields.io/badge/Platform-Linux-0A1E1E?style=plastic&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJsdWNpZGUgbHVjaWRlLWxhcHRvcC1taW5pbWFsIj48cmVjdCB3aWR0aD0iMTgiIGhlaWdodD0iMTIiIHg9IjMiIHk9IjQiIHJ4PSIyIiByeT0iMiIvPjxsaW5lIHgxPSIyIiB4Mj0iMjIiIHkxPSIyMCIgeTI9IjIwIi8+PC9zdmc+
[21]: ./LICENSE.md
[22]: ./.github/logo-exported.svg

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "snipinator",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "github, testing, markdown, readme, snippets, documentation, jinja2, templates, preprocessor, documentation-tool, include, readme-template, readme-md, dynamic-documentation",
    "author": null,
    "author_email": "AYF <realazthat@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/55/a6/d905ab5fed099f8093100356961b8e7ee184af87fbf15fafa1e6df3d75db/snipinator-1.3.1.tar.gz",
    "platform": null,
    "description": "<!--\n\nWARNING: This file is auto-generated by snipinator. Do not edit directly.\nSOURCE: `README.md.jinja2`.\n\n-->\n<!--\n\n\n\n\n-->\n\n# <div align=\"center\">![Snipinator][22]</div>\n\n<div align=\"center\">\n\n<!-- Icons from https://lucide.dev/icons/users -->\n<!-- Icons from https://lucide.dev/icons/laptop-minimal -->\n\n![**Audience:** Developers][19] ![**Platform:** Linux][20]\n\n</div>\n\n<p align=\"center\">\n  <strong>\n    <a href=\"#-features\">\ud83c\udf87Features</a> &nbsp;&bull;&nbsp;\n    <a href=\"#-installation\">\ud83d\udee0\ufe0fInstallation</a> &nbsp;&bull;&nbsp;\n    <a href=\"#-usage\">\ud83d\udd27Usage</a> &nbsp;&bull;&nbsp;\n    <a href=\"#-command-line-options\">\ud83d\udcbbCLI</a> &nbsp;&bull;&nbsp;\n    <a href=\"#-examples\">\ud83d\udca1Examples</a> &nbsp;&bull;&nbsp;\n    <a href=\"#-api\">\ud83e\udd16API</a> &nbsp;&bull;&nbsp;\n    <a href=\"#-requirements\">\u2705Requirements</a> &nbsp;&bull;&nbsp;\n    <a href=\"#-gotchas-and-limitations\">\ud83d\udeb8Gotchas</a>\n  </strong>\n</p>\n\n<div align=\"center\">\n\n![Top language][9] [![GitHub License][3]][21] [![PyPI - Version][4]][5]\n[![Python Version][8]][5]\n\n**CLI to embed (testable) snippets from your codebase into your README**\n\n</div>\n\n---\n\n<div align=\"center\">\n\n|                   | Status                     | Stable                    | Unstable                  |                    |\n| ----------------- | -------------------------- | ------------------------- | ------------------------- | ------------------ |\n| **[Master][17]**  | [![Build and Test][1]][2]  | [![since tagged][6]][10]  |                           | ![last commit][7]  |\n| **[Develop][18]** | [![Build and Test][11]][2] | [![since tagged][12]][13] | [![since tagged][15]][16] | ![last commit][14] |\n\n</div>\n\n<img src=\".github/demo.gif\" alt=\"Demo\" width=\"100%\">\n\n## \u2754 What\n\nWhat it does: **Snipinator** lets you take a `EXAMPLE.md` template and include\nsnippets from your (working and tested) codebase.\n\nTurn this ([./snipinator/examples/EXAMPLE.md.jinja2](./snipinator/examples/EXAMPLE.md.jinja2)):\n\n<!---->\n```md\n# A README\n\nHere is a code snippet:\n\n<!--{{ pysnippet(path='snipinator/examples/code.py', symbol='MyClass', backtickify='py', decomentify='nl') }}-->\n\nNote that `code.py` has a test:\n{{path('./snipinator/examples/code_test.py', link='md')}}.\n\n```\n<!---->\n\nInto this ([./snipinator/examples/EXAMPLE.generated.md](./snipinator/examples/EXAMPLE.generated.md)):\n\n<!---->\n````md\n<!--\n\nWARNING: This file is auto-generated by snipinator. Do not edit directly.\nSOURCE: `snipinator/examples/EXAMPLE.md.jinja2`.\n\n-->\n# A README\n\nHere is a code snippet:\n\n<!---->\n```py\nclass MyClass:\n  \"\"\"This is a global class\"\"\"\n\n  def __init__(self, name):\n    self.name = name\n\n  def MyClassMethod(self):\n    \"\"\"This is a method of MyClass\"\"\"\n    print(self.name)\n```\n<!---->\n\nNote that `code.py` has a test:\n[./snipinator/examples/code_test.py](./snipinator/examples/code_test.py).\n\n````\n<!---->\n\n## \ud83c\udf87 Features\n\n- \ud83d\udce6\u2705\ud83e\ude84 Supports anything **[Jinja2](https://github.com/pallets/jinja)**\n  supports.\n- \ud83e\udd47\ud83d\udc0d\ud83d\udcdc First-class support for **python** source code.\n  - Can include python function signatures, docstrings, entire function source\n    code, classes.\n- \u2702\ud83c\udf10\ud83d\uddc2\ufe0f Snip from **any source code language**.\n  - Put delimiter markers into the code (e.g `# START_SNIPPET`,\n    `# END_TEMPLATE`), and use [snippet()](#snippet).\n- \ud83e\udd47\ud83d\udd16\ud83d\udcdc First-class support for **Markdown** templates (with `backtickify`,\n  `decomentify`).\n- \ud83d\udce6\ud83d\udc1a\ud83d\udda8\ufe0f Can include **[shell](#shell) output**.\n  - Supports ANSI colors :heart: :green_heart: :blue_heart: with SVG output\n    :camera:.\n- \u2699\ufe0f\ud83d\udd17\ud83d\uddc3\ufe0f More robust **references/links** to local files using [path()](#path).\n\n## \ud83d\udee0\ufe0f Installation\n\n```bash\n# Install from pypi (https://pypi.org/project/snipinator/)\npip install snipinator\n\n# Install from git (https://github.com/realazthat/snipinator)\npip install git+https://github.com/realazthat/snipinator.git@v1.3.1\n```\n\n## \ud83d\udd27 Usage\n\nExample template README:\n([./snipinator/examples/EXAMPLE.md.jinja2](./snipinator/examples/EXAMPLE.md.jinja2)):\n\n<!---->\n```md\n# A README\n\nHere is a code snippet:\n\n<!--{{ pysnippet(path='snipinator/examples/code.py', symbol='MyClass', backtickify='py', decomentify='nl') }}-->\n\nNote that `code.py` has a test:\n{{path('./snipinator/examples/code_test.py', link='md')}}.\n\n```\n<!---->\n\nGenerating the README:\n\n<!---->\n````bash\n$ python -m snipinator.cli -t snipinator/examples/EXAMPLE.md.jinja2\n<!--\n\nWARNING: This file is auto-generated by snipinator. Do not edit directly.\nSOURCE: `snipinator/examples/EXAMPLE.md.jinja2`.\n\n-->\n# A README\n\nHere is a code snippet:\n\n<!---->\n```py\nclass MyClass:\n  \"\"\"This is a global class\"\"\"\n\n  def __init__(self, name):\n    self.name = name\n\n  def MyClassMethod(self):\n    \"\"\"This is a method of MyClass\"\"\"\n    print(self.name)\n```\n<!---->\n\nNote that `code.py` has a test:\n[./snipinator/examples/code_test.py](./snipinator/examples/code_test.py).\n\n````\n<!---->\n\n## \ud83d\udcbb Command Line Options\n\n<!---->\n<img src=\"README.help.generated.svg\" alt=\"Output of `python -m snipinator.cli --help`\" />\n<!---->\n\n## \ud83d\udca1 Examples\n\n- Snipinator's own `README`:\n  - Template: [./README.md.jinja2](./README.md.jinja2).\n  - Generated: [./README.md](./README.md).\n  - Generation script: [./scripts/generate-readme.sh](./scripts/generate-readme.sh).\n- Example:\n  - Template: [./snipinator/examples/EXAMPLE.md.jinja2](./snipinator/examples/EXAMPLE.md.jinja2).\n  - Generated:\n    [./snipinator/examples/EXAMPLE.generated.md](./snipinator/examples/EXAMPLE.generated.md).\n  - Generation script: [./snipinator/examples/example.sh](./snipinator/examples/example.sh).\n- Long example of many features:\n  - Template:\n    [./snipinator/examples/LONG-EXAMPLE.md.jinja2](./snipinator/examples/LONG-EXAMPLE.md.jinja2).\n  - Generated:\n    [./snipinator/examples/LONG-EXAMPLE.generated.md](./snipinator/examples/LONG-EXAMPLE.generated.md).\n  - Generation script:\n    [./snipinator/examples/long-example.sh](./snipinator/examples/long-example.sh).\n- Projects using Snipinator:\n  - [github.com/realazthat/snipinator](https://github.com/realazthat/snipinator),\n    See\n    [snipinator/README.md.jinja2](https://github.com/realazthat/snipinator/blob/61cb88593baa099dc375cf5fd40679e4be673fc5/README.md.jinja2).\n  - [github.com/realazthat/changeguard](https://github.com/realazthat/changeguard),\n    See\n    [changeguard/README.md.jinja2](https://github.com/realazthat/changeguard/blob/87d5104b52e651bb9195a3d46dd7f050acbcb534/README.md.jinja2).\n  - [github.com/realazthat/comfy-catapult](https://github.com/realazthat/comfy-catapult),\n    See\n    [comfy-catapult/README.md.jinja2](https://github.com/realazthat/comfy-catapult/blob/ff353d48b25fa7b9c35fa11b31d5f2b3039c41c8/README.md.jinja2).\n  - [github.com/realazthat/comfylowda](https://github.com/realazthat/comfylowda),\n    See\n    [comfylowda/README.md.jinja2](https://github.com/realazthat/comfylowda/blob/e01a32c38107aa0b89ccea21c4678d193a186a78/README.md.jinja2).\n  - [github.com/realazthat/excalidraw-brute-export-cli](https://github.com/realazthat/excalidraw-brute-export-cli),\n    See\n    [excalidraw-brute-export-cli/README.md.jinja2](https://github.com/realazthat/excalidraw-brute-export-cli/blob/54a3b5b08b644e61c721ab565c576094234c5cc7/README.md.jinja2).\n\n## \ud83e\udd16 API\n\n(Jinja2) Functions made available:\n\n### pysnippet\n\nUsed several times in\n[./snipinator/examples/LONG-EXAMPLE.md.jinja2](./snipinator/examples/LONG-EXAMPLE.md.jinja2).\n\nDocumentation:\n\n<!---->\n```py\ndef pysnippet(path: str,\n              symbol: Optional[str],\n              *,\n              escape: bool = False,\n              indent: Union[str, int, None] = None,\n              backtickify: Union[bool, str] = False,\n              decomentify: Union[bool, Literal['nl']] = False,\n              _ctx: _Context) -> Union[str, markupsafe.Markup]:\n  \"\"\"Return a python snippet, allowing you to specify a class or function.\n\n  Args:\n      path (str): The path to the file.\n      symbol (Optional[str]): The symbol to extract. If None, the entire file is\n        returned. Defaults to None.\n      escape (bool, optional): Should use HTML entities escaping? Defaults to\n        False.\n      indent (Union[str, int, None], optional): Should indent? By how much, or\n        with what prefix? Defaults to None.\n      backtickify (Union[bool, str], optional): Should surround with backticks?\n        With what language? Defaults to False.\n      decomentify (Union[bool, Literal['nl']]): Assuming that you will be using\n        HTML comments around this call, setting this to true will add\n        correspondingcomments to uncomment the output. This allows you to have\n        the Jinja2 call unmolested by markdown formatters, because they will be\n        inside of a comment section. \"nl\" adds additional newlines after the\n        newline delimiters. Defaults to False.\n      _ctx (_Context): This is used by the system and is not available as an\n        argument.\n\n  Returns:\n      Union[str, markupsafe.Markup]: The snippet.\n  \"\"\"\n```\n<!---->\n\n### pysignature\n\nUsed several times in [./README.md.jinja2](./README.md.jinja2).\n\nDocumentation:\n\n<!---->\n```py\ndef pysignature(path: str,\n                symbol: str,\n                *,\n                escape: bool = False,\n                indent: Union[str, int, None] = None,\n                backtickify: Union[bool, str] = False,\n                decomentify: Union[bool, Literal['nl']] = False,\n                _ctx: _Context) -> str:\n  \"\"\"Return the signature of a class or function in a python file.\n\n  Returns the {class,function} signature and the docstring.\n\n  Args:\n      path (str): The path to the file.\n      symbol (str): The symbol to extract.\n      escape (bool, optional): Should use HTML entities escaping? Defaults to\n        False.\n      indent (Union[str, int, None], optional): Should indent? By how much, or\n        with what prefix? Defaults to None.\n      backtickify (Union[bool, str], optional): Should surround with backticks?\n        With what language? Defaults to False.\n      decomentify (Union[bool, Literal['nl']]): Assuming that you will be using\n        HTML comments around this call, setting this to true will add\n        correspondingcomments to uncomment the output. This allows you to have\n        the Jinja2 call unmolested by markdown formatters, because they will be\n        inside of a comment section. \"nl\" adds additional newlines after the\n        newline delimiters. Defaults to False.\n      _ctx (_Context): This is used by the system and is not available as an\n        argument.\n\n  Returns:\n      str: The signature and docstring.\n  \"\"\"\n```\n<!---->\n\n### rawsnippet\n\nUsed several times in [./README.md.jinja2](./README.md.jinja2).\n\nDocumentation:\n\n<!---->\n```py\ndef rawsnippet(path: str,\n               *,\n               escape: bool = False,\n               indent: Union[str, int, None] = None,\n               backtickify: Union[bool, str] = False,\n               decomentify: Union[bool, Literal['nl']] = False,\n               _ctx: _Context) -> Union[str, markupsafe.Markup]:\n  \"\"\"Return an entire file as a snippet.\n\n  Args:\n      path (str): The path to the file.\n      escape (bool, optional): Should use HTML entities escaping? Defaults to\n        False.\n      indent (Union[str, int, None], optional): Should indent? By how much, or\n        with what prefix? Defaults to None.\n      backtickify (Union[bool, str], optional): Should surround with backticks?\n        With what language? Defaults to False.\n      decomentify (Union[bool, Literal['nl']]): Assuming that you will be using\n        HTML comments around this call, setting this to true will add\n        correspondingcomments to uncomment the output. This allows you to have\n        the Jinja2 call unmolested by markdown formatters, because they will be\n        inside of a comment section. \"nl\" adds additional newlines after the\n        newline delimiters. Defaults to False.\n      _ctx (_Context): This is used by the system and is not available as an\n        argument.\n\n  Returns:\n      Union[str, markupsafe.Markup]: The snippet.\n  \"\"\"\n\n```\n<!---->\n\n### snippet\n\nExample in [./snipinator/examples/LONG-EXAMPLE.md.jinja2](./snipinator/examples/LONG-EXAMPLE.md.jinja2).\n\nDocumentation:\n\n<!---->\n```py\ndef snippet(path: str,\n            start: str,\n            end: str,\n            *,\n            escape: bool = False,\n            indent: Union[str, int, None] = None,\n            backtickify: Union[bool, str] = False,\n            decomentify: Union[bool, Literal['nl']] = False,\n            _ctx: _Context) -> Union[str, markupsafe.Markup]:\n  \"\"\"Returns a _delimited_ snippet from a file.\n\n  Does not return the delimiters themselves.\n\n  Args:\n      path (str): The path to the file.\n      start (str): A string that indicates the start of the snippet.\n      end (str): A string that indicates the end of the snippet.\n      escape (bool, optional): Should use HTML entities escaping? Defaults to\n        False.\n      indent (Union[str, int, None], optional): Should indent? By how much, or\n        with what prefix? Defaults to None.\n      backtickify (Union[bool, str], optional): Should surround with backticks?\n        With what language? Defaults to False.\n      decomentify (Union[bool, Literal['nl']]): Assuming that you will be using\n        HTML comments around this call, setting this to true will add\n        correspondingcomments to uncomment the output. This allows you to have\n        the Jinja2 call unmolested by markdown formatters, because they will be\n        inside of a comment section. \"nl\" adds additional newlines after the\n        newline delimiters. Defaults to False.\n      _ctx (_Context): This is used by the system and is not available as an\n        argument.\n\n  Returns:\n      Union[str, markupsafe.Markup]: The snippet.\n  \"\"\"\n\n```\n<!---->\n\n### shell\n\nUsed several times in [./README.md.jinja2](./README.md.jinja2).\n\nDocumentation:\n\n<!---->\n```py\ndef shell(args: str,\n          *,\n          escape: bool = False,\n          indent: Union[str, int, None] = None,\n          backtickify: Union[bool, str] = False,\n          decomentify: Union[bool, Literal['nl']] = False,\n          rich: Union[Literal['svg'], Literal['img+b64+svg'], Literal['raw'],\n                      str] = 'raw',\n          rich_alt: Optional[str] = None,\n          rich_bg_color: Optional[str] = None,\n          rich_term: Optional[str] = None,\n          rich_rows: int = 24,\n          rich_cols: int = 80,\n          include_args: bool = True,\n          _ctx: _Context) -> Union[str, markupsafe.Markup]:\n  \"\"\"Run a shell command and return the output.\n\n  Use at your own risk, this can potentially introduce security vulnerabilities.\n  Only use if you know what you are doing. Ensure that no untrusted input can\n  be injected into the `args` parameter, or, into anything the command might\n  access. If an adversary can control the `args` parameter, they can execute\n  arbitrary commands on your system.\n\n  Args:\n      args (str): The command to run.\n      escape (bool, optional): Should use HTML entities escaping? Defaults to\n        False.\n      indent (Union[str, int, None], optional): Should indent? By how much, or with\n        what prefix? Defaults to None.\n      backtickify (Union[bool, str], optional): Should surround with backticks? With\n        what language? Defaults to False.\n      decomentify (bool, optional): Assuming that you will be using HTML\n        comments around this call, setting this to true will add corresponding\n        uncomments to uncomment the output. This allows you to have the Jinja2\n        call unmolested by markdown formatters, because they will be inside of\n        a comment section. Defaults to False.\n      rich (Union[Literal['svg'], Literal['img+b64+svg'], Literal['raw'], str], optional):\n        Optionally outputs colored terminal output as an image.\n        * If `rich` is a relative file path that ends with \".svg\", the svg will\n          be saved to that location and an img tag will be emitted. The path\n          will be relative to the template file, which is specified on the\n          command line. If the template is from stdin, the path will be relative\n          to the current working directory (cwd) which is also specified on the\n          command line.\n        * If 'svg' a raw svg tag will be dumped into the markdown with the\n          colored terminal output. Note that your markdown renderer may not\n          support this.\n        * If 'img+svg' a base64 encoded image will be dumped into the markdown\n          with the colored terminal output.\n        * If 'raw' the raw (uncolored) terminal output will be dumped into the\n          markdown directly.\n        * Defaults to 'raw.\n      rich_alt (Optional[str], optional): The alt text for the img tag. Defaults\n        to None.\n      rich_bg_color (Optional[str], optional): The background color for the terminal\n        output. Valid colors include anything valid for SVG colors. See\n        <https://developer.mozilla.org/en-US/docs/Web/CSS/color>. Defaults to\n        None (fully transparent).\n      rich_term: (Optional[str], optional): Sets the TERM env var. Defaults to\n        None, which uses whatever the env vars already have.\n      rich_rows (int, optional): The number of rows to use for the terminal\n        output. Doesn't seem to have much effect. Defaults to 24.\n      rich_cols (int, optional): The number of columns to use for the terminal\n        output. Defaults to 80.\n      include_args (bool, optional): Should include the command that was run in\n        the output? Defaults to True.\n      _ctx (_Context): This is used by the system and is not available as an\n        argument.\n\n  Returns:\n      Union[str, markupsafe.Markup]: Returns the output of the command.\n  \"\"\"\n```\n<!---->\n\n### path\n\nUsed several times in [./README.md.jinja2](./README.md.jinja2).\n\nDocumentation:\n\n<!---->\n```py\ndef path(path: str,\n         *,\n         escape: bool = False,\n         indent: Union[str, int, None] = None,\n         backtickify: Union[bool, str] = False,\n         decomentify: Union[bool, Literal['nl']] = False,\n         link: Optional[Literal['md', 'html']] = None,\n         text: Optional[str] = None,\n         _ctx: _Context) -> Union[str, markupsafe.Markup]:\n  \"\"\"Verifies that `path` exists, and just returns `path`.\n\n  Unfortunately, I don't know how to use this inside a link, because the\n  formatters will destroy it, and it cannot be put into a code block (as the url\n  section of a link in markdown does not allow code blocks).\n\n  Args:\n      path (str): The path to verify.\n      escape (bool, optional): Should use HTML entities escaping? Defaults to\n        False.\n      indent (Union[str, int, None], optional): Should indent? By how much, or\n        with what prefix? Defaults to None.\n      backtickify (Union[bool, str], optional): Should surround with backticks?\n        With what language? Defaults to False.\n      decomentify (Union[bool, Literal['nl']]): Assuming that you will be using\n        HTML comments around this call, setting this to true will add\n        correspondingcomments to uncomment the output. This allows you to have\n        the Jinja2 call unmolested by markdown formatters, because they will be\n        inside of a comment section. \"nl\" adds additional newlines after the\n        newline delimiters. Defaults to False.\n      link (Optional[Literal['md', 'html']], optional): If specified, will\n        return a markdown or html link to the path. Defaults to None.\n      text (Optional[str], optional): If specified, will use this text as the\n        return value instead of the path. If used with link, will return this\n        text as the link text instead of the path. Defaults to None.\n      _ctx (_Context): This is used by the system and is not available as an\n        argument.\n\n  Returns:\n      Union[str, markupsafe.Markup]: Just returns the path. If the path doesn't exist,\n        it will raise an error.\n  \"\"\"\n```\n<!---->\n\nAlso see Jinja2 v3\n[Template Designer Documentation](https://jinja.palletsprojects.com/en/3.1.x/templates/).\n\n## \u2705 Requirements\n\n- Linux-like environment\n  - Why: Uses pexpect.spawn().\n- Python 3.8+\n  - Why: Some dev dependencies require Python 3.8+.\n\n### Tested on\n\n- WSL2 Ubuntu 20.04, Python 3.8.0\n- Ubuntu 20.04, Python 3.8.0, 3.9.0, 3.10.0, 3.11.0, 3.12.0, tested in GitHub\n  Actions workflow\n  ([build-and-test.yml](./.github/workflows/build-and-test.yml)).\n\n## \ud83d\udeb8 Gotchas and Limitations\n\n- **Security:** This tool is NOT designed to be used with untrusted input. It is\n  designed to be used with your own codebase. Even when using your own input, be\n  careful that your own code won't be doing anything that might inadvertently\n  include untrusted input.\n- Be careful to escape `{{` and `}}`,\n  or `{%` and `%}` or anything jinja2\n  is sensitive to, in the templates. You'll have to escape it properly for\n  jinja2, which involves using `{% raw %}` and\n  `{% endraw %}` tags.\n- Recursion: Snipinator doesn't directly support recursive inclusion of\n  generated content. You can generate the contents of one file first, and\n  include that generated content into another template. This would mean that you\n  have to worry about order of generation.\n- Embedded Backticks: If there are backticks in the included snippet, it might\n  ruin the backticks you have in your markdown. This is why `backtickify`\n  parameter exists in the API, so that Snipinator provides the backticks, and it\n  will detect if there are backticks in the snippet and use a different number\n  of backticks on the entire snippet. So if the snippet contains\n  ` ```My Snippet``` `, Snipinator will use\n  ` ````language ```My Snippet``` ```` ` and this is a method that Markdown uses\n  to allow embedded backticks inside a code block.\n- Formatting: The `{{` `}}` used to\n  surround the snippet calls will unfortunately be formatted by a Markdown\n  formatter and make the call invalid. Workarounds:\n  - **Decommentify**: Put the snippet call inside a HTML comment, then use\n    `decommentify` parameter. See\n    [./snipinator/examples/LONG-EXAMPLE.md.jinja2](./snipinator/examples/LONG-EXAMPLE.md.jinja2) for\n    examples.\n  - [prettier](https://prettier.io/) formatter is pretty good at leaving the\n    Jinja2 calls alone, especially if you don't have any spaces. This especially\n    helps for markdown \"reference-style links\" that have Jinja2 calls in them\n    generating part of the URL, mdformat will URL encode the Jinja2 calls,\n    and/or split them on spaces, which is not what we want. prettier will leave\n    them alone.\n  - For code blocks: If you embed the snippet call in a code block, it will not\n    be formatted. However, because of **Embedded Backticks** gotcha, (see\n    above), this is not recommended, unless you know for sure that there are no\n    embedded backticks.\n  - If your formatter supports a comment that disabled formatting, you can\n    surround the snippet call with that comment.\n- Editing the wrong file: When you have a template and a generated file, it is\n  easy to edit the wrong file. To combat this:\n  - Snipinator provides a warning at the top of the generated file to remind you\n    that it is auto-generated.\n  - Snipinator will optionally chmod the file for you to make it read-only.\n- Newlines: This program assumes LF newlines. I don't know if it will work for\n  anything else.\n- Combining `backtickify` and `indent`: Doesn't make much sense, but if you do\n  it, it will run backtickify first, then indent everything including the\n  backticks.\n\n## Versioning\n\nWe use SemVer for versioning. For the versions available, see the tags on this\nrepository.\n\n## \ud83d\udd11 License\n\nThis project is licensed under the MIT License - see the\n[./LICENSE.md](./LICENSE.md) file for details.\n\n## \ud83d\ude4f Thanks\n\nMain libraries used in Snipinator are:\n\n- Templating: [Jinja2](https://github.com/pallets/jinja).\n- Snippet inclusion: Python's AST library.\n- Colorful CLI help: [rich-argparse](https://github.com/hamdanal/rich-argparse).\n- ANSI coloring shell output:\n  {[pexpect](https://pexpect.readthedocs.io/en/stable/),\n  [rich](https://github.com/Textualize/rich)}.\n\n## Related Projects\n\n- [markdown-code-example-inserter](https://github.com/electrovir/markdown-code-example-inserter)\n  \"Syncs code examples with markdown documentation.\"\n- [ARMmbed/snippet](https://github.com/ARMmbed/snippet) \"A Python3 tool to\n  extract code snippets from source files\".\n- [SimonCropp/MarkdownSnippets](https://github.com/SimonCropp/MarkdownSnippets)\n  \"Extracts snippets from code files and merges them into markdown documents\".\n- [shiftkey/scribble](https://github.com/shiftkey/scribble) \"Making\n  documentation for .NET projects easy and fun\".\n\n## \ud83e\udee1 Contributions\n\n### Development environment: Linux-like\n\n- For running `pre.sh` (Linux-like environment).\n  - Requires `pyenv`, or an exact matching version of python as in\n    `.python-version` (which is currently\n    `3.8.0\n`).\n  - `jq`, ([installation](https://jqlang.github.io/jq/)) required for\n    [yq](https://github.com/kislyuk/yq), which is itself required for our\n    `./README.md` generation, which uses `tomlq` (from the\n    [yq](https://github.com/kislyuk/yq) package) to include version strings from\n    `./pyproject.toml`.\n  - `bash`, `grep`, `awk`, `sed` `xxd`, `git`, `xxhash` (for tests/workflows).\n  - Requires nodejs (for act).\n  - Requires Go (to run act).\n  - docker (for act).\n\n### Commit Process\n\n1. (Optionally) Fork the `develop` branch.\n2. Stage your files: `git add path/to/file.py`.\n3. `bash scripts/pre.sh`, this will format, lint, and test the code.\n4. `git status` check if anything changed (generated `./README.md`\n   for example), if so, `git add` the changes, and go back to the previous step.\n5. `git commit -m \"...\"`.\n6. Make a PR to `develop` (or push to develop if you have the rights).\n\n## \u26d9 Release Process\n\nThese instructions are for maintainers of the project.\n\n1. In the `develop` branch, run `bash ./scripts/pre.sh` to ensure\n   everything is in order.\n2. In the `develop` branch, bump the version in `./pyproject.toml`,\n   following semantic versioning principles. Also modify the\n   `last_unstable_release` and `last_stable_release` in the\n   `[tool.changeguard-project-metadata]` table as appropriate. Run\n   `bash scripts/pre.sh` to ensure everything is in order.\n3. In the `develop` branch, commit these changes with a message like\n   `\"Prepare release X.Y.Z\"`. (See the contributions section\n   [above](#commit-process)).\n4. Merge the `develop` branch into the `master` branch:\n   `git checkout master && git merge develop --no-ff`.\n5. `master` branch: Tag the release: Create a git tag for the release with\n   `git tag -a vX.Y.Z -m \"Version X.Y.Z\"`.\n6. Publish to PyPI: Publish the release to PyPI with\n   `bash scripts/deploy-to-pypi.sh`.\n7. Push to GitHub: Push the commit and tags to GitHub with\n   `git push && git push --tags`.\n8. The `--no-ff` option adds a commit to the master branch for the merge, so\n   refork the develop branch from the master branch:\n   `git checkout develop && git merge master`.\n9. Push the develop branch to GitHub: `git push origin develop`.\n\n[1]:\n  https://img.shields.io/github/actions/workflow/status/realazthat/snipinator/build-and-test.yml?branch=master&style=plastic\n[2]:\n  https://github.com/realazthat/snipinator/actions/workflows/build-and-test.yml\n[3]:\n  https://img.shields.io/github/license/realazthat/snipinator?style=plastic&color=0A1E1E\n[4]:\n  https://img.shields.io/pypi/v/snipinator?style=plastic&color=0A1E1E\n[5]: https://pypi.org/project/snipinator/\n[6]:\n  https://img.shields.io/github/commits-since/realazthat/snipinator/v1.3.1/master?style=plastic\n[7]:\n  https://img.shields.io/github/last-commit/realazthat/snipinator/master?style=plastic\n[8]:\n  https://img.shields.io/pypi/pyversions/snipinator?style=plastic&color=0A1E1E\n[9]:\n  https://img.shields.io/github/languages/top/realazthat/snipinator.svg?&cacheSeconds=28800&style=plastic&color=0A1E1E\n[10]:\n  https://github.com/realazthat/snipinator/compare/v1.3.1...master\n[11]:\n  https://img.shields.io/github/actions/workflow/status/realazthat/snipinator/build-and-test.yml?branch=develop&style=plastic\n[12]:\n  https://img.shields.io/github/commits-since/realazthat/snipinator/v1.3.1/develop?style=plastic\n[13]:\n  https://github.com/realazthat/snipinator/compare/v1.3.1...develop\n[14]:\n  https://img.shields.io/github/last-commit/realazthat/snipinator/develop?style=plastic\n[15]:\n  https://img.shields.io/github/commits-since/realazthat/snipinator/v1.3.1/develop?style=plastic\n[16]:\n  https://github.com/realazthat/snipinator/compare/v1.3.1...develop\n[17]: https://github.com/realazthat/snipinator/tree/master\n[18]: https://github.com/realazthat/snipinator/tree/develop\n\n<!-- Logo from https://lucide.dev/icons/users -->\n\n[19]:\n  https://img.shields.io/badge/Audience-Developers-0A1E1E?style=plastic&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJsdWNpZGUgbHVjaWRlLXVzZXJzIj48cGF0aCBkPSJNMTYgMjF2LTJhNCA0IDAgMCAwLTQtNEg2YTQgNCAwIDAgMC00IDR2MiIvPjxjaXJjbGUgY3g9IjkiIGN5PSI3IiByPSI0Ii8+PHBhdGggZD0iTTIyIDIxdi0yYTQgNCAwIDAgMC0zLTMuODciLz48cGF0aCBkPSJNMTYgMy4xM2E0IDQgMCAwIDEgMCA3Ljc1Ii8+PC9zdmc+\n\n<!-- Logo from https://lucide.dev/icons/laptop-minimal -->\n\n[20]:\n  https://img.shields.io/badge/Platform-Linux-0A1E1E?style=plastic&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJsdWNpZGUgbHVjaWRlLWxhcHRvcC1taW5pbWFsIj48cmVjdCB3aWR0aD0iMTgiIGhlaWdodD0iMTIiIHg9IjMiIHk9IjQiIHJ4PSIyIiByeT0iMiIvPjxsaW5lIHgxPSIyIiB4Mj0iMjIiIHkxPSIyMCIgeTI9IjIwIi8+PC9zdmc+\n[21]: ./LICENSE.md\n[22]: ./.github/logo-exported.svg\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Azriel Fasten.  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Python code snippets for markdown files, e.g READMEs, from actual (testable) code.",
    "version": "1.3.1",
    "project_urls": {
        "Documentation": "https://github.com/realazthat/snipinator",
        "Homepage": "https://github.com/realazthat/snipinator",
        "Repository": "https://github.com/realazthat/snipinator"
    },
    "split_keywords": [
        "github",
        " testing",
        " markdown",
        " readme",
        " snippets",
        " documentation",
        " jinja2",
        " templates",
        " preprocessor",
        " documentation-tool",
        " include",
        " readme-template",
        " readme-md",
        " dynamic-documentation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "120976bb4031a10a85196e8edc6ab26403dc01aedede7041da4927eca63cffb0",
                "md5": "b7d60053765f2c01209a5df3d7b00765",
                "sha256": "6b79e4757e76f383b95abdd82fc72f9526d0fbe288eab23bcc3319d625d27d49"
            },
            "downloads": -1,
            "filename": "snipinator-1.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b7d60053765f2c01209a5df3d7b00765",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 34671,
            "upload_time": "2024-04-22T15:34:27",
            "upload_time_iso_8601": "2024-04-22T15:34:27.979074Z",
            "url": "https://files.pythonhosted.org/packages/12/09/76bb4031a10a85196e8edc6ab26403dc01aedede7041da4927eca63cffb0/snipinator-1.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "55a6d905ab5fed099f8093100356961b8e7ee184af87fbf15fafa1e6df3d75db",
                "md5": "1716cbd9e458faaca7f6359d678d9dce",
                "sha256": "3dcc70679144773a69c971f27aed04d110e2538aff20d0b6a617fb1dd1dbfd6b"
            },
            "downloads": -1,
            "filename": "snipinator-1.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "1716cbd9e458faaca7f6359d678d9dce",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 43400,
            "upload_time": "2024-04-22T15:34:30",
            "upload_time_iso_8601": "2024-04-22T15:34:30.295834Z",
            "url": "https://files.pythonhosted.org/packages/55/a6/d905ab5fed099f8093100356961b8e7ee184af87fbf15fafa1e6df3d75db/snipinator-1.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-22 15:34:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "realazthat",
    "github_project": "snipinator",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "snipinator"
}
        
Elapsed time: 0.25588s