mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Fixed "DeprecationWarning: the imp module is deprecated in favour of importlib" PY2/PY3
This commit is contained in:
@ -29,6 +29,8 @@ def get_filesystem_encoding():
|
|||||||
|
|
||||||
|
|
||||||
if PY2:
|
if PY2:
|
||||||
|
import imp
|
||||||
|
|
||||||
# pylint: disable=undefined-variable
|
# pylint: disable=undefined-variable
|
||||||
string_types = (str, unicode)
|
string_types = (str, unicode)
|
||||||
|
|
||||||
@ -76,8 +78,12 @@ if PY2:
|
|||||||
pathname = _magic_check.sub(r"[\1]", pathname)
|
pathname = _magic_check.sub(r"[\1]", pathname)
|
||||||
return drive + pathname
|
return drive + pathname
|
||||||
|
|
||||||
|
def load_python_module(name, pathname):
|
||||||
|
return imp.load_source(name, pathname)
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
import importlib.util
|
||||||
from glob import escape as glob_escape # pylint: disable=no-name-in-module
|
from glob import escape as glob_escape # pylint: disable=no-name-in-module
|
||||||
|
|
||||||
string_types = (str,)
|
string_types = (str,)
|
||||||
@ -107,3 +113,9 @@ else:
|
|||||||
if isinstance(obj, string_types):
|
if isinstance(obj, string_types):
|
||||||
return obj
|
return obj
|
||||||
return json.dumps(obj, ensure_ascii=False, sort_keys=True)
|
return json.dumps(obj, ensure_ascii=False, sort_keys=True)
|
||||||
|
|
||||||
|
def load_python_module(name, pathname):
|
||||||
|
spec = importlib.util.spec_from_file_location(name, pathname)
|
||||||
|
module = importlib.util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(module)
|
||||||
|
return module
|
||||||
|
@ -16,14 +16,13 @@ import base64
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
from imp import load_source
|
|
||||||
from os.path import basename, dirname, isdir, isfile, join
|
from os.path import basename, dirname, isdir, isfile, join
|
||||||
|
|
||||||
import click
|
import click
|
||||||
import semantic_version
|
import semantic_version
|
||||||
|
|
||||||
from platformio import __version__, app, exception, fs, util
|
from platformio import __version__, app, exception, fs, util
|
||||||
from platformio.compat import PY2, hashlib_encode_data, is_bytes
|
from platformio.compat import PY2, hashlib_encode_data, is_bytes, load_python_module
|
||||||
from platformio.managers.core import get_core_package_dir
|
from platformio.managers.core import get_core_package_dir
|
||||||
from platformio.managers.package import BasePkgManager, PackageManager
|
from platformio.managers.package import BasePkgManager, PackageManager
|
||||||
from platformio.proc import (
|
from platformio.proc import (
|
||||||
@ -230,12 +229,10 @@ class PlatformFactory(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def load_module(name, path):
|
def load_module(name, path):
|
||||||
module = None
|
|
||||||
try:
|
try:
|
||||||
module = load_source("platformio.managers.platform.%s" % name, path)
|
return load_python_module("platformio.managers.platform.%s" % name, path)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise exception.UnknownPlatform(name)
|
raise exception.UnknownPlatform(name)
|
||||||
return module
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def newPlatform(cls, name, requirements=None):
|
def newPlatform(cls, name, requirements=None):
|
||||||
|
Reference in New Issue
Block a user