diff --git a/platformio/managers/__init__.py b/platformio/managers/__init__.py deleted file mode 100644 index b0514903..00000000 --- a/platformio/managers/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (c) 2014-present PlatformIO -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/platformio/managers/platform.py b/platformio/managers/platform.py deleted file mode 100644 index 9ef5e646..00000000 --- a/platformio/managers/platform.py +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright (c) 2014-present PlatformIO -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Backward compatibility with legacy dev-platforms -from platformio.platform.base import PlatformBase # pylint: disable=unused-import diff --git a/platformio/platform/factory.py b/platformio/platform/factory.py index 2df9e1b4..7b6348ac 100644 --- a/platformio/platform/factory.py +++ b/platformio/platform/factory.py @@ -14,11 +14,12 @@ import os import re +import sys from platformio import fs from platformio.compat import load_python_module from platformio.package.meta import PackageItem -from platformio.platform.base import PlatformBase +from platformio.platform import base from platformio.platform.exception import UnknownPlatform @@ -28,15 +29,18 @@ class PlatformFactory(object): name = re.sub(r"[^\da-z\_]+", "", name, flags=re.I) return "%sPlatform" % name.lower().capitalize() - @staticmethod - def load_module(name, path): + @classmethod + def load_platform_module(cls, name, path, by_fallback=False): try: return load_python_module("platformio.platform.%s" % name, path) - except ImportError: + except ImportError as exc: + if "platformio.managers" in str(exc) and not by_fallback: + sys.modules["platformio.managers.platform"] = base + return cls.load_platform_module(name, path, by_fallback=True) raise UnknownPlatform(name) @classmethod - def new(cls, pkg_or_spec, autoinstall=False) -> PlatformBase: + def new(cls, pkg_or_spec, autoinstall=False) -> base.PlatformBase: # pylint: disable=import-outside-toplevel from platformio.package.manager.platform import PlatformPackageManager @@ -72,16 +76,16 @@ class PlatformFactory(object): platform_cls = None if os.path.isfile(os.path.join(platform_dir, "platform.py")): platform_cls = getattr( - cls.load_module( + cls.load_platform_module( platform_name, os.path.join(platform_dir, "platform.py") ), cls.get_clsname(platform_name), ) else: platform_cls = type( - str(cls.get_clsname(platform_name)), (PlatformBase,), {} + str(cls.get_clsname(platform_name)), (base.PlatformBase,), {} ) _instance = platform_cls(os.path.join(platform_dir, "platform.json")) - assert isinstance(_instance, PlatformBase) + assert isinstance(_instance, base.PlatformBase) return _instance