envglobals
Class info¶
🛈 DocStrings¶
add
¶
Add a pre- or suffix to a value if the value is true-ish.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str | None
|
The text to check |
required |
prefix
|
str
|
Prefix to add if text is true-ish |
''
|
suffix
|
str
|
Suffix to add if text is true-ish |
''
|
Source code in src/jinjarope/envglobals.py
get_output_from_call
¶
get_output_from_call(
call: str | Sequence[str],
cwd: str | PathLike[str] | None = None,
use_cache: bool = False,
) -> str | None
Execute a system call and return its output as a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
call
|
str | Sequence[str]
|
The system call to make |
required |
cwd
|
str | PathLike[str] | None
|
The working directory for the call |
None
|
use_cache
|
bool
|
Whether to cache the output of calls |
False
|
Source code in src/jinjarope/envglobals.py
has_internet
¶
Return true if machine is connected to internet.
Checks connection with a HEAD request to the Google DNS server.
Source code in src/jinjarope/envglobals.py
load_file_cached
¶
Return the text-content of file at given path.
Call is cached based on resolved file path. Also supports fsspec-style URLs and UPaths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
AnyPath
|
The path to get str content from |
required |
Source code in src/jinjarope/envglobals.py
match
¶
A filter trying to imitate a python match-case statement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
match object |
required |
mapping
|
dict[str | type, str] | None
|
a mapping for the different cases. If key is type, an isinstance will be performed. If key is a str, check for equality. |
None
|
kwargs
|
Any
|
Same functionality as mapping, but provided as keyword arguments for convenience. |
{}
|
Examples:
Source code in src/jinjarope/envglobals.py
now
¶
Get current Datetime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tz
|
tzinfo | None
|
timezone for retuned datetime |
None
|
ternary
¶
ternary(
value: Any, true_val: TTrue, false_val: TFalse, none_val: TNone | None = None
) -> bool | TTrue | TFalse | TNone
Value ? true_val : false_val.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
The value to check. |
required |
true_val
|
TTrue
|
The value to return if given value is true-ish |
required |
false_val
|
TFalse
|
The value to return if given value is false-ish |
required |
none_val
|
TNone | None
|
Optional value to return if given value is None |
None
|