pipen-filters


Namepipen-filters JSON
Version 0.14.0 PyPI version JSON
download
home_pagehttps://github.com/pwwang/pipen-filters
SummaryAdd a set of useful filters for pipen templates
upload_time2024-07-23 22:33:39
maintainerNone
docs_urlNone
authorpwwang
requires_python<4.0,>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <img src="docs/pipen-filters.png" align="center" width="200px"/>
<hr />

Add a set of useful filters for [pipen][1] templates.

These filters can be used for both liquid and jinja2 templating in pipen.

[API documentation](https://pwwang.github.io/pipen-filters/api/pipen_filters.filters/)

## Installation

```shell
pip install -U pipen-filters
```

## Enabling/Disabling the plugin

The plugin is registered via entrypoints. It's by default enabled. To disable it:
`plugins=[..., "no:filters"]`, or uninstall this plugin.

## Usage

```python
from pipen import Proc

class MyProc(Proc):
    input = "infile:file"
    output = "outfile:file:{{in.infile | stem}}.txt"
    ...
```

## Filters

- Parse the symbolic links

  - `realpath`: `os.path.realpath`
  - `readlink`: `os.readlink`
  - `abspath`: `os.path.abspath`

- Find common prefix of given paths

  - `commonprefix`:

      ```python
      >>> commonprefix("/a/b/abc.txt", "/a/b/abc.png")
      >>> # "abc."
      >>> commonprefix("/a/b/abc.txt", "/a/b/abc.png", basename_only=False)
      >>> # "/a/b/abc."
      ```

- Get parts of the path

  - `dirname`: `path.dirname`
  - `basename`: `path.basename`
  - `ext`, `suffix`: get the extension (`/a/b/c.txt -> .txt`)
  - `ext0`, `suffix0`: get the extension without dot (`/a/b/c.txt -> txt`)
  - `prefix`: get the prefix of a path (`/a/b/c.d.txt -> /a/b/c.d`)
  - `prefix0`: get the prefix of a path without dot in basename (`/a/b/c.d.txt -> /a/b/c`)
  - `filename`, `fn`, `stem`: get the stem of a path (`/a/b.c.txt -> b.c`)
  - `filename0`, `fn0`, `stem0`: get the stem of a path without dot (`/a/b.c.txt -> b`)
  - `joinpaths`, `joinpath`: join path parts (`os.path.join`)
  - `as_path`: convert a string into a `pathlib.Path` object

- Path stat

  - `isdir`: `os.path.isdir`
  - `isfile`: `os.path.isfile`
  - `islink`: `os.path.islink`
  - `exists`: `os.path.exists`
  - `getsize`: `os.path.getsize`, return -1 if the path doesn't exist
  - `getmtime`: `os.path.getmtime`, return -1 if the path doesn't exist
  - `getctime`: `os.path.getctime`, return -1 if the path doesn't exist
  - `getatime`: `os.path.getatime`, return -1 if the path doesn't exist
  - `isempty`: check if a file is empty

- Quote data

  - `quote`: put double quotes around data (`1 -> "1"`)
  - `squote`: put single quotes around data (`1 -> '1'`)

- Configurations
  - `json`, `json_dumps`: `json.dumps`
  - `json_load`: Load json from a file
  - `json_loads`: `json.loads`
  - `toml`: `toml.dumps`
  - `toml_dump`: Load toml from a file
  - `toml_dumps`: Alias of `toml`
  - `toml_loads`: `toml.loads`
  - `config`: Load configuration from an object, a string or a file

- Globs

  - `glob`: Like `glob.glob`, but allows passing multiple parts of a path
  - `glob0`: Like `glob`, but only returns the first matched path

- Read file contents

  - `read`: Read file content. You can also pass arguments to `open`
  - `readlines`: Read file content as a list of lines. Additional arguments will be passed to `open`

- Other

  - `regex_replace`: Replace a string using regex
  - `slugify`: Slugify a string

[1]: https://github.com/pwwang/pipen

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pwwang/pipen-filters",
    "name": "pipen-filters",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "pwwang",
    "author_email": "pwwang@pwwang.com",
    "download_url": "https://files.pythonhosted.org/packages/55/2d/e059d4181885bf0ad277c2bab34ae2d568d3e0bd0998e63f7b18320f6dec/pipen_filters-0.14.0.tar.gz",
    "platform": null,
    "description": "<img src=\"docs/pipen-filters.png\" align=\"center\" width=\"200px\"/>\n<hr />\n\nAdd a set of useful filters for [pipen][1] templates.\n\nThese filters can be used for both liquid and jinja2 templating in pipen.\n\n[API documentation](https://pwwang.github.io/pipen-filters/api/pipen_filters.filters/)\n\n## Installation\n\n```shell\npip install -U pipen-filters\n```\n\n## Enabling/Disabling the plugin\n\nThe plugin is registered via entrypoints. It's by default enabled. To disable it:\n`plugins=[..., \"no:filters\"]`, or uninstall this plugin.\n\n## Usage\n\n```python\nfrom pipen import Proc\n\nclass MyProc(Proc):\n    input = \"infile:file\"\n    output = \"outfile:file:{{in.infile | stem}}.txt\"\n    ...\n```\n\n## Filters\n\n- Parse the symbolic links\n\n  - `realpath`: `os.path.realpath`\n  - `readlink`: `os.readlink`\n  - `abspath`: `os.path.abspath`\n\n- Find common prefix of given paths\n\n  - `commonprefix`:\n\n      ```python\n      >>> commonprefix(\"/a/b/abc.txt\", \"/a/b/abc.png\")\n      >>> # \"abc.\"\n      >>> commonprefix(\"/a/b/abc.txt\", \"/a/b/abc.png\", basename_only=False)\n      >>> # \"/a/b/abc.\"\n      ```\n\n- Get parts of the path\n\n  - `dirname`: `path.dirname`\n  - `basename`: `path.basename`\n  - `ext`, `suffix`: get the extension (`/a/b/c.txt -> .txt`)\n  - `ext0`, `suffix0`: get the extension without dot (`/a/b/c.txt -> txt`)\n  - `prefix`: get the prefix of a path (`/a/b/c.d.txt -> /a/b/c.d`)\n  - `prefix0`: get the prefix of a path without dot in basename (`/a/b/c.d.txt -> /a/b/c`)\n  - `filename`, `fn`, `stem`: get the stem of a path (`/a/b.c.txt -> b.c`)\n  - `filename0`, `fn0`, `stem0`: get the stem of a path without dot (`/a/b.c.txt -> b`)\n  - `joinpaths`, `joinpath`: join path parts (`os.path.join`)\n  - `as_path`: convert a string into a `pathlib.Path` object\n\n- Path stat\n\n  - `isdir`: `os.path.isdir`\n  - `isfile`: `os.path.isfile`\n  - `islink`: `os.path.islink`\n  - `exists`: `os.path.exists`\n  - `getsize`: `os.path.getsize`, return -1 if the path doesn't exist\n  - `getmtime`: `os.path.getmtime`, return -1 if the path doesn't exist\n  - `getctime`: `os.path.getctime`, return -1 if the path doesn't exist\n  - `getatime`: `os.path.getatime`, return -1 if the path doesn't exist\n  - `isempty`: check if a file is empty\n\n- Quote data\n\n  - `quote`: put double quotes around data (`1 -> \"1\"`)\n  - `squote`: put single quotes around data (`1 -> '1'`)\n\n- Configurations\n  - `json`, `json_dumps`: `json.dumps`\n  - `json_load`: Load json from a file\n  - `json_loads`: `json.loads`\n  - `toml`: `toml.dumps`\n  - `toml_dump`: Load toml from a file\n  - `toml_dumps`: Alias of `toml`\n  - `toml_loads`: `toml.loads`\n  - `config`: Load configuration from an object, a string or a file\n\n- Globs\n\n  - `glob`: Like `glob.glob`, but allows passing multiple parts of a path\n  - `glob0`: Like `glob`, but only returns the first matched path\n\n- Read file contents\n\n  - `read`: Read file content. You can also pass arguments to `open`\n  - `readlines`: Read file content as a list of lines. Additional arguments will be passed to `open`\n\n- Other\n\n  - `regex_replace`: Replace a string using regex\n  - `slugify`: Slugify a string\n\n[1]: https://github.com/pwwang/pipen\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Add a set of useful filters for pipen templates",
    "version": "0.14.0",
    "project_urls": {
        "Homepage": "https://github.com/pwwang/pipen-filters",
        "Repository": "https://github.com/pwwang/pipen-filters"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b6d758e51153197f71838f27fc18d446c8533b71e124d35f9a4fb6f9cbf451ba",
                "md5": "191674c5f69469744a8f4e6f4793e250",
                "sha256": "b7ff4f875d901aee5e2bbe7103224a43b02a269a87bcf58a567ae0dd38a1046b"
            },
            "downloads": -1,
            "filename": "pipen_filters-0.14.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "191674c5f69469744a8f4e6f4793e250",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 6488,
            "upload_time": "2024-07-23T22:33:37",
            "upload_time_iso_8601": "2024-07-23T22:33:37.813356Z",
            "url": "https://files.pythonhosted.org/packages/b6/d7/58e51153197f71838f27fc18d446c8533b71e124d35f9a4fb6f9cbf451ba/pipen_filters-0.14.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "552de059d4181885bf0ad277c2bab34ae2d568d3e0bd0998e63f7b18320f6dec",
                "md5": "a3058aee62ad7d4a2c62254452a18e2e",
                "sha256": "50e6c57786eba0a1760ed8bd4b05dd4ff6ec3dfb3df04a294ad284a4466cb2cd"
            },
            "downloads": -1,
            "filename": "pipen_filters-0.14.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a3058aee62ad7d4a2c62254452a18e2e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 6843,
            "upload_time": "2024-07-23T22:33:39",
            "upload_time_iso_8601": "2024-07-23T22:33:39.333226Z",
            "url": "https://files.pythonhosted.org/packages/55/2d/e059d4181885bf0ad277c2bab34ae2d568d3e0bd0998e63f7b18320f6dec/pipen_filters-0.14.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-23 22:33:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pwwang",
    "github_project": "pipen-filters",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pipen-filters"
}
        
Elapsed time: 0.29553s