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
68 69 70 71 72 73 74 75 76 |
|
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
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
has_internet
¶
has_internet() -> bool
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
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
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
|
str | PathLike[str]
|
The path to get str content from |
required |
Source code in src/jinjarope/envglobals.py
21 22 23 24 25 26 27 28 29 30 31 |
|
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:
{{ "a" | match(a="hit", b="miss")
{{ MyClass() | match({MyClass: "hit", OtherClass: "miss"}) }}
Source code in src/jinjarope/envglobals.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
now
¶
Get current Datetime.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tz
|
tzinfo | None
|
timezone for retuned datetime |
None
|
Source code in src/jinjarope/envglobals.py
139 140 141 142 143 144 145 |
|
ternary
¶
Value ? true_val : false_val.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Any
|
The value to check. |
required |
true_val
|
Any
|
The value to return if given value is true-ish |
required |
false_val
|
Any
|
The value to return if given value is false-ish |
required |
none_val
|
Any
|
Optional value to return if given value is None |
None
|
Source code in src/jinjarope/envglobals.py
79 80 81 82 83 84 85 86 87 88 89 90 |
|