gitmopy.utils

Utility functions and constants for gitmopy.

Module Contents

gitmopy.utils.check_config(config)[source]

Check that the user configuration is valid.

Parameters:

config (Dict[str, Union[bool, str]]) – Current gitmopy configuration that should be saved

Raises:
Return type:

None

gitmopy.utils.choice_separator(title='', width=30, sep='─')[source]

Create an InquirerPy separator with a title.

Parameters:
  • title (str, optional) – Title in-between separator characters. Defaults to "".

  • width (int, optional) – Total length of sperator line. Defaults to 30.

  • sep (str, optional) – Character to use around the title. Defaults to "─".

Returns:

_description_

Return type:

Separator

gitmopy.utils.clear_line_and_move_up()[source]

Clear the current line and move up one line in the terminal.

gitmopy.utils.col(txt, color, bold=False)[source]

Return a coloured string with Rich.

Parameters:
  • txt (str) – String to colour.

  • colour (str) – Colour to use.

  • bold (bool, optional) – Whether to use bold font. Defaults to False.

Returns:

Coloured string.

Return type:

str

gitmopy.utils.load_config()[source]

Load the configuration from ${APP_PATH}/config.yaml.

Returns the default configuration if the file does not exist.

Returns:

User gitmopy configuration.

Return type:

Dict[str, bool]

gitmopy.utils.load_user_gitmojis()[source]

Load custom gitmojis from ${APP_PATH}/custom_gitmojis.yaml.

Returns:

Custom gitmojis.

Return type:

List[Dict[str, str]]

gitmopy.utils.message_from_commit_dict(commit_dict)[source]

Create a commit message from a commit dictionary.

Depending on whether scope is set, will look like

  • {emoji} ({scope}): {title}

  • {emoji}: {title}

Then \n\n{message} is appended if a message is specified.

Parameters:

commit_dict (Dict[str, str]) – Commit specs from the prompt.

Returns:

formatted commit message.

Return type:

str

gitmopy.utils.print_staged_files(staged)[source]

Print the currently staged files with Rich colours.

Parameters:

staged (List[str]) – List of staged files paths.

Return type:

None

gitmopy.utils.resolve_path(path)[source]

Resolve a path with expandvars, expanduser and resolve.

Parameters:

path (Union[str, Path]) – Path to resolve.

Returns:

Resolved (absolute) path.

Return type:

Path

gitmopy.utils.safe_capitalize(s)[source]

Capitalize a string if it is not empty, but keeps all-caps words.

Example: ..code-block:: python

>>> safe_capitalize("hello")
"Hello"
>>> safe_capitalize("HELLO")
"HELLO"
>>> "HELLO".capitalize()
"Hello"
Parameters:

s (str) – String to capitalize

gitmopy.utils.save_config(config)[source]

Save the configuration to ${APP_PATH}/config.yaml.

Creates the parent directory if it does not exist.

Parameters:

config (Dict[str, Union[bool, str]]) – Current gitmopy configuration.

Return type:

None

gitmopy.utils.set_start_options()[source]

Set the options for the default commit arguments automatically from the gitmopy commit command’s signature.

gitmopy.utils.standard_width_emoji(emoji, to=2)[source]

Return a standard width emoji of width 2.

Parameters:

emoji (str)

Return type:

str

gitmopy.utils.terminal_separator(margin=10)[source]

Create a separator for the terminal.

Returns:

Terminal separator

Return type:

str

gitmopy.utils.validate_user_emojis(custom_emos)[source]

Validate user emojis.

  • Must be a list of dictionaries (possibly empty)

  • Each dictionary must have an emoji key and a description key

  • Each key must be a string

  • Each key must be non-empty

Raises:

ValueError – If any of the above conditions are not met.

Parameters:

custom_emos (Any) – User defined emojis.

Returns:

Validated emojis.

Return type:

List[Dict[str, str]]

gitmopy.utils.console[source]
gitmopy.utils.print[source]