mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-29 17:47:14 +02:00
Drop support for Python 2
This commit is contained in:
@ -22,7 +22,7 @@ import click
|
||||
|
||||
from platformio import __version__, exception
|
||||
from platformio.commands import PlatformioCLI
|
||||
from platformio.compat import CYGWIN, PY2, ensure_python3
|
||||
from platformio.compat import IS_CYGWIN, PY2, ensure_python3
|
||||
|
||||
try:
|
||||
import click_completion # pylint: disable=import-error
|
||||
@ -76,7 +76,7 @@ def process_result(ctx, result, *_, **__):
|
||||
|
||||
|
||||
def configure():
|
||||
if CYGWIN:
|
||||
if IS_CYGWIN:
|
||||
raise exception.CygwinEnvDetected()
|
||||
|
||||
# https://urllib3.readthedocs.org
|
||||
|
@ -24,7 +24,7 @@ import uuid
|
||||
from os.path import dirname, isdir, isfile, join, realpath
|
||||
|
||||
from platformio import __version__, exception, fs, proc
|
||||
from platformio.compat import WINDOWS, hashlib_encode_data
|
||||
from platformio.compat import IS_WINDOWS, hashlib_encode_data
|
||||
from platformio.package.lockfile import LockFile
|
||||
from platformio.project.helpers import get_default_projects_dir, get_project_core_dir
|
||||
|
||||
@ -277,7 +277,7 @@ def get_cid():
|
||||
uid = uuid.getnode()
|
||||
cid = uuid.UUID(bytes=hashlib.md5(hashlib_encode_data(uid)).digest())
|
||||
cid = str(cid)
|
||||
if WINDOWS or os.getuid() > 0: # pylint: disable=no-member
|
||||
if IS_WINDOWS or os.getuid() > 0: # pylint: disable=no-member
|
||||
set_state_item("cid", cid)
|
||||
return cid
|
||||
|
||||
|
@ -129,7 +129,7 @@ env.Replace(
|
||||
)
|
||||
|
||||
if (
|
||||
compat.WINDOWS
|
||||
compat.IS_WINDOWS
|
||||
and sys.version_info >= (3, 8)
|
||||
and env["PROJECT_DIR"].startswith("\\\\")
|
||||
):
|
||||
|
@ -33,7 +33,7 @@ from SCons.Script import DefaultEnvironment # pylint: disable=import-error
|
||||
from platformio import exception, fs, util
|
||||
from platformio.builder.tools import platformio as piotool
|
||||
from platformio.clients.http import InternetIsOffline
|
||||
from platformio.compat import WINDOWS, hashlib_encode_data, string_types
|
||||
from platformio.compat import IS_WINDOWS, hashlib_encode_data, string_types
|
||||
from platformio.package.exception import UnknownPackageError
|
||||
from platformio.package.manager.library import LibraryPackageManager
|
||||
from platformio.package.manifest.parser import (
|
||||
@ -142,7 +142,7 @@ class LibBuilderBase(object):
|
||||
def __contains__(self, path):
|
||||
p1 = self.path
|
||||
p2 = path
|
||||
if WINDOWS:
|
||||
if IS_WINDOWS:
|
||||
p1 = p1.lower()
|
||||
p2 = p2.lower()
|
||||
if p1 == p2:
|
||||
|
@ -21,20 +21,20 @@ import re
|
||||
from SCons.Platform import TempFileMunge # pylint: disable=import-error
|
||||
from SCons.Subst import quote_spaces # pylint: disable=import-error
|
||||
|
||||
from platformio.compat import WINDOWS, hashlib_encode_data
|
||||
from platformio.compat import IS_WINDOWS, hashlib_encode_data
|
||||
|
||||
# There are the next limits depending on a platform:
|
||||
# - Windows = 8192
|
||||
# - Unix = 131072
|
||||
# We need ~512 characters for compiler and temporary file paths
|
||||
MAX_LINE_LENGTH = (8192 if WINDOWS else 131072) - 512
|
||||
MAX_LINE_LENGTH = (8192 if IS_WINDOWS else 131072) - 512
|
||||
|
||||
WINPATHSEP_RE = re.compile(r"\\([^\"'\\]|$)")
|
||||
|
||||
|
||||
def tempfile_arg_esc_func(arg):
|
||||
arg = quote_spaces(arg)
|
||||
if not WINDOWS:
|
||||
if not IS_WINDOWS:
|
||||
return arg
|
||||
# GCC requires double Windows slashes, let's use UNIX separator
|
||||
return WINPATHSEP_RE.sub(r"/\1", arg)
|
||||
|
@ -21,7 +21,7 @@ from SCons.Script import ARGUMENTS # pylint: disable=import-error
|
||||
from SCons.Script import COMMAND_LINE_TARGETS # pylint: disable=import-error
|
||||
|
||||
from platformio import fs, util
|
||||
from platformio.compat import WINDOWS
|
||||
from platformio.compat import IS_MACOS, IS_WINDOWS
|
||||
from platformio.package.meta import PackageItem
|
||||
from platformio.package.version import get_original_version
|
||||
from platformio.platform.exception import UnknownBoard
|
||||
@ -71,7 +71,6 @@ def LoadPioPlatform(env):
|
||||
env["PIOPLATFORM"] = p.name
|
||||
|
||||
# Add toolchains and uploaders to $PATH and $*_LIBRARY_PATH
|
||||
systype = util.get_systype()
|
||||
for pkg in p.get_installed_packages():
|
||||
type_ = p.get_package_type(pkg.metadata.name)
|
||||
if type_ not in ("toolchain", "uploader", "debugger"):
|
||||
@ -83,12 +82,12 @@ def LoadPioPlatform(env):
|
||||
else pkg.path,
|
||||
)
|
||||
if (
|
||||
not WINDOWS
|
||||
not IS_WINDOWS
|
||||
and os.path.isdir(os.path.join(pkg.path, "lib"))
|
||||
and type_ != "toolchain"
|
||||
):
|
||||
env.PrependENVPath(
|
||||
"DYLD_LIBRARY_PATH" if "darwin" in systype else "LD_LIBRARY_PATH",
|
||||
"DYLD_LIBRARY_PATH" if IS_MACOS else "LD_LIBRARY_PATH",
|
||||
os.path.join(pkg.path, "lib"),
|
||||
)
|
||||
|
||||
|
@ -24,8 +24,8 @@ from os.path import isdir, join, splitdrive
|
||||
from elftools.elf.descriptions import describe_sh_flags
|
||||
from elftools.elf.elffile import ELFFile
|
||||
|
||||
from platformio.compat import IS_WINDOWS
|
||||
from platformio.proc import exec_command
|
||||
from platformio.util import get_systype
|
||||
|
||||
|
||||
def _run_tool(cmd, env, tool_args):
|
||||
@ -164,7 +164,7 @@ def _collect_symbols_info(env, elffile, elf_path, sections):
|
||||
location = symbol_locations.get(hex(symbol["addr"]))
|
||||
if not location or "?" in location:
|
||||
continue
|
||||
if "windows" in get_systype():
|
||||
if IS_WINDOWS:
|
||||
drive, tail = splitdrive(location)
|
||||
location = join(drive.upper(), tail)
|
||||
symbol["file"] = location
|
||||
|
@ -31,7 +31,7 @@ def VerboseAction(_, act, actstr):
|
||||
|
||||
def PioClean(env, clean_dir):
|
||||
def _relpath(path):
|
||||
if compat.WINDOWS:
|
||||
if compat.IS_WINDOWS:
|
||||
prefix = os.getcwd()[:2].lower()
|
||||
if (
|
||||
":" not in prefix
|
||||
|
@ -26,7 +26,7 @@ from SCons.Script import ARGUMENTS # pylint: disable=import-error
|
||||
from serial import Serial, SerialException
|
||||
|
||||
from platformio import exception, fs, util
|
||||
from platformio.compat import WINDOWS
|
||||
from platformio.compat import IS_WINDOWS
|
||||
from platformio.proc import exec_command
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
@ -134,7 +134,7 @@ def AutodetectUploadPort(*args, **kwargs):
|
||||
continue
|
||||
port = item["port"]
|
||||
if upload_protocol.startswith("blackmagic"):
|
||||
if WINDOWS and port.startswith("COM") and len(port) > 4:
|
||||
if IS_WINDOWS and port.startswith("COM") and len(port) > 4:
|
||||
port = "\\\\.\\%s" % port
|
||||
if "GDB" in item["description"]:
|
||||
return port
|
||||
|
@ -27,7 +27,7 @@ from SCons.Script import Export # pylint: disable=import-error
|
||||
from SCons.Script import SConscript # pylint: disable=import-error
|
||||
|
||||
from platformio import __version__, fs
|
||||
from platformio.compat import MACOS, string_types
|
||||
from platformio.compat import IS_MACOS, string_types
|
||||
from platformio.package.version import pepver_to_semver
|
||||
|
||||
SRC_HEADER_EXT = ["h", "hpp"]
|
||||
@ -69,7 +69,7 @@ def BuildProgram(env):
|
||||
if (
|
||||
env.get("LIBS")
|
||||
and env.GetCompilerType() == "gcc"
|
||||
and (env.PioPlatform().is_embedded() or not MACOS)
|
||||
and (env.PioPlatform().is_embedded() or not IS_MACOS)
|
||||
):
|
||||
env.Prepend(_LIBFLAGS="-Wl,--start-group ")
|
||||
env.Append(_LIBFLAGS=" -Wl,--end-group")
|
||||
|
@ -19,9 +19,10 @@ from xml.etree.ElementTree import fromstring
|
||||
|
||||
import click
|
||||
|
||||
from platformio import proc, util
|
||||
from platformio import proc
|
||||
from platformio.commands.check.defect import DefectItem
|
||||
from platformio.commands.check.tools.base import CheckToolBase
|
||||
from platformio.compat import IS_WINDOWS
|
||||
from platformio.package.manager.core import get_core_package_dir
|
||||
|
||||
|
||||
@ -34,7 +35,7 @@ class PvsStudioCheckTool(CheckToolBase): # pylint: disable=too-many-instance-at
|
||||
self._tmp_cmd_file = self._generate_tmp_file_path() + ".cmd"
|
||||
self.tool_path = os.path.join(
|
||||
get_core_package_dir("tool-pvs-studio"),
|
||||
"x64" if "windows" in util.get_systype() else "bin",
|
||||
"x64" if IS_WINDOWS else "bin",
|
||||
"pvs-studio",
|
||||
)
|
||||
super(PvsStudioCheckTool, self).__init__(*args, **kwargs)
|
||||
@ -70,9 +71,7 @@ class PvsStudioCheckTool(CheckToolBase): # pylint: disable=too-many-instance-at
|
||||
def _demangle_report(self, output_file):
|
||||
converter_tool = os.path.join(
|
||||
get_core_package_dir("tool-pvs-studio"),
|
||||
"HtmlGenerator"
|
||||
if "windows" in util.get_systype()
|
||||
else os.path.join("bin", "plog-converter"),
|
||||
"HtmlGenerator" if IS_WINDOWS else os.path.join("bin", "plog-converter"),
|
||||
)
|
||||
|
||||
cmd = (
|
||||
|
@ -23,7 +23,7 @@ import click
|
||||
|
||||
from platformio import app, exception, fs, proc
|
||||
from platformio.commands.platform import platform_install as cmd_platform_install
|
||||
from platformio.compat import WINDOWS
|
||||
from platformio.compat import IS_WINDOWS
|
||||
from platformio.debug import helpers
|
||||
from platformio.debug.config.factory import DebugConfigFactory
|
||||
from platformio.debug.exception import DebugInvalidOptionsError
|
||||
@ -150,12 +150,12 @@ def cli(ctx, project_dir, project_conf, environment, verbose, interface, __unpro
|
||||
if not os.path.isfile(debug_config.program_path):
|
||||
raise DebugInvalidOptionsError("Program/firmware is missed")
|
||||
|
||||
loop = asyncio.ProactorEventLoop() if WINDOWS else asyncio.get_event_loop()
|
||||
loop = asyncio.ProactorEventLoop() if IS_WINDOWS else asyncio.get_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
client = DebugClientProcess(project_dir, debug_config)
|
||||
coro = client.run(__unprocessed)
|
||||
loop.run_until_complete(coro)
|
||||
if WINDOWS:
|
||||
if IS_WINDOWS:
|
||||
# an issue with asyncio executor and STIDIN, it cannot be closed gracefully
|
||||
proc.force_exit()
|
||||
loop.close()
|
||||
|
@ -18,7 +18,7 @@ import requests
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
|
||||
from platformio import util
|
||||
from platformio.compat import WINDOWS
|
||||
from platformio.compat import IS_WINDOWS
|
||||
from platformio.proc import where_is_program
|
||||
|
||||
|
||||
@ -37,15 +37,13 @@ def requests_session():
|
||||
|
||||
@util.memoized(expire="60s")
|
||||
def get_core_fullpath():
|
||||
return where_is_program(
|
||||
"platformio" + (".exe" if "windows" in util.get_systype() else "")
|
||||
)
|
||||
return where_is_program("platformio" + (".exe" if IS_WINDOWS else ""))
|
||||
|
||||
|
||||
def is_port_used(host, port):
|
||||
socket.setdefaulttimeout(1)
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
if WINDOWS:
|
||||
if IS_WINDOWS:
|
||||
try:
|
||||
s.bind((host, port))
|
||||
s.close()
|
||||
|
@ -69,7 +69,7 @@ def system_info(json_output):
|
||||
data["platformio_exe"] = {
|
||||
"title": "PlatformIO Core Executable",
|
||||
"value": proc.where_is_program(
|
||||
"platformio.exe" if proc.WINDOWS else "platformio"
|
||||
"platformio.exe" if compat.IS_WINDOWS else "platformio"
|
||||
),
|
||||
}
|
||||
data["python_exe"] = {
|
||||
|
@ -21,7 +21,7 @@ import click
|
||||
|
||||
from platformio import VERSION, __version__, app, exception
|
||||
from platformio.clients.http import fetch_remote_content
|
||||
from platformio.compat import WINDOWS
|
||||
from platformio.compat import IS_WINDOWS
|
||||
from platformio.proc import exec_command, get_pythonexe_path
|
||||
from platformio.project.helpers import get_project_cache_dir
|
||||
|
||||
@ -73,7 +73,7 @@ def cli(dev):
|
||||
if not r:
|
||||
raise exception.UpgradeError("\n".join([str(cmd), str(e)]))
|
||||
permission_errors = ("permission denied", "not permitted")
|
||||
if any(m in r["err"].lower() for m in permission_errors) and not WINDOWS:
|
||||
if any(m in r["err"].lower() for m in permission_errors) and not IS_WINDOWS:
|
||||
click.secho(
|
||||
"""
|
||||
-----------------
|
||||
|
@ -30,9 +30,9 @@ if sys.version_info >= (3,):
|
||||
|
||||
|
||||
PY2 = sys.version_info[0] == 2
|
||||
CYGWIN = sys.platform.startswith("cygwin")
|
||||
WINDOWS = sys.platform.startswith("win")
|
||||
MACOS = sys.platform.startswith("darwin")
|
||||
IS_CYGWIN = sys.platform.startswith("cygwin")
|
||||
IS_WINDOWS = WINDOWS = sys.platform.startswith("win")
|
||||
IS_MACOS = sys.platform.startswith("darwin")
|
||||
string_types = (str,)
|
||||
|
||||
|
||||
|
@ -23,7 +23,7 @@ from os.path import isfile
|
||||
from platformio import util
|
||||
from platformio.commands import PlatformioCLI
|
||||
from platformio.commands.run.command import cli as cmd_run
|
||||
from platformio.compat import is_bytes
|
||||
from platformio.compat import IS_WINDOWS, is_bytes
|
||||
from platformio.debug.exception import DebugInvalidOptionsError
|
||||
|
||||
|
||||
@ -152,11 +152,7 @@ def reveal_debug_port(env_debug_port, tool_name, tool_settings):
|
||||
continue
|
||||
port = item["port"]
|
||||
if tool_name.startswith("blackmagic"):
|
||||
if (
|
||||
"windows" in util.get_systype()
|
||||
and port.startswith("COM")
|
||||
and len(port) > 4
|
||||
):
|
||||
if IS_WINDOWS and port.startswith("COM") and len(port) > 4:
|
||||
port = "\\\\.\\%s" % port
|
||||
if "GDB" in item["description"]:
|
||||
return port
|
||||
|
@ -19,7 +19,7 @@ import sys
|
||||
import time
|
||||
|
||||
from platformio.compat import (
|
||||
WINDOWS,
|
||||
IS_WINDOWS,
|
||||
aio_create_task,
|
||||
aio_get_running_loop,
|
||||
get_locale_encoding,
|
||||
@ -93,7 +93,7 @@ class DebugBaseProcess:
|
||||
|
||||
async def _read_stdin_pipe(self):
|
||||
loop = aio_get_running_loop()
|
||||
if WINDOWS:
|
||||
if IS_WINDOWS:
|
||||
while True:
|
||||
self.stdin_data_received(
|
||||
await loop.run_in_executor(None, sys.stdin.buffer.readline)
|
||||
|
@ -19,9 +19,14 @@ import signal
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
from platformio import fs, proc, telemetry, util
|
||||
from platformio import fs, proc, telemetry
|
||||
from platformio.cache import ContentCache
|
||||
from platformio.compat import aio_get_running_loop, hashlib_encode_data, is_bytes
|
||||
from platformio.compat import (
|
||||
IS_WINDOWS,
|
||||
aio_get_running_loop,
|
||||
hashlib_encode_data,
|
||||
is_bytes,
|
||||
)
|
||||
from platformio.debug import helpers
|
||||
from platformio.debug.process.base import DebugBaseProcess
|
||||
from platformio.debug.process.server import DebugServerProcess
|
||||
@ -230,7 +235,7 @@ class DebugClientProcess(
|
||||
cc.delete(self._session_id)
|
||||
if not pid:
|
||||
return
|
||||
if "windows" in util.get_systype():
|
||||
if IS_WINDOWS:
|
||||
kill = ["Taskkill", "/PID", pid, "/F"]
|
||||
else:
|
||||
kill = ["kill", pid]
|
||||
|
@ -13,12 +13,11 @@
|
||||
# limitations under the License.
|
||||
|
||||
import asyncio
|
||||
import fnmatch
|
||||
import os
|
||||
import time
|
||||
|
||||
from platformio import fs
|
||||
from platformio.compat import MACOS, WINDOWS
|
||||
from platformio.compat import IS_MACOS, IS_WINDOWS
|
||||
from platformio.debug.exception import DebugInvalidOptionsError
|
||||
from platformio.debug.helpers import escape_gdbmi_stream, is_gdbmi_mode
|
||||
from platformio.debug.process.base import DebugBaseProcess
|
||||
@ -41,7 +40,7 @@ class DebugServerProcess(DebugBaseProcess):
|
||||
if server["cwd"]:
|
||||
server_executable = os.path.join(server["cwd"], server_executable)
|
||||
if (
|
||||
WINDOWS
|
||||
IS_WINDOWS
|
||||
and not server_executable.endswith(".exe")
|
||||
and os.path.isfile(server_executable + ".exe")
|
||||
):
|
||||
@ -81,11 +80,11 @@ class DebugServerProcess(DebugBaseProcess):
|
||||
env = os.environ.copy()
|
||||
# prepend server "lib" folder to LD path
|
||||
if (
|
||||
not WINDOWS
|
||||
not IS_WINDOWS
|
||||
and server["cwd"]
|
||||
and os.path.isdir(os.path.join(server["cwd"], "lib"))
|
||||
):
|
||||
ld_key = "DYLD_LIBRARY_PATH" if MACOS else "LD_LIBRARY_PATH"
|
||||
ld_key = "DYLD_LIBRARY_PATH" if IS_MACOS else "LD_LIBRARY_PATH"
|
||||
env[ld_key] = os.path.join(server["cwd"], "lib")
|
||||
if os.environ.get(ld_key):
|
||||
env[ld_key] = "%s:%s" % (env[ld_key], os.environ.get(ld_key))
|
||||
|
@ -25,7 +25,7 @@ import sys
|
||||
import click
|
||||
|
||||
from platformio import exception
|
||||
from platformio.compat import WINDOWS
|
||||
from platformio.compat import IS_WINDOWS
|
||||
|
||||
|
||||
class cd(object):
|
||||
@ -176,7 +176,7 @@ def match_src_files(src_dir, src_filter=None, src_exts=None, followlinks=True):
|
||||
|
||||
|
||||
def to_unix_path(path):
|
||||
if not WINDOWS or not path:
|
||||
if not IS_WINDOWS or not path:
|
||||
return path
|
||||
return re.sub(r"[\\]+", "/", path)
|
||||
|
||||
@ -185,7 +185,7 @@ 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:
|
||||
if not IS_WINDOWS or not path.startswith("~") or "USERPROFILE" not in os.environ:
|
||||
return os.path.expanduser(path)
|
||||
return os.environ["USERPROFILE"] + path[1:]
|
||||
|
||||
|
@ -20,7 +20,6 @@ import sys
|
||||
from datetime import date
|
||||
|
||||
from platformio import __core_packages__, exception, fs, util
|
||||
from platformio.compat import PY2
|
||||
from platformio.package.exception import UnknownPackageError
|
||||
from platformio.package.manager.tool import ToolPackageManager
|
||||
from platformio.package.meta import PackageItem, PackageSpec
|
||||
@ -207,7 +206,7 @@ def get_contrib_pysite_deps():
|
||||
sys_type = util.get_systype()
|
||||
py_version = "%d%d" % (sys.version_info.major, sys.version_info.minor)
|
||||
|
||||
twisted_version = "19.10.0" if PY2 else "20.3.0"
|
||||
twisted_version = "20.3.0"
|
||||
result = [
|
||||
"twisted == %s" % twisted_version,
|
||||
]
|
||||
|
@ -20,7 +20,7 @@ import tarfile
|
||||
import tempfile
|
||||
|
||||
from platformio import fs
|
||||
from platformio.compat import WINDOWS, ensure_python3
|
||||
from platformio.compat import IS_WINDOWS, ensure_python3
|
||||
from platformio.package.exception import PackageException, UserSideException
|
||||
from platformio.package.manifest.parser import ManifestFileType, ManifestParserFactory
|
||||
from platformio.package.manifest.schema import ManifestSchema
|
||||
@ -117,7 +117,7 @@ class PackagePacker(object):
|
||||
|
||||
# if zip/tar.gz -> unpack to tmp dir
|
||||
if not os.path.isdir(src):
|
||||
if WINDOWS:
|
||||
if IS_WINDOWS:
|
||||
raise UserSideException(
|
||||
"Packaging from an archive does not work on Windows OS. Please "
|
||||
"extract data from `%s` manually and pack a folder instead"
|
||||
|
@ -20,7 +20,7 @@ import sys
|
||||
import click
|
||||
|
||||
from platformio import app, fs, proc, telemetry
|
||||
from platformio.compat import PY2, hashlib_encode_data, is_bytes
|
||||
from platformio.compat import hashlib_encode_data, is_bytes
|
||||
from platformio.package.manager.core import get_core_package_dir
|
||||
from platformio.platform.exception import BuildScriptNotFound
|
||||
|
||||
@ -90,14 +90,9 @@ class PlatformRunMixin(object):
|
||||
|
||||
def _run_scons(self, variables, targets, jobs):
|
||||
scons_dir = get_core_package_dir("tool-scons")
|
||||
script_path = (
|
||||
os.path.join(scons_dir, "script", "scons")
|
||||
if PY2
|
||||
else os.path.join(scons_dir, "scons.py")
|
||||
)
|
||||
args = [
|
||||
proc.get_pythonexe_path(),
|
||||
script_path,
|
||||
os.path.join(scons_dir, "scons.py"),
|
||||
"-Q",
|
||||
"--warn=no-no-parallel-support",
|
||||
"--jobs",
|
||||
|
@ -15,7 +15,6 @@
|
||||
import os
|
||||
|
||||
from platformio import fs, telemetry, util
|
||||
from platformio.compat import PY2
|
||||
from platformio.debug.exception import DebugInvalidOptionsError, DebugSupportError
|
||||
from platformio.exception import UserSideException
|
||||
from platformio.platform.exception import InvalidBoardManifest
|
||||
@ -40,15 +39,6 @@ class PlatformBoardConfig(object):
|
||||
value = self._manifest
|
||||
for k in path.split("."):
|
||||
value = value[k]
|
||||
# pylint: disable=undefined-variable
|
||||
if PY2 and isinstance(value, unicode):
|
||||
# cast to plain string from unicode for PY2, resolves issue in
|
||||
# dev/platform when BoardConfig.get() is used in pair with
|
||||
# os.path.join(file_encoding, unicode_encoding)
|
||||
try:
|
||||
value = value.encode("utf-8")
|
||||
except UnicodeEncodeError:
|
||||
pass
|
||||
return value
|
||||
except KeyError:
|
||||
if default is not None:
|
||||
|
@ -20,8 +20,7 @@ from threading import Thread
|
||||
|
||||
from platformio import exception
|
||||
from platformio.compat import (
|
||||
PY2,
|
||||
WINDOWS,
|
||||
IS_WINDOWS,
|
||||
get_filesystem_encoding,
|
||||
get_locale_encoding,
|
||||
string_types,
|
||||
@ -31,10 +30,7 @@ from platformio.compat import (
|
||||
class AsyncPipeBase(object):
|
||||
def __init__(self):
|
||||
self._fd_read, self._fd_write = os.pipe()
|
||||
if PY2:
|
||||
self._pipe_reader = os.fdopen(self._fd_read)
|
||||
else:
|
||||
self._pipe_reader = os.fdopen(self._fd_read, errors="backslashreplace")
|
||||
self._pipe_reader = os.fdopen(self._fd_read, errors="backslashreplace")
|
||||
self._buffer = ""
|
||||
self._thread = Thread(target=self.run)
|
||||
self._thread.start()
|
||||
@ -129,9 +125,7 @@ def exec_command(*args, **kwargs):
|
||||
result[s[3:]] = kwargs[s].get_buffer()
|
||||
|
||||
for k, v in result.items():
|
||||
if PY2 and isinstance(v, unicode): # pylint: disable=undefined-variable
|
||||
result[k] = v.encode()
|
||||
elif not PY2 and isinstance(result[k], bytes):
|
||||
if isinstance(result[k], bytes):
|
||||
try:
|
||||
result[k] = result[k].decode(
|
||||
get_locale_encoding() or get_filesystem_encoding()
|
||||
@ -178,7 +172,7 @@ def copy_pythonpath_to_osenv():
|
||||
_PYTHONPATH = os.environ.get("PYTHONPATH").split(os.pathsep)
|
||||
for p in os.sys.path:
|
||||
conditions = [p not in _PYTHONPATH]
|
||||
if not WINDOWS:
|
||||
if not IS_WINDOWS:
|
||||
conditions.append(
|
||||
os.path.isdir(os.path.join(p, "click"))
|
||||
or os.path.isdir(os.path.join(p, "platformio"))
|
||||
@ -195,7 +189,7 @@ def where_is_program(program, envpath=None):
|
||||
|
||||
# try OS's built-in commands
|
||||
try:
|
||||
result = exec_command(["where" if WINDOWS else "which", program], env=env)
|
||||
result = exec_command(["where" if IS_WINDOWS else "which", program], env=env)
|
||||
if result["returncode"] == 0 and os.path.isfile(result["out"].strip()):
|
||||
return result["out"].strip()
|
||||
except OSError:
|
||||
|
@ -21,7 +21,7 @@ import re
|
||||
import click
|
||||
|
||||
from platformio import fs
|
||||
from platformio.compat import PY2, WINDOWS, hashlib_encode_data, string_types
|
||||
from platformio.compat import IS_WINDOWS, hashlib_encode_data, string_types
|
||||
from platformio.project import exception
|
||||
from platformio.project.options import ProjectOptions
|
||||
|
||||
@ -88,11 +88,7 @@ class ProjectConfigBase(object):
|
||||
self.expand_interpolations = expand_interpolations
|
||||
self.warnings = []
|
||||
self._parsed = []
|
||||
self._parser = (
|
||||
ConfigParser.ConfigParser()
|
||||
if PY2
|
||||
else ConfigParser.ConfigParser(inline_comment_prefixes=("#", ";"))
|
||||
)
|
||||
self._parser = ConfigParser.ConfigParser(inline_comment_prefixes=("#", ";"))
|
||||
if path and os.path.isfile(path):
|
||||
self.read(path, parse_extra)
|
||||
|
||||
@ -359,7 +355,7 @@ class ProjectConfigDirsMixin(object):
|
||||
default = ProjectOptions["platformio.core_dir"].default
|
||||
core_dir = self.get("platformio", "core_dir")
|
||||
win_core_dir = None
|
||||
if WINDOWS and core_dir == default:
|
||||
if IS_WINDOWS and core_dir == default:
|
||||
win_core_dir = os.path.splitdrive(core_dir)[0] + "\\.platformio"
|
||||
if os.path.isdir(win_core_dir):
|
||||
core_dir = win_core_dir
|
||||
|
@ -21,7 +21,7 @@ from os.path import dirname, isdir, isfile, join
|
||||
from click.testing import CliRunner
|
||||
|
||||
from platformio import __version__, exception, fs
|
||||
from platformio.compat import WINDOWS, hashlib_encode_data
|
||||
from platformio.compat import IS_WINDOWS, hashlib_encode_data
|
||||
from platformio.project.config import ProjectConfig
|
||||
|
||||
|
||||
@ -92,7 +92,7 @@ def get_project_libdeps_dir():
|
||||
def get_default_projects_dir():
|
||||
docs_dir = join(fs.expanduser("~"), "Documents")
|
||||
try:
|
||||
assert WINDOWS
|
||||
assert IS_WINDOWS
|
||||
import ctypes.wintypes # pylint: disable=import-outside-toplevel
|
||||
|
||||
buf = ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH)
|
||||
@ -128,7 +128,7 @@ def compute_project_checksum(config):
|
||||
if not chunks:
|
||||
continue
|
||||
chunks_to_str = ",".join(sorted(chunks))
|
||||
if WINDOWS: # case insensitive OS
|
||||
if IS_WINDOWS: # case insensitive OS
|
||||
chunks_to_str = chunks_to_str.lower()
|
||||
checksum.update(hashlib_encode_data(chunks_to_str))
|
||||
|
||||
|
@ -26,7 +26,7 @@ from glob import glob
|
||||
import click
|
||||
|
||||
from platformio import __version__, compat, exception, proc
|
||||
from platformio.compat import PY2, WINDOWS
|
||||
from platformio.compat import IS_MACOS, IS_WINDOWS
|
||||
from platformio.fs import cd, load_json # pylint: disable=unused-import
|
||||
from platformio.proc import exec_command # pylint: disable=unused-import
|
||||
|
||||
@ -106,12 +106,6 @@ def get_serial_ports(filter_hwid=False):
|
||||
for p, d, h in comports():
|
||||
if not p:
|
||||
continue
|
||||
if WINDOWS and PY2:
|
||||
try:
|
||||
# pylint: disable=undefined-variable
|
||||
d = unicode(d, errors="ignore")
|
||||
except TypeError:
|
||||
pass
|
||||
if not filter_hwid or "VID:PID" in h:
|
||||
result.append({"port": p, "description": d, "hwid": h})
|
||||
|
||||
@ -119,7 +113,7 @@ def get_serial_ports(filter_hwid=False):
|
||||
return result
|
||||
|
||||
# fix for PySerial
|
||||
if not result and "darwin" in get_systype():
|
||||
if not result and IS_MACOS:
|
||||
for p in glob("/dev/tty.*"):
|
||||
result.append({"port": p, "description": "n/a", "hwid": "n/a"})
|
||||
return result
|
||||
@ -131,7 +125,7 @@ get_serialports = get_serial_ports
|
||||
|
||||
def get_logical_devices():
|
||||
items = []
|
||||
if WINDOWS:
|
||||
if IS_WINDOWS:
|
||||
try:
|
||||
result = proc.exec_command(
|
||||
["wmic", "logicaldisk", "get", "name,VolumeName"]
|
||||
|
@ -19,7 +19,7 @@ import tarfile
|
||||
import jsondiff
|
||||
import pytest
|
||||
|
||||
from platformio.compat import WINDOWS
|
||||
from platformio.compat import IS_WINDOWS
|
||||
from platformio.package.manifest import parser
|
||||
from platformio.package.manifest.schema import ManifestSchema, ManifestValidationError
|
||||
|
||||
@ -715,7 +715,7 @@ def test_examples_from_dir(tmpdir_factory):
|
||||
pio_dir.join(".vimrc").write("")
|
||||
pio_ini = pio_dir.join("platformio.ini")
|
||||
pio_ini.write("")
|
||||
if not WINDOWS:
|
||||
if not IS_WINDOWS:
|
||||
pio_dir.join("platformio.ini.copy").mksymlinkto(pio_ini)
|
||||
pio_dir.mkdir("include").join("main.h").write("")
|
||||
pio_dir.mkdir("src").join("main.cpp").write("")
|
||||
|
@ -19,12 +19,10 @@ import tarfile
|
||||
import pytest
|
||||
|
||||
from platformio import fs
|
||||
from platformio.compat import PY2, WINDOWS
|
||||
from platformio.compat import IS_WINDOWS
|
||||
from platformio.package.exception import UnknownManifestError
|
||||
from platformio.package.pack import PackagePacker
|
||||
|
||||
pytestmark = pytest.mark.skipif(PY2, reason="Requires Python 3.5 or higher")
|
||||
|
||||
|
||||
def test_base(tmpdir_factory):
|
||||
pkg_dir = tmpdir_factory.mktemp("package")
|
||||
@ -99,7 +97,7 @@ def test_filters(tmpdir_factory):
|
||||
|
||||
def test_symlinks(tmpdir_factory):
|
||||
# Windows does not support symbolic links
|
||||
if WINDOWS:
|
||||
if IS_WINDOWS:
|
||||
return
|
||||
pkg_dir = tmpdir_factory.mktemp("package")
|
||||
src_dir = pkg_dir.mkdir("src")
|
||||
|
Reference in New Issue
Block a user