diff --git a/platformio/project/config.py b/platformio/project/config.py index 739429f6..ff53dd56 100644 --- a/platformio/project/config.py +++ b/platformio/project/config.py @@ -13,6 +13,7 @@ # limitations under the License. import glob +import io import json import os import re @@ -30,7 +31,8 @@ try: except ImportError: import configparser as ConfigParser -CONFIG_HEADER = """; PlatformIO Project Configuration File +CONFIG_HEADER = """ +; PlatformIO Project Configuration File ; ; Build options: build flags, source filter ; Upload options: custom upload port, speed and extra flags @@ -39,7 +41,6 @@ CONFIG_HEADER = """; PlatformIO Project Configuration File ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html - """ @@ -449,6 +450,8 @@ class ProjectConfig(ProjectConfigBase, ProjectConfigDirsMixin): if path in self._instances: del self._instances[path] with open(path or self.path, "w") as fp: - fp.write(CONFIG_HEADER) - self._parser.write(fp) + fp.write(CONFIG_HEADER.strip()) + buf = io.StringIO() + self._parser.write(buf) + fp.write("\n\n%s\n" % buf.getvalue().strip()) return True diff --git a/tests/test_projectconf.py b/tests/test_projectconf.py index b601cece..c65c5737 100644 --- a/tests/test_projectconf.py +++ b/tests/test_projectconf.py @@ -330,9 +330,11 @@ board = myboard ] config.save() + contents = tmpdir.join("platformio.ini").read() + assert contents[-4:] == "yes\n" lines = [ line.strip() - for line in tmpdir.join("platformio.ini").readlines() + for line in contents.split("\n") if line.strip() and not line.startswith((";", "#")) ] assert lines == [