l2tscaffolder.lib package¶
Submodules¶
l2tscaffolder.lib.code_formatter module¶
Formatter for generated code.
l2tscaffolder.lib.definitions module¶
The format specification classes.
l2tscaffolder.lib.engine module¶
The scaffolder engine.
-
class
l2tscaffolder.lib.engine.ScaffolderEngine[source]¶ Bases:
objectThe engine, responsible for file handling and setting up scaffolders.
-
GenerateFiles() → Iterator[str][source]¶ Generates needed files.
Raises: errors.EngineNotConfigured– when not all attributes have been configured.Yields: str – the full path to a file that was generated and written to disk.
-
SetModuleName(module_name: str)[source]¶ Sets the module name as chosen by the user.
Parameters: module_name (str) – name of the module to be generated by the scaffolder.
-
SetProjectRootPath(root_path: str)[source]¶ Sets the path to the root of the project tree.
Raises: errors.NoValidDefinition– when root path is not identified as a valid definition path.
-
SetScaffolder(scaffolder: l2tscaffolder.scaffolders.interface.Scaffolder)[source]¶ Stores and initializes the scaffolder object in the engine.
Parameters: scaffolder (scaffolder_interface.Scaffolder) – the scaffolder class that the engine will use to generate files.
-
StoreScaffolderAttribute(name: str, value: object, value_type: Type[CT_co])[source]¶ Stores an attribute read from the CLI.
Parameters: - name (str) – the attribute name.
- value (object) – the attribute value.
- value_type (type) – the attribute type.
Raises: KeyError– if the attribute name is already defined.ScaffolderNotConfigured– if the scaffolder has not yet been set.ValueError– if the value is not of the correct type.
-
l2tscaffolder.lib.errors module¶
This file contains the error classes.
-
exception
l2tscaffolder.lib.errors.EngineNotConfigured[source]¶ Bases:
l2tscaffolder.lib.errors.ErrorRaised when the scaffolder engine has not been configured correctly.
-
exception
l2tscaffolder.lib.errors.FileHandlingError[source]¶ Bases:
l2tscaffolder.lib.errors.ErrorRaised when the file handler is unable to do file operation.
-
exception
l2tscaffolder.lib.errors.NoValidDefinition[source]¶ Bases:
l2tscaffolder.lib.errors.ErrorRaised when no valid project definition has been identified.
-
exception
l2tscaffolder.lib.errors.ScaffolderNotConfigured[source]¶ Bases:
l2tscaffolder.lib.errors.ErrorRaised when the scaffolder has not been configured correctly.
-
exception
l2tscaffolder.lib.errors.UnableToConfigure[source]¶ Bases:
l2tscaffolder.lib.errors.ErrorRaised when the scaffolder tool has issues with configuration.
-
exception
l2tscaffolder.lib.errors.WrongCliInput[source]¶ Bases:
l2tscaffolder.lib.errors.ErrorRaised when wrong input is entered into the CLI.
l2tscaffolder.lib.file_handler module¶
The file handler.
-
class
l2tscaffolder.lib.file_handler.FileHandler[source]¶ Bases:
objectHandles the creation of files.
-
AddContent(source: str, content: str) → str[source]¶ Adds content to a file and create file if non existing.
Parameters: - source (str) – path of the file to edit.
- content (str) – content to append to the file.
Returns: path of the edited file.
Return type: str
-
AddImportToInit(path: str, entry: str)[source]¶ Adds an import into an init file in the correct order.
Parameters: - path (str) – path to the __init__ file.
- entry (str) – the import statement.
-
CopyFile(source: str, destination: str) → str[source]¶ Copies a file.
Parameters: - source (str) – path of the file to copy
- destination (str) – path to copy the file to.
Returns: the path of the copied file
Return type: str
Raises: errors.FileHandlingError– when file copy operation fails.
-
CreateFile(directory_path: str, file_name: str, filename_extension: str) → str[source]¶ Creates a empty file.
Parameters: - directory_path (str) – path to the directory the file should be created in.
- file_name (str) – name of the new file.
- filename_extension (str) – extension of the new file.
Returns: path of the created file
Return type: str
-
CreateFileFromPath(file_path: str) → str[source]¶ Creates a empty file.
Parameters: file_path (str) – path to the file. Returns: the path of the created file Return type: str
-
classmethod
CreateFilePath(path: str, name: str, extension: str) → str[source]¶ Creates the file path from the directory path, filename and suffix.
Parameters: - path (str) – path to the file directory.
- name (str) – filename.
- extension (str) – file extension.
Returns: the path to the file.
Return type: str
-
l2tscaffolder.lib.mapping_helper module¶
Helper methods for mapping.
-
class
l2tscaffolder.lib.mapping_helper.MappingHelper(template_path: str = '', formatter_path: str = '')[source]¶ Bases:
objectMapping helper for scaffolders.
-
GenerateClassName(scaffolder_name: str) → str[source]¶ Generates a class name from the scaffolder name for file generation.
Parameters: scaffolder_name (str) – name of the scaffolder Returns: name of the class Return type: str
-
RenderTemplate(template_filename: str, context: dict) → str[source]¶ Renders the template with the context to return a string.
Parameters: - template_filename (str) – the name of the template
- context (dict) – the context of the template as a dictionary
Returns: the rendered template as a string
Return type: str
-
Module contents¶
Library code for l2tscaffolder.