Be compatible with Python 3.8, on Windows skip HOME and check for USERPROFILE

This commit is contained in:
Ivan Kravets
2019-10-17 20:57:40 +03:00
parent 5cfa2b7fdd
commit be9aaf8902
10 changed files with 33 additions and 30 deletions

View File

@ -22,16 +22,7 @@ import hashlib
import os
import re
import sys
from os.path import (
basename,
commonprefix,
expanduser,
isdir,
isfile,
join,
realpath,
sep,
)
from os.path import basename, commonprefix, isdir, isfile, join, realpath, sep
import click
import SCons.Scanner # pylint: disable=import-error
@ -943,7 +934,8 @@ def GetLibSourceDirs(env):
items = env.GetProjectOption("lib_extra_dirs", [])
items.extend(env["LIBSOURCE_DIRS"])
return [
env.subst(expanduser(item) if item.startswith("~") else item) for item in items
env.subst(fs.expanduser(item) if item.startswith("~") else item)
for item in items
]

View File

@ -14,7 +14,7 @@
from glob import glob
from os import getenv, makedirs, remove
from os.path import abspath, basename, expanduser, isdir, isfile, join
from os.path import abspath, basename, isdir, isfile, join
from shutil import copyfile, copytree
from tempfile import mkdtemp
@ -34,7 +34,7 @@ def validate_path(ctx, param, value): # pylint: disable=unused-argument
value = list(value)
for i, p in enumerate(value):
if p.startswith("~"):
value[i] = expanduser(p)
value[i] = fs.expanduser(p)
value[i] = abspath(value[i])
if not glob(value[i]):
invalid_path = p

View File

@ -171,6 +171,15 @@ def to_unix_path(path):
return re.sub(r"[\\]+", "/", path)
def expanduser(path):
"""
Be compatible with Python 3.8, on Windows skip HOME and check for USERPROFILE
"""
if not WINDOWS or not path.startswith("~") or "USERPROFILE" not in os.environ:
return os.path.expanduser(path)
return os.environ["USERPROFILE"] + path[1:]
def rmtree(path):
def _onerror(func, path, __):
try:

View File

@ -14,9 +14,9 @@
from __future__ import absolute_import
from os.path import expanduser, join
from os.path import join
from platformio import __version__, app, util
from platformio import __version__, app, fs, util
from platformio.project.helpers import get_project_core_dir, is_platformio_project
@ -54,7 +54,7 @@ class AppRPC(object):
for name, data in app.DEFAULT_SETTINGS.items()
}
storage["homeDir"] = expanduser("~")
storage["homeDir"] = fs.expanduser("~")
storage["projectsDir"] = storage["coreSettings"]["projects_dir"]["value"]
# skip non-existing recent projects

View File

@ -19,12 +19,12 @@ import glob
import os
import shutil
from functools import cmp_to_key
from os.path import expanduser, isdir, isfile, join
from os.path import isdir, isfile, join
import click
from twisted.internet import defer # pylint: disable=import-error
from platformio import app, util
from platformio import app, fs, util
from platformio.compat import PY2, get_filesystem_encoding
from platformio.home import helpers
@ -126,7 +126,7 @@ class OSRPC(object):
items = []
if path.startswith("~"):
path = expanduser(path)
path = fs.expanduser(path)
if not isdir(path):
return items
for item in os.listdir(path):

View File

@ -17,7 +17,7 @@ from __future__ import absolute_import
import os
import shutil
import time
from os.path import basename, expanduser, getmtime, isdir, isfile, join, realpath, sep
from os.path import basename, getmtime, isdir, isfile, join, realpath, sep
import jsonrpc # pylint: disable=import-error
@ -56,7 +56,7 @@ class ProjectRPC(object):
# skip non existing folders and resolve full path
for key in ("envLibdepsDirs", "libExtraDirs"):
data[key] = [
expanduser(d) if d.startswith("~") else realpath(d)
fs.expanduser(d) if d.startswith("~") else realpath(d)
for d in data[key]
if isdir(d)
]

View File

@ -15,7 +15,7 @@
import io
import os
import sys
from os.path import abspath, basename, expanduser, isdir, isfile, join, relpath
from os.path import abspath, basename, isdir, isfile, join, relpath
import bottle
@ -64,7 +64,7 @@ class ProjectGenerator(object):
"project_name": basename(self.project_dir),
"project_dir": self.project_dir,
"env_name": self.env_name,
"user_home_dir": abspath(expanduser("~")),
"user_home_dir": abspath(fs.expanduser("~")),
"platformio_path": sys.argv[0]
if isfile(sys.argv[0])
else where_is_program("platformio"),

View File

@ -20,7 +20,7 @@ from hashlib import sha1
import click
from platformio import exception
from platformio import exception, fs
from platformio.compat import WINDOWS, hashlib_encode_data
from platformio.project.options import ProjectOptions
@ -106,7 +106,7 @@ class ProjectConfigBase(object):
# load extra configs
for pattern in self.get("platformio", "extra_configs", []):
if pattern.startswith("~"):
pattern = os.path.expanduser(pattern)
pattern = fs.expanduser(pattern)
for item in glob.glob(pattern):
self.read(item)
@ -380,7 +380,7 @@ class ProjectConfigDirsMixin(object):
)
if result.startswith("~"):
result = os.path.expanduser(result)
result = fs.expanduser(result)
result = os.path.realpath(result)

View File

@ -16,11 +16,11 @@ import json
import os
from hashlib import sha1
from os import walk
from os.path import dirname, expanduser, isdir, isfile, join
from os.path import dirname, isdir, isfile, join
from click.testing import CliRunner
from platformio import __version__, exception
from platformio import __version__, exception, fs
from platformio.compat import WINDOWS, hashlib_encode_data
from platformio.project.config import ProjectConfig
@ -90,7 +90,7 @@ def get_project_libdeps_dir():
def get_default_projects_dir():
docs_dir = join(expanduser("~"), "Documents")
docs_dir = join(fs.expanduser("~"), "Documents")
try:
assert WINDOWS
import ctypes.wintypes # pylint: disable=import-outside-toplevel

View File

@ -19,6 +19,8 @@ from collections import OrderedDict, namedtuple
import click
from platformio import fs
ConfigOptionClass = namedtuple(
"ConfigOption",
[
@ -77,7 +79,7 @@ ProjectOptions = OrderedDict(
name="core_dir",
oldnames=["home_dir"],
sysenvvar="PLATFORMIO_CORE_DIR",
default=os.path.join(os.path.expanduser("~"), ".platformio"),
default=os.path.join(fs.expanduser("~"), ".platformio"),
),
ConfigPlatformioOption(
name="globallib_dir",