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 apathlib.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 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_dump
: Load json froma filejson_dumps
: Alias ofjson
json_loads
:json.loads
toml
:toml.dumps
toml_dump
: Load toml from a filetoml_dumps
: Alias oftoml
toml_loads
:toml.loads
config
: 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 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.7.0.tar.gz
(5.1 kB
view details)
Built Distribution
File details
Details for the file pipen_filters-0.7.0.tar.gz
.
File metadata
- Download URL: pipen_filters-0.7.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.10.6 Linux/5.15.0-1035-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43df52d167965ae9308f5c706363eeade442cc9689814cdf36c80a7eecf86fdc |
|
MD5 | 416d085a410cb7280bf7a4a14e6f2f2f |
|
BLAKE2b-256 | ec972f5ddd8629e9df2c0b59ce8c1412dacc1058d09656d1b206a2bb8d4ad36a |
File details
Details for the file pipen_filters-0.7.0-py3-none-any.whl
.
File metadata
- Download URL: pipen_filters-0.7.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.10.6 Linux/5.15.0-1035-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 225d706c6ad5c600b5e51345c0fb5c59a9b676703dbaa63381028f54805d8090 |
|
MD5 | cd44c94762a47c1ed2aade6228a417c0 |
|
BLAKE2b-256 | 9f267b8cd8cbcfb7745aaaefb2273cb81598c07e97ad459a88704f9b0c8c41e7 |