3030UPDATE_INTERVAL = 60 * 60 * 24 * 3 # 3 days
3131
3232
33- def get_core_dir ():
33+ def get_core_dir (force_to_root = False ):
3434 if os .getenv ("PLATFORMIO_CORE_DIR" ):
3535 return os .getenv ("PLATFORMIO_CORE_DIR" )
3636
3737 core_dir = os .path .join (util .expanduser ("~" ), ".platformio" )
3838 if not util .IS_WINDOWS :
3939 return core_dir
4040
41- win_core_dir = os .path .splitdrive (core_dir )[0 ] + "\\ .platformio"
42- if os .path .isdir (win_core_dir ):
43- return win_core_dir
41+ win_root_dir = os .path .splitdrive (core_dir )[0 ] + "\\ .platformio"
42+ if os .path .isdir (win_root_dir ):
43+ return win_root_dir
4444 try :
45- if util .has_non_ascii_char (core_dir ):
46- os .makedirs (win_core_dir )
47- with open (os .path .join (win_core_dir , "file.tmp" ), "w" ) as fp :
45+ if util .has_non_ascii_char (core_dir ) or force_to_root :
46+ os .makedirs (win_root_dir )
47+ with open (os .path .join (win_root_dir , "file.tmp" ), "w" ) as fp :
4848 fp .write ("test" )
49- os .remove (os .path .join (win_core_dir , "file.tmp" ))
50- return win_core_dir
49+ os .remove (os .path .join (win_root_dir , "file.tmp" ))
50+ return win_root_dir
5151 except : # pylint:disable=bare-except
5252 pass
5353
@@ -63,6 +63,29 @@ def get_cache_dir(path=None):
6363
6464
6565def install_platformio_core (shutdown_piohome = True , develop = False , ignore_pythons = None ):
66+ try :
67+ return _install_platformio_core (
68+ shutdown_piohome = shutdown_piohome ,
69+ develop = develop ,
70+ ignore_pythons = ignore_pythons ,
71+ )
72+ except subprocess .CalledProcessError as exc :
73+ # Issue #221: Workaround for Windows OS when username contains a space
74+ # https://github.com/platformio/platformio-core-installer/issues/221
75+ if (
76+ util .IS_WINDOWS
77+ and " " in get_core_dir ()
78+ and " " not in get_core_dir (force_to_root = True )
79+ ):
80+ return _install_platformio_core (
81+ shutdown_piohome = shutdown_piohome ,
82+ develop = develop ,
83+ ignore_pythons = ignore_pythons ,
84+ )
85+ raise exc
86+
87+
88+ def _install_platformio_core (shutdown_piohome = True , develop = False , ignore_pythons = None ):
6689 # pylint: disable=bad-option-value, import-outside-toplevel, unused-import, import-error, unused-variable, cyclic-import
6790 from pioinstaller import penv
6891
@@ -96,10 +119,6 @@ def install_platformio_core(shutdown_piohome=True, develop=False, ignore_pythons
96119 penv .get_penv_bin_dir (penv_dir ),
97120 "platformio.exe" if util .IS_WINDOWS else "platformio" ,
98121 )
99- try :
100- home .install_pio_home (platformio_exe )
101- except Exception as e : # pylint:disable=broad-except
102- log .debug (e )
103122
104123 click .secho (
105124 "\n PlatformIO Core has been successfully installed into an isolated environment `%s`!\n "
@@ -126,7 +145,8 @@ def check(dev=False, auto_upgrade=False, version_spec=None):
126145 from pioinstaller import penv
127146
128147 platformio_exe = os .path .join (
129- penv .get_penv_bin_dir (), "platformio.exe" if util .IS_WINDOWS else "platformio" ,
148+ penv .get_penv_bin_dir (),
149+ "platformio.exe" if util .IS_WINDOWS else "platformio" ,
130150 )
131151 python_exe = os .path .join (
132152 penv .get_penv_bin_dir (), "python.exe" if util .IS_WINDOWS else "python"
@@ -185,7 +205,8 @@ def check(dev=False, auto_upgrade=False, version_spec=None):
185205 penv_state = json .load (fp )
186206 if penv_state .get ("platform" ) != platform .platform (terse = True ):
187207 raise exception .InvalidPlatformIOCore (
188- "PlatformIO installed using another platform `%s`. Your platform: %s"
208+ "PlatformIO Core was installed using another platform `%s`. "
209+ "Your current platform: %s"
189210 % (penv_state .get ("platform" ), platform .platform (terse = True ))
190211 )
191212
@@ -227,18 +248,33 @@ def check(dev=False, auto_upgrade=False, version_spec=None):
227248
228249
229250def fetch_python_state (python_exe ):
230- code = """import platform
251+ code = """
231252import json
253+ import platform
254+ import sys
255+
232256import platformio
233257
258+ if sys.version_info < (3, 6):
259+ raise Exception(
260+ "Unsupported Python version: %s. "
261+ "Minimum supported Python version is 3.6 or above."
262+ % platform.python_version(),
263+ )
264+
234265state = {
235266 "core_version": platformio.__version__,
236267 "python_version": platform.python_version()
237268}
238269print(json.dumps(state))
239270"""
240271 state = subprocess .check_output (
241- [python_exe , "-c" , code ,], stderr = subprocess .STDOUT ,
272+ [
273+ python_exe ,
274+ "-c" ,
275+ code ,
276+ ],
277+ stderr = subprocess .STDOUT ,
242278 )
243279 return json .loads (state .decode ())
244280
@@ -256,7 +292,8 @@ def upgrade_core(platformio_exe, dev=False):
256292 command .append ("--dev" )
257293 try :
258294 subprocess .check_output (
259- command , stderr = subprocess .PIPE ,
295+ command ,
296+ stderr = subprocess .PIPE ,
260297 )
261298 return True
262299 except Exception as e : # pylint:disable=broad-except
0 commit comments