forked from platformio/platformio-core
Init dev-platform with autoinstallation
This commit is contained in:
@ -318,15 +318,6 @@ def platform_update( # pylint: disable=too-many-locals, too-many-arguments
|
||||
#
|
||||
|
||||
|
||||
def init_platform(name, skip_default_package=True, auto_install=True):
|
||||
try:
|
||||
return PlatformFactory.new(name)
|
||||
except UnknownPlatform:
|
||||
if auto_install:
|
||||
_platform_install([name], skip_default_package=skip_default_package)
|
||||
return PlatformFactory.new(name)
|
||||
|
||||
|
||||
def _print_platforms(platforms):
|
||||
for platform in platforms:
|
||||
click.echo(
|
||||
|
@ -12,9 +12,9 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from platformio.commands.platform import init_platform
|
||||
from platformio.commands.test.processor import CTX_META_TEST_RUNNING_NAME
|
||||
from platformio.package.commands.install import install_project_env_dependencies
|
||||
from platformio.platform.factory import PlatformFactory
|
||||
from platformio.project.exception import UndefinedEnvPlatformError
|
||||
|
||||
# pylint: disable=too-many-instance-attributes
|
||||
@ -70,7 +70,7 @@ class EnvironmentProcessor(object):
|
||||
{"project_targets": build_targets},
|
||||
)
|
||||
|
||||
result = init_platform(self.options["platform"]).run(
|
||||
result = PlatformFactory.new(self.options["platform"]).run(
|
||||
build_vars, build_targets, self.silent, self.verbose, self.jobs
|
||||
)
|
||||
return result["returncode"] == 0
|
||||
|
@ -23,10 +23,10 @@ import click
|
||||
from tabulate import tabulate
|
||||
|
||||
from platformio import app, exception, fs, util
|
||||
from platformio.commands.platform import init_platform
|
||||
from platformio.commands.test.embedded import EmbeddedTestProcessor
|
||||
from platformio.commands.test.helpers import get_test_names
|
||||
from platformio.commands.test.native import NativeTestProcessor
|
||||
from platformio.platform.factory import PlatformFactory
|
||||
from platformio.project.config import ProjectConfig
|
||||
|
||||
|
||||
@ -142,7 +142,9 @@ def cli( # pylint: disable=redefined-builtin
|
||||
cls = (
|
||||
EmbeddedTestProcessor
|
||||
if config.get(section, "platform")
|
||||
and init_platform(config.get(section, "platform")).is_embedded()
|
||||
and PlatformFactory.new(
|
||||
config.get(section, "platform"), autoinstall=True
|
||||
).is_embedded()
|
||||
else NativeTestProcessor
|
||||
)
|
||||
tp = cls(
|
||||
|
@ -23,12 +23,12 @@ import subprocess
|
||||
import click
|
||||
|
||||
from platformio import app, exception, fs, proc
|
||||
from platformio.commands.platform import init_platform
|
||||
from platformio.compat import IS_WINDOWS
|
||||
from platformio.debug import helpers
|
||||
from platformio.debug.config.factory import DebugConfigFactory
|
||||
from platformio.debug.exception import DebugInvalidOptionsError
|
||||
from platformio.debug.process.gdb import GDBClientProcess
|
||||
from platformio.platform.factory import PlatformFactory
|
||||
from platformio.project.config import ProjectConfig
|
||||
from platformio.project.exception import ProjectEnvsNotAvailableError
|
||||
from platformio.project.helpers import is_platformio_project
|
||||
@ -96,7 +96,9 @@ def debug_cmd(
|
||||
|
||||
with fs.cd(project_dir):
|
||||
debug_config = DebugConfigFactory.new(
|
||||
init_platform(env_options["platform"]), project_config, env_name
|
||||
PlatformFactory.new(env_options["platform"], autoinstall=True),
|
||||
project_config,
|
||||
env_name,
|
||||
)
|
||||
|
||||
if "--version" in __unprocessed:
|
||||
|
@ -36,8 +36,9 @@ class PlatformFactory(object):
|
||||
raise UnknownPlatform(name)
|
||||
|
||||
@classmethod
|
||||
def new(cls, pkg_or_spec):
|
||||
def new(cls, pkg_or_spec, autoinstall=False):
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from platformio.package.manager.platform import PlatformPackageManager
|
||||
|
||||
platform_dir = None
|
||||
platform_name = None
|
||||
@ -47,17 +48,20 @@ class PlatformFactory(object):
|
||||
elif isinstance(pkg_or_spec, (str, bytes)) and os.path.isdir(pkg_or_spec):
|
||||
platform_dir = pkg_or_spec
|
||||
else:
|
||||
from platformio.package.manager.platform import PlatformPackageManager
|
||||
|
||||
pkg = PlatformPackageManager().get_package(pkg_or_spec)
|
||||
if not pkg:
|
||||
raise UnknownPlatform(pkg_or_spec)
|
||||
platform_dir = pkg.path
|
||||
platform_name = pkg.metadata.name
|
||||
if pkg:
|
||||
platform_dir = pkg.path
|
||||
platform_name = pkg.metadata.name
|
||||
|
||||
if not platform_dir or not os.path.isfile(
|
||||
os.path.join(platform_dir, "platform.json")
|
||||
):
|
||||
if autoinstall:
|
||||
return cls.new(
|
||||
PlatformPackageManager().install(
|
||||
pkg_or_spec, skip_dependencies=True
|
||||
)
|
||||
)
|
||||
raise UnknownPlatform(pkg_or_spec)
|
||||
|
||||
if not platform_name:
|
||||
|
Reference in New Issue
Block a user