Skip to content

Commit 37d1dac

Browse files
committed
Implement json format for configuration files
1 parent 3e9b71f commit 37d1dac

6 files changed

Lines changed: 47 additions & 5 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ python:
33
- "2.6"
44
- "2.7"
55
- "3.2"
6-
install: "pip install -r requirements.txt --use-mirrors"
6+
install: "pip install -r requirements-dev.txt --use-mirrors"
77
script: python tests/run-tests.py

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ To use buildploy, you need:
8383
3. A configuration file informing buildploy of where the repositories are
8484
and how the project should be built.
8585

86-
Configuration files are in YAML format and look like this:
86+
Configuration files can be in YAML or JSON format.
87+
YAML configuration files look like this:
8788

8889
src_repo: git@github.com:foo/foo.git
8990
deploy_repo: git@github.com:foo/foo-deploy.git
@@ -99,6 +100,15 @@ path accepted by Git, including a local filesystem path.
99100
deployable trees.
100101
- ``build_cmd`` - Command used to perform the build.
101102

103+
JSON configuration files use the same schema but serialized in JSON.
104+
Buildploy detects configuration file type via its extension: .yaml and .yml
105+
files are considered YAML files, .json files are considered JSON files.
106+
The default for other extensions is currently YAML, although an automatic
107+
detection facility may be added in the future.
108+
109+
JSON is part of Python standard library as of 2.6, and when using it
110+
buildploy has no dependencies. Using YAML requires installing PyYAML.
111+
102112
Then, execute ``buildploy path/to/config.yaml``.
103113

104114
## Branches

TODO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
- json support for configuration files
1+
- command line option to force yaml/json for configuration file
22
- branch command line option
33
- test for building without reset into an empty repository
44
- add tests for transforming a branch that does and does not exist in deploy repo

buildploy.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import subprocess
77
import os.path
88
import sys
9-
import yaml
109
import time
1110

1211
py3 = sys.version_info[0] == 3
@@ -124,8 +123,14 @@ def git_reset_to_empty_tree(deploy_dir, branch):
124123
git_in_dir(deploy_dir, ['branch', '-d', 'newbranch'])
125124

126125
def load_config_file(path):
126+
if path.endswith('.json'):
127+
import json
128+
load_fn = json.load
129+
else:
130+
import yaml
131+
load_fn = yaml.load
127132
with open(path) as f:
128-
config = yaml.load(f)
133+
config = load_fn(f)
129134
return config
130135

131136
def main():

requirements-dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mock
2+
pyyaml

tests/config_test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
import os.path
22
import buildploy
33
import unittest
4+
import mock
5+
6+
try:
7+
# py 2
8+
base_exception = StandardError
9+
except NameError:
10+
# py 3
11+
base_exception = Exception
12+
13+
class YamlDisabled(base_exception):
14+
pass
15+
16+
def disabled_yaml(*args):
17+
raise YamlDisabled
418

519
class UnitTest(unittest.TestCase):
620
def setUp(self):
@@ -12,6 +26,17 @@ def test_yaml(self):
1226
def test_yml(self):
1327
self.check('yaml_config.yml')
1428

29+
@mock.patch('yaml.load', disabled_yaml)
30+
def test_yaml_patching(self):
31+
# this just checks that our patch works
32+
try:
33+
self.check('yaml_config.yml')
34+
except YamlDisabled:
35+
pass
36+
else:
37+
self.fail('Patch did not work')
38+
39+
@mock.patch('yaml.load', disabled_yaml)
1540
def test_json(self):
1641
self.check('json_config.json')
1742

0 commit comments

Comments
 (0)