mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Improve detecting of Python EXE Path
This commit is contained in:
@ -12,9 +12,9 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import hashlib
|
||||||
import json
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
import hashlib
|
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from os import environ, getenv
|
from os import environ, getenv
|
||||||
from os.path import getmtime, isfile, join
|
from os.path import getmtime, isfile, join
|
||||||
|
@ -14,9 +14,8 @@
|
|||||||
|
|
||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
import sys
|
|
||||||
from os import environ
|
from os import environ
|
||||||
from os.path import join, normpath
|
from os.path import join
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
from SCons.Script import (ARGUMENTS, COMMAND_LINE_TARGETS,
|
from SCons.Script import (ARGUMENTS, COMMAND_LINE_TARGETS,
|
||||||
@ -91,7 +90,7 @@ DEFAULT_ENV_OPTIONS = dict(
|
|||||||
util.get_projectlib_dir(), util.get_projectlibdeps_dir(),
|
util.get_projectlib_dir(), util.get_projectlibdeps_dir(),
|
||||||
join("$PIOHOME_DIR", "lib")
|
join("$PIOHOME_DIR", "lib")
|
||||||
],
|
],
|
||||||
PYTHONEXE=normpath(sys.executable))
|
PYTHONEXE=util.get_pythonexe_path())
|
||||||
|
|
||||||
if not int(ARGUMENTS.get("PIOVERBOSE", 0)):
|
if not int(ARGUMENTS.get("PIOVERBOSE", 0)):
|
||||||
print "Verbose mode can be enabled via `-v, --verbose` option"
|
print "Verbose mode can be enabled via `-v, --verbose` option"
|
||||||
|
@ -12,9 +12,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
import sys
|
|
||||||
|
|
||||||
import click
|
import click
|
||||||
import requests
|
import requests
|
||||||
@ -43,7 +41,7 @@ def cli():
|
|||||||
r = None
|
r = None
|
||||||
try:
|
try:
|
||||||
for cmd in cmds:
|
for cmd in cmds:
|
||||||
cmd = [os.path.normpath(sys.executable), "-m"] + cmd
|
cmd = [util.get_pythonexe_path(), "-m"] + cmd
|
||||||
r = None
|
r = None
|
||||||
r = util.exec_command(cmd)
|
r = util.exec_command(cmd)
|
||||||
|
|
||||||
|
@ -15,9 +15,7 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
from os.path import abspath, basename, expanduser, isdir, isfile, join, relpath
|
||||||
from os.path import (abspath, basename, expanduser, isdir, isfile, join,
|
|
||||||
normpath, relpath)
|
|
||||||
|
|
||||||
import bottle
|
import bottle
|
||||||
|
|
||||||
@ -63,7 +61,7 @@ class ProjectGenerator(object):
|
|||||||
envdata = self.get_project_env()
|
envdata = self.get_project_env()
|
||||||
if "env_name" not in envdata:
|
if "env_name" not in envdata:
|
||||||
return data
|
return data
|
||||||
cmd = [normpath(sys.executable), "-m", "platformio", "-f"]
|
cmd = [util.get_pythonexe_path(), "-m", "platformio", "-f"]
|
||||||
if app.get_session_var("caller_id"):
|
if app.get_session_var("caller_id"):
|
||||||
cmd.extend(["-c", app.get_session_var("caller_id")])
|
cmd.extend(["-c", app.get_session_var("caller_id")])
|
||||||
cmd.extend(["run", "-t", "idedata", "-e", envdata['env_name']])
|
cmd.extend(["run", "-t", "idedata", "-e", envdata['env_name']])
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
import base64
|
import base64
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
|
||||||
from imp import load_source
|
from imp import load_source
|
||||||
from multiprocessing import cpu_count
|
from multiprocessing import cpu_count
|
||||||
from os.path import basename, dirname, isdir, isfile, join
|
from os.path import basename, dirname, isdir, isfile, join
|
||||||
@ -260,18 +259,8 @@ class PlatformRunMixin(object):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def _run_scons(self, variables, targets):
|
def _run_scons(self, variables, targets):
|
||||||
# pass current PYTHONPATH to SCons
|
|
||||||
if "PYTHONPATH" in os.environ:
|
|
||||||
_PYTHONPATH = os.environ.get("PYTHONPATH").split(os.pathsep)
|
|
||||||
else:
|
|
||||||
_PYTHONPATH = []
|
|
||||||
for p in os.sys.path:
|
|
||||||
if p not in _PYTHONPATH:
|
|
||||||
_PYTHONPATH.append(p)
|
|
||||||
os.environ['PYTHONPATH'] = os.pathsep.join(_PYTHONPATH)
|
|
||||||
|
|
||||||
cmd = [
|
cmd = [
|
||||||
os.path.normpath(sys.executable),
|
util.get_pythonexe_path(),
|
||||||
join(self.get_package_dir("tool-scons"), "script", "scons"), "-Q",
|
join(self.get_package_dir("tool-scons"), "script", "scons"), "-Q",
|
||||||
"-j %d" % self.get_job_nums(), "--warn=no-no-parallel-support",
|
"-j %d" % self.get_job_nums(), "--warn=no-no-parallel-support",
|
||||||
"-f", join(util.get_source_dir(), "builder", "main.py")
|
"-f", join(util.get_source_dir(), "builder", "main.py")
|
||||||
@ -283,6 +272,7 @@ class PlatformRunMixin(object):
|
|||||||
for key, value in variables.items():
|
for key, value in variables.items():
|
||||||
cmd.append("%s=%s" % (key.upper(), base64.b64encode(value)))
|
cmd.append("%s=%s" % (key.upper(), base64.b64encode(value)))
|
||||||
|
|
||||||
|
util.copy_pythonpath_to_osenv()
|
||||||
result = util.exec_command(
|
result = util.exec_command(
|
||||||
cmd,
|
cmd,
|
||||||
stdout=util.AsyncPipe(self.on_run_out),
|
stdout=util.AsyncPipe(self.on_run_out),
|
||||||
|
@ -22,7 +22,7 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from os.path import (abspath, basename, dirname, expanduser, isdir, isfile,
|
from os.path import (abspath, basename, dirname, expanduser, isdir, isfile,
|
||||||
join, splitdrive)
|
join, normpath, splitdrive)
|
||||||
from platform import system, uname
|
from platform import system, uname
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
@ -299,6 +299,16 @@ def exec_command(*args, **kwargs):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def copy_pythonpath_to_osenv():
|
||||||
|
_PYTHONPATH = []
|
||||||
|
if "PYTHONPATH" in os.environ:
|
||||||
|
_PYTHONPATH = os.environ.get("PYTHONPATH").split(os.pathsep)
|
||||||
|
for p in os.sys.path:
|
||||||
|
if p not in _PYTHONPATH:
|
||||||
|
_PYTHONPATH.append(p)
|
||||||
|
os.environ['PYTHONPATH'] = os.pathsep.join(_PYTHONPATH)
|
||||||
|
|
||||||
|
|
||||||
def get_serialports():
|
def get_serialports():
|
||||||
try:
|
try:
|
||||||
from serial.tools.list_ports import comports
|
from serial.tools.list_ports import comports
|
||||||
@ -446,6 +456,10 @@ def get_frameworks(type_=None):
|
|||||||
return frameworks
|
return frameworks
|
||||||
|
|
||||||
|
|
||||||
|
def get_pythonexe_path():
|
||||||
|
return os.environ.get("PYTHONEXEPATH", normpath(sys.executable))
|
||||||
|
|
||||||
|
|
||||||
def where_is_program(program, envpath=None):
|
def where_is_program(program, envpath=None):
|
||||||
env = os.environ
|
env = os.environ
|
||||||
if envpath:
|
if envpath:
|
||||||
|
Reference in New Issue
Block a user