ryd


Nameryd JSON
Version 0.9.2 PyPI version JSON
download
home_page
SummaryRuamel Yaml Doc preprocessor (pronounced: /rɑɪt/, like the verb "write")
upload_time2023-11-21 09:12:16
maintainer
docs_urlNone
authorAnthon van der Neut
requires_python>=3
licenseMIT
keywords restructuredtext markdown markup preprocessing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# ryd

[![image](https://sourceforge.net/p/ryd/code/ci/default/tree/_doc/_static/license.svg?format=raw)](https://opensource.org/licenses/MIT)
[![image](https://sourceforge.net/p/ryd/code/ci/default/tree/_doc/_static/pypi.svg?format=raw)](https://pypi.org/project/ryd/)
[![image](https://sourceforge.net/p/oitnb/code/ci/default/tree/_doc/_static/oitnb.svg?format=raw)](https://pypi.org/project/oitnb/)
[![image](https://sourceforge.net/p/ryd/code/ci/default/tree/_doc/_static/ryd.svg?format=raw)](https://pypi.org/project/ryd/)

`ryd` ( /rɑɪt/, pronounced like the verb \"write\" ) is a preprocessor
for text based documents, that builds upon the multi-document
capabilities of YAML files/streams.

The use of multiple-documents in `ryd` allows for clear separation
between document text and any programs referenced in those text. Thereby
making it possible to run (c.q. compile) the program parts of a
document, e.g. to check whether they are syntactically correct. It can
also capture the *actual* output of those programs to be included in the
document. It is also possible to recognise different documents and thus
run different formatters then recombining the documents.

This allows for easier maintenance of (correct) program sources, in
document source texts like reStructuredText, LaTeX, Markdown, etc.

The first of the documents in a `ryd` file has, at the root-level, a
mapping. This mapping is the **ryd configuration metadata** for the rest
of the stream of documents in the file. The metadata is used to define
`ryd` document version used, what the basic **text style** is (currently
`rst` for RestructuredText, `so` for StackOverflow-markdown), if any
postprocessing (PDF, HTML) needs to be done, and other configuration
information. This first document doesn\'t normally have any directives.
That the document is YAML 1.2 is implicit, so no `%YAML 1.2` directive
is needed and without directive and no preceding document, you do not
have a directives-end marker line (`---`) at the top.

The documents following the first document are normally block style
literal scalars with an optional tag. The tag influences how the scalar
string is processed within the selected output text style.

## Example

    version: 0.2
    text: rst
    fix_inline_single_backquotes: true
    --- |
    Example Python program
    ++++++++++++++++++++++

    This is an example of a python program:
    --- !python |
    n = 7
    print(n**2 - n)
    --- !stdout |
    The answer is:

this will generate (using: `ryd convert test.ryd`) the following
`test.rst`:

    Example Python program
    ++++++++++++++++++++++

    This is an example of a Python program:

    .. code:: python

      n = 7
      print(n**2 - n)

    The answer is:

    .. code::

      42

## Postprocessing

The output can be converted to PDF using `rst2pdf` or HTML using
`rst2html` with images embedded using `webpage2html`. Invocation of
these programs can be specified in the metatada (e.g. `post: pdf`).

The (image embedded) HTML output has the indent of indented lines of
included code fragments inserted as actual spaces. So you copy and paste
program code (or YAML) from HTML without a problem, something not
possible with PDF files generated by `rst2pdf`.

`ryd` generates its text output stand-alone, but the programs actually
used for postprocessing have to be installed seperately and available in
your PATH.

(There is currently no postprocessing for Markdown, as pandoc is not
working on Arch (Mark 2022))

## Config

You can create a file `~/.config/ryd/ryd.yaml` with defaults for the
commandline options. To always embed images when converting to HTML and
always run the (global) verbose option:

> global:
>
> :   verbose: true
>
> convert:
>
> :   embed: true

### Command-line options

The command-line of `ryd` consists of multiple components:

    ryd [--global-option] command [--options] [arguments]

Although not indicated most global options can occur after the command
as well.

#### commands

    convert             generate output as per first YAML document
    roundtrip           roundtrip .ryd file, updating sections
    from-rst (fromrst)  convert .rst to .ryd

You\'ll most often use `convert` it takes one or more filenames as
argument and generates output as specified in the ryd configuration
data. Some options allow you to override settings there (e.g. `--pdf`
and `-no-pdf`)

The command `from-rst` converts a `.rst` file into `.ryd` doing some
section underline checking and adding the ryd configuration data
document.

The `roundtrip` command updates sections by running in place
code-formatting on the `!python` (using `oitnb`) and `!zig` sections of
the `.ryd` file. ( There is currently no config option to use `blue` or
`black`, but you can copy `ryd/_tag/python.tag` to your
`.config/ryd/tag` directory and make the minor adjustment to use those,
see the section on making our own tag).

Doing `ryd command --help` might indicate extra options that have not
yet made it into the documentation and/or that are incompletely
implemented.

# Documents and document tags

Each YAML document has to be separated from other documents in the
stream by at least the end of directive marker `---`. Apart from the
first document, most documents contain a single, multi-line,
non-indented, scalar. The end of directives marker is therefor followed
by the pipe (`|`) symbol, which is the YAML indication for a multi-line
literal scalar.

That scalar can be \"typed\" in the normal way of YAML by inserting a
tag before the `|`. E.g. a document that is a type of Python program has
a tag `!python` and thus starts with:

    --- !python |

What a document tag exactly does, depends on the tag, but, potentially,
also, on the output file format selected, on previously processed tagged
documents, other `.ryd` files processed previously and the environment.

In addition to the basic tag (like `!python`), a tag can have
subfunctions such as `!python-pre`. If an unknown subfunction is
specified you\'ll get a runtime error.

The following are short descriptions for all tags, independent of the selected
output format:

`!changelog`<br>  input is a mapping keys are (version, date) tuples, or the word NEXT

`!code`<br>  Include program in text. Do not mark as executable, doesn't influence ``!stdout``.

`!comment`<br>  The whole document will be discarded, i.e. not included in the output.

`!inc`<br>  Include the content of the listed files (indented), without other processing,          into the output. Preceed with ``::`` if necessary

`!inc-raw`<br>  Include the content of the listed files (indented), without other processing,          into the output. Preceed with ``::`` if necessary

`!lastcompile`<br>  Include output from last compilation as code.

`!nim`<br>  Include Nim program in text. Prefix and mark as executable.

`!nim-pre`<br>  Include Nim program in text. Prefix and mark as executable.

`!python`<br>  Include Python program in text. Prefix and mark as executable.

`!python-hidden`<br>  Include Python program in text. Prefix and mark as executable.

`!python-hiddenstdoutraw`<br>  Include Python program in text. Prefix and mark as executable.

`!python-pre`<br>  Include Python program in text. Prefix and mark as executable.

`!stdout`<br>  Include output from last executable document (e.g. ``!python``) as code.

`!stdout-raw`<br>  Include output from last executable document (e.g. ``!python``) as code.

`!table`<br>  create a table, for now headerless

`!toc`<br>  insert an index

`!yamlout`<br>  Include output from last executable document (e.g. ``!python``) as code tagged as         YAML document.

`!zig`<br>  Include Zig program in text. Prefix and execute setting !stdout.

`!zig-pre`<br>  Include Zig program in text. Prefix and execute setting !stdout.

`!zsh`<br>  run each line in zsh, interspacing the lines with the output

# MD

The output to `.md` expects non-code YAML documents to be valid
Markdown.

Because of the special meaning of `---` (and `...`) at the beginning of
a line, followed by newline or space, these should not be used. Either
use a longer sequence ( e.g. for divider lines use `----` ), or
indent the whole document:

```
  --- |
    line followed by divider
    ---
    another line
```

## mkdocs

If you have a file `_doc/README.ryd`, you can use `ryd serve` to
convert and serve this with mkdocs. The contents of the necessary
mkdocs configuration file will be written from the mkdocs entry in the metadata
of the `README.ryd` file (so you don't need to put more cruft in your packages root
directory):

```
 version: 0.2
 text: md
 pdf: false
 mkdocs:
   # if site_name key not provided set to current directory name
   site_name: your_project_name
   docs_dir: _doc
   site_author: Anthon van der Neut

   theme:
     name: readthedocs

   exclude_docs: |
     *.ryd
     *.rst

   markdown_extensions:
   - toc:
       permalink: true
```

 
# RST

The output to `.rst` expects non-code YAML documents to be valid
reStructuredText. Any non-tagged documents, i.e. those starting with:

    --- |

are assumed to be text input, in the format specified in the ryd
configuration data.

## Section underlining

Because of the special meaning of `---` (and `...`) at the beginning of
a line, followed by newline or space, the section under/over-line
characters used in `.ryd` files that are source for `.rst` should not
use `-` or `.` sequences if a any of those section names consist of
three letters (e.g. a section named API or RST). It is recommended to
use the following scheme:

    Sections, subsections, etc. in .ryd files
     # with over-line, for parts
     * with over-line, for chapters
     =, for sections
     +, for subsections
     ^, for sub-subsections
     ", for paragraphs

## Single backquotes

The `fix_inline_single_backquotes: true` tells `ryd` to indicate lines
that have single backquotes, that need fixing (by replacing them with
double backquotes):

    README.ryd
    47: this will generate (`ryd convert test.ryd`) the following
                          --^
                                               --^

(If you are used to other inline code markup editing e.g. on Stack
Overflow, that uses single backquotes, you\'ll come to appreciate this.)

## Python

Python code is indicated by:

    --- !python |

The document is inserted into the `.rst` preceded by `.. code:: python`
and each line with a two space indent.

If your program relies on specific packages, those packages, need to be
available in the environment in which `ryd` is started (which can e.g.
be a specifically set up `virtualenv`)

It is possible to have \"partial programs\" by preceding a python
document with e.g.:

    --- !python-pre |
    from __future__ import print_function
    import sys
    import ruamel.yaml
    from ruamel.std.pathlib import Path, pushd, popd, PathLibConversionHelper
    pl = PathLibConversionHelper()

Such a block is pre-pended to all following `--- !python |` documents
(until superseded by another `--- !python-pre |` block)

## Captured output

The output from the last program that was run (`--- !python |`) is
stored and can be post-pended to a reStructuredText document by tagging
it with `!stdout` (i.e. `--- !stdout |`)

## non-running code

A document tagged `!code` will be represented as one tagged `!python`,
but the code will not be run (and hence the output used for `!stdout`
not changed).

## Zig

Zig code is indicated by:

    --- !zig |

The document is inserted as with Python, there can be a `!zig-pre`
document, and output is captured and displayed with `--- !stdout |`):

```zig
// const std = @import("std");   is defined in zig-pre

pub fn main() !void {
    const stdout = std.io.getStdOut().writer();
    try stdout.print("Hello, {s}!\n", .{"world"});
}
```

which outputs:

```lang-none
Hello, world!
```

The compilation is done with option `build-exe`.


compiler output
^^^^^^^^^^^^^^^

If you are interested in the textual output of the compiler you can use
``--- !lastcompile |``:

# Nim

Nim code is indicated by:

    --- !nim |

The document is inserted as with Python, there can be a `!nim-pre`
document, and output is captured and displayed with `--- !stdout |`):

```lang-none
let a = 123
let x = 0b0010_1010
echo(fmt"The answer to the question: {x}")
```

which outputs:

    The answer to the question: 42

The compilation is done with options
`--verbosity:0 --hint[Processing]:off` .

# compiler output

If you are interested in the textual output of the compiler you can use
`--- !lastcompile |`:

    /tmp/ryd-of-anthon/ryd-1169/tmp_02.nim(4, 5) Hint: 'a' is declared but not used [XDeclaredButNotUsed]

# Comments

Block style literal scalars do not allow YAML comments. To insert
comments in a text, either use the format acceptable by the output, e.g.
when generating `.rst` use:

    ..
       this will show up in the resulting .rst file, but will
       not render

Alternatively you can create a comment YAML document (`--- !comment |`),
for which the text will not be represented in the output file format
**at all**.

If you already have a tagged document, e.g. `--- !python |` document,
you can make it into a comment by inserting `comment-`:

    --- !comment-python |

This has been implemented by **not** reporting an error when an unkown
subfunction on `!comment` is invoked.

# Tasklists

If you set `tasklist: true` in the metadata, then lines that *start*
with one of the following tasklist patterns, are transformed to their
unicode counterpart:

    [ ] not done yet
    [v] done
    [x] no longer going to do

resulting in

☐ not done yet

☑ done

☒ no longer going to do

(it would be nice to know if there is a way to create a real list with
user specified bullet items)

# Making your own tag

Before trying to load a tag `!yourtag` from its know files, `ryd` tries
to load them from `~/.config/ryd/tag/`. This mechanism can be used to
implement your improvements over existing tags or extendeding the tags
with your own.

Let\'s assume you want to explain the use of `mypy` in your `ryd`
document, including output of a `mypy` run on some source. First create
a file `~/.config/ryd/tag/mypy.tag` with the following content:

    # coding: 'utf-8'

    from __future__ import annotations

    import os
    import subprocess
    from typing import Any, TYPE_CHECKING
    from ryd._tag._handler import ProgramHandler

    if TYPE_CHECKING:
        from ryd._convertor._base import ConvertorBase
    else:
        ConvertorBase = Any


    class Mypy(ProgramHandler):   # class name is capitalization of the stem of the filename
        def __init__(self, convertor: ConvertorBase) -> None:
            super().__init__(convertor)
            self._pre = ''

        def pre(self, d: Any) -> None:  # like !python-pre you can have !mypy-pre
            self._pre = str(d)

        def __call__(self, d: Any) -> None:
            """
            Include Python program in text. Prefix, save and run mypy, setting !stdout.
            """
            s = str(d)
            # depending on the util, you may not need to do a chdir to the tempdir
            old_dir = os.getcwd()
            self.c.temp_dir.chdir()
            path = self.c.temp_file_path('.py')
            path.write_text(self._pre + s)
            self.c.last_output = subprocess.run([
                'mypy',
                '--strict', '--follow-imports', 'silent', '--implicit-reexport',
                str(path),
            ], stderr=subprocess.STDOUT, stdout=subprocess.PIPE, encoding='utf-8').stdout
            os.chdir(old_dir)
            self.c.add_code(s, 'python')  # format the code as python

and you include in your `ryd` document:

    --- !mypy |
    def main(arg1, arg2):
        return arg1

    --- !stdout |
    which gives:

    --- |

    from the mypy output you can see ....

Your `.rst` will then contain the Python source and the mypy output:

    .. code:: python

      def main(arg1, arg2):
          return arg1

    which gives:

    .. code::

      tmp_03.py:2: error: Function is missing a type annotation
      Found 1 error in 1 file (checked 1 source file)

    from the mypy output you can see ....

# History

`ryd` grew out of a in-house solution where sections of reStructuredText
files were updated, in-place, by running Python programs specified in
separate files. Also allowing the inclusion of the (error) output.

An example of this can be seen in
[this](https://bitbucket.org/ruamel/yaml/raw/0be7d3cb8449b15d9ac9b097322f09e52b92f868/_doc/example.rst)
old version of the `example.rst` file of the `ruamel.yaml` package:

    Basic round trip of parsing YAML to Python objects, modifying
    and generating YAML::

      import sys
      from ruamel.yaml import YAML

      inp = """\
      # example
      name:
        # details
        family: Smith   # very common
        given: Alice    # one of the siblings
      """

      yaml = YAML()
      code = yaml.load(inp)
      code['name']['given'] = 'Bob'

      yaml.dump(code, sys.stdout)

    .. example code small.py

    Resulting in ::

      # example
      name:
        # details
        family: Smith   # very common
        given: Bob      # one of the siblings


    .. example output small.py

The program was inserted before the `.. example code` line and its
output before `.. example output`, replacing all the text starting after
the previous `::`

The `small.py` referenced a separate file for this piece of code. This
resulted in multiple source files that were associated with a single
`.rst` file. There was no mechanism to have partial programs that could
be tested by execution, which precluded getting output from such program
as well.

Although the code could have been edited in place, and used to get the
output, this would force one to use the extra indentation required for
lines following ReST\'s `::`.

Once this system came under review, the solution with a structured YAML
header, as used with various file formats, combined with multiple
document consisting of (tagged) top level, non-indented, block style
literal scalars, was chosen instead.

In early 2022 an update of the 0.1 format was implemented to make tags
and convertors into seperate files, thereby making them more easily
upgradable and extensible.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "ryd",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3",
    "maintainer_email": "",
    "keywords": "restructuredtext markdown markup preprocessing",
    "author": "Anthon van der Neut",
    "author_email": "a.van.der.neut@ruamel.eu",
    "download_url": "https://files.pythonhosted.org/packages/31/b9/45f05987f94b1fbc851ae11544447d0a06867665a8e826c94d41e7530e77/ryd-0.9.2.tar.gz",
    "platform": null,
    "description": "\n# ryd\n\n[![image](https://sourceforge.net/p/ryd/code/ci/default/tree/_doc/_static/license.svg?format=raw)](https://opensource.org/licenses/MIT)\n[![image](https://sourceforge.net/p/ryd/code/ci/default/tree/_doc/_static/pypi.svg?format=raw)](https://pypi.org/project/ryd/)\n[![image](https://sourceforge.net/p/oitnb/code/ci/default/tree/_doc/_static/oitnb.svg?format=raw)](https://pypi.org/project/oitnb/)\n[![image](https://sourceforge.net/p/ryd/code/ci/default/tree/_doc/_static/ryd.svg?format=raw)](https://pypi.org/project/ryd/)\n\n`ryd` ( /r\u0251\u026at/, pronounced like the verb \\\"write\\\" ) is a preprocessor\nfor text based documents, that builds upon the multi-document\ncapabilities of YAML files/streams.\n\nThe use of multiple-documents in `ryd` allows for clear separation\nbetween document text and any programs referenced in those text. Thereby\nmaking it possible to run (c.q. compile) the program parts of a\ndocument, e.g. to check whether they are syntactically correct. It can\nalso capture the *actual* output of those programs to be included in the\ndocument. It is also possible to recognise different documents and thus\nrun different formatters then recombining the documents.\n\nThis allows for easier maintenance of (correct) program sources, in\ndocument source texts like reStructuredText, LaTeX, Markdown, etc.\n\nThe first of the documents in a `ryd` file has, at the root-level, a\nmapping. This mapping is the **ryd configuration metadata** for the rest\nof the stream of documents in the file. The metadata is used to define\n`ryd` document version used, what the basic **text style** is (currently\n`rst` for RestructuredText, `so` for StackOverflow-markdown), if any\npostprocessing (PDF, HTML) needs to be done, and other configuration\ninformation. This first document doesn\\'t normally have any directives.\nThat the document is YAML 1.2 is implicit, so no `%YAML 1.2` directive\nis needed and without directive and no preceding document, you do not\nhave a directives-end marker line (`---`) at the top.\n\nThe documents following the first document are normally block style\nliteral scalars with an optional tag. The tag influences how the scalar\nstring is processed within the selected output text style.\n\n## Example\n\n    version: 0.2\n    text: rst\n    fix_inline_single_backquotes: true\n    --- |\n    Example Python program\n    ++++++++++++++++++++++\n\n    This is an example of a python program:\n    --- !python |\n    n = 7\n    print(n**2 - n)\n    --- !stdout |\n    The answer is:\n\nthis will generate (using: `ryd convert test.ryd`) the following\n`test.rst`:\n\n    Example Python program\n    ++++++++++++++++++++++\n\n    This is an example of a Python program:\n\n    .. code:: python\n\n      n = 7\n      print(n**2 - n)\n\n    The answer is:\n\n    .. code::\n\n      42\n\n## Postprocessing\n\nThe output can be converted to PDF using `rst2pdf` or HTML using\n`rst2html` with images embedded using `webpage2html`. Invocation of\nthese programs can be specified in the metatada (e.g. `post: pdf`).\n\nThe (image embedded) HTML output has the indent of indented lines of\nincluded code fragments inserted as actual spaces. So you copy and paste\nprogram code (or YAML) from HTML without a problem, something not\npossible with PDF files generated by `rst2pdf`.\n\n`ryd` generates its text output stand-alone, but the programs actually\nused for postprocessing have to be installed seperately and available in\nyour PATH.\n\n(There is currently no postprocessing for Markdown, as pandoc is not\nworking on Arch (Mark 2022))\n\n## Config\n\nYou can create a file `~/.config/ryd/ryd.yaml` with defaults for the\ncommandline options. To always embed images when converting to HTML and\nalways run the (global) verbose option:\n\n> global:\n>\n> :   verbose: true\n>\n> convert:\n>\n> :   embed: true\n\n### Command-line options\n\nThe command-line of `ryd` consists of multiple components:\n\n    ryd [--global-option] command [--options] [arguments]\n\nAlthough not indicated most global options can occur after the command\nas well.\n\n#### commands\n\n    convert             generate output as per first YAML document\n    roundtrip           roundtrip .ryd file, updating sections\n    from-rst (fromrst)  convert .rst to .ryd\n\nYou\\'ll most often use `convert` it takes one or more filenames as\nargument and generates output as specified in the ryd configuration\ndata. Some options allow you to override settings there (e.g. `--pdf`\nand `-no-pdf`)\n\nThe command `from-rst` converts a `.rst` file into `.ryd` doing some\nsection underline checking and adding the ryd configuration data\ndocument.\n\nThe `roundtrip` command updates sections by running in place\ncode-formatting on the `!python` (using `oitnb`) and `!zig` sections of\nthe `.ryd` file. ( There is currently no config option to use `blue` or\n`black`, but you can copy `ryd/_tag/python.tag` to your\n`.config/ryd/tag` directory and make the minor adjustment to use those,\nsee the section on making our own tag).\n\nDoing `ryd command --help` might indicate extra options that have not\nyet made it into the documentation and/or that are incompletely\nimplemented.\n\n# Documents and document tags\n\nEach YAML document has to be separated from other documents in the\nstream by at least the end of directive marker `---`. Apart from the\nfirst document, most documents contain a single, multi-line,\nnon-indented, scalar. The end of directives marker is therefor followed\nby the pipe (`|`) symbol, which is the YAML indication for a multi-line\nliteral scalar.\n\nThat scalar can be \\\"typed\\\" in the normal way of YAML by inserting a\ntag before the `|`. E.g. a document that is a type of Python program has\na tag `!python` and thus starts with:\n\n    --- !python |\n\nWhat a document tag exactly does, depends on the tag, but, potentially,\nalso, on the output file format selected, on previously processed tagged\ndocuments, other `.ryd` files processed previously and the environment.\n\nIn addition to the basic tag (like `!python`), a tag can have\nsubfunctions such as `!python-pre`. If an unknown subfunction is\nspecified you\\'ll get a runtime error.\n\nThe following are short descriptions for all tags, independent of the selected\noutput format:\n\n`!changelog`<br>  input is a mapping keys are (version, date) tuples, or the word NEXT\n\n`!code`<br>  Include program in text. Do not mark as executable, doesn't influence ``!stdout``.\n\n`!comment`<br>  The whole document will be discarded, i.e. not included in the output.\n\n`!inc`<br>  Include the content of the listed files (indented), without other processing,          into the output. Preceed with ``::`` if necessary\n\n`!inc-raw`<br>  Include the content of the listed files (indented), without other processing,          into the output. Preceed with ``::`` if necessary\n\n`!lastcompile`<br>  Include output from last compilation as code.\n\n`!nim`<br>  Include Nim program in text. Prefix and mark as executable.\n\n`!nim-pre`<br>  Include Nim program in text. Prefix and mark as executable.\n\n`!python`<br>  Include Python program in text. Prefix and mark as executable.\n\n`!python-hidden`<br>  Include Python program in text. Prefix and mark as executable.\n\n`!python-hiddenstdoutraw`<br>  Include Python program in text. Prefix and mark as executable.\n\n`!python-pre`<br>  Include Python program in text. Prefix and mark as executable.\n\n`!stdout`<br>  Include output from last executable document (e.g. ``!python``) as code.\n\n`!stdout-raw`<br>  Include output from last executable document (e.g. ``!python``) as code.\n\n`!table`<br>  create a table, for now headerless\n\n`!toc`<br>  insert an index\n\n`!yamlout`<br>  Include output from last executable document (e.g. ``!python``) as code tagged as         YAML document.\n\n`!zig`<br>  Include Zig program in text. Prefix and execute setting !stdout.\n\n`!zig-pre`<br>  Include Zig program in text. Prefix and execute setting !stdout.\n\n`!zsh`<br>  run each line in zsh, interspacing the lines with the output\n\n# MD\n\nThe output to `.md` expects non-code YAML documents to be valid\nMarkdown.\n\nBecause of the special meaning of `---` (and `...`) at the beginning of\na line, followed by newline or space, these should not be used. Either\nuse a longer sequence ( e.g. for divider lines use `----` ), or\nindent the whole document:\n\n```\n  --- |\n    line followed by divider\n    ---\n    another line\n```\n\n## mkdocs\n\nIf you have a file `_doc/README.ryd`, you can use `ryd serve` to\nconvert and serve this with mkdocs. The contents of the necessary\nmkdocs configuration file will be written from the mkdocs entry in the metadata\nof the `README.ryd` file (so you don't need to put more cruft in your packages root\ndirectory):\n\n```\n version: 0.2\n text: md\n pdf: false\n mkdocs:\n   # if site_name key not provided set to current directory name\n   site_name: your_project_name\n   docs_dir: _doc\n   site_author: Anthon van der Neut\n\n   theme:\n     name: readthedocs\n\n   exclude_docs: |\n     *.ryd\n     *.rst\n\n   markdown_extensions:\n   - toc:\n       permalink: true\n```\n\n \n# RST\n\nThe output to `.rst` expects non-code YAML documents to be valid\nreStructuredText. Any non-tagged documents, i.e. those starting with:\n\n    --- |\n\nare assumed to be text input, in the format specified in the ryd\nconfiguration data.\n\n## Section underlining\n\nBecause of the special meaning of `---` (and `...`) at the beginning of\na line, followed by newline or space, the section under/over-line\ncharacters used in `.ryd` files that are source for `.rst` should not\nuse `-` or `.` sequences if a any of those section names consist of\nthree letters (e.g. a section named API or RST). It is recommended to\nuse the following scheme:\n\n    Sections, subsections, etc. in .ryd files\n     # with over-line, for parts\n     * with over-line, for chapters\n     =, for sections\n     +, for subsections\n     ^, for sub-subsections\n     \", for paragraphs\n\n## Single backquotes\n\nThe `fix_inline_single_backquotes: true` tells `ryd` to indicate lines\nthat have single backquotes, that need fixing (by replacing them with\ndouble backquotes):\n\n    README.ryd\n    47: this will generate (`ryd convert test.ryd`) the following\n                          --^\n                                               --^\n\n(If you are used to other inline code markup editing e.g. on Stack\nOverflow, that uses single backquotes, you\\'ll come to appreciate this.)\n\n## Python\n\nPython code is indicated by:\n\n    --- !python |\n\nThe document is inserted into the `.rst` preceded by `.. code:: python`\nand each line with a two space indent.\n\nIf your program relies on specific packages, those packages, need to be\navailable in the environment in which `ryd` is started (which can e.g.\nbe a specifically set up `virtualenv`)\n\nIt is possible to have \\\"partial programs\\\" by preceding a python\ndocument with e.g.:\n\n    --- !python-pre |\n    from __future__ import print_function\n    import sys\n    import ruamel.yaml\n    from ruamel.std.pathlib import Path, pushd, popd, PathLibConversionHelper\n    pl = PathLibConversionHelper()\n\nSuch a block is pre-pended to all following `--- !python |` documents\n(until superseded by another `--- !python-pre |` block)\n\n## Captured output\n\nThe output from the last program that was run (`--- !python |`) is\nstored and can be post-pended to a reStructuredText document by tagging\nit with `!stdout` (i.e. `--- !stdout |`)\n\n## non-running code\n\nA document tagged `!code` will be represented as one tagged `!python`,\nbut the code will not be run (and hence the output used for `!stdout`\nnot changed).\n\n## Zig\n\nZig code is indicated by:\n\n    --- !zig |\n\nThe document is inserted as with Python, there can be a `!zig-pre`\ndocument, and output is captured and displayed with `--- !stdout |`):\n\n```zig\n// const std = @import(\"std\");   is defined in zig-pre\n\npub fn main() !void {\n    const stdout = std.io.getStdOut().writer();\n    try stdout.print(\"Hello, {s}!\\n\", .{\"world\"});\n}\n```\n\nwhich outputs:\n\n```lang-none\nHello, world!\n```\n\nThe compilation is done with option `build-exe`.\n\n\ncompiler output\n^^^^^^^^^^^^^^^\n\nIf you are interested in the textual output of the compiler you can use\n``--- !lastcompile |``:\n\n# Nim\n\nNim code is indicated by:\n\n    --- !nim |\n\nThe document is inserted as with Python, there can be a `!nim-pre`\ndocument, and output is captured and displayed with `--- !stdout |`):\n\n```lang-none\nlet a = 123\nlet x = 0b0010_1010\necho(fmt\"The answer to the question: {x}\")\n```\n\nwhich outputs:\n\n    The answer to the question: 42\n\nThe compilation is done with options\n`--verbosity:0 --hint[Processing]:off` .\n\n# compiler output\n\nIf you are interested in the textual output of the compiler you can use\n`--- !lastcompile |`:\n\n    /tmp/ryd-of-anthon/ryd-1169/tmp_02.nim(4, 5) Hint: 'a' is declared but not used [XDeclaredButNotUsed]\n\n# Comments\n\nBlock style literal scalars do not allow YAML comments. To insert\ncomments in a text, either use the format acceptable by the output, e.g.\nwhen generating `.rst` use:\n\n    ..\n       this will show up in the resulting .rst file, but will\n       not render\n\nAlternatively you can create a comment YAML document (`--- !comment |`),\nfor which the text will not be represented in the output file format\n**at all**.\n\nIf you already have a tagged document, e.g. `--- !python |` document,\nyou can make it into a comment by inserting `comment-`:\n\n    --- !comment-python |\n\nThis has been implemented by **not** reporting an error when an unkown\nsubfunction on `!comment` is invoked.\n\n# Tasklists\n\nIf you set `tasklist: true` in the metadata, then lines that *start*\nwith one of the following tasklist patterns, are transformed to their\nunicode counterpart:\n\n    [ ] not done yet\n    [v] done\n    [x] no longer going to do\n\nresulting in\n\n\u2610 not done yet\n\n\u2611 done\n\n\u2612 no longer going to do\n\n(it would be nice to know if there is a way to create a real list with\nuser specified bullet items)\n\n# Making your own tag\n\nBefore trying to load a tag `!yourtag` from its know files, `ryd` tries\nto load them from `~/.config/ryd/tag/`. This mechanism can be used to\nimplement your improvements over existing tags or extendeding the tags\nwith your own.\n\nLet\\'s assume you want to explain the use of `mypy` in your `ryd`\ndocument, including output of a `mypy` run on some source. First create\na file `~/.config/ryd/tag/mypy.tag` with the following content:\n\n    # coding: 'utf-8'\n\n    from __future__ import annotations\n\n    import os\n    import subprocess\n    from typing import Any, TYPE_CHECKING\n    from ryd._tag._handler import ProgramHandler\n\n    if TYPE_CHECKING:\n        from ryd._convertor._base import ConvertorBase\n    else:\n        ConvertorBase = Any\n\n\n    class Mypy(ProgramHandler):   # class name is capitalization of the stem of the filename\n        def __init__(self, convertor: ConvertorBase) -> None:\n            super().__init__(convertor)\n            self._pre = ''\n\n        def pre(self, d: Any) -> None:  # like !python-pre you can have !mypy-pre\n            self._pre = str(d)\n\n        def __call__(self, d: Any) -> None:\n            \"\"\"\n            Include Python program in text. Prefix, save and run mypy, setting !stdout.\n            \"\"\"\n            s = str(d)\n            # depending on the util, you may not need to do a chdir to the tempdir\n            old_dir = os.getcwd()\n            self.c.temp_dir.chdir()\n            path = self.c.temp_file_path('.py')\n            path.write_text(self._pre + s)\n            self.c.last_output = subprocess.run([\n                'mypy',\n                '--strict', '--follow-imports', 'silent', '--implicit-reexport',\n                str(path),\n            ], stderr=subprocess.STDOUT, stdout=subprocess.PIPE, encoding='utf-8').stdout\n            os.chdir(old_dir)\n            self.c.add_code(s, 'python')  # format the code as python\n\nand you include in your `ryd` document:\n\n    --- !mypy |\n    def main(arg1, arg2):\n        return arg1\n\n    --- !stdout |\n    which gives:\n\n    --- |\n\n    from the mypy output you can see ....\n\nYour `.rst` will then contain the Python source and the mypy output:\n\n    .. code:: python\n\n      def main(arg1, arg2):\n          return arg1\n\n    which gives:\n\n    .. code::\n\n      tmp_03.py:2: error: Function is missing a type annotation\n      Found 1 error in 1 file (checked 1 source file)\n\n    from the mypy output you can see ....\n\n# History\n\n`ryd` grew out of a in-house solution where sections of reStructuredText\nfiles were updated, in-place, by running Python programs specified in\nseparate files. Also allowing the inclusion of the (error) output.\n\nAn example of this can be seen in\n[this](https://bitbucket.org/ruamel/yaml/raw/0be7d3cb8449b15d9ac9b097322f09e52b92f868/_doc/example.rst)\nold version of the `example.rst` file of the `ruamel.yaml` package:\n\n    Basic round trip of parsing YAML to Python objects, modifying\n    and generating YAML::\n\n      import sys\n      from ruamel.yaml import YAML\n\n      inp = \"\"\"\\\n      # example\n      name:\n        # details\n        family: Smith   # very common\n        given: Alice    # one of the siblings\n      \"\"\"\n\n      yaml = YAML()\n      code = yaml.load(inp)\n      code['name']['given'] = 'Bob'\n\n      yaml.dump(code, sys.stdout)\n\n    .. example code small.py\n\n    Resulting in ::\n\n      # example\n      name:\n        # details\n        family: Smith   # very common\n        given: Bob      # one of the siblings\n\n\n    .. example output small.py\n\nThe program was inserted before the `.. example code` line and its\noutput before `.. example output`, replacing all the text starting after\nthe previous `::`\n\nThe `small.py` referenced a separate file for this piece of code. This\nresulted in multiple source files that were associated with a single\n`.rst` file. There was no mechanism to have partial programs that could\nbe tested by execution, which precluded getting output from such program\nas well.\n\nAlthough the code could have been edited in place, and used to get the\noutput, this would force one to use the extra indentation required for\nlines following ReST\\'s `::`.\n\nOnce this system came under review, the solution with a structured YAML\nheader, as used with various file formats, combined with multiple\ndocument consisting of (tagged) top level, non-indented, block style\nliteral scalars, was chosen instead.\n\nIn early 2022 an update of the 0.1 format was implemented to make tags\nand convertors into seperate files, thereby making them more easily\nupgradable and extensible.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Ruamel Yaml Doc preprocessor (pronounced: /r\u0251\u026at/, like the verb \"write\")",
    "version": "0.9.2",
    "project_urls": {
        "Home": "https://sourceforge.net/p/ryd/",
        "Source": "https://sourceforge.net/p/ryd/code/ci/default/tree/",
        "Tracker": "https://sourceforge.net/p/ryd/tickets/"
    },
    "split_keywords": [
        "restructuredtext",
        "markdown",
        "markup",
        "preprocessing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "630d4149947340418fb657d01b247cbc9127fea1ebe6c3eb82c92e21ac1eb8f1",
                "md5": "de3bba7964c915c68cfa3dca32c68b09",
                "sha256": "b725021847f126752555045a05391e47df565690ba823038fc1da4235d29138b"
            },
            "downloads": -1,
            "filename": "ryd-0.9.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "de3bba7964c915c68cfa3dca32c68b09",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3",
            "size": 50958,
            "upload_time": "2023-11-21T09:12:13",
            "upload_time_iso_8601": "2023-11-21T09:12:13.910728Z",
            "url": "https://files.pythonhosted.org/packages/63/0d/4149947340418fb657d01b247cbc9127fea1ebe6c3eb82c92e21ac1eb8f1/ryd-0.9.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "31b945f05987f94b1fbc851ae11544447d0a06867665a8e826c94d41e7530e77",
                "md5": "2c49d2879c6c9e3986a41b599e535f6f",
                "sha256": "9ec9016c1042f3f7c073bf658cec2ff0ae19134abe2c2014cf800539b7b708a2"
            },
            "downloads": -1,
            "filename": "ryd-0.9.2.tar.gz",
            "has_sig": false,
            "md5_digest": "2c49d2879c6c9e3986a41b599e535f6f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3",
            "size": 52896,
            "upload_time": "2023-11-21T09:12:16",
            "upload_time_iso_8601": "2023-11-21T09:12:16.348429Z",
            "url": "https://files.pythonhosted.org/packages/31/b9/45f05987f94b1fbc851ae11544447d0a06867665a8e826c94d41e7530e77/ryd-0.9.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-21 09:12:16",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "ryd"
}
        
Elapsed time: 0.55144s