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
)
-
Quote data
quote
: put double quotes around data (1 -> "1"
)squote
: put single quotes around data (1 -> '1'
)
-
Data conversion
json
:json.dumps
json_dumps
: Alias ofjson
json_loads
:json.loads
toml
:toml.dumps
toml_dumps
: Alias oftoml
toml_loads
:toml.loads
-
Globs
glob
: Likeglob.glob
, but allows passing multiple parts of a pathglob0
: Likeglob
, but only returns the first matched path
-
Read file contents
read
: Read file content. You can also pass arguments toopen
readlines
: Read file content as a list of lines. Additional arguments will be passed toopen
Project details
Release history Release notifications | RSS feed
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.1.0.tar.gz
(3.9 kB
view details)
Built Distribution
File details
Details for the file pipen-filters-0.1.0.tar.gz
.
File metadata
- Download URL: pipen-filters-0.1.0.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.4 Linux/5.13.0-1022-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f33b6290a6ac3c59be7105de2f467530bb84b723354663da81e450c945b94ea0 |
|
MD5 | 581fffaf5d403a774e7c4b7ac806fcdf |
|
BLAKE2b-256 | ef9c7c03561e65a7c1eaaa2489c99a739e99ccad6f6baf48d3782ef259440791 |
File details
Details for the file pipen_filters-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: pipen_filters-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.4 Linux/5.13.0-1022-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d9b3257dc1004b23e22790f92cd403ebc91dbd43a84b73225d826b2c084b26d |
|
MD5 | 0548c6ef4c441d2057cda9302c4e28f9 |
|
BLAKE2b-256 | 1d7fd160e3347b0ddc1e89c5ef75fc04dfc342b6c378c32dbb0888df700eed32 |