Skip to content

Commit 533ded2

Browse files
committed
Install PlatformIO Core to the WinRoot when space is detected in username // Issue platformio#221
1 parent c7becd1 commit 533ded2

File tree

3 files changed

+45
-19
lines changed

3 files changed

+45
-19
lines changed

get-platformio.py

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pioinstaller/__main__.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,18 @@ def cli(
4343
if verbose:
4444
logging.getLogger("pioinstaller").setLevel(logging.DEBUG)
4545
ctx.obj["dev"] = dev
46-
if not ctx.invoked_subcommand:
47-
click.echo("Installer version: %s" % __version__)
48-
click.echo("Platform: %s" % platform.platform(terse=True))
49-
click.echo("Python version: %s" % sys.version)
50-
click.echo("Python path: %s" % sys.executable)
51-
try:
52-
core.install_platformio_core(shutdown_piohome, dev, ignore_python)
53-
except exception.PIOInstallerException as e:
54-
raise click.ClickException(str(e))
46+
if ctx.invoked_subcommand:
47+
return
48+
49+
click.echo("Installer version: %s" % __version__)
50+
click.echo("Platform: %s" % platform.platform(terse=True))
51+
click.echo("Python version: %s" % sys.version)
52+
click.echo("Python path: %s" % sys.executable)
53+
54+
try:
55+
core.install_platformio_core(shutdown_piohome, dev, ignore_python)
56+
except exception.PIOInstallerException as exc:
57+
raise click.ClickException(str(exc))
5558

5659

5760
@cli.command()

pioinstaller/core.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,24 @@
3030
UPDATE_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

6565
def 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

0 commit comments

Comments
 (0)