grascii.dictionary package
Submodules
grascii.dictionary.build module
Acts as the main entry point for the grascii build command and contains the dictionary builder implementation.
This can be invoked as a standalone program: $ python -m grascii.dictionary.build –help
- class grascii.dictionary.build.BuildMessage(file_name, line, line_number, message, level)
Bases:
NamedTuple- file_name: str
Alias for field number 0
- level: int
Alias for field number 4
- line: str
Alias for field number 1
- line_number: int
Alias for field number 2
- message: str
Alias for field number 3
- class grascii.dictionary.build.BuildSummary(time: float, duplicate_count: int, warnings: list[BuildMessage], errors: list[BuildMessage], output_dir: PathLike[str] | None, entry_counts: dict[str, int] | None)
Bases:
objectResults of a dictionary build.
- Parameters:
time (float) – The duration of the build in seconds.
duplicate_count (int) – The number of duplicate entries detected.
warnings (List[BuildMessage]) – A list of warnings that occurred during the build.
errors (List[BuildMessage]) – A list of errors that occurred during the build.
output_dir (Optional[os.PathLike]) – The output directory of the dictionary.
entry_counts (Optional[Dict[str, int]]) – A dictionary of file names in the output directory to the number of entries written to that file.
- duplicate_count: int
- entry_counts: dict[str, int] | None
- errors: list[BuildMessage]
- output_dir: PathLike[str] | None
- time: float
- warnings: list[BuildMessage]
- grascii.dictionary.build.DEFAULT_PIPELINE: list[Callable[[str, str, LoggerAdapter], tuple[str, str]]] = [<function remove_boundaries>, <function standardize_case>]
The default pipeline used for dictionary builds.
- class grascii.dictionary.build.DictionaryBuilder(**kwargs)
Bases:
objectA class that runs the build process for a grascii dictionary.
- Parameters:
pipeline (List[PipelineFunc]) – A list of pipeline functions used to process entries. (Optional)
count_words (bool) – Whether to enable word count validation. (Default:
False)dedup (bool) – Whether to enable duplicate entry prevention. (Default:
True)verbosity (int) – Increase the output verbosity. (Default:
0)quiet (bool) – Suppress output. (Default:
False)
- build(infiles: Iterable[os.PathLike], output: DictionaryOutputOptions | None) BuildSummary
Run the build based on the build settings given in the constructor.
- Parameters:
infiles (Iterable[os.PathLike]) – A collection of file paths to dictionary source files.
output (Optional[DictionaryOutputOptions]) – Options for dictionary output.
- Returns:
A BuildSummary
- class grascii.dictionary.build.DictionaryOutputOptions(output_dir: PathLike, clean: bool = False)
Bases:
objectOptions for dictionary build output.
- Parameters:
output_dir (os.PathLike) – The directory where to output the dictionary files.
clean (bool) – Whether to delete all files in the output directory before building.
- clean: bool = False
- output_dir: PathLike
- exception grascii.dictionary.build.NoMatchingOutputFile
Bases:
Exception
- grascii.dictionary.build.build_argparser(argparser: ArgumentParser) None
Configure an ArgumentParser parser to parse the build command-line options.
- Parameters:
argparser – A fresh ArgumentParser to configure.
- grascii.dictionary.build.cli_build(args: Namespace) None
Run a build using arguments parsed from the command line.
- Parameters:
args – A namespace of parsed arguments.
- grascii.dictionary.build.main() None
Run a build using arguments retrieved from sys.argv.
grascii.dictionary.common module
- exception grascii.dictionary.common.DictionaryAlreadyExists(name: str)
Bases:
DictionaryException
- exception grascii.dictionary.common.DictionaryException
Bases:
ExceptionThe base class for all dictionary-related exceptions.
- exception grascii.dictionary.common.DictionaryNotFound(name: str)
Bases:
DictionaryException
- grascii.dictionary.common.get_dictionary_installed_name(name: str) str
Get the installed name of a dictionary.
i.e. Prefixed with ‘:’
- grascii.dictionary.common.get_dictionary_path_name(name: str) str
Get the path name of a dictionary.
i.e. Not prefixed with ‘:’
- grascii.dictionary.common.is_dictionary_installed_name(name: str) bool
Check whether the given name represents an installed dictionary.
grascii.dictionary.install module
- grascii.dictionary.install.build_argparser(argparser: ArgumentParser) None
- grascii.dictionary.install.cli_install(args: Namespace) None
- grascii.dictionary.install.install_dictionary(dictionary: Path, install_dir: Path, name: str | None = None, force: bool = False) str
Install a dictionary to an installation directory.
- Parameters:
dictionary (Path) – A path to the output directory of a dictionary build.
install_dir (Path) – A path to install the dictionary to.
name (str) – An optional name to give the installed dictionary.
force (bool) – If True, an existing dictionary can be overwritten.
- Returns:
The installed name of the dictionary.
- grascii.dictionary.install.main() None
Run the install command using arguments from sys.argv.
grascii.dictionary.list module
- grascii.dictionary.list.build_argparser(argparser: ArgumentParser) None
- grascii.dictionary.list.cli_list(args: Namespace) None
- grascii.dictionary.list.get_built_ins() Collection[str]
Get a collection of the installed names of all built-in dictionaries.
- Returns:
A collection of built-in dictionary names.
- grascii.dictionary.list.get_installed() Collection[str]
Get a collection of the installed names of all user-installed dictionaries.
- Returns:
A collection of installed dictionary names.
- grascii.dictionary.list.main() None
Run the list command using arguments from sys.argv.
grascii.dictionary.pipeline module
- exception grascii.dictionary.pipeline.CancelPipeline
Bases:
ExceptionAn Exception that can be thrown from a pipeline function to cancel the entire pipeline for a given entry.
- grascii.dictionary.pipeline.PipelineFunc
A function for dictionary builds that checks and/or transforms a Grascii string and its translation in a dictionary entry.
The first parameter is a Grascii string, the second parameter is its translation, and the third parameter is a logger. The function must return a Grascii string and a translation or raise a
CancelPipelineexception.alias of
Callable[[str,str,LoggerAdapter],tuple[str,str]]
- grascii.dictionary.pipeline.create_grascii_check(ignore_case: bool = True) Callable[[str, str, LoggerAdapter], tuple[str, str]]
Create a pipeline function that validates the Grascii string.
- Parameters:
ignore_case (bool) – Whether to ignore the case of the Grascii string. If
False, the Grascii string must be uppercase.
- grascii.dictionary.pipeline.create_spell_check(words_file: os.PathLike) PipelineFunc
Create a pipeline function that checks the words in a translation using the words from a file.
- Parameters:
words_file (os.PathLike) – A path to a line-delimited words file.
- grascii.dictionary.pipeline.remove_boundaries(grascii: str, translation: str, logger: LoggerAdapter)
A pipeline function that removes boundary characters from the Grascii string.
- grascii.dictionary.pipeline.standardize_case(grascii: str, translation: str, logger: LoggerAdapter)
A pipeline function that uppercases the Grascii string and capitalizes each word in the translation.
grascii.dictionary.uninstall module
- grascii.dictionary.uninstall.build_argparser(argparser: ArgumentParser) None
- grascii.dictionary.uninstall.cli_uninstall(args: Namespace) None
- grascii.dictionary.uninstall.main() None
Run the uninstall command using arguments from sys.argv.
- grascii.dictionary.uninstall.uninstall_dictionary(name: str, install_dir: Path, force: bool = False) None
Uninstall a dictionary from an installation directory.
- Parameters:
name (Path) – The name of the dictionary to uninstall.
install_dir (Path) – A path to uninstall the dictionary from.
force (bool) – If True, forces the uninstallation of a dictionary even in the case of corruption.
Module contents
- class grascii.dictionary.Dictionary(path: Traversable, dtype: DictionaryType, name: str | None = None)
Bases:
objectA class that represents a grascii dictionary and provides methods for reading entries from the dictionary.
- dump() list[DictionaryEntry]
Get all the entries in this dictionary.
- Returns:
A list of all entries in this dictionary.
- classmethod new(name: str | os.PathLike) Dictionary
Create a new dictionary from its installed name or a file path.
- Parameters:
name (Union[str, os.PathLike]) – The name of an installed dictionary (starting with ‘:’) or a path to a dictionary.
- Returns:
A new Dictionary for the given name.
- open(name: str) IO[str]
Open a file from the dictionary with the given name for reading. The caller is responsible for closing the file.
- Parameters:
name (str) – The name of the file to open.
- Returns:
A text stream.
- class grascii.dictionary.DictionaryEntry(grascii, translation)
Bases:
NamedTuple- grascii: str
Alias for field number 0
- translation: str
Alias for field number 1
- class grascii.dictionary.DictionaryType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum- BUILTIN = 0
- INSTALLED = 1
- LOCAL = 2
- grascii.dictionary.build_argparser(argparser: argparse.ArgumentParser) None