qwikstart.utils package¶
Submodules¶
qwikstart.utils.core module¶
-
qwikstart.utils.core.assert_has_dataclass_fields(dataclass: Any) → None¶
-
qwikstart.utils.core.ensure_path(path: Union[pathlib.Path, str]) → pathlib.Path¶ Return path object from
pathlib.Pathor string.While
Pathcan be called on strings orPathand return aPath, it does not behave correctly for mock path instances. This helper function ensures we can support normal usage and mocked paths used for testing.
-
qwikstart.utils.core.first(iterable: Iterable[T]) → T¶
-
qwikstart.utils.core.full_class_name(obj: Any) → str¶
-
qwikstart.utils.core.get_dataclass_keys(dataclass: Any) → Iterable[Any]¶
-
qwikstart.utils.core.get_dataclass_values(dataclass: Any) → Iterable[Any]¶
-
qwikstart.utils.core.indent(text: str, space_count: int) → str¶ Return
textindented byspace_countspaces.
-
qwikstart.utils.core.resolve_path(path: Union[pathlib.Path, str]) → pathlib.Path¶ Return resolved path object from
pathlib.Pathor string.
qwikstart.utils.dict_utils module¶
-
qwikstart.utils.dict_utils.get_nested_dict_value(nested_dict: Dict[str, Any], nested_key: str, separator: str = '.') → Any¶
-
qwikstart.utils.dict_utils.merge_nested_dicts(default: Mapping[str, Any], overwrite: Mapping[str, Any]) → Dict[str, Any]¶ Return new dictionary from the combination of
defaultandoverwrite.Dict values that are dictionaries themselves will be updated, whilst preserving existing keys.
Adapted from
cookiecutter.config.merge_configs.
-
qwikstart.utils.dict_utils.pop_nested_dict_value(nested_dict: Dict[str, Any], nested_key: str, separator: str = '.') → Any¶
-
qwikstart.utils.dict_utils.remap_dict(original_dict: Mapping[str, Any], key_mapping: Mapping[str, str], nested_key_separator: str = '.') → Dict[str, Any]¶ Return dict with any keys in
key_mappingrenamed.Parameters: - original_dict – Dictionary with keys to be renamed.
- key_mapping – Dictionary mapping keys in
original_dictto new keys. Any keys not inkey_mappingare returned unchanged. - nested_key_separator – Separator used in keys in
key_mappingto specify nested dictionaries.
-
qwikstart.utils.dict_utils.set_nested_dict_value(nested_dict: Dict[str, Any], nested_key: str, value: Any, separator: str = '.') → None¶
qwikstart.utils.filesystem module¶
-
class
qwikstart.utils.filesystem.FileTreeGenerator(source_dir: pathlib.Path, target_dir: pathlib.Path, renderer: qwikstart.utils.templates.TemplateRenderer, ignore_patterns: Optional[List[str]] = None)¶ Bases:
object-
copy() → None¶
-
-
qwikstart.utils.filesystem.fnmatches_to_regex(patterns: Optional[Iterable[str]], case_insensitive: bool = False, flags: int = 0) → Pattern[str]¶ Return a compiled regex Convert fnmatch patterns to that matches any of them.
Slashes are always converted to match either slash or backslash, for Windows support, even when running elsewhere.
Parameters: partial – If True, then the pattern will match if the target string starts with the pattern. Otherwise, it must match the entire string. Adapted from coveragepy’s
fnmatches_to_regex. See https://github.com/nedbat/coveragepy/blob/master/coverage/files.py
-
qwikstart.utils.filesystem.join_regex(regexes: Iterable[str]) → str¶ Combine a list of regexes into one that matches any of them.
qwikstart.utils.input_types module¶
Low-level input types using prompt_toolkit to request input.
Higher-level functionality should be put in prompt module.
-
class
qwikstart.utils.input_types.BoolInput(**kwargs)¶ Bases:
qwikstart.utils.input_types.InputType-
cast(input_text: str) → bool¶
-
default_prefix= ' (y/n): '¶
-
error_msg= "Response must be 'y' or 'n'"¶
-
is_valid(text: str) → bool¶
-
raw_prompt(message: str, suffix: Optional[str] = None, **prompt_kwargs) → str¶
-
-
class
qwikstart.utils.input_types.InputType(**kwargs)¶ Bases:
typing.Generic-
cast(input_text: str) → T¶
-
completer= None¶
-
default_prefix= ': '¶
-
error_msg= 'Input does not pass validation'¶
-
is_valid(text: str) → bool¶
-
prompt(message: str, **prompt_kwargs) → T¶
-
raw_prompt(message: str, suffix: Optional[str] = None, **prompt_kwargs) → str¶
-
validator¶
-
-
class
qwikstart.utils.input_types.IntegerInput(**kwargs)¶ Bases:
qwikstart.utils.input_types.InputType-
cast(input_text: str) → int¶
-
is_valid(text: str) → bool¶
-
raw_prompt(message: str, suffix: Optional[str] = None, **prompt_kwargs) → str¶
-
-
class
qwikstart.utils.input_types.NumberRange(min_value: int, max_value: int, **kwargs)¶ Bases:
qwikstart.utils.input_types.IntegerInput-
is_valid(text: str) → bool¶
-
-
class
qwikstart.utils.input_types.PathInput(allow_empty: bool = False, **kwargs)¶ Bases:
qwikstart.utils.input_types.StringInput-
completer= <prompt_toolkit.completion.filesystem.PathCompleter object>¶
-
-
class
qwikstart.utils.input_types.StringInput(allow_empty: bool = False, **kwargs)¶ Bases:
qwikstart.utils.input_types.InputType-
error_msg= 'Input cannot be empty'¶
-
is_valid(text: str) → bool¶
-
qwikstart.utils.logging module¶
-
qwikstart.utils.logging.configure_logger(level: str = 'INFO') → None¶
qwikstart.utils.prompt module¶
Input prompts to request data from users.
-
class
qwikstart.utils.prompt.PromptSpec(name: str, default: Optional[Any] = None, choices: Optional[List[Any]] = None, input_type: Type[qwikstart.utils.input_types.InputType[Any]] = qwikstart.utils.input_types.StringInput, input_config: Dict[str, Any] = <factory>)¶ Bases:
objectData class used to specify input prompts.
-
choices= None¶
-
default= None¶
-
input_type¶
-
-
qwikstart.utils.prompt.create_prompt_spec(**prompt_kwargs) → qwikstart.utils.prompt.PromptSpec¶ Return PromptSpec instance from attributes in dictionary.
This raises a UserFacingError if the PromptSpec is incorrectly defined.
-
qwikstart.utils.prompt.get_param_type(**prompt_kwargs) → Type[qwikstart.utils.input_types.InputType[Any]]¶
-
qwikstart.utils.prompt.read_user_choice(prompt_spec: qwikstart.utils.prompt.PromptSpec) → Any¶ Prompt user to choose from several options for the given variable.
The first item will be returned if no input provided.
Adapted from
cookiecutter.prompt(see https://github.com/cookiecutter/cookiecutter).
-
qwikstart.utils.prompt.read_user_variable(prompt_spec: qwikstart.utils.prompt.PromptSpec) → Any¶ Prompt user for variable and return the entered value or given default.
Adapted from
cookiecutter.prompt(see https://github.com/cookiecutter/cookiecutter).For more info, see https://click.palletsprojects.com/en/7.x/api/#click.prompt
qwikstart.utils.templates module¶
-
class
qwikstart.utils.templates.TemplateContext(*args, **kwargs)¶ Bases:
typing_extensions.Protocol-
execution_context¶
-
template_variable_prefix¶
-
template_variables¶
-
-
class
qwikstart.utils.templates.TemplateRenderer(template_loader: jinja2.loaders.BaseLoader, template_variables: Optional[Dict[str, Any]] = None, template_variable_prefix: Optional[str] = None, source_dir: Optional[pathlib.Path] = None)¶ Bases:
object-
add_template_filters(**kwargs) → None¶
-
add_template_variable(key: str, value: Any) → None¶
-
classmethod
from_context(context: qwikstart.utils.templates.TemplateContext) → TRenderer¶
-
get_template(path_str: str) → jinja2.environment.Template¶
-
render(template_path: str) → str¶
-
render_string(string: str) → str¶
-
resolve_template_path(path_str: str) → pathlib.Path¶
-
update_template_variables(kwargs: Any) → None¶
-
qwikstart.utils.text_utils module¶
-
qwikstart.utils.text_utils.index_of_non_empty_line(lines_of_text: Iterable[str]) → int¶
-
qwikstart.utils.text_utils.strip_empty_lines(text: Optional[str]) → str¶ Return multi-line string with leading and trailing empty lines stripped.
Module contents¶
-
qwikstart.utils.ensure_path(path: Union[pathlib.Path, str]) → pathlib.Path¶ Return path object from
pathlib.Pathor string.While
Pathcan be called on strings orPathand return aPath, it does not behave correctly for mock path instances. This helper function ensures we can support normal usage and mocked paths used for testing.
-
qwikstart.utils.first(iterable: Iterable[T]) → T¶
-
qwikstart.utils.full_class_name(obj: Any) → str¶
-
qwikstart.utils.get_dataclass_keys(dataclass: Any) → Iterable[Any]¶
-
qwikstart.utils.get_dataclass_values(dataclass: Any) → Iterable[Any]¶
-
qwikstart.utils.indent(text: str, space_count: int) → str¶ Return
textindented byspace_countspaces.
-
qwikstart.utils.merge_nested_dicts(default: Mapping[str, Any], overwrite: Mapping[str, Any]) → Dict[str, Any]¶ Return new dictionary from the combination of
defaultandoverwrite.Dict values that are dictionaries themselves will be updated, whilst preserving existing keys.
Adapted from
cookiecutter.config.merge_configs.
-
qwikstart.utils.remap_dict(original_dict: Mapping[str, Any], key_mapping: Mapping[str, str], nested_key_separator: str = '.') → Dict[str, Any]¶ Return dict with any keys in
key_mappingrenamed.Parameters: - original_dict – Dictionary with keys to be renamed.
- key_mapping – Dictionary mapping keys in
original_dictto new keys. Any keys not inkey_mappingare returned unchanged. - nested_key_separator – Separator used in keys in
key_mappingto specify nested dictionaries.
-
qwikstart.utils.strip_empty_lines(text: Optional[str]) → str¶ Return multi-line string with leading and trailing empty lines stripped.