Skip to main content

Add a set of useful filters for pipen templates

Project description

pipen-filters

Add a set of useful filters for pipen templates.

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

Installation

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

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
  • Find common prefix of given paths

    • commonprefix:

      >>> 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: get the extension (/a/b/c.txt -> .txt)
    • ext0: 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: 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_dump: Load json froma file
    • json_dumps: Alias of json
    • 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pipen_filters-0.11.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

pipen_filters-0.11.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file pipen_filters-0.11.0.tar.gz.

File metadata

  • Download URL: pipen_filters-0.11.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/6.2.0-1018-azure

File hashes

Hashes for pipen_filters-0.11.0.tar.gz
Algorithm Hash digest
SHA256 bdec774158d99cb143fd6618aa0207c1471e9d92520cbf7272dcb1356dbc9680
MD5 9f1ff91ec1e9d6703541f22ebeae8d62
BLAKE2b-256 152049f324f0a1fc328177fcafabdb5fca82650932c6452022bd0bf3c9081493

See more details on using hashes here.

File details

Details for the file pipen_filters-0.11.0-py3-none-any.whl.

File metadata

  • Download URL: pipen_filters-0.11.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/6.2.0-1018-azure

File hashes

Hashes for pipen_filters-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0f2d80d83e423d4494596a30e0f040ead41c4cc774a4805185f8dc4910ac114d
MD5 ee86cafa9520239f76b4cdb8c6640b77
BLAKE2b-256 00dfd661c3bca53dd1c3b78c52d5b51820754c6171ac888a9df92c5eb613a729

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page