Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Add a warning about indentation to generated config (#6920)
Browse files Browse the repository at this point in the history
Fixes #6916.
  • Loading branch information
richvdh authored Feb 14, 2020
1 parent 02e8902 commit 97a42bb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/6920.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a warning about indentation to generated configuration files.
4 changes: 3 additions & 1 deletion docs/.sample_config_header.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# The config is maintained as an up-to-date snapshot of the default
# This file is maintained as an up-to-date snapshot of the default
# homeserver.yaml configuration generated by Synapse.
#
# It is intended to act as a reference for the default configuration,
Expand All @@ -10,3 +10,5 @@
# homeserver.yaml. Instead, if you are starting from scratch, please generate
# a fresh config using Synapse by following the instructions in INSTALL.md.

################################################################################

12 changes: 11 additions & 1 deletion docs/sample_config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# The config is maintained as an up-to-date snapshot of the default
# This file is maintained as an up-to-date snapshot of the default
# homeserver.yaml configuration generated by Synapse.
#
# It is intended to act as a reference for the default configuration,
Expand All @@ -10,6 +10,16 @@
# homeserver.yaml. Instead, if you are starting from scratch, please generate
# a fresh config using Synapse by following the instructions in INSTALL.md.

################################################################################

# Configuration file for Synapse.
#
# This is a YAML file: see [1] for a quick introduction. Note in particular
# that *indentation is important*: all the elements of a list or dictionary
# should have the same indentation.
#
# [1] https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html

## Server ##

# The domain name of the server, with optional explicit port.
Expand Down
16 changes: 14 additions & 2 deletions synapse/config/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ class ConfigError(Exception):
"""


CONFIG_FILE_HEADER = """\
# Configuration file for Synapse.
#
# This is a YAML file: see [1] for a quick introduction. Note in particular
# that *indentation is important*: all the elements of a list or dictionary
# should have the same indentation.
#
# [1] https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html
"""


def path_exists(file_path):
"""Check if a file exists
Expand Down Expand Up @@ -344,7 +356,7 @@ def generate_config(
str: the yaml config file
"""

return "\n\n".join(
return CONFIG_FILE_HEADER + "\n\n".join(
dedent(conf)
for conf in self.invoke_all(
"generate_config_section",
Expand Down Expand Up @@ -574,8 +586,8 @@ def load_or_generate_config(cls, description, argv):
if not path_exists(config_dir_path):
os.makedirs(config_dir_path)
with open(config_path, "w") as config_file:
config_file.write("# vim:ft=yaml\n\n")
config_file.write(config_str)
config_file.write("\n\n# vim:ft=yaml")

config_dict = yaml.safe_load(config_str)
obj.generate_missing_files(config_dict, config_dir_path)
Expand Down

0 comments on commit 97a42bb

Please sign in to comment.