2727import argparse
2828import glob
2929import logging
30+ import re
3031from collections import defaultdict
3132from pathlib import Path
3233from typing import List , Dict , Any
@@ -505,7 +506,6 @@ def analyze_source_files(
505506 # Make the pattern absolute
506507 absolute_pattern = os .path .join (project_root , pattern )
507508 source_files .extend (glob .glob (absolute_pattern , recursive = True ))
508-
509509 # PASS 1: Build the request argument schema from the types files.
510510 request_arg_schema = _build_request_arg_schema (source_files , project_root )
511511
@@ -566,14 +566,14 @@ def generate_code(config: Dict[str, Any], analysis_results: tuple) -> None:
566566 Generates source code files using Jinja2 templates.
567567 """
568568 data , all_imports , all_types , request_arg_schema = analysis_results
569- project_root = config ["project_root" ]
570- config_dir = config ["config_dir" ]
571569
572570 templates_config = config .get ("templates" , [])
573571 for item in templates_config :
574- template_path = str ( Path ( config_dir ) / item ["template" ])
575- output_path = str ( Path ( project_root ) / item ["output" ])
572+ template_name = item ["template" ]
573+ output_name = item ["output" ]
576574
575+ template_path = str (Path (config ["config_dir" ]) / template_name )
576+ output_path = str (Path (config ["project_root" ]) / output_name )
577577 template = utils .load_template (template_path )
578578 methods_context = []
579579 for class_name , methods in data .items ():
@@ -669,18 +669,20 @@ def find_project_root(start_path: str, markers: list[str]) -> str | None:
669669 return None
670670 current_path = parent_path
671671
672- # Load configuration from the YAML file.
673- config = utils .load_config (config_path )
672+ # Get the absolute path of the config file
673+ abs_config_path = os .path .abspath (config_path )
674+ config = utils .load_config (abs_config_path )
674675
675- # Determine the project root.
676- script_dir = os .path .dirname (os .path .abspath (__file__ ))
677- project_root = find_project_root (script_dir , ["setup.py" , ".git" ])
676+ # Determine the project root
677+ # Start searching from the directory of this script file
678+ script_file_dir = os .path .dirname (os .path .abspath (__file__ ))
679+ project_root = find_project_root (script_file_dir , [".git" ])
678680 if not project_root :
679- project_root = os .getcwd () # Fallback to current directory
681+ # Fallback to the directory from which the script was invoked
682+ project_root = os .getcwd ()
680683
681- # Set paths in the config dictionary.
682684 config ["project_root" ] = project_root
683- config ["config_dir" ] = os .path .dirname (os . path . abspath ( config_path ) )
685+ config ["config_dir" ] = os .path .dirname (abs_config_path )
684686
685687 return config
686688
@@ -721,9 +723,12 @@ def _execute_post_processing(config: Dict[str, Any]):
721723 all_end_index = i
722724
723725 if all_start_index != - 1 and all_end_index != - 1 :
724- for i in range (all_start_index + 1 , all_end_index ):
725- member = lines [i ].strip ().replace ('"' , "" ).replace ("," , "" )
726- if member :
726+ all_content = "" .join (lines [all_start_index + 1 : all_end_index ])
727+
728+ # Extract quoted strings
729+ found_members = re .findall (r'"([^"]+)"' , all_content )
730+ for member in found_members :
731+ if member not in all_list :
727732 all_list .append (member )
728733
729734 # --- Add new items and sort ---
@@ -736,7 +741,9 @@ def _execute_post_processing(config: Dict[str, Any]):
736741 for new_member in job .get ("add_to_all" , []):
737742 if new_member not in all_list :
738743 all_list .append (new_member )
739- all_list .sort ()
744+ all_list = sorted (list (set (all_list ))) # Ensure unique and sorted
745+ # Format for the template
746+ all_list = [f' "{ item } ",\n ' for item in all_list ]
740747
741748 # --- Render the new file content ---
742749 template = utils .load_template (template_path )
0 commit comments