Improve detecting of Python EXE Path

This commit is contained in:
Ivan Kravets
2016-08-29 20:20:12 +03:00
parent 023e2978ba
commit f8e70c9362
6 changed files with 23 additions and 24 deletions

View File

@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import hashlib
import json
import uuid
import hashlib
from copy import deepcopy
from os import environ, getenv
from os.path import getmtime, isfile, join

View File

@ -14,9 +14,8 @@
import base64
import json
import sys
from os import environ
from os.path import join, normpath
from os.path import join
from time import time
from SCons.Script import (ARGUMENTS, COMMAND_LINE_TARGETS,
@ -91,7 +90,7 @@ DEFAULT_ENV_OPTIONS = dict(
util.get_projectlib_dir(), util.get_projectlibdeps_dir(),
join("$PIOHOME_DIR", "lib")
],
PYTHONEXE=normpath(sys.executable))
PYTHONEXE=util.get_pythonexe_path())
if not int(ARGUMENTS.get("PIOVERBOSE", 0)):
print "Verbose mode can be enabled via `-v, --verbose` option"

View File

@ -12,9 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import re
import sys
import click
import requests
@ -43,7 +41,7 @@ def cli():
r = None
try:
for cmd in cmds:
cmd = [os.path.normpath(sys.executable), "-m"] + cmd
cmd = [util.get_pythonexe_path(), "-m"] + cmd
r = None
r = util.exec_command(cmd)

View File

@ -15,9 +15,7 @@
import json
import os
import re
import sys
from os.path import (abspath, basename, expanduser, isdir, isfile, join,
normpath, relpath)
from os.path import abspath, basename, expanduser, isdir, isfile, join, relpath
import bottle
@ -63,7 +61,7 @@ class ProjectGenerator(object):
envdata = self.get_project_env()
if "env_name" not in envdata:
return data
cmd = [normpath(sys.executable), "-m", "platformio", "-f"]
cmd = [util.get_pythonexe_path(), "-m", "platformio", "-f"]
if app.get_session_var("caller_id"):
cmd.extend(["-c", app.get_session_var("caller_id")])
cmd.extend(["run", "-t", "idedata", "-e", envdata['env_name']])

View File

@ -15,7 +15,6 @@
import base64
import os
import re
import sys
from imp import load_source
from multiprocessing import cpu_count
from os.path import basename, dirname, isdir, isfile, join
@ -260,18 +259,8 @@ class PlatformRunMixin(object):
return result
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 = [
os.path.normpath(sys.executable),
util.get_pythonexe_path(),
join(self.get_package_dir("tool-scons"), "script", "scons"), "-Q",
"-j %d" % self.get_job_nums(), "--warn=no-no-parallel-support",
"-f", join(util.get_source_dir(), "builder", "main.py")
@ -283,6 +272,7 @@ class PlatformRunMixin(object):
for key, value in variables.items():
cmd.append("%s=%s" % (key.upper(), base64.b64encode(value)))
util.copy_pythonpath_to_osenv()
result = util.exec_command(
cmd,
stdout=util.AsyncPipe(self.on_run_out),

View File

@ -22,7 +22,7 @@ import subprocess
import sys
from glob import glob
from os.path import (abspath, basename, dirname, expanduser, isdir, isfile,
join, splitdrive)
join, normpath, splitdrive)
from platform import system, uname
from shutil import rmtree
from threading import Thread
@ -299,6 +299,16 @@ def exec_command(*args, **kwargs):
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():
try:
from serial.tools.list_ports import comports
@ -446,6 +456,10 @@ def get_frameworks(type_=None):
return frameworks
def get_pythonexe_path():
return os.environ.get("PYTHONEXEPATH", normpath(sys.executable))
def where_is_program(program, envpath=None):
env = os.environ
if envpath: