scaffold_kit.scaffold
Creates project structure from a structured data file.
This module provides the core logic for the scaffolding utility. It can read a project structure definition from a YAML or JSON file and create the corresponding folders and files in the current working directory. It handles common use cases like root-level project folders, nested structures, and skipping existing files.
Usage
To run this script, navigate to your project’s root directory or parent directory and execute it as a module:
Generate from project’s root directory:#
$ uv run python -m scaffold_kit.scaffold
Generate project’s parent directory:#
$ uv run python -m scaffold_kit.scaffold –root
main()
#
Main entry point to run the scaffolding process.
Parses command-line arguments and runs the scaffolding process.
Source code in src/scaffold_kit/scaffold.py
read_structure_file(scaffold_file)
#
Reads a project structure file and returns its content.
This function attempts to load a project structure definition from either a YAML or JSON file. It prioritizes the file extension provided, but will raise an error if the file is not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scaffold_file
|
str
|
The name of the file to read (e.g., ‘scaffold.yaml’). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The content of the file as a dictionary. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a found file has invalid YAML or JSON syntax. |
FileNotFoundError
|
If the specified |
Source code in src/scaffold_kit/scaffold.py
scaffold_project(root=False, scaffold_file='scaffold.yaml')
#
Creates a project structure from a structured data file.
This function reads a project structure definition from a YAML or JSON file and creates the corresponding folders and files. It supports creating a top-level root folder and recursively creating nested files and directories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
bool
|
If True, creates the top-level folder defined in the structure file. If False, it scaffolds the contents directly in the current directory. |
False
|
scaffold_file
|
str
|
The path to the project structure definition file. |
'scaffold.yaml'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The parsed data from the structure file as a dictionary. |
Raises:
| Type | Description |
|---|---|
OSError
|
If a file or directory cannot be created due to permissions. |
ValueError
|
If a found file is not valid YAML or JSON. |
FileNotFoundError
|
If the specified file is not found. |
Source code in src/scaffold_kit/scaffold.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |