Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More promissing way to find the bddcli-bootstrapper. Added windows in…
…to Github actions matrix
- Loading branch information
Showing
4 changed files
with
65 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,60 @@ | ||
''' A module for platform-dependent functions | ||
''' | ||
import os | ||
import sys | ||
import subprocess as sp | ||
|
||
|
||
def killpg(pid, s): | ||
if os.name == "nt": | ||
# On Windows, os module can't kill processes by group | ||
# Kill all children indiscriminately instead | ||
sp.call(['taskkill', '/T', '/F', '/PID', | ||
str(pid)]) | ||
else: | ||
if os.name == 'nt': | ||
BOOTSTRAPPER_FILENAME = 'bddcli-bootstrapper.exe' | ||
VENV_BINDIR = 'Scripts' | ||
|
||
# On Windows, os module can't kill processes by group | ||
# Kill all children indiscriminately instead | ||
def killpg_by_pid(pid, s): | ||
# FIXME: use s here | ||
sp.call(['taskkill', '/T', '/F', '/PID', str(pid)]) | ||
|
||
else: | ||
BOOTSTRAPPER_FILENAME = 'bddcli-bootstrapper' | ||
VENV_BINDIR = 'bin' | ||
|
||
def killpg_by_pid(pid, s): | ||
os.killpg(os.getpgid(pid), s) | ||
|
||
|
||
def popen(command, environ, **kw): | ||
if os.name == "nt": | ||
# On Windows, the specified env must include a valid SystemRoot | ||
# Use a current value | ||
if environ is not None: | ||
environ["SystemRoot"] = os.environ["SystemRoot"] | ||
process = sp.Popen( | ||
' '.join(command), | ||
stdout=sp.PIPE, | ||
stderr=sp.PIPE, | ||
shell=True, | ||
env=environ, | ||
**kw, | ||
) | ||
# Find bootstrapper location | ||
if 'VIRTUAL_ENV' in os.environ: | ||
BOOTSTRAPPER_PATH = os.path.join(os.environ['VIRTUAL_ENV'], VENV_BINDIR) | ||
else: | ||
for d in sys.path: | ||
if os.path.isfile(d): | ||
d = os.path.dirname(d) | ||
try: | ||
if BOOTSTRAPPER_FILENAME in os.listdir(d): | ||
BOOTSTRAPPER_PATH = d | ||
break | ||
except (FileNotFoundError, NotADirectoryError): | ||
# Nothing guarantees a PATH entry is valid | ||
continue | ||
|
||
else: | ||
process = sp.Popen( | ||
' '.join(command), | ||
stdout=sp.PIPE, | ||
stderr=sp.PIPE, | ||
shell=True, | ||
env=environ, | ||
preexec_fn=os.setpgrp, | ||
**kw, | ||
raise FileNotFoundError( | ||
f'Cannot find {BOOTSTRAPPER_FILENAME} in your PATH ' | ||
f'environment variable: {sys.path}' | ||
) | ||
return process | ||
|
||
|
||
def bootstrapper_name(): | ||
if os.name == "nt": | ||
return 'bddcli_bootstrapper' | ||
else: | ||
return 'bddcli-bootstrapper' | ||
BOOTSTRAPPER_FULLPATH = os.path.join(BOOTSTRAPPER_PATH, BOOTSTRAPPER_FILENAME) | ||
|
||
|
||
def form_bootstrapper_path(bindir, bootstrapper): | ||
def Popen(command, env=None, **kw): | ||
if os.name == "nt": | ||
return os.path.join(bindir, bootstrapper, "__init__.py") | ||
# On Windows, the specified env must include a valid SystemRoot | ||
# Use a current value | ||
if env is None: | ||
env = {} | ||
|
||
env["SystemRoot"] = os.environ["SystemRoot"] | ||
kw['creationflags'] = sp.CREATE_NEW_PROCESS_GROUP | ||
else: | ||
return os.path.join(bindir, bootstrapper) | ||
kw['preexec_fn'] = os.setpgrp | ||
|
||
return sp.Popen(command, env=env, **kw) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters