Skip to content

Commit 1fe6977

Browse files
authored
hides subprocess windows on os.system = "nt" (#1148)
* hides subprocess windows on os.system = "nt" * improved subprocess_startupinfo
1 parent cbb45be commit 1fe6977

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

mslib/utils.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,19 @@
101101
UR.define("pptv = 1e-12 fraction")
102102

103103

104+
def subprocess_startupinfo():
105+
"""
106+
config options to hide windows terminals on subprocess call
107+
"""
108+
startupinfo = None
109+
if os.name == 'nt':
110+
# thx to https://gist.github.com/nitely/3862493
111+
startupinfo = subprocess.STARTUPINFO()
112+
startupinfo.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW
113+
startupinfo.wShowWindow = subprocess.SW_HIDE
114+
return startupinfo
115+
116+
104117
def parse_iso_datetime(string):
105118
try:
106119
result = isodate.parse_datetime(string)
@@ -830,7 +843,8 @@ def __init__(self, parent=None):
830843

831844
# Check if mamba is installed
832845
try:
833-
subprocess.run(["mamba"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
846+
subprocess.run(["mamba"], startupinfo=subprocess_startupinfo(),
847+
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
834848
self.command = "mamba"
835849
except FileNotFoundError:
836850
pass
@@ -854,7 +868,9 @@ def _check_version(self):
854868
"""
855869
# Don't notify on updates if mss is in a git repo, as you are most likely a developer
856870
try:
857-
git = subprocess.run(["git", "rev-parse", "--is-inside-work-tree"], stdout=subprocess.PIPE,
871+
git = subprocess.run(["git", "rev-parse", "--is-inside-work-tree"],
872+
startupinfo=subprocess_startupinfo(),
873+
stdout=subprocess.PIPE,
858874
stderr=subprocess.STDOUT, encoding="utf8")
859875
if "true" in git.stdout:
860876
self.is_git_env = True
@@ -863,7 +879,8 @@ def _check_version(self):
863879

864880
# Return if conda is not installed
865881
try:
866-
subprocess.run(["conda"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
882+
subprocess.run(["conda"], startupinfo=subprocess_startupinfo(),
883+
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
867884
except FileNotFoundError:
868885
return
869886

@@ -926,7 +943,11 @@ def _execute_command(self, command):
926943
"""
927944
Handles proper execution of conda subprocesses and logging
928945
"""
929-
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf8")
946+
process = subprocess.Popen(command.split(),
947+
startupinfo=subprocess_startupinfo(),
948+
stdout=subprocess.PIPE,
949+
stderr=subprocess.STDOUT,
950+
encoding="utf8")
930951
self.on_log_update.emit(" ".join(process.args) + "\n")
931952

932953
text = ""
@@ -1193,7 +1214,8 @@ def update_airspace(force_download=False, countries=["de"]):
11931214

11941215
if (force_download or is_outdated or not file_exists) \
11951216
and QtWidgets.QMessageBox.question(None, "Allow download",
1196-
f"The selected {country} airspace needs to be downloaded ({data[-1]})"
1217+
f"The selected {country} airspace "
1218+
f"needs to be downloaded ({data[-1]})"
11971219
f"\nIs now a good time?",
11981220
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No) \
11991221
== QtWidgets.QMessageBox.Yes:

0 commit comments

Comments
 (0)