MCPcopy Index your code
hub / github.com/zappa/Zappa / load_settings_file

Method load_settings_file

zappa/cli.py:2878–2927  ·  view source on GitHub ↗

Load our settings file. If no settings file exists, attempt to generate settings from environment variables.

(self, settings_file=None)

Source from the content-addressed store, hash-verified

2876 return settings_file
2877
2878 def load_settings_file(self, settings_file=None):
2879 """
2880 Load our settings file. If no settings file exists, attempt to generate
2881 settings from environment variables.
2882 """
2883
2884 if not settings_file:
2885 try:
2886 settings_file = self.get_json_or_yaml_settings()
2887 except ClickException:
2888 # No settings file found, we'll generate from environment variables
2889 settings_file = None
2890
2891 if settings_file and os.path.isfile(settings_file):
2892 # Load from file
2893 path, ext = os.path.splitext(settings_file)
2894 if ext == ".yml" or ext == ".yaml":
2895 with open(settings_file) as yaml_file:
2896 try:
2897 self.zappa_settings = yaml.safe_load(yaml_file)
2898 except ValueError: # pragma: no cover
2899 raise ValueError("Unable to load the Zappa settings YAML. It may be malformed.")
2900 elif ext == ".toml":
2901 with open(settings_file) as toml_file:
2902 try:
2903 self.zappa_settings = toml.load(toml_file)
2904 except ValueError: # pragma: no cover
2905 raise ValueError("Unable to load the Zappa settings TOML. It may be malformed.")
2906 else:
2907 with open(settings_file) as json_file:
2908 try:
2909 self.zappa_settings = json.load(json_file)
2910 except ValueError: # pragma: no cover
2911 raise ValueError("Unable to load the Zappa settings JSON. It may be malformed.")
2912 else:
2913
2914 # No settings file exists, try to generate default from environment
2915 stage = self.stage_env if self.stage_env else "dev"
2916
2917 # Use the common settings generation method
2918 self.zappa_settings = self._generate_settings_dict(stage=stage)
2919
2920 # Check if we got valid settings from environment
2921 # If no settings were provided via environment variables, the dict will only have defaults
2922 stage_config = self._get_config_from_environment_and_args()
2923 if not stage_config:
2924 raise ClickException(
2925 "No zappa_settings file found and no ZAPPA_ environment variables set.\n"
2926 "Please configure your zappa_settings file, use 'zappa init', or set ZAPPA_ environment variables."
2927 )
2928
2929 def create_package(self, output=None, use_zappa_release: Optional[str] = None):
2930 """