aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside-tools/deploy_lib/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside-tools/deploy_lib/config.py')
-rw-r--r--sources/pyside-tools/deploy_lib/config.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/sources/pyside-tools/deploy_lib/config.py b/sources/pyside-tools/deploy_lib/config.py
index de19b0a1d..180c4f7e5 100644
--- a/sources/pyside-tools/deploy_lib/config.py
+++ b/sources/pyside-tools/deploy_lib/config.py
@@ -5,6 +5,7 @@ from __future__ import annotations
import sys
import configparser
import logging
+import tempfile
import warnings
from configparser import ConfigParser
from pathlib import Path
@@ -42,8 +43,26 @@ class BaseConfig:
def update_config(self):
logging.info(f"[DEPLOY] Creating {self.config_file}")
- with open(self.config_file, "w+") as config_file:
- self.parser.write(config_file, space_around_delimiters=True)
+
+ # This section of code is done to preserve the formatting of the original deploy.spec
+ # file where there is blank line before the comments
+ with tempfile.NamedTemporaryFile('w+', delete=False) as temp_file:
+ self.parser.write(temp_file, space_around_delimiters=True)
+ temp_file_path = temp_file.name
+
+ # Read the temporary file and write back to the original file with blank lines before
+ # comments
+ with open(temp_file_path, 'r') as temp_file, open(self.config_file, 'w') as config_file:
+ previous_line = None
+ for line in temp_file:
+ if (line.lstrip().startswith('#') and previous_line is not None
+ and not previous_line.lstrip().startswith('#')):
+ config_file.write('\n')
+ config_file.write(line)
+ previous_line = line
+
+ # Clean up the temporary file
+ Path(temp_file_path).unlink()
def set_value(self, section: str, key: str, new_value: str, raise_warning: bool = True):
try: