@@ -868,7 +868,8 @@ def write_item(item):
868868 + f"'filename': '{ item .filename } ', "
869869 + f"'function_name': '{ item .function_name } ', "
870870 + f"'language': '{ str (item .language )} ', "
871- + f"'path': r'{ str (item .path )} '" # Raw string to ensure backslash is not interpreted as escape
871+ # Raw string to ensure backslash is not interpreted as escape
872+ + f"'path': r'{ str (try_relative_to (item .path , script_path .parent ))} '"
872873 + "}"
873874 )
874875 return item_str
@@ -932,7 +933,7 @@ def make_custom_file_dict(item):
932933 "name" : item .name ,
933934 "filename" : item .filename ,
934935 "language" : item .language ,
935- "path" : try_relative_to (item .path , filepath ),
936+ "path" : try_relative_to (item .path , filepath . parent ),
936937 }
937938
938939 json_dict ["custom_files" ] = [make_custom_file_dict (file ) for file in attr ]
@@ -968,7 +969,7 @@ def load(cls, path: Union[str, Path]) -> "Project":
968969 # file paths are saved as relative to the project directory
969970 for file in model_dict ["custom_files" ]:
970971 if not Path (file ["path" ]).is_absolute ():
971- file ["path" ] = Path (path , file ["path" ])
972+ file ["path" ] = Path (path . parent , file ["path" ]). resolve ( )
972973
973974 return cls .model_validate (model_dict )
974975
@@ -1038,7 +1039,7 @@ def try_relative_to(path: Path, relative_to: Path) -> str:
10381039 return str (path .relative_to (relative_to ))
10391040 else :
10401041 warnings .warn (
1041- "Could not save custom file path as relative to the project directory, "
1042+ "Could not write custom file path as relative to the project directory, "
10421043 "which means that it may not work on other devices. If you would like to share your project, "
10431044 "make sure your custom files are in a subfolder of the project save location." ,
10441045 stacklevel = 2 ,
0 commit comments