forked from platformio/platformio-core
Improve detecting if PlatformIO Core is run in container
This commit is contained in:
@ -25,9 +25,8 @@ from time import time
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from platformio import __version__, exception, fs, lockfile
|
from platformio import __version__, exception, fs, lockfile, proc
|
||||||
from platformio.compat import WINDOWS, dump_json_to_unicode, hashlib_encode_data
|
from platformio.compat import WINDOWS, dump_json_to_unicode, hashlib_encode_data
|
||||||
from platformio.proc import is_ci
|
|
||||||
from platformio.project.helpers import (
|
from platformio.project.helpers import (
|
||||||
get_default_projects_dir,
|
get_default_projects_dir,
|
||||||
get_project_cache_dir,
|
get_project_cache_dir,
|
||||||
@ -383,7 +382,7 @@ def is_disabled_progressbar():
|
|||||||
return any(
|
return any(
|
||||||
[
|
[
|
||||||
get_session_var("force_option"),
|
get_session_var("force_option"),
|
||||||
is_ci(),
|
proc.is_ci(),
|
||||||
getenv("PLATFORMIO_DISABLE_PROGRESSBAR") == "true",
|
getenv("PLATFORMIO_DISABLE_PROGRESSBAR") == "true",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@ -420,7 +419,11 @@ def get_cid():
|
|||||||
|
|
||||||
|
|
||||||
def get_user_agent():
|
def get_user_agent():
|
||||||
data = ["PlatformIO/%s" % __version__, "CI/%d" % int(is_ci())]
|
data = [
|
||||||
|
"PlatformIO/%s" % __version__,
|
||||||
|
"CI/%d" % int(proc.is_ci()),
|
||||||
|
"Container/%d" % int(proc.is_container()),
|
||||||
|
]
|
||||||
if get_session_var("caller_id"):
|
if get_session_var("caller_id"):
|
||||||
data.append("Caller/%s" % get_session_var("caller_id"))
|
data.append("Caller/%s" % get_session_var("caller_id"))
|
||||||
if os.getenv("PLATFORMIO_IDE"):
|
if os.getenv("PLATFORMIO_IDE"):
|
||||||
|
@ -66,10 +66,9 @@ def on_platformio_exception(e):
|
|||||||
|
|
||||||
|
|
||||||
def set_caller(caller=None):
|
def set_caller(caller=None):
|
||||||
|
caller = caller or getenv("PLATFORMIO_CALLER")
|
||||||
if not caller:
|
if not caller:
|
||||||
if getenv("PLATFORMIO_CALLER"):
|
if getenv("VSCODE_PID") or getenv("VSCODE_NLS_CONFIG"):
|
||||||
caller = getenv("PLATFORMIO_CALLER")
|
|
||||||
elif getenv("VSCODE_PID") or getenv("VSCODE_NLS_CONFIG"):
|
|
||||||
caller = "vscode"
|
caller = "vscode"
|
||||||
elif is_container():
|
elif is_container():
|
||||||
if getenv("C9_UID"):
|
if getenv("C9_UID"):
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from os.path import isdir, isfile, join, normpath
|
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from platformio import exception
|
from platformio import exception
|
||||||
@ -143,18 +142,16 @@ def is_ci():
|
|||||||
|
|
||||||
|
|
||||||
def is_container():
|
def is_container():
|
||||||
if not isfile("/proc/1/cgroup"):
|
if os.path.exists("/.dockerenv"):
|
||||||
|
return True
|
||||||
|
if not os.path.isfile("/proc/1/cgroup"):
|
||||||
return False
|
return False
|
||||||
with open("/proc/1/cgroup") as fp:
|
with open("/proc/1/cgroup") as fp:
|
||||||
for line in fp:
|
return ":/docker/" in fp.read()
|
||||||
line = line.strip()
|
|
||||||
if ":" in line and not line.endswith(":/"):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def get_pythonexe_path():
|
def get_pythonexe_path():
|
||||||
return os.environ.get("PYTHONEXEPATH", normpath(sys.executable))
|
return os.environ.get("PYTHONEXEPATH", os.path.normpath(sys.executable))
|
||||||
|
|
||||||
|
|
||||||
def copy_pythonpath_to_osenv():
|
def copy_pythonpath_to_osenv():
|
||||||
@ -164,7 +161,10 @@ def copy_pythonpath_to_osenv():
|
|||||||
for p in os.sys.path:
|
for p in os.sys.path:
|
||||||
conditions = [p not in _PYTHONPATH]
|
conditions = [p not in _PYTHONPATH]
|
||||||
if not WINDOWS:
|
if not WINDOWS:
|
||||||
conditions.append(isdir(join(p, "click")) or isdir(join(p, "platformio")))
|
conditions.append(
|
||||||
|
os.path.isdir(os.path.join(p, "click"))
|
||||||
|
or os.path.isdir(os.path.join(p, "platformio"))
|
||||||
|
)
|
||||||
if all(conditions):
|
if all(conditions):
|
||||||
_PYTHONPATH.append(p)
|
_PYTHONPATH.append(p)
|
||||||
os.environ["PYTHONPATH"] = os.pathsep.join(_PYTHONPATH)
|
os.environ["PYTHONPATH"] = os.pathsep.join(_PYTHONPATH)
|
||||||
@ -178,16 +178,16 @@ def where_is_program(program, envpath=None):
|
|||||||
# try OS's built-in commands
|
# try OS's built-in commands
|
||||||
try:
|
try:
|
||||||
result = exec_command(["where" if WINDOWS else "which", program], env=env)
|
result = exec_command(["where" if WINDOWS else "which", program], env=env)
|
||||||
if result["returncode"] == 0 and isfile(result["out"].strip()):
|
if result["returncode"] == 0 and os.path.isfile(result["out"].strip()):
|
||||||
return result["out"].strip()
|
return result["out"].strip()
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# look up in $PATH
|
# look up in $PATH
|
||||||
for bin_dir in env.get("PATH", "").split(os.pathsep):
|
for bin_dir in env.get("PATH", "").split(os.pathsep):
|
||||||
if isfile(join(bin_dir, program)):
|
if os.path.isfile(os.path.join(bin_dir, program)):
|
||||||
return join(bin_dir, program)
|
return os.path.join(bin_dir, program)
|
||||||
if isfile(join(bin_dir, "%s.exe" % program)):
|
if os.path.isfile(os.path.join(bin_dir, "%s.exe" % program)):
|
||||||
return join(bin_dir, "%s.exe" % program)
|
return os.path.join(bin_dir, "%s.exe" % program)
|
||||||
|
|
||||||
return program
|
return program
|
||||||
|
Reference in New Issue
Block a user