Helpers
Helpers or helper function are common functions used throughout the project.
Addon Manager
Use this module as addon manager.
- matrixctl.addon_manager.import_addons_from(addon_directory, addon_module, parser_name)[source]
Import addons in (global) addons.
- Parameters
- addon_directory
str
The absolute path as string to the addon directory.
- addon_module
str
The import path (with dots
.
not slashes/
) to the addons from project root e.g. “matrixctl.addons”.- parser_name
str
The name of the module the subparser is in.
- ..Note:
The nothing will be imported, when the subparser is not in (global) addons. To add the subparse to addons you need to decorate the subparsers with
matrixctl.addon_manager.subparser
- addon_directory
- Returns
- matrixctl.addon_manager.setup(func)[source]
Add subparsers to the (main) parser.
- Parameters
- func
matrixctl.addon_manager.ParserSetupType
A callback to the main parser.
- func
- Returns
- parser
argparse.ArgumentParser
The parser which includes all subparsers.
- :rtype:
py
ArgumentParser
- parser
- matrixctl.addon_manager.subparser(func)[source]
Decorate subparsers with, to add them to (global) addons on import.
- Parameters
- func
matrixctl.addon_manager.SubParserType
A subparser.
- ..Note:
The nothing will be imported, when the subparser is not in (global) addons. To add the subparse to addons you need to decorate the subparsers with
matrixctl.addon_manager.subparser
- func
- Returns
Package Version
Get the packages version.
The package’s version is determined by first checking if a
pyproject.toml``exists. If this is given, the version variable is
searched line by line in the file using a regular expression. When a
match occurs, the version is returned. If the ``pyproject.toml
does
not exist, e.g. because the package was installed, it uses the version
stored in the package’s metadata. In any case, if the version could not
be determined, it will return None
.
- matrixctl.package_version.get_version(name, file)[source]
Get the version of a Python package.
- Parameters
- Returns
Examples
# file: __init__.py from .package_version import get_version __version__: str | None = get_version(__name__, __file__) # or __version__: str = get_version(__name__, __file__) or "Unknown" # Optional: if __version__ is None: raise ValueError("Could not find the version of the package.")
# file: conf.py (sphinx) import sys sys.path.insert(0, os.path.abspath("../")) sys.path.insert(0, os.path.abspath("../..")) from matrixctl.package_version import get_version __version__: str = ( get_version("matrixctl", Path(__file__).parent) or "Unknown" )
Print
Use the functions of this module as printing helpers.
Password
Use the functions of this module as helpers for passwords.
- matrixctl.password_helpers.ask_password()[source]
Ask the user to create a password.
The user will be asked twice for a password. After that the function compares the two entered passwords. If they are the same, and not empty, the function will return the password.
- matrixctl.password_helpers.ask_question(question='Is everything correct?')[source]
Asks the user a simple yes/no a question.
- Parameters
- question
str
The yes/no question the user should be asked
- question
- Returns
Notes
The user entered value is case-insensitive.
If the user answered with an invalid answer (not
y
/j
/n
) the function asks again.
- matrixctl.password_helpers.create_user(user, admin=None)[source]
Ask the user to create a password.
The user will be asked twice for a password. After that the function compares the two entered passwords. If they are the same, and not empty, the function will ask the user if the data is correct without disclosing the password.