Add a set of useful filters for pipen templates
Project description
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.realpathreadlink:os.readlinkabspath:os.path.abspath
-
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.dirnamebasename:path.basenameext,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 apathlib.Pathobject
-
Path stat
isdir:os.path.isdirisfile:os.path.isfileislink:os.path.islinkexists:os.path.existsgetsize:os.path.getsize, return -1 if the path doesn't existgetmtime:os.path.getmtime, return -1 if the path doesn't existgetctime:os.path.getctime, return -1 if the path doesn't existgetatime:os.path.getatime, return -1 if the path doesn't existisempty: 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.dumpsjson_load: Load json from a filejson_loads:json.loadstoml:toml.dumpstoml_dump: Load toml from a filetoml_dumps: Alias oftomltoml_loads:toml.loadsconfig: Load configuration from an object, a string or a file
-
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 toopenreadlines: Read file content as a list of lines. Additional arguments will be passed toopen
-
Other
regex_replace: Replace a string using regexslugify: Slugify a string
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pipen_filters-1.1.2.tar.gz.
File metadata
- Download URL: pipen_filters-1.1.2.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8831495d6ef8f91f184f1d7b5ef54db0a756885812f45d9411523e85f89ccab
|
|
| MD5 |
9df5b8303cc50657a9947b0f88d10fa7
|
|
| BLAKE2b-256 |
b5f3b4e05125928a75534139956cc06b1908ee1d834093d5db61afaf55b34f44
|
File details
Details for the file pipen_filters-1.1.2-py3-none-any.whl.
File metadata
- Download URL: pipen_filters-1.1.2-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51442f822eb04ece770f2a1aa95eaf328b8e5761b19d6f22394c41a03e59b787
|
|
| MD5 |
8f6f67f08a659d6a533ccc06fa1f7cb6
|
|
| BLAKE2b-256 |
e23f02b070473106e8152d59db2b983da51b4d56c06c29f8e26851f9410e9508
|