mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-29 17:47:14 +02:00
Improve detecting if PlatformIO Core is run in container
This commit is contained in:
@ -25,9 +25,8 @@ from time import time
|
||||
|
||||
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.proc import is_ci
|
||||
from platformio.project.helpers import (
|
||||
get_default_projects_dir,
|
||||
get_project_cache_dir,
|
||||
@ -383,7 +382,7 @@ def is_disabled_progressbar():
|
||||
return any(
|
||||
[
|
||||
get_session_var("force_option"),
|
||||
is_ci(),
|
||||
proc.is_ci(),
|
||||
getenv("PLATFORMIO_DISABLE_PROGRESSBAR") == "true",
|
||||
]
|
||||
)
|
||||
@ -420,7 +419,11 @@ def get_cid():
|
||||
|
||||
|
||||
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"):
|
||||
data.append("Caller/%s" % get_session_var("caller_id"))
|
||||
if os.getenv("PLATFORMIO_IDE"):
|
||||
|
@ -66,10 +66,9 @@ def on_platformio_exception(e):
|
||||
|
||||
|
||||
def set_caller(caller=None):
|
||||
caller = caller or getenv("PLATFORMIO_CALLER")
|
||||
if not caller:
|
||||
if getenv("PLATFORMIO_CALLER"):
|
||||
caller = getenv("PLATFORMIO_CALLER")
|
||||
elif getenv("VSCODE_PID") or getenv("VSCODE_NLS_CONFIG"):
|
||||
if getenv("VSCODE_PID") or getenv("VSCODE_NLS_CONFIG"):
|
||||
caller = "vscode"
|
||||
elif is_container():
|
||||
if getenv("C9_UID"):
|
||||
|
@ -15,7 +15,6 @@
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from os.path import isdir, isfile, join, normpath
|
||||
from threading import Thread
|
||||
|
||||
from platformio import exception
|
||||
@ -143,18 +142,16 @@ def is_ci():
|
||||
|
||||
|
||||
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
|
||||
with open("/proc/1/cgroup") as fp:
|
||||
for line in fp:
|
||||
line = line.strip()
|
||||
if ":" in line and not line.endswith(":/"):
|
||||
return True
|
||||
return False
|
||||
return ":/docker/" in fp.read()
|
||||
|
||||
|
||||
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():
|
||||
@ -164,7 +161,10 @@ def copy_pythonpath_to_osenv():
|
||||
for p in os.sys.path:
|
||||
conditions = [p not in _PYTHONPATH]
|
||||
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):
|
||||
_PYTHONPATH.append(p)
|
||||
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:
|
||||
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()
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
# look up in $PATH
|
||||
for bin_dir in env.get("PATH", "").split(os.pathsep):
|
||||
if isfile(join(bin_dir, program)):
|
||||
return join(bin_dir, program)
|
||||
if isfile(join(bin_dir, "%s.exe" % program)):
|
||||
return join(bin_dir, "%s.exe" % program)
|
||||
if os.path.isfile(os.path.join(bin_dir, program)):
|
||||
return os.path.join(bin_dir, program)
|
||||
if os.path.isfile(os.path.join(bin_dir, "%s.exe" % program)):
|
||||
return os.path.join(bin_dir, "%s.exe" % program)
|
||||
|
||||
return program
|
||||
|
Reference in New Issue
Block a user