From 82a8bd01fc0e94adbb3bcd639244ba444a3d3345 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 9 Sep 2015 00:45:51 +0300 Subject: [PATCH] Fix `SConsNotInstalled` error for Linux Debian-based distributives --- HISTORY.rst | 5 +++++ docs/installation.rst | 2 +- platformio/__init__.py | 2 +- platformio/builder/main.py | 17 ++++++++++------- platformio/platforms/base.py | 17 +++++++++++++++++ 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 51201155..6572ee96 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -4,6 +4,11 @@ Release History PlatformIO 2.0 -------------- +2.3.2 (2015-09-??) +~~~~~~~~~~~~~~~~~~ + +* Fixed `SConsNotInstalled` error for Linux Debian-based distributives + 2.3.1 (2015-09-06) ~~~~~~~~~~~~~~~~~~ diff --git a/docs/installation.rst b/docs/installation.rst index 93999493..85b6e847 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -47,7 +47,7 @@ The latest stable version of PlatformIO may be done via .. code-block:: bash # update dependent packages to the latest versions - pip install -U pip setuptools + pip install -U pip setuptools virtualenv # install the latest version of PlatformIO pip install -U platformio diff --git a/platformio/__init__.py b/platformio/__init__.py index 7b31d423..8be279ed 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -1,7 +1,7 @@ # Copyright (C) Ivan Kravets # See LICENSE for details. -VERSION = (2, 3, "2.dev0") +VERSION = (2, 3, "2.dev1") __version__ = ".".join([str(s) for s in VERSION]) __title__ = "platformio" diff --git a/platformio/builder/main.py b/platformio/builder/main.py index 0dd206f3..4495e15b 100644 --- a/platformio/builder/main.py +++ b/platformio/builder/main.py @@ -6,13 +6,16 @@ try: except ImportError: import sys for p in sys.path: - _new_path = None - if not p.endswith("site-packages") and "site-packages" in p: - _new_path = p[:p.rfind("site-packages") + 13] - elif "platformio" in p: - _new_path = p[:p.rfind("platformio") - 1] - if _new_path and _new_path not in sys.path: - sys.path.insert(0, _new_path) + _new_paths = [] + for item in ("dist-packages", "site-packages"): + if not p.endswith(item) and item in p: + _new_paths.append(p[:p.rfind(item) + len(item)]) + if "platformio" in p: + _new_paths.append(p[:p.rfind("platformio") - 1]) + + for _p in _new_paths: + if _p not in sys.path: + sys.path.insert(0, _p) try: from platformio import util break diff --git a/platformio/platforms/base.py b/platformio/platforms/base.py index 6a71da0a..ddc21a5b 100644 --- a/platformio/platforms/base.py +++ b/platformio/platforms/base.py @@ -4,6 +4,7 @@ import os import re import sys +from glob import glob from imp import load_source from os.path import isdir, isfile, join @@ -400,6 +401,22 @@ class BasePlatform(object): def test_scons(): try: r = util.exec_command(["scons", "--version"]) + if "ImportError: No module named SCons.Script" in r['err']: + _PYTHONPATH = [] + for p in sys.path: + if not p.endswith("-packages"): + continue + for item in glob(join(p, "scons*")): + if isdir(join(item, "SCons")) and item not in sys.path: + _PYTHONPATH.append(item) + sys.path.insert(0, item) + if _PYTHONPATH: + _PYTHONPATH = str(os.pathsep).join(_PYTHONPATH) + if os.getenv("PYTHONPATH"): + os.environ['PYTHONPATH'] += os.pathsep + _PYTHONPATH + else: + os.environ['PYTHONPATH'] = _PYTHONPATH + r = util.exec_command(["scons", "--version"]) assert r['returncode'] == 0 return True except (OSError, AssertionError):