rybak


Namerybak JSON
Version 0.4.0 PyPI version JSON
download
home_pageNone
SummaryDirectory-tree generator library
upload_time2024-06-25 19:53:46
maintainerNone
docs_urlNone
authorRaphael Krupinski
requires_python<4.0,>=3.8
licenseBSD-3-Clause
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Rybak

_/ˈrɨ.bak/_

Directory-tree generator library.

## Synopsis

Rybak is an extension of template engines, which instead of rendering a single file or string, renders a whole
directory.

In a way it's similar to
[Cookiecutter](https://pypi.org/project/cookiecutter/) or
[Copier](https://pypi.org/project/copier/),
but while these programs are designed specifically for generating software projects scaffolding,
Rybak is a library for generating arbitrary directory tree structures.

Rybak template is a directory consisting of template files.
[Jinja](https://pypi.org/project/jinja2/), and
[Mako](https://pypi.org/project/mako/)
are supported, though one project can only use a single template engine.

Goals:

- [x] generate directory-tree based on a user-provided template and data,
- [x] keep track and remove files that aren't produced by the template,
- [x] allow for multiple files to be generated from a single template file,
- [ ] support but don't require templates to be git or other DCVS repositories.

Non-goals:

- command line interface,
- prompting users for template data.

## Usage

```python
from pathlib import Path
from rybak import TreeTemplate
from rybak.jinja import JinjaAdapter
from jinja2.loaders import FileSystemLoader

TreeTemplate(
    JinjaAdapter(loader=FileSystemLoader('template_root')),
).render(
    {'likes': {
        'Alice': 'Bob',
        'Bob': 'Charlie',
        'Charlie': 'cats',
    }},
    Path('target_root'),
)
```

- `template_root`:
  is the directory containing template files, in this case Jinja templates. Templates can be used in file content, file
  names and directory names.

### Single template multiple data

Template files can be applied to collections of items.
In order to do so, a special function is made available, `loop_over` that iterates over a passed collection. The
function can only be used in templates in file names.

`loop_over` returns the element of the collection, so that it can be used to render name.

model:

```python
names = [
    'Alice',
    'Bob',
    'Charlie',
]
```

file name:
`{{loop_over(names)}}`
would produce three files: Alice, Bob and Charlie.

The current item is also available during rendering the file contents, as model variable `item`.

Of course, we might want different value in the file name and its content. For that we can manipulate the `loop_over`s
result:

model:

```python
likes = {
    'Alice': 'Bob',
    'Bob': 'Charlie',
    'Charlie': 'cats',
}
```

file name: `{{loop_over(likes.items())[0]}}`

file content: `{{item[1]}}`

`loop_over(likes.items())` produces a key-value tuple for each file, and `[0]` accesses the key.

Similarly, `{{items}}` would produce the same key-value pair, and [1] accesses the value.

Alternatively, the model could be a list of complex objects:

model:

```python
likes = [
    {'name': 'Alice', 'likes': 'Bob'},
    {'name': 'Bob', 'likes': 'Charlie'},
    {'name': 'Charlie', 'likes': 'cats'},
]
```

In this case the file name template simplifies to `{{loop_over(likes).name}}` and the content template
to `{{item.likes}}`.

## Installation

Rybak templates can work with either of Jinja, Mako or Torado; so typically you need to install Rybak and one of those
libraries.

installing `rybak[jinja]` or `rybak[mako]` will handle this.

## Name

'y' is pronounced like in 'sit',
'a' like in 'father', just shorter.

Rybak is a Polish word for fisherman.

The original idea was to only support Mako templates, which is named by a species of a shark.

Functionality of this library is provided by the template engine, so picture a fisherman pulled by a shark.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "rybak",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Raphael Krupinski",
    "author_email": "10319569-mattesilver@users.noreply.gitlab.com",
    "download_url": "https://files.pythonhosted.org/packages/3e/13/1ba00248aa69957e0b5c4eba2d751bd374103476837f136bffcfa1dab8d7/rybak-0.4.0.tar.gz",
    "platform": null,
    "description": "# Rybak\n\n_/\u02c8r\u0268.bak/_\n\nDirectory-tree generator library.\n\n## Synopsis\n\nRybak is an extension of template engines, which instead of rendering a single file or string, renders a whole\ndirectory.\n\nIn a way it's similar to\n[Cookiecutter](https://pypi.org/project/cookiecutter/) or\n[Copier](https://pypi.org/project/copier/),\nbut while these programs are designed specifically for generating software projects scaffolding,\nRybak is a library for generating arbitrary directory tree structures.\n\nRybak template is a directory consisting of template files.\n[Jinja](https://pypi.org/project/jinja2/), and\n[Mako](https://pypi.org/project/mako/)\nare supported, though one project can only use a single template engine.\n\nGoals:\n\n- [x] generate directory-tree based on a user-provided template and data,\n- [x] keep track and remove files that aren't produced by the template,\n- [x] allow for multiple files to be generated from a single template file,\n- [ ] support but don't require templates to be git or other DCVS repositories.\n\nNon-goals:\n\n- command line interface,\n- prompting users for template data.\n\n## Usage\n\n```python\nfrom pathlib import Path\nfrom rybak import TreeTemplate\nfrom rybak.jinja import JinjaAdapter\nfrom jinja2.loaders import FileSystemLoader\n\nTreeTemplate(\n    JinjaAdapter(loader=FileSystemLoader('template_root')),\n).render(\n    {'likes': {\n        'Alice': 'Bob',\n        'Bob': 'Charlie',\n        'Charlie': 'cats',\n    }},\n    Path('target_root'),\n)\n```\n\n- `template_root`:\n  is the directory containing template files, in this case Jinja templates. Templates can be used in file content, file\n  names and directory names.\n\n### Single template multiple data\n\nTemplate files can be applied to collections of items.\nIn order to do so, a special function is made available, `loop_over` that iterates over a passed collection. The\nfunction can only be used in templates in file names.\n\n`loop_over` returns the element of the collection, so that it can be used to render name.\n\nmodel:\n\n```python\nnames = [\n    'Alice',\n    'Bob',\n    'Charlie',\n]\n```\n\nfile name:\n`{{loop_over(names)}}`\nwould produce three files: Alice, Bob and Charlie.\n\nThe current item is also available during rendering the file contents, as model variable `item`.\n\nOf course, we might want different value in the file name and its content. For that we can manipulate the `loop_over`s\nresult:\n\nmodel:\n\n```python\nlikes = {\n    'Alice': 'Bob',\n    'Bob': 'Charlie',\n    'Charlie': 'cats',\n}\n```\n\nfile name: `{{loop_over(likes.items())[0]}}`\n\nfile content: `{{item[1]}}`\n\n`loop_over(likes.items())` produces a key-value tuple for each file, and `[0]` accesses the key.\n\nSimilarly, `{{items}}` would produce the same key-value pair, and [1] accesses the value.\n\nAlternatively, the model could be a list of complex objects:\n\nmodel:\n\n```python\nlikes = [\n    {'name': 'Alice', 'likes': 'Bob'},\n    {'name': 'Bob', 'likes': 'Charlie'},\n    {'name': 'Charlie', 'likes': 'cats'},\n]\n```\n\nIn this case the file name template simplifies to `{{loop_over(likes).name}}` and the content template\nto `{{item.likes}}`.\n\n## Installation\n\nRybak templates can work with either of Jinja, Mako or Torado; so typically you need to install Rybak and one of those\nlibraries.\n\ninstalling `rybak[jinja]` or `rybak[mako]` will handle this.\n\n## Name\n\n'y' is pronounced like in 'sit',\n'a' like in 'father', just shorter.\n\nRybak is a Polish word for fisherman.\n\nThe original idea was to only support Mako templates, which is named by a species of a shark.\n\nFunctionality of this library is provided by the template engine, so picture a fisherman pulled by a shark.\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "Directory-tree generator library",
    "version": "0.4.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6ac298aa5f0706743ab29f9859b572c04124604f73a9ad6a3f9d4dca976ebec8",
                "md5": "3e928559ad635348101ead0488bc00f7",
                "sha256": "45fbc6bf850a7ea6ff37f05cfd7d706dfa8b39b10a9e7c134dc9e11ea147dea2"
            },
            "downloads": -1,
            "filename": "rybak-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3e928559ad635348101ead0488bc00f7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 8537,
            "upload_time": "2024-06-25T19:53:45",
            "upload_time_iso_8601": "2024-06-25T19:53:45.488564Z",
            "url": "https://files.pythonhosted.org/packages/6a/c2/98aa5f0706743ab29f9859b572c04124604f73a9ad6a3f9d4dca976ebec8/rybak-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3e131ba00248aa69957e0b5c4eba2d751bd374103476837f136bffcfa1dab8d7",
                "md5": "d30aa2e16a4b2a54620814b78a3bd4c6",
                "sha256": "b40c8d8c8654d959b973fa5e9a150d3914d4209ff05aaff9103159c39845e387"
            },
            "downloads": -1,
            "filename": "rybak-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d30aa2e16a4b2a54620814b78a3bd4c6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 8353,
            "upload_time": "2024-06-25T19:53:46",
            "upload_time_iso_8601": "2024-06-25T19:53:46.553785Z",
            "url": "https://files.pythonhosted.org/packages/3e/13/1ba00248aa69957e0b5c4eba2d751bd374103476837f136bffcfa1dab8d7/rybak-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-25 19:53:46",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "rybak"
}
        
Elapsed time: 0.34770s