Modular Conversion --fix_and_overwrite on Windows (#36583)

* Modular Conversion --fix_and_overwrite on Windows

* -newline on read
This commit is contained in:
hlky 2025-03-06 13:12:30 +00:00 committed by GitHub
parent 9e385109cf
commit bc30dd1efb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View File

@ -23,7 +23,7 @@ def process_file(modular_file_path, generated_modeling_content, file_type="model
file_name_suffix = file_type.split("*")[-1] if "*" in file_type else "" file_name_suffix = file_type.split("*")[-1] if "*" in file_type else ""
file_path = modular_file_path.replace("modular_", f"{file_name_prefix}_").replace(".py", f"{file_name_suffix}.py") file_path = modular_file_path.replace("modular_", f"{file_name_prefix}_").replace(".py", f"{file_name_suffix}.py")
# Read the actual modeling file # Read the actual modeling file
with open(file_path, "r") as modeling_file: with open(file_path, "r", encoding="utf-8") as modeling_file:
content = modeling_file.read() content = modeling_file.read()
output_buffer = StringIO(generated_modeling_content[file_type][0]) output_buffer = StringIO(generated_modeling_content[file_type][0])
output_buffer.seek(0) output_buffer.seek(0)
@ -39,7 +39,7 @@ def process_file(modular_file_path, generated_modeling_content, file_type="model
# Check for differences # Check for differences
if diff_list: if diff_list:
if fix_and_overwrite: if fix_and_overwrite:
with open(file_path, "w") as modeling_file: with open(file_path, "w", encoding="utf-8", newline="\n") as modeling_file:
modeling_file.write(generated_modeling_content[file_type][0]) modeling_file.write(generated_modeling_content[file_type][0])
console.print(f"[bold blue]Overwritten {file_path} with the generated content.[/bold blue]") console.print(f"[bold blue]Overwritten {file_path} with the generated content.[/bold blue]")
else: else:

View File

@ -30,7 +30,7 @@ def topological_sort(dependencies: dict):
# Function to extract class and import info from a file # Function to extract class and import info from a file
def extract_classes_and_imports(file_path): def extract_classes_and_imports(file_path):
with open(file_path, "r") as file: with open(file_path, "r", encoding="utf-8") as file:
tree = ast.parse(file.read(), filename=file_path) tree = ast.parse(file.read(), filename=file_path)
imports = set() imports = set()