Remove double blank lines when saving project config // Resolve #3293

This commit is contained in:
Ivan Kravets
2020-01-24 22:15:33 +02:00
parent decf482367
commit ba441ca77c
2 changed files with 10 additions and 5 deletions

View File

@ -13,6 +13,7 @@
# limitations under the License. # limitations under the License.
import glob import glob
import io
import json import json
import os import os
import re import re
@ -30,7 +31,8 @@ try:
except ImportError: except ImportError:
import configparser as ConfigParser import configparser as ConfigParser
CONFIG_HEADER = """; PlatformIO Project Configuration File CONFIG_HEADER = """
; PlatformIO Project Configuration File
; ;
; Build options: build flags, source filter ; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags ; 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 ; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html ; https://docs.platformio.org/page/projectconf.html
""" """
@ -449,6 +450,8 @@ class ProjectConfig(ProjectConfigBase, ProjectConfigDirsMixin):
if path in self._instances: if path in self._instances:
del self._instances[path] del self._instances[path]
with open(path or self.path, "w") as fp: with open(path or self.path, "w") as fp:
fp.write(CONFIG_HEADER) fp.write(CONFIG_HEADER.strip())
self._parser.write(fp) buf = io.StringIO()
self._parser.write(buf)
fp.write("\n\n%s\n" % buf.getvalue().strip())
return True return True

View File

@ -330,9 +330,11 @@ board = myboard
] ]
config.save() config.save()
contents = tmpdir.join("platformio.ini").read()
assert contents[-4:] == "yes\n"
lines = [ lines = [
line.strip() line.strip()
for line in tmpdir.join("platformio.ini").readlines() for line in contents.split("\n")
if line.strip() and not line.startswith((";", "#")) if line.strip() and not line.startswith((";", "#"))
] ]
assert lines == [ assert lines == [