2727import argparse
2828import glob
2929import logging
30+ import re
3031from collections import defaultdict
3132from pathlib import Path
3233from typing import List , Dict , Any
@@ -498,7 +499,6 @@ def analyze_source_files(
498499 # Make the pattern absolute
499500 absolute_pattern = os .path .join (project_root , pattern )
500501 source_files .extend (glob .glob (absolute_pattern , recursive = True ))
501-
502502 # PASS 1: Build the request argument schema from the types files.
503503 request_arg_schema = _build_request_arg_schema (source_files , project_root )
504504
@@ -559,14 +559,14 @@ def generate_code(config: Dict[str, Any], analysis_results: tuple) -> None:
559559 Generates source code files using Jinja2 templates.
560560 """
561561 data , all_imports , all_types , request_arg_schema = analysis_results
562- project_root = config ["project_root" ]
563- config_dir = config ["config_dir" ]
564562
565563 templates_config = config .get ("templates" , [])
566564 for item in templates_config :
567- template_path = str ( Path ( config_dir ) / item ["template" ])
568- output_path = str ( Path ( project_root ) / item ["output" ])
565+ template_name = item ["template" ]
566+ output_name = item ["output" ]
569567
568+ template_path = str (Path (config ["config_dir" ]) / template_name )
569+ output_path = str (Path (config ["project_root" ]) / output_name )
570570 template = utils .load_template (template_path )
571571 methods_context = []
572572 for class_name , methods in data .items ():
@@ -662,18 +662,20 @@ def find_project_root(start_path: str, markers: list[str]) -> str | None:
662662 return None
663663 current_path = parent_path
664664
665- # Load configuration from the YAML file.
666- config = utils .load_config (config_path )
665+ # Get the absolute path of the config file
666+ abs_config_path = os .path .abspath (config_path )
667+ config = utils .load_config (abs_config_path )
667668
668- # Determine the project root.
669- script_dir = os .path .dirname (os .path .abspath (__file__ ))
670- project_root = find_project_root (script_dir , ["setup.py" , ".git" ])
669+ # Determine the project root
670+ # Start searching from the directory of this script file
671+ script_file_dir = os .path .dirname (os .path .abspath (__file__ ))
672+ project_root = find_project_root (script_file_dir , [".git" ])
671673 if not project_root :
672- project_root = os .getcwd () # Fallback to current directory
674+ # Fallback to the directory from which the script was invoked
675+ project_root = os .getcwd ()
673676
674- # Set paths in the config dictionary.
675677 config ["project_root" ] = project_root
676- config ["config_dir" ] = os .path .dirname (os . path . abspath ( config_path ) )
678+ config ["config_dir" ] = os .path .dirname (abs_config_path )
677679
678680 return config
679681
@@ -714,9 +716,12 @@ def _execute_post_processing(config: Dict[str, Any]):
714716 all_end_index = i
715717
716718 if all_start_index != - 1 and all_end_index != - 1 :
717- for i in range (all_start_index + 1 , all_end_index ):
718- member = lines [i ].strip ().replace ('"' , "" ).replace ("," , "" )
719- if member :
719+ all_content = "" .join (lines [all_start_index + 1 : all_end_index ])
720+
721+ # Extract quoted strings
722+ found_members = re .findall (r'"([^"]+)"' , all_content )
723+ for member in found_members :
724+ if member not in all_list :
720725 all_list .append (member )
721726
722727 # --- Add new items and sort ---
@@ -729,7 +734,9 @@ def _execute_post_processing(config: Dict[str, Any]):
729734 for new_member in job .get ("add_to_all" , []):
730735 if new_member not in all_list :
731736 all_list .append (new_member )
732- all_list .sort ()
737+ all_list = sorted (list (set (all_list ))) # Ensure unique and sorted
738+ # Format for the template
739+ all_list = [f' "{ item } ",\n ' for item in all_list ]
733740
734741 # --- Render the new file content ---
735742 template = utils .load_template (template_path )
0 commit comments