From 1d18d747a53212d6ca5136a18b5f742e7a402189 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Tue, 28 Jan 2014 00:43:23 +0000 Subject: [PATCH] Support loading in Figfiles with .yaml extension Add basic boilerplate text - feel free to change --- fig/cli/command.py | 12 +++++++++++- tests/cli_test.py | 7 +++++++ tests/fixtures/longer-filename-figfile/fig.yaml | 3 +++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/longer-filename-figfile/fig.yaml diff --git a/fig/cli/command.py b/fig/cli/command.py index 2ccc8c1bc..9641a05e6 100644 --- a/fig/cli/command.py +++ b/fig/cli/command.py @@ -36,8 +36,9 @@ If it's at a non-standard location, specify the URL with the DOCKER_HOST environ @cached_property def project(self): try: - yaml_path = os.path.join(self.base_dir, 'fig.yml') + yaml_path = self.check_yaml_filename() config = yaml.load(open(yaml_path)) + except IOError as e: if e.errno == errno.ENOENT: log.error("Can't find %s. Are you in the right directory?", os.path.basename(e.filename)) @@ -60,3 +61,12 @@ If it's at a non-standard location, specify the URL with the DOCKER_HOST environ def formatter(self): return Formatter() + def check_yaml_filename(self): + if os.path.exists(os.path.join(self.base_dir, 'fig.yaml')): + + log.warning("Fig just read the file 'fig.yaml' on startup, rather than 'fig.yml'") + log.warning("Please be aware that fig.yml the expected extension in most cases, and using .yaml can cause compatibility issues in future") + + return os.path.join(self.base_dir, 'fig.yaml') + else: + os.path.join(self.base_dir, 'fig.yml') diff --git a/tests/cli_test.py b/tests/cli_test.py index f6d372681..b6d02daad 100644 --- a/tests/cli_test.py +++ b/tests/cli_test.py @@ -15,6 +15,13 @@ class CLITestCase(DockerClientTestCase): self.command.project.kill() self.command.project.remove_stopped() + def test_yaml_filename_check(self): + self.command.base_dir = 'tests/fixtures/longer-filename-figfile' + + project = self.command.project + + self.assertTrue( project.get_service('definedinyamlnotyml'), "Service: definedinyamlnotyml should have been loaded from .yaml file" ) + def test_help(self): self.assertRaises(SystemExit, lambda: self.command.dispatch(['-h'], None)) diff --git a/tests/fixtures/longer-filename-figfile/fig.yaml b/tests/fixtures/longer-filename-figfile/fig.yaml new file mode 100644 index 000000000..81efaa2a8 --- /dev/null +++ b/tests/fixtures/longer-filename-figfile/fig.yaml @@ -0,0 +1,3 @@ +definedinyamlnotyml: + image: ubuntu + command: /bin/sleep 300 \ No newline at end of file