Utils
Utils module.
======================================================================================================================== Name: pymodeller/utils.py Description: Utils module. Project: PyModeller
Copyright ©2026 PyModeller. All rights reserved.
Functions:
| Name | Description |
|---|---|
compare_dirs |
Compare dirs. |
deep_merge |
Combine two dicts. |
ensure_init_py_in_subdirectories |
Recursively walks through all directories starting from root_dir |
file_hash |
Generate hash. |
generate_init_file |
Inspects Python files within a directory, extracts classes, and generates an init.py file. |
get_file_hash |
Compute SHA-256 hash of a file. |
get_import_path |
Converts a file path structure into a valid Python dot-notation import path. |
get_variants |
Convert a string into snake_case, camelCase, and UPPER_CASE. |
to_camel_case |
Convert snake_case or UPPER_CASE to camelCase. |
to_pascal_case |
Generate class. |
to_snake_case |
Convert CamelCase or mixed strings to snake_case. |
write_env_file |
Save env file. |
ensure_init_py_in_subdirectories
Recursively walks through all directories starting from root_dir and creates an empty init.py file if one does not exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root_dir
|
str | Path
|
The target directory path to inspect. |
required |
Returns:
| Type | Description |
|---|---|
list[Path]
|
List of Path objects representing all init.py files created. |
generate_init_file
Inspects Python files within a directory, extracts classes, and generates an init.py file.
Scans all .py files inside the target directory, gathers exported class definitions,
and uses a Jinja2 template to generate an alphabetically sorted __init__.py.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_dir
|
Path | str
|
The directory path containing the Python files to inspect. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
The file path to the generated |
get_import_path
Converts a file path structure into a valid Python dot-notation import path.
Example
'./src/event_driven', 'domain/schemas', 'user.py'
becomes 'event_driven.domain.schemas.user'
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_dir
|
str
|
The base directory path (e.g., './src/event_driven'). |
required |
subfolder
|
str
|
The relative subfolder path (e.g., 'domain/schemas'). |
required |
file_name
|
str
|
The target filename (e.g., 'user.py'). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The dot-separated Python import module path. |