formelsammlung package¶
Submodules¶
formelsammlung.env_exe_runner module¶
-
formelsammlung.env_exe_runner.
env_exe_runner
(venv_runner, envs, tool, tool_args=None)[source]¶ Call given
tool
from given tox or nox or virtual env considering OS.- Parameters
venv_runner (
List
[str
]) – List containing: ‘nox’ and/or ‘tox’ and/or one or more ‘virtual environment’senvs (
List
[str
]) – List of environments to search thetool
in when ‘tox’ or ‘nox’ is in venv_runner. If neither ‘tox’ nor ‘nox’ is invenv_runner
you may pass an empty list.tool (
str
) – Name of the executable to run.tool_args (
Optional
[List
[str
]]) – Arguments to give to thetool
.
- Return type
- Returns
Exit code 127 if no executable is found or the exit code of the called cmd.
-
formelsammlung.env_exe_runner.
cli_caller
()[source]¶ Warp
env_exe_runner
to be callable by cli.Script to call executables in tox/nox/virtual envs considering OS.
The script takes three mandatory arguments:
A string with comma separated runner (tox and/or nox) and/or virtual envs.
A string with comma separated tox/nox envs to check for the executable. The envs are checked in given order. If tox/nox are not part of the first arg you may pass a ‘-‘ as second arg.
The executable to call like e.g. pylint.
All other arguments after are passed to the tool on call.
- Return type
- Returns
Exit code from
env_exe_runner
formelsammlung.envvar module¶
-
formelsammlung.envvar.
TRUE_BOOL_VALUES
= ('1', 'y', 'yes', 't', 'True')¶ Default values to convert to
True
for environment variables.
-
formelsammlung.envvar.
FALSE_BOOL_VALUES
= ('0', 'n', 'no', 'f', 'False')¶ Default values to convert to
False
for environment variables.
-
formelsammlung.envvar.
INT_REGEX
= '^[\\d]+(_\\d+)*$'¶ Default regex to check if a string could be an
int
.
-
formelsammlung.envvar.
FLOAT_REGEX
= '^[\\d]+(_\\d+)*\\.\\d+$'¶ Default regex to check if a string could be an
float
.
-
class
formelsammlung.envvar.
EnvVarGetter
(*, raise_error_if_no_value=False, true_bool_values=None, false_bool_values=None, int_regex=None, float_regex=None)[source]¶ Bases:
object
Class containing the config for
EnvVarGetter.getenv_typed()
.Initialize
EnvVarGetter
with config values.Use the
EnvVarGetter
instance to callEnvVarGetter.getenv_typed()
with the set config.Note
Parameters below are all keyword only.
- Parameters
raise_error_if_no_value (
bool
) –If
True
raises anKeyError
when no value is found byEnvVarGetter.getenv_typed()
forvar_name
anddefault
isNone
.Default:
False
true_bool_values (
Optional
[Iterable
]) –Set of objects whose string representations are matched case-insensitive against the environment variable’s value to check if the value is a
True
bool.Default:
TRUE_BOOL_VALUES
false_bool_values (
Optional
[Iterable
]) –Set of objects whose string representations are matched case-insensitive against the environment variable’s value to check if the value is a
False
bool.Default:
FALSE_BOOL_VALUES
Regex string to identify integers.
Default:
INT_REGEX
Regex string to identify floats.
Default:
FLOAT_REGEX
- Return type
-
property
true_bool_values
¶ Set of objects to identify a
True
boolean.See parameters of
EnvVarGetter
.
-
property
false_bool_values
¶ Set of objects to identify a
False
boolean.See parameters of
EnvVarGetter
.
-
property
int_regex
¶ Regex string used for checking if a string is an
int
.See parameters of
EnvVarGetter
.- Return type
-
property
int_regex_pattern
¶ Regex pattern of
EnvVarGetter.int_regex()
.Cannot be set. Set via
EnvVarGetter.int_regex()
.
-
property
float_regex
¶ Regex string used for checking if a string is a
float
.See parameters of
EnvVarGetter
.- Return type
-
property
float_regex_pattern
¶ Regex pattern of
EnvVarGetter.float_regex()
.Cannot be set. Set via
EnvVarGetter.float_regex()
.
-
getenv_typed
(var_name, default=None, rv_type=None)[source]¶ Wrap
os.getenv()
to adjust the type of the return values.Instead of returning the environments variable’s value as
str
likeos.getenv()
you can setrv_type
to atype
to convert the value into. Ifrv_type
is not set thetype
gets guessed and used for conversion.Guessable types are (checked in this order):
For
bool
guessing the value returned byos.getenv()
is compared againstEnvVarGetter.true_bool_values()
andEnvVarGetter.false_bool_values()
and if a match is found returns the corresponding boolean.For
int
guessing the value returned byos.getenv()
is checked by the regexEnvVarGetter.int_regex_pattern()
which can be changed by settingEnvVarGetter.int_regex()
.For
float
guessing the value returned byos.getenv()
is checked by the regexEnvVarGetter.float_regex_pattern()
which can be changed by settingEnvVarGetter.float_regex()
.Warning
Because
bool
is guessed beforeint
0
and1
are converted intobool
instead ofint
whenrv_type
is not set.How to use:
>>> os.environ["TEST_ENV_VAR"] = "2" >>> getter = EnvVarGetter() >>> getter.getenv_typed("TEST_ENV_VAR", 1, int) 2
- Parameters
- Raises
- Return type
- Returns
Value for
var_name
ordefault
converted torv_type
or guessed type.
-
formelsammlung.envvar.
getenv_typed
(var_name, default=None, rv_type=None, **kwargs)[source]¶ Shortcut for
EnvVarGetter(...).getenv_typed(...)
.How to use:
>>> os.environ["TEST_ENV_VAR"] = "2" >>> getenv_typed("TEST_ENV_VAR", 1, int) 2
- Parameters
var_name (
str
) – Same argument as for and gets given toEnvVarGetter.getenv_typed()
.default (
Optional
[Any
]) – Same argument as for and gets given toEnvVarGetter.getenv_typed()
.rv_type (
Optional
[type
]) – Same argument as for and gets given toEnvVarGetter.getenv_typed()
.kwargs (
Any
) – Arguments taken byEnvVarGetter
- Return type
- Returns
Return value of
EnvVarGetter.getenv_typed()
.
formelsammlung.flask_sphinx_docs module¶
-
class
formelsammlung.flask_sphinx_docs.
SphinxDocServer
(app=None, *, doc_dir=None, index_file='index.html')[source]¶ Bases:
object
Serve your sphinx docs under /docs/ on your own flask app.
Init SphinxDocServer class.
You can invoke it in your app factory:
sds = SphinxDocServer() def create_app(): app = Flask(__name__) sds.init_app(app) return app
or you can include the plugin directly without setting a
doc_dir
:app = Flask(__name__) SphinxDocServer(app)
or with setting a
doc_dir
:app = Flask(__name__) SphinxDocServer(app, doc_dir="../../docs/build/html")
- Parameters
app (
Optional
[Flask
]) – Same argument as for and gets given toSphinxDocServer.init_app()
.doc_dir (
Optional
[str
]) – Same argument as for and gets given toSphinxDocServer.init_app()
.index_file (
str
) – Same argument as for and gets given toSphinxDocServer.init_app()
.
- Return type
formelsammlung.nox_session module¶
-
formelsammlung.nox_session.
session_w_poetry
(session_func)¶ Decorator function for
nox
session fcuntions.The decorator replaces
nox
’s ownSession
class withformelsammlung
’sSession
class. The later introduces theSession.poetry_install()
method for easier usage ofnox
withpoetry
managed projects.The decorator must come after
nox
’ssession
decorator as it takes theSession
object given bysession
as its argument to change it.Example:
import nox from formelsammlung.nox_session import session_w_poetry @nox.session @session_w_poetry def some_nox_session(session): ...
-
class
formelsammlung.nox_session.
Session
(runner)[source]¶ Bases:
Session
Subclass of nox’s Session class to add
poetry_install
method.- Parameters
runner (SessionRunner) –
- Return type
-
poetry_install
(extras=None, *, no_root=False, no_dev=False, pip_require_venv=False, **kwargs)[source]¶ Wrap
poetry install
command for usage innox
sessions.- Parameters
extras (
Optional
[str
]) – string of space separated extras to installno_dev (
bool
) –if
--no-dev
should be setDefault:
False
no_root (
bool
) –if
--no-root
should be setDefault:
False
pip_require_venv (
bool
) – ifTrue
sets environment variablePIP_REQUIRE_VIRTUALENV
totrue
for this call.pip
then requires to be run inside a venv.pip
is used to installpoetry
inside the venv, if nopoetry
executable can be found.kwargs (
Any
) – same kwargs asSession.install()
(seenox
docs)
- Return type
formelsammlung.strcalc module¶
-
exception
formelsammlung.strcalc.
StringCalculatorError
[source]¶ Bases:
Exception
Exception for the StringCalculator.
-
formelsammlung.strcalc.
calculate_string
(expression)[source]¶ Calculate the given expression.
The given arithmetic expression string is parsed as an
ast
and then handled by theast.NodeVisitor
.Python exceptions are risen like with normal arithmetic expression e.g.
ZeroDivisionError
.Supported number types:
Warning
On PyPy3 only: When working with
complex
numbers containing or resulting withfloat
numbers be aware that the result ofcalculate_string()
and the equivalent arithmetic expression can divert in the decimals. The result fromcalculate_string()
is then less precise.Supported mathematical operators:
Positive (
operator.pos()
)+ a
Negative (
operator.neg()
)- a
Addition (
operator.add()
)a + b
Subtraction (
operator.sub()
)a - b
Multiplication (
operator.mul()
)a * b
Exponentiation (
operator.pow()
)a ** b
Division (
operator.truediv()
)a / b
FloorDivision (
operator.floordiv()
)a // b
Modulo (
operator.mod()
)a % b
How to use:
>>> calculate_string("(1+2)/3") 1.0
formelsammlung.venv_utils module¶
-
formelsammlung.venv_utils.
get_venv_path
()[source]¶ Get path to the venv from where the python executable runs.
- Raises
FileNotFoundError – when no calling venv can be detected.
- Return type
- Returns
Return venv path
-
formelsammlung.venv_utils.
get_venv_bin_dir
(venv_path)[source]¶ Return path to bin/Scripts dir of given venv.
- Parameters
- Raises
FileNotFoundError – when no bin/Scripts dir can be found for given venv.
- Return type
- Returns
Path to bin/Scripts dir
-
formelsammlung.venv_utils.
get_venv_tmp_dir
(venv_path, search_tmp_dirs=None, create_if_missing=False, create_dir_name=None)[source]¶ Return path to tmp/temp dir of given venv.
- Parameters
- Raises
FileNotFoundError – when no tmp/temp dir can be found for given venv.
- Return type
- Returns
Path to tmp/temp dir
-
formelsammlung.venv_utils.
get_venv_site_packages_dir
(venv_path)[source]¶ Return path to site-packages dir of given venv.
- Parameters
- Raises
FileNotFoundError – when no site-packages dir can be found for given venv.
- Return type
- Returns
Path to site-packages dir