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
toolfrom 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 thetoolin when ‘tox’ or ‘nox’ is in venv_runner. If neither ‘tox’ nor ‘nox’ is invenv_runneryou 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_runnerto 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
Truefor environment variables.
-
formelsammlung.envvar.FALSE_BOOL_VALUES= ('0', 'n', 'no', 'f', 'False')¶ Default values to convert to
Falsefor 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:
objectClass containing the config for
EnvVarGetter.getenv_typed().Initialize
EnvVarGetterwith config values.Use the
EnvVarGetterinstance to callEnvVarGetter.getenv_typed()with the set config.Note
Parameters below are all keyword only.
- Parameters
raise_error_if_no_value (
bool) –If
Trueraises anKeyErrorwhen no value is found byEnvVarGetter.getenv_typed()forvar_nameanddefaultisNone.Default:
Falsetrue_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
Truebool.Default:
TRUE_BOOL_VALUESfalse_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
Falsebool.Default:
FALSE_BOOL_VALUESRegex string to identify integers.
Default:
INT_REGEXRegex string to identify floats.
Default:
FLOAT_REGEX
- Return type
-
property
true_bool_values¶ Set of objects to identify a
Trueboolean.See parameters of
EnvVarGetter.
-
property
false_bool_values¶ Set of objects to identify a
Falseboolean.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
strlikeos.getenv()you can setrv_typeto atypeto convert the value into. Ifrv_typeis not set thetypegets guessed and used for conversion.Guessable types are (checked in this order):
For
boolguessing 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
intguessing the value returned byos.getenv()is checked by the regexEnvVarGetter.int_regex_pattern()which can be changed by settingEnvVarGetter.int_regex().For
floatguessing the value returned byos.getenv()is checked by the regexEnvVarGetter.float_regex_pattern()which can be changed by settingEnvVarGetter.float_regex().Warning
Because
boolis guessed beforeint0and1are converted intoboolinstead ofintwhenrv_typeis 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_nameordefaultconverted torv_typeor 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:
objectServe 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
noxsession fcuntions.The decorator replaces
nox’s ownSessionclass withformelsammlung’sSessionclass. The later introduces theSession.poetry_install()method for easier usage ofnoxwithpoetrymanaged projects.The decorator must come after
nox’ssessiondecorator as it takes theSessionobject given bysessionas 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:
SessionSubclass of nox’s Session class to add
poetry_installmethod.- Parameters
runner (SessionRunner) –
- Return type
-
poetry_install(extras=None, *, no_root=False, no_dev=False, pip_require_venv=False, **kwargs)[source]¶ Wrap
poetry installcommand for usage innoxsessions.- Parameters
extras (
Optional[str]) – string of space separated extras to installno_dev (
bool) –if
--no-devshould be setDefault:
Falseno_root (
bool) –if
--no-rootshould be setDefault:
Falsepip_require_venv (
bool) – ifTruesets environment variablePIP_REQUIRE_VIRTUALENVtotruefor this call.pipthen requires to be run inside a venv.pipis used to installpoetryinside the venv, if nopoetryexecutable can be found.kwargs (
Any) – same kwargs asSession.install()(seenoxdocs)
- Return type
formelsammlung.strcalc module¶
-
exception
formelsammlung.strcalc.StringCalculatorError[source]¶ Bases:
ExceptionException for the StringCalculator.
-
formelsammlung.strcalc.calculate_string(expression)[source]¶ Calculate the given expression.
The given arithmetic expression string is parsed as an
astand 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
complexnumbers containing or resulting withfloatnumbers 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())+ aNegative (
operator.neg())- aAddition (
operator.add())a + bSubtraction (
operator.sub())a - bMultiplication (
operator.mul())a * bExponentiation (
operator.pow())a ** bDivision (
operator.truediv())a / bFloorDivision (
operator.floordiv())a // bModulo (
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