diff --git a/HISTORY.rst b/HISTORY.rst index 8b6dd9ad..adb3d3d3 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -32,6 +32,8 @@ PlatformIO 3.0 (`issue #1061 `_) * Fixed missing toolchain include paths for project generator (`issue #1154 `_) +* Fixed "get-platformio.py" script which hangs on Windows 10 + (`issue #1118 `_) 3.4.1 (2017-08-02) ~~~~~~~~~~~~~~~~~~ diff --git a/scripts/get-platformio.py b/scripts/get-platformio.py index 6d3cbe1d..90ad5fea 100644 --- a/scripts/get-platformio.py +++ b/scripts/get-platformio.py @@ -14,6 +14,7 @@ import os import subprocess +import site import sys from platform import system from tempfile import NamedTemporaryFile @@ -26,39 +27,34 @@ def fix_winpython_pathenv(): """ Add Python & Python Scripts to the search path on Windows """ - import ctypes - from ctypes.wintypes import HWND, UINT, WPARAM, LPARAM, LPVOID try: import _winreg as winreg except ImportError: import winreg # took these lines from the native "win_add2path.py" - pythonpath = os.path.dirname(CURINTERPRETER_PATH) + pythonpath = os.path.dirname(os.path.normpath(sys.executable)) scripts = os.path.join(pythonpath, "Scripts") - if not os.path.isdir(scripts): - os.makedirs(scripts) + appdata = os.environ["APPDATA"] + if hasattr(site, "USER_SITE"): + userpath = site.USER_SITE.replace(appdata, "%APPDATA%") + userscripts = os.path.join(userpath, "Scripts") + else: + userscripts = None - with winreg.CreateKey(winreg.HKEY_CURRENT_USER, u"Environment") as key: + with winreg.CreateKey(winreg.HKEY_CURRENT_USER, "Environment") as key: try: - envpath = winreg.QueryValueEx(key, u"PATH")[0] + envpath = winreg.QueryValueEx(key, "PATH")[0] except WindowsError: envpath = u"%PATH%" paths = [envpath] - for path in (pythonpath, scripts): + for path in (pythonpath, scripts, userscripts): if path and path not in envpath and os.path.isdir(path): paths.append(path) envpath = os.pathsep.join(paths) - winreg.SetValueEx(key, u"PATH", 0, winreg.REG_EXPAND_SZ, envpath) - winreg.ExpandEnvironmentStrings(envpath) - - # notify the system about the changes - SendMessage = ctypes.windll.user32.SendMessageW - SendMessage.argtypes = HWND, UINT, WPARAM, LPVOID - SendMessage.restype = LPARAM - SendMessage(0xFFFF, 0x1A, 0, u"Environment") + winreg.SetValueEx(key, "PATH", 0, winreg.REG_EXPAND_SZ, envpath) return True