Skip to content

Commit

Permalink
Merge pull request #24 from Anaconda-Platform/block-format
Browse files Browse the repository at this point in the history
Use block-style formatting for lists in default anaconda-project.yml
  • Loading branch information
havocp committed Mar 3, 2017
2 parents ad9452b + 069b40d commit 25d8a98
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
41 changes: 26 additions & 15 deletions anaconda_project/test/test_project_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@
# but can have its own unique ones also.
# Use `anaconda-project add-env-spec` to add environment specs.
#
env_specs: {default: {packages: [], channels: []}}
env_specs:
default:
packages: []
channels: []
"""


Expand Down Expand Up @@ -137,21 +140,13 @@ def read_missing_file(dirname):
with_directory_contents(dict(), read_missing_file)


abc_xyz_populated_env_specs = """#
# You can define multiple, named environment specs.
# Each inherits any global packages or channels,
# but can have its own unique ones also.
# Use `anaconda-project add-env-spec` to add environment specs.
#
env_specs: {abc: {description: ABC, packages: [anaconda], channels: [mychannel]}}
"""

anaconda_global_packages = """#
# In the packages section, list any packages that must be installed
# before your code runs.
# Use `anaconda-project add-packages` to add packages.
#
packages: [anaconda]
packages:
- anaconda
"""

mychannel_global_channels = """#
Expand All @@ -163,7 +158,8 @@ def read_missing_file(dirname):
# channels:
# - mychannel
#
channels: [mychannel]
channels:
- mychannel
"""

abc_empty_env_spec = """#
Expand All @@ -172,7 +168,11 @@ def read_missing_file(dirname):
# but can have its own unique ones also.
# Use `anaconda-project add-env-spec` to add environment specs.
#
env_specs: {abc: {description: ABC, packages: [], channels: []}}
env_specs:
abc:
description: ABC
packages: []
channels: []
"""

expected_one_env_spec_contents = _make_file_contents(packages=anaconda_global_packages,
Expand Down Expand Up @@ -211,8 +211,19 @@ def default_env_specs_func():
# but can have its own unique ones also.
# Use `anaconda-project add-env-spec` to add environment specs.
#
env_specs: {abc: {description: ABC, packages: [anaconda], channels: [mychannel]},
xyz: {description: XYZ, packages: [foo], channels: [bar]}}
env_specs:
abc:
description: ABC
packages:
- anaconda
channels:
- mychannel
xyz:
description: XYZ
packages:
- foo
channels:
- bar
"""

expected_two_env_spec_contents = _make_file_contents(packages=empty_global_packages,
Expand Down
14 changes: 14 additions & 0 deletions anaconda_project/yaml_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ def _save_file(yaml, filename):
_atomic_replace(filename, contents)


def _block_style_all_nodes(yaml):
if hasattr(yaml, 'fa'):
yaml.fa.set_block_style()

if isinstance(yaml, list):
for element in yaml:
_block_style_all_nodes(element)
elif isinstance(yaml, dict):
for value in yaml.values():
_block_style_all_nodes(value)


class YamlFile(object):
"""Abstract YAML file, base class for ``ProjectFile`` and ``LocalStateFile``.
Expand Down Expand Up @@ -149,6 +161,8 @@ def load(self):

if self._yaml is None:
self._yaml = self._default_content()
# make it pretty
_block_style_all_nodes(self._yaml)
self._dirty = True

def _default_comment(self):
Expand Down

0 comments on commit 25d8a98

Please sign in to comment.