pipen_filters.filters
Provides the filters
add_filter
(
aliases
)
(Callable) — Add a filter to the FILTERS</>as_path
(
pth
)
(Path) — Convert a path to a Path object</>basename
(
pth
)
(str) — Get the basename of a path</>commonprefix
(
*paths
,basename_only
)
(str) — Get the common prefix of a set of paths</>config
(
x
,loader
)
(Mapping) — Get the configuration (python dictionary) from a file</>dirname
(
pth
)
(str) — Get the directory name of a path</>exists
(
pth
)
(bool) — Check if a path exists</>ext
(
pth
,ignore
,recursive
)
(str) — Get the extension of a file</>ext0
(
pth
,ignore
,recursive
)
(str) — Get the extension of a file without the leading dot</>filename
(
pth
,ignore
,recursive
)
(str) — Get the filename of a file.</>filename0
(
pth
,ignore
,recursive
)
(str) — Get the filename of a file without the extension</>getatime
(
pth
)
(int) — Get the access time of a file, return -1 if the file does not exist</>getctime
(
pth
)
(int) — Get the creation time of a file, return -1 if the file does not exist</>getmtime
(
pth
)
(int) — Get the modification time of a file, return -1 if the file does not exist</>getsize
(
pth
)
(int) — Get the size of a file, return -1 if the file does not exist</>glob
(
*paths
)
(List) — Glob a path</>glob0
(
*paths
)
(str) — Glob a path and return the first result</>isdir
(
pth
)
(bool) — Check if a path is a directory</>isempty
(
pth
,ignore_ws
,nonfile_as_empty
)
(bool) — Check if a file is empty</>isfile
(
pth
)
(bool) — Check if a path is a file</>islink
(
pth
)
(bool) — Check if a path is a symlink</>joinpaths
(
*paths
)
(str) — Join paths.</>json_dumps
(
var
)
(str) — Dump an object to json.</>json_load
(
pth
)
(Any) — Load a json file</>json_loads
(
jsonstr
)
(Any) — Load a json string to an object</>prefix
(
pth
,ignore
,recursive
)
(str) — Get the prefix of a file</>prefix0
(
pth
,ignore
,recursive
)
(str) — Get the prefix of a file without the extension</>quote
(
var
)
(str) — Quote a string</>read
(
file
,*args
,**kwargs
)
(Union) — Read the contents from a file</>readlines
(
file
,*args
,**kwargs
)
(Union) — Read the lines from a file</>readlink
(
pth
)
(str) — Get the link of a symlink</>realpath
(
pth
)
(str) — Get the real path of a path</>regex_replace
(
string
,pattern
,repl
,count
,flags
)
(str) — Replace the matched pattern with a string</>slugify
(
string
,*args
,**kwargs
)
(str) — Slugify a string</>squote
(
var
)
(str) — Quote a string with single quotes</>toml
(
var
)
(str) — Dump an object to toml.</>toml_load
(
pth
)
(Any) — Load a toml file.null
will be loaded as None</>toml_loads
(
tomlstr
)
(Any) — Load a toml string to an object,null
will be loaded as None</>
pipen_filters.filters.
add_filter
(
aliases=None
)
Add a filter to the FILTERS
Filters added: myfilter
>>> @add_filter
... def myfilter(var):
... return var
>>> @add_filter()
... def myfilter(var):
... return var
Filters added: myfilter
, myfilter2
>>> @add_filter("myfilter2")
... def myfilter(var):
... return var
aliases
(Union, optional) — The aliases of the filter, the filter itself, or None
The filter itself if used directly @add_filter
; orThe decorator to add the filter if used with arguments @add_filter(...)
pipen_filters.filters.
realpath
(
pth
)
Get the real path of a path
pth
(PathLike) — The path to the file
The real path of the file
pipen_filters.filters.
readlink
(
pth
)
Get the link of a symlink
pth
(PathLike) — The path to the symlink
The link of the symlink
pipen_filters.filters.
commonprefix
(
*paths
, basename_only=True
)
Get the common prefix of a set of paths
>>> 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."
*paths
(PathLike) — The paths to find commonprefix agaistbasename_only
(bool, optional) — Only search on the basenames
The common prefix of the paths
pipen_filters.filters.
dirname
(
pth
)
Get the directory name of a path
For example, /a/b/c.txt => /a/b/
pth
(PathLike) — The path to the file
The directory name of the file
pipen_filters.filters.
basename
(
pth
)
Get the basename of a path
For example, /a/b/c.txt => c.txt
pth
(PathLike) — The path to the file
The basename of the file
pipen_filters.filters.
ext
(
pth
, ignore=[]
, recursive=False
)
Get the extension of a file
For example, /a/b/c.txt => .txt
.
Aliases: suffix
pth
(PathLike) — The path to the fileignore
(list[str] | str, optional) — The extensions to ignoreThe extensions can be with or without leading dotrecursive
(bool, optional) — Recursively ignore the extensions from the end
The extension of the file
pipen_filters.filters.
ext0
(
pth
, ignore=[]
, recursive=False
)
Get the extension of a file without the leading dot
For example, /a/b/c.txt => txt
.
Aliases: suffix0
pth
(PathLike) — The path to the fileignore
(list[str] | str, optional) — The extensions to ignoreThe extensions can be with or without leading dotrecursive
(bool, optional) — Recursively ignore the extensions from the end
The extension of the file without the leading dot
pipen_filters.filters.
prefix
(
pth
, ignore=[]
, recursive=False
)
Get the prefix of a file
For example, /a/b/c.txt => /a/b/c
pth
(PathLike) — The path to the fileignore
(list[str] | str, optional) — The extensions to ignoreThe extensions can be with or without leading dotrecursive
(bool, optional) — Recursively ignore the extensions from the end
The prefix of the file
pipen_filters.filters.
prefix0
(
pth
, ignore=[]
, recursive=False
)
Get the prefix of a file without the extension
For example, /a/b/c.d.txt => /a/b/c.d
pth
(PathLike) — The path to the fileignore
(list[str] | str, optional) — The extensions to ignoreThe extensions can be with or without leading dotrecursive
(bool, optional) — Recursively ignore the extensions from the end
The prefix of the file without the extension
pipen_filters.filters.
filename
(
pth
, ignore=[]
, recursive=False
)
Get the filename of a file.
For example, /a/b/c.d.txt => c.d
.
Aliases: fn
, stem
pth
(PathLike) — The path to the fileignore
(list[str] | str, optional) — The extensions to ignoreThe extensions can be with or without leading dotrecursive
(bool, optional) — Recursively ignore the extensions from the end
The filename of the file
pipen_filters.filters.
filename0
(
pth
, ignore=[]
, recursive=False
)
Get the filename of a file without the extension
For example, /a/b/c.d.txt => c
.
Aliases: fn0
, stem0
pth
(PathLike) — The path to the fileignore
(list[str] | str, optional) — The extensions to ignoreThe extensions can be with or without leading dotrecursive
(bool, optional) — Recursively ignore the extensions from the end
The filename of the file without the extension
pipen_filters.filters.
joinpaths
(
*paths
)
Join paths.
For example, joinpaths("a", "b") => "a/b"
.
Aliases: joinpath
*paths
(PathLike) — The paths to join
The joined path
pipen_filters.filters.
as_path
(
pth
)
Convert a path to a Path object
pth
(PathLike) — The path to convert
The Path object
pipen_filters.filters.
isdir
(
pth
)
Check if a path is a directory
pth
(PathLike) — The path to check
True if the path is a directory, False otherwise
pipen_filters.filters.
isfile
(
pth
)
Check if a path is a file
pth
(PathLike) — The path to check
True if the path is a file, False otherwise
pipen_filters.filters.
islink
(
pth
)
Check if a path is a symlink
pth
(PathLike) — The path to check
True if the path is a symlink, False otherwise
pipen_filters.filters.
exists
(
pth
)
Check if a path exists
pth
(PathLike) — The path to check
True if the path exists, False otherwise
pipen_filters.filters.
getsize
(
pth
)
Get the size of a file, return -1 if the file does not exist
pth
(PathLike) — The path to the file
The size of the file
pipen_filters.filters.
getmtime
(
pth
)
Get the modification time of a file, return -1 if the file does not exist
pth
(PathLike) — The path to the file
The modification time of the file
pipen_filters.filters.
getctime
(
pth
)
Get the creation time of a file, return -1 if the file does not exist
pth
(PathLike) — The path to the file
The creation time of the file
pipen_filters.filters.
getatime
(
pth
)
Get the access time of a file, return -1 if the file does not exist
pth
(PathLike) — The path to the file
The access time of the file
pipen_filters.filters.
isempty
(
pth
, ignore_ws=True
, nonfile_as_empty=False
)
Check if a file is empty
pth
(PathLike) — The path to the fileignore_ws
(bool, optional) — Ignore whitespaces?nonfile_as_empty
(bool, optional) — Treat non-file as empty?
True if the file is empty, False otherwise
pipen_filters.filters.
quote
(
var
)
Quote a string
var
(Any) — The string to quote
The quoted string
pipen_filters.filters.
squote
(
var
)
Quote a string with single quotes
var
(Any) — The string to quote
The quoted string
pipen_filters.filters.
json_dumps
(
var
)
Dump an object to json.
Aliases: json
var
(Any) — The object to dump
The json string
pipen_filters.filters.
json_load
(
pth
)
Load a json file
pth
(PathLike) — The path to the json file
The loaded object
pipen_filters.filters.
json_loads
(
jsonstr
)
Load a json string to an object
jsonstr
(str) — The json string
The loaded object
pipen_filters.filters.
toml
(
var
)
Dump an object to toml.
Aliases: toml_dumps
var
(Any) — The object to dump
The toml string
pipen_filters.filters.
toml_load
(
pth
)
Load a toml file. null
will be loaded as None
pth
(PathLike) — The path to the toml file
The loaded object
pipen_filters.filters.
toml_loads
(
tomlstr
)
Load a toml string to an object, null
will be loaded as None
tomlstr
(str) — The toml string
The loaded object
pipen_filters.filters.
config
(
x
, loader=None
)
Get the configuration (python dictionary) from a file
x
(Any) — The path to the file, dict or string of configurations (json or toml)loader
(str, optional) — The loader to use, defaults to auto-detectIf x is a dict, this argument is ignored if x is a string and is not a file path, then x will be loaded as a toml string if loader is not specified if x is a file path, then x will be loaded according to the file extension
The config
pipen_filters.filters.
glob
(
*paths
)
Glob a path
*paths
(PathLike) — The paths to glob
The globbed paths
pipen_filters.filters.
glob0
(
*paths
)
Glob a path and return the first result
*paths
(PathLike) — The paths to glob
The first globbed path
pipen_filters.filters.
read
(
file
, *args
, **kwargs
)
Read the contents from a file
file
(PathLike) — The path to the file*args
(Any) — and**kwargs
(Any) — Other arguments passed toopen()
The contents of the file
pipen_filters.filters.
readlines
(
file
, *args
, **kwargs
)
Read the lines from a file
file
(PathLike) — The path to the file*args
(Any) — and**kwargs
(Any) — Other arguments toopen()
A list of lines in the file
pipen_filters.filters.
regex_replace
(
string
, pattern
, repl
, count=0
, flags=0
)
Replace the matched pattern with a string
string
(str) — The string to searchpattern
(str) — The pattern to searchrepl
(str) — The string to replaceflags
(int, optional) — The regex flags
The replaced string
pipen_filters.filters.
slugify
(
string
, *args
, **kwargs
)
Slugify a string
string
(str) — The string to slugify*args
(Any) — and**kwargs
(Any) — Other arguments toslugify()
The slugified string