forked from platformio/platformio-core
Be compatible with Python 3.8, on Windows skip HOME and check for USERPROFILE
This commit is contained in:
@ -22,16 +22,7 @@ import hashlib
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
from os.path import (
|
from os.path import basename, commonprefix, isdir, isfile, join, realpath, sep
|
||||||
basename,
|
|
||||||
commonprefix,
|
|
||||||
expanduser,
|
|
||||||
isdir,
|
|
||||||
isfile,
|
|
||||||
join,
|
|
||||||
realpath,
|
|
||||||
sep,
|
|
||||||
)
|
|
||||||
|
|
||||||
import click
|
import click
|
||||||
import SCons.Scanner # pylint: disable=import-error
|
import SCons.Scanner # pylint: disable=import-error
|
||||||
@ -943,7 +934,8 @@ def GetLibSourceDirs(env):
|
|||||||
items = env.GetProjectOption("lib_extra_dirs", [])
|
items = env.GetProjectOption("lib_extra_dirs", [])
|
||||||
items.extend(env["LIBSOURCE_DIRS"])
|
items.extend(env["LIBSOURCE_DIRS"])
|
||||||
return [
|
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
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from os import getenv, makedirs, remove
|
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 shutil import copyfile, copytree
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ def validate_path(ctx, param, value): # pylint: disable=unused-argument
|
|||||||
value = list(value)
|
value = list(value)
|
||||||
for i, p in enumerate(value):
|
for i, p in enumerate(value):
|
||||||
if p.startswith("~"):
|
if p.startswith("~"):
|
||||||
value[i] = expanduser(p)
|
value[i] = fs.expanduser(p)
|
||||||
value[i] = abspath(value[i])
|
value[i] = abspath(value[i])
|
||||||
if not glob(value[i]):
|
if not glob(value[i]):
|
||||||
invalid_path = p
|
invalid_path = p
|
||||||
|
@ -171,6 +171,15 @@ def to_unix_path(path):
|
|||||||
return re.sub(r"[\\]+", "/", 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 rmtree(path):
|
||||||
def _onerror(func, path, __):
|
def _onerror(func, path, __):
|
||||||
try:
|
try:
|
||||||
|
@ -14,9 +14,9 @@
|
|||||||
|
|
||||||
from __future__ import absolute_import
|
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
|
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()
|
for name, data in app.DEFAULT_SETTINGS.items()
|
||||||
}
|
}
|
||||||
|
|
||||||
storage["homeDir"] = expanduser("~")
|
storage["homeDir"] = fs.expanduser("~")
|
||||||
storage["projectsDir"] = storage["coreSettings"]["projects_dir"]["value"]
|
storage["projectsDir"] = storage["coreSettings"]["projects_dir"]["value"]
|
||||||
|
|
||||||
# skip non-existing recent projects
|
# skip non-existing recent projects
|
||||||
|
@ -19,12 +19,12 @@ import glob
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
from functools import cmp_to_key
|
from functools import cmp_to_key
|
||||||
from os.path import expanduser, isdir, isfile, join
|
from os.path import isdir, isfile, join
|
||||||
|
|
||||||
import click
|
import click
|
||||||
from twisted.internet import defer # pylint: disable=import-error
|
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.compat import PY2, get_filesystem_encoding
|
||||||
from platformio.home import helpers
|
from platformio.home import helpers
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ class OSRPC(object):
|
|||||||
|
|
||||||
items = []
|
items = []
|
||||||
if path.startswith("~"):
|
if path.startswith("~"):
|
||||||
path = expanduser(path)
|
path = fs.expanduser(path)
|
||||||
if not isdir(path):
|
if not isdir(path):
|
||||||
return items
|
return items
|
||||||
for item in os.listdir(path):
|
for item in os.listdir(path):
|
||||||
|
@ -17,7 +17,7 @@ from __future__ import absolute_import
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import time
|
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
|
import jsonrpc # pylint: disable=import-error
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ class ProjectRPC(object):
|
|||||||
# skip non existing folders and resolve full path
|
# skip non existing folders and resolve full path
|
||||||
for key in ("envLibdepsDirs", "libExtraDirs"):
|
for key in ("envLibdepsDirs", "libExtraDirs"):
|
||||||
data[key] = [
|
data[key] = [
|
||||||
expanduser(d) if d.startswith("~") else realpath(d)
|
fs.expanduser(d) if d.startswith("~") else realpath(d)
|
||||||
for d in data[key]
|
for d in data[key]
|
||||||
if isdir(d)
|
if isdir(d)
|
||||||
]
|
]
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
import sys
|
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
|
import bottle
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ class ProjectGenerator(object):
|
|||||||
"project_name": basename(self.project_dir),
|
"project_name": basename(self.project_dir),
|
||||||
"project_dir": self.project_dir,
|
"project_dir": self.project_dir,
|
||||||
"env_name": self.env_name,
|
"env_name": self.env_name,
|
||||||
"user_home_dir": abspath(expanduser("~")),
|
"user_home_dir": abspath(fs.expanduser("~")),
|
||||||
"platformio_path": sys.argv[0]
|
"platformio_path": sys.argv[0]
|
||||||
if isfile(sys.argv[0])
|
if isfile(sys.argv[0])
|
||||||
else where_is_program("platformio"),
|
else where_is_program("platformio"),
|
||||||
|
@ -20,7 +20,7 @@ from hashlib import sha1
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from platformio import exception
|
from platformio import exception, fs
|
||||||
from platformio.compat import WINDOWS, hashlib_encode_data
|
from platformio.compat import WINDOWS, hashlib_encode_data
|
||||||
from platformio.project.options import ProjectOptions
|
from platformio.project.options import ProjectOptions
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ class ProjectConfigBase(object):
|
|||||||
# load extra configs
|
# load extra configs
|
||||||
for pattern in self.get("platformio", "extra_configs", []):
|
for pattern in self.get("platformio", "extra_configs", []):
|
||||||
if pattern.startswith("~"):
|
if pattern.startswith("~"):
|
||||||
pattern = os.path.expanduser(pattern)
|
pattern = fs.expanduser(pattern)
|
||||||
for item in glob.glob(pattern):
|
for item in glob.glob(pattern):
|
||||||
self.read(item)
|
self.read(item)
|
||||||
|
|
||||||
@ -380,7 +380,7 @@ class ProjectConfigDirsMixin(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if result.startswith("~"):
|
if result.startswith("~"):
|
||||||
result = os.path.expanduser(result)
|
result = fs.expanduser(result)
|
||||||
|
|
||||||
result = os.path.realpath(result)
|
result = os.path.realpath(result)
|
||||||
|
|
||||||
|
@ -16,11 +16,11 @@ import json
|
|||||||
import os
|
import os
|
||||||
from hashlib import sha1
|
from hashlib import sha1
|
||||||
from os import walk
|
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 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.compat import WINDOWS, hashlib_encode_data
|
||||||
from platformio.project.config import ProjectConfig
|
from platformio.project.config import ProjectConfig
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ def get_project_libdeps_dir():
|
|||||||
|
|
||||||
|
|
||||||
def get_default_projects_dir():
|
def get_default_projects_dir():
|
||||||
docs_dir = join(expanduser("~"), "Documents")
|
docs_dir = join(fs.expanduser("~"), "Documents")
|
||||||
try:
|
try:
|
||||||
assert WINDOWS
|
assert WINDOWS
|
||||||
import ctypes.wintypes # pylint: disable=import-outside-toplevel
|
import ctypes.wintypes # pylint: disable=import-outside-toplevel
|
||||||
|
@ -19,6 +19,8 @@ from collections import OrderedDict, namedtuple
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
|
from platformio import fs
|
||||||
|
|
||||||
ConfigOptionClass = namedtuple(
|
ConfigOptionClass = namedtuple(
|
||||||
"ConfigOption",
|
"ConfigOption",
|
||||||
[
|
[
|
||||||
@ -77,7 +79,7 @@ ProjectOptions = OrderedDict(
|
|||||||
name="core_dir",
|
name="core_dir",
|
||||||
oldnames=["home_dir"],
|
oldnames=["home_dir"],
|
||||||
sysenvvar="PLATFORMIO_CORE_DIR",
|
sysenvvar="PLATFORMIO_CORE_DIR",
|
||||||
default=os.path.join(os.path.expanduser("~"), ".platformio"),
|
default=os.path.join(fs.expanduser("~"), ".platformio"),
|
||||||
),
|
),
|
||||||
ConfigPlatformioOption(
|
ConfigPlatformioOption(
|
||||||
name="globallib_dir",
|
name="globallib_dir",
|
||||||
|
Reference in New Issue
Block a user