@@ -110,14 +110,10 @@ def find_workspace_dir() -> str:
110110
111111class BootstrapConfig (BaseModel ):
112112 workspace_dir : str = Field (
113- default_factory = find_workspace_dir ,
114- description = "ghostos workspace directory" ,
113+ default = "app" ,
114+ description = "ghostos relative workspace directory" ,
115115 )
116116 dotenv_file_path : str = Field (".env" , description = "ghostos workspace .env file" )
117- ghostos_dir : str = Field (
118- default = dirname (dirname (__file__ )),
119- description = "ghostos source code directory" ,
120- )
121117 workspace_configs_dir : str = Field (
122118 "configs" ,
123119 description = "ghostos workspace relative path for configs directory" ,
@@ -129,19 +125,34 @@ class BootstrapConfig(BaseModel):
129125
130126 __from_file__ : str = ""
131127
128+ @staticmethod
129+ def abs_ghostos_dir () -> str :
130+ return dirname (dirname (__file__ ))
131+
132+ def abs_workspace_dir (self ) -> str :
133+ from os .path import abspath , exists , isdir
134+ app_dir = abspath (self .workspace_dir )
135+ if exists (app_dir ) and isdir (app_dir ):
136+ return app_dir
137+ return find_workspace_dir ()
138+
132139 def abs_runtime_dir (self ) -> str :
133- return join (self .workspace_dir , "runtime" )
140+ workspace_dir = self .abs_workspace_dir ()
141+ return join (workspace_dir , "runtime" )
134142
135143 def abs_asserts_dir (self ) -> str :
136- return join (self .workspace_dir , "assets" )
144+ workspace_dir = self .abs_workspace_dir ()
145+ return join (workspace_dir , "assets" )
137146
138147 def env_file (self ) -> str :
139- return join (self .workspace_dir , self .dotenv_file_path )
148+ workspace_dir = self .abs_workspace_dir ()
149+ return join (workspace_dir , self .dotenv_file_path )
140150
141151 def env_example_file (self ) -> str :
142- return join (self .workspace_dir , ".example.env" )
152+ workspace_dir = self .abs_workspace_dir ()
153+ return join (workspace_dir , ".example.env" )
143154
144- def save (self , dir_path : str = None ):
155+ def save (self , dir_path : str = None ) -> str :
145156 from ghostos .helpers import yaml_pretty_dump
146157 if dir_path is None :
147158 filename = join (abspath (".ghostos.yml" ))
@@ -150,6 +161,7 @@ def save(self, dir_path: str = None):
150161 content = yaml_pretty_dump (self .model_dump ())
151162 with open (filename , "w" ) as f :
152163 f .write (content )
164+ return filename
153165
154166
155167def get_bootstrap_config (local : bool = True ) -> BootstrapConfig :
@@ -273,7 +285,7 @@ def default_application_providers(
273285 DefaultLoggerProvider (),
274286 # --- workspace --- #
275287 BasicWorkspaceProvider (
276- workspace_dir = config .workspace_dir ,
288+ workspace_dir = config .abs_workspace_dir () ,
277289 configs_path = config .workspace_configs_dir ,
278290 runtime_path = config .workspace_runtime_dir ,
279291 ),
@@ -327,7 +339,7 @@ def make_app_container(
327339 if bootstrap_conf is None :
328340 bootstrap_conf = get_bootstrap_config (local = True )
329341 workspace_dir = bootstrap_conf .workspace_dir
330- if workspace_dir .startswith (bootstrap_conf .ghostos_dir ):
342+ if workspace_dir .startswith (bootstrap_conf .abs_ghostos_dir () ):
331343 warn (
332344 f"GhostOS workspace dir is not found, better run `ghostos init` at first."
333345 f"Currently using `{ workspace_dir } ` as workspace."
0 commit comments