Skip to content

Commit d81f9b3

Browse files
committed
🚚 Refactor(config_generator): Move write_yaml_config function to utils
1 parent 8a38944 commit d81f9b3

File tree

2 files changed

+31
-33
lines changed

2 files changed

+31
-33
lines changed

vuegen/config_generator.py

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import yaml
32
from pathlib import Path
43
import report as r
54
from typing import Dict, List, Union, Tuple
@@ -195,7 +194,7 @@ def generate_section_data(section_folder: Path, base_folder: Path) -> Dict[str,
195194

196195
for subsection_folder in sorted_subsections:
197196
if subsection_folder.is_dir():
198-
section_data["subsections"].append(generate_subsection_data(subsection_folder, base_folder))
197+
section_data["subsections"].append(generate_subsection_data(subsection_folder))
199198

200199
return section_data
201200

@@ -261,34 +260,4 @@ def generate_yaml_structure(folder: str) -> Tuple[Dict[str, Union[str, List[Dict
261260
if section_folder.is_dir():
262261
yaml_structure["sections"].append(generate_section_data(section_folder, folder_path))
263262

264-
return yaml_structure, folder_path
265-
266-
def write_yaml_to_file(yaml_data: Dict, folder_path: Path) -> None:
267-
"""
268-
Writes the generated YAML structure to a file.
269-
270-
Parameters
271-
----------
272-
yaml_data : Dict
273-
The YAML data to write.
274-
folder_path : Path
275-
The path where the YAML file should be saved.
276-
277-
Returns
278-
-------
279-
None
280-
"""
281-
assert isinstance(yaml_data, dict), "YAML data must be a dictionary."
282-
283-
# Generate the output YAML file path based on the folder name
284-
output_yaml = folder_path / (folder_path.name + "_config.yaml")
285-
286-
# Ensure the directory exists (but don't create a new folder)
287-
if not folder_path.exists():
288-
raise FileNotFoundError(f"The directory {folder_path} does not exist.")
289-
290-
# Now write the YAML file
291-
with open(output_yaml, "w") as yaml_file:
292-
yaml.dump(yaml_data, yaml_file, default_flow_style=False, sort_keys=False)
293-
294-
print(f"YAML file has been written to {output_yaml}")
263+
return yaml_structure, folder_path

vuegen/utils.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from enum import StrEnum
1212
from typing import Type
1313
from bs4 import BeautifulSoup
14+
from pathlib import Path
1415
from urllib.parse import urlparse
1516

1617
## CHECKS
@@ -419,6 +420,34 @@ def load_yaml_config(file_path: str) -> dict:
419420

420421
return config
421422

423+
def write_yaml_config(yaml_data: dict, directory_path: Path) -> None:
424+
"""
425+
Writes the generated YAML structure to a file.
426+
427+
Parameters
428+
----------
429+
yaml_data : dict
430+
The YAML data to write.
431+
directory_path : Path
432+
The path where the YAML file should be saved.
433+
434+
Returns
435+
-------
436+
None
437+
"""
438+
assert isinstance(yaml_data, dict), "YAML data must be a dictionary."
439+
440+
# Generate the output YAML file path based on the folder name
441+
output_yaml = directory_path / (directory_path.name + "_config.yaml")
442+
443+
# Ensure the directory exists (but don't create a new folder)
444+
if not directory_path.exists():
445+
raise FileNotFoundError(f"The directory {directory_path} does not exist.")
446+
447+
# Now write the YAML file
448+
with open(output_yaml, "w") as yaml_file:
449+
yaml.dump(yaml_data, yaml_file, default_flow_style=False, sort_keys=False)
450+
422451
## LOGGING
423452
def get_basename(fname: None | str = None) -> str:
424453
"""

0 commit comments

Comments
 (0)