1414from yaml import safe_load
1515
1616import gravity .io
17- from gravity .settings import Settings
18- from gravity .state import ConfigFile , service_for_service_type
17+ from gravity .settings import (
18+ ProcessManager ,
19+ Settings ,
20+ )
21+ from gravity .state import (
22+ ConfigFile ,
23+ service_for_service_type ,
24+ galaxy_installed ,
25+ )
1926from gravity .util import recursive_update
2027
2128log = logging .getLogger (__name__ )
3542
3643
3744@contextlib .contextmanager
38- def config_manager (config_file = None , state_dir = None , user_mode = None ):
39- yield ConfigManager (config_file = config_file , state_dir = state_dir , user_mode = user_mode )
45+ def config_manager (config_file = None , state_dir = None , user_mode = None , process_manager = None ):
46+ yield ConfigManager (
47+ config_file = config_file ,
48+ state_dir = state_dir ,
49+ user_mode = user_mode ,
50+ process_manager = process_manager
51+ )
4052
4153
4254class ConfigManager (object ):
4355 galaxy_server_config_section = "galaxy"
4456 gravity_config_section = "gravity"
4557 app_config_file_option = "galaxy_config_file"
4658
47- def __init__ (self , config_file = None , state_dir = None , user_mode = None ):
59+ def __init__ (self , config_file = None , state_dir = None , user_mode = None , process_manager = None ):
4860 self .__configs = {}
4961 self .state_dir = None
5062 if state_dir is not None :
5163 # convert from pathlib.Path
5264 self .state_dir = str (state_dir )
5365 self .user_mode = user_mode
66+ self .process_manager = process_manager or ProcessManager .supervisor .value
5467
5568 gravity .io .debug (f"Gravity state dir: { state_dir } " )
5669
@@ -151,12 +164,13 @@ def __load_config(self, gravity_config_dict, app_config):
151164 f"{ self .__configs [gravity_settings .instance_name ].gravity_config_file } " )
152165 gravity .io .exception (f"Duplicate instance name { gravity_settings .instance_name } , instance names must be unique" )
153166
154- gravity_config_file = gravity_config_dict [ "__file__" ]
167+ gravity_config_file = gravity_config_dict . get ( "__file__" )
155168 galaxy_config_file = app_config .get ("__file__" , gravity_config_file )
156169 galaxy_root = gravity_settings .galaxy_root or app_config .get ("root" )
157170
158171 # TODO: document that the default state_dir is data_dir/gravity and that setting state_dir overrides this
159- gravity_data_dir = self .state_dir or os .path .join (app_config .get ("data_dir" , "database" ), "gravity" )
172+ default_data_dir = "data" if galaxy_installed else "database"
173+ gravity_data_dir = self .state_dir or os .path .join (app_config .get ("data_dir" , default_data_dir ), "gravity" )
160174 log_dir = gravity_settings .log_dir or os .path .join (gravity_data_dir , "log" )
161175
162176 # TODO: this should use galaxy.util.properties.load_app_properties() so that env vars work
@@ -175,7 +189,7 @@ def __load_config(self, gravity_config_dict, app_config):
175189 gravity_config_file = gravity_config_file ,
176190 galaxy_config_file = galaxy_config_file ,
177191 instance_name = gravity_settings .instance_name ,
178- process_manager = gravity_settings .process_manager ,
192+ process_manager = gravity_settings .process_manager or self . process_manager ,
179193 service_command_style = gravity_settings .service_command_style ,
180194 app_server = gravity_settings .app_server ,
181195 virtualenv = gravity_settings .virtualenv ,
@@ -212,7 +226,7 @@ def create_static_handler_services(self, config: ConfigFile, app_config: dict):
212226 job_config = app_config ["job_config" ]
213227 else :
214228 # config in an external file
215- config_dir = os .path .dirname (config .galaxy_config_file )
229+ config_dir = os .path .dirname (config .galaxy_config_file or os . getcwd () )
216230 job_config = app_config .get ("job_config_file" )
217231 if not job_config :
218232 for job_config in [os .path .abspath (os .path .join (config_dir , c )) for c in DEFAULT_JOB_CONFIG_FILES ]:
@@ -383,9 +397,15 @@ def auto_load(self):
383397 * glob .glob ("/etc/galaxy/gravity.d/*.yaml" ),
384398 )
385399 else :
386- configs = (os .path .join ("config" , "galaxy.yml" ), os .path .join ("config" , "galaxy.yml.sample" ))
400+ configs = (os .path .join ("config" , "galaxy.yml" ), "galaxy.yml" , os .path .join ("config" , "galaxy.yml.sample" ))
401+ configs = tuple (config for config in configs if os .path .exists (config ))
402+ if not configs and galaxy_installed :
403+ gravity .io .warn (
404+ "Warning: No configuration file found but Galaxy is installed in this Python environment, running with "
405+ "default config. Use -c / --config-file or set $GALAXY_CONFIG_FILE to specify a config file."
406+ )
407+ self .__load_config ({}, {})
387408 for config in configs :
388- if os .path .exists (config ):
389- self .load_config_file (os .path .abspath (config ))
390- if not load_all :
391- return
409+ self .load_config_file (os .path .abspath (config ))
410+ if not load_all :
411+ return
0 commit comments