@@ -837,18 +837,17 @@ def classlist_script(name, classlist):
837837 + "\n )"
838838 )
839839
840- def save (self , filepath : Union [str , Path ], filename : str = "project" ):
840+ def save (self , filepath : Union [str , Path ] = "./ project.json " ):
841841 """Save a project to a JSON file.
842842
843843 Parameters
844844 ----------
845845 filepath : str or Path
846- The path in which the project will be written.
847- filename : str
848- The name of the generated project file.
846+ The path to where the project file will be written.
849847
850848 """
851- filepath = Path (filepath )
849+ filepath = Path (filepath ).with_suffix (".json" )
850+
852851 json_dict = {}
853852 for field in self .model_fields :
854853 attr = getattr (self , field )
@@ -882,8 +881,7 @@ def make_custom_file_dict(item):
882881 else :
883882 json_dict [field ] = attr
884883
885- file = Path (filepath , f"{ filename .removesuffix ('.json' )} .json" )
886- file .write_text (json .dumps (json_dict ))
884+ filepath .write_text (json .dumps (json_dict ))
887885
888886 @classmethod
889887 def load (cls , path : Union [str , Path ]) -> "Project" :
@@ -979,17 +977,23 @@ def try_relative_to(path: Path, relative_to: Path) -> Path:
979977 try :
980978 relative_path = abs_path .relative_to (abs_base )
981979 except ValueError as err :
982- warnings .warn ("Could not save a custom file path as relative to the project directory. "
983- "This may mean the project may not open on other devices. "
984- f"Error message: { err } " , stacklevel = 2 )
985- return abs_path
980+ warnings .warn (
981+ "Could not save a custom file path as relative to the project directory. "
982+ "This may mean the project may not open on other devices. "
983+ f"Error message: { err } " ,
984+ stacklevel = 2 ,
985+ )
986+ return abs_path
986987 else :
987988 try :
988- relative_path = abs_path .relative_to (abs_base , walk_up = True )
989+ relative_path = abs_path .relative_to (abs_base , walk_up = True )
989990 except ValueError as err :
990- warnings .warn ("Could not save a custom file path as relative to the project directory. "
991- "This may mean the project may not open on other devices. "
992- f"Error message: { err } " , stacklevel = 2 )
993- return abs_path
991+ warnings .warn (
992+ "Could not save a custom file path as relative to the project directory. "
993+ "This may mean the project may not open on other devices. "
994+ f"Error message: { err } " ,
995+ stacklevel = 2 ,
996+ )
997+ return abs_path
994998
995999 return relative_path
0 commit comments