Repository: Miserlou/Zappa

Issue:
Support .yaml extension for zappa settings
Zappa doesn't support looking for ```zappa_settings.yaml```, it only looks for the .yml extension

According to http://www.yaml.org/faq.html:
```
Is there an official extension for YAML files?
Please use ".yaml" when possible.
```

Should be a fairly minor/easy change. Maybe the only question is which should take precedence?


Discussion:
![image](https://user-images.githubusercontent.com/139987/27715120-0bdd2cf6-5d03-11e7-8226-9c838fd85f30.png)

Haha, fair, though I don't mind doing the work here.
Sure. PR welcome. If you could, do it for TML/TOML as well while you're at it.

Resolving patch:
diff --git a/zappa/cli.py b/zappa/cli.py
--- a/zappa/cli.py
+++ b/zappa/cli.py
@@ -1974,11 +1974,13 @@ def get_json_or_yaml_settings(self, settings_name="zappa_settings"):
         Return zappa_settings path as JSON or YAML (or TOML), as appropriate.
         """
         zs_json = settings_name + ".json"
-        zs_yaml = settings_name + ".yml"
+        zs_yml = settings_name + ".yml"
+        zs_yaml = settings_name + ".yaml"
         zs_toml = settings_name + ".toml"
 
         # Must have at least one
         if not os.path.isfile(zs_json) \
+            and not os.path.isfile(zs_yml) \
             and not os.path.isfile(zs_yaml) \
             and not os.path.isfile(zs_toml):
             raise ClickException("Please configure a zappa_settings file or call `zappa init`.")
@@ -1988,6 +1990,8 @@ def get_json_or_yaml_settings(self, settings_name="zappa_settings"):
             settings_file = zs_json
         elif os.path.isfile(zs_toml):
             settings_file = zs_toml
+        elif os.path.isfile(zs_yml):
+            settings_file = zs_yml
         else:
             settings_file = zs_yaml
 
@@ -2003,13 +2007,14 @@ def load_settings_file(self, settings_file=None):
         if not os.path.isfile(settings_file):
             raise ClickException("Please configure your zappa_settings file or call `zappa init`.")
 
-        if '.yml' in settings_file:
+        path, ext = os.path.splitext(settings_file)
+        if ext == '.yml' or ext == '.yaml':
             with open(settings_file) as yaml_file:
                 try:
                     self.zappa_settings = yaml.load(yaml_file)
                 except ValueError: # pragma: no cover
                     raise ValueError("Unable to load the Zappa settings YAML. It may be malformed.")
-        elif '.toml' in settings_file:
+        elif ext == '.toml':
             with open(settings_file) as toml_file:
                 try:
                     self.zappa_settings = toml.load(toml_file)


Test patch:
diff --git a/tests/test_settings.yaml b/tests/test_settings.yaml
new file mode 100644
--- /dev/null
+++ b/tests/test_settings.yaml
@@ -0,0 +1,57 @@
+---
+ttt888:
+  touch: false
+  s3_bucket: lmbda
+  app_function: tests.test_app.hello_world
+  callbacks:
+    settings: test_settings.callback
+    post: test_settings.callback
+    zip: test_settings.callback
+  delete_local_zip: true
+  debug: true
+  parameter_depth: 2
+  prebuild_script: test_settings.prebuild_me
+  events:
+  - function: tests.test_app.schedule_me
+    expression: rate(1 minute)
+  - function: test.test_app.method
+    event_source:
+      arn: arn:aws:sns:::1
+      events:
+      - sns:Publish
+devor:
+  s3_bucket: lmbda
+  app_function: tests.test_app.hello_world
+  callbacks:
+    settings: tests.test_app.callback
+    post: tests.test_app.callback
+    zip: test_settings.callback
+  delete_local_zip: true
+  debug: true
+  parameter_depth: 2
+  prebuild_script: test_settings.prebuild_me
+  events:
+  - function: tests.test_app.schedule_me
+    expression: rate(1 minute)
+extendo:
+  extends: ttt888
+  touch: true
+  prebuild_script: test_settings.prebuild_me
+  environment_variables:
+    EXTENDO: You bet
+extendo2:
+  extends: extendo
+  s3_bucket: lmbda2
+deprecated_remote_env:
+  s3_bucket: lmbda
+  remote_env_bucket: lmbda-env
+  remote_env_file: dev/env.json
+remote_env:
+  s3_bucket: lmbda
+  remote_env: s3://lmbda-env/prod/env.json
+extendofail:
+  extends: failfail
+  prebuild_script: test_settings.prebuild_me
+  environment_variables:
+    EXTENDO: You bet
+
diff --git a/tests/tests.py b/tests/tests.py
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -713,7 +713,7 @@ def test_load_extended_settings(self):
         self.assertTrue(zappa_cli.stage_config['touch'])  # First Extension
         self.assertTrue(zappa_cli.stage_config['delete_local_zip'])  # The base
 
-    def test_load_settings_yaml(self):
+    def test_load_settings_yml(self):
         zappa_cli = ZappaCLI()
         zappa_cli.api_stage = 'ttt888'
         zappa_cli.load_settings('tests/test_settings.yml')
@@ -725,6 +725,18 @@ def test_load_settings_yaml(self):
         self.assertEqual('lmbda', zappa_cli.stage_config['s3_bucket'])
         self.assertEqual(True, zappa_cli.stage_config['touch'])
 
+    def test_load_settings_yaml(self):
+        zappa_cli = ZappaCLI()
+        zappa_cli.api_stage = 'ttt888'
+        zappa_cli.load_settings('tests/test_settings.yaml')
+        self.assertEqual(False, zappa_cli.stage_config['touch'])
+
+        zappa_cli = ZappaCLI()
+        zappa_cli.api_stage = 'extendo'
+        zappa_cli.load_settings('tests/test_settings.yaml')
+        self.assertEqual('lmbda', zappa_cli.stage_config['s3_bucket'])
+        self.assertEqual(True, zappa_cli.stage_config['touch'])
+
     def test_load_settings_toml(self):
         zappa_cli = ZappaCLI()
         zappa_cli.api_stage = 'ttt888'
@@ -738,6 +750,7 @@ def test_settings_extension(self):
         tempdir = tempfile.mkdtemp(prefix="zappa-test-settings")
         shutil.copy("tests/test_one_env.json", tempdir + "/zappa_settings.json")
         shutil.copy("tests/test_settings.yml", tempdir + "/zappa_settings.yml")
+        shutil.copy("tests/test_settings.yml", tempdir + "/zappa_settings.yaml")
         shutil.copy("tests/test_settings.toml", tempdir + "/zappa_settings.toml")
 
         orig_cwd = os.getcwd()
@@ -768,6 +781,13 @@ def test_settings_extension(self):
             self.assertIn("devor", zappa_cli.zappa_settings)
             os.unlink("zappa_settings.yml")
 
+            self.assertEqual(zappa_cli.get_json_or_yaml_settings(),
+                             "zappa_settings.yaml")
+            zappa_cli.load_settings_file()
+            self.assertIn("ttt888", zappa_cli.zappa_settings)
+            self.assertIn("devor", zappa_cli.zappa_settings)
+            os.unlink("zappa_settings.yaml")
+
             # Without anything, we should get an exception.
             self.assertRaises(
                 ClickException, zappa_cli.get_json_or_yaml_settings)