Added support for "pythonPackages" in platform.json

This commit is contained in:
Ivan Kravets
2020-01-24 19:47:47 +02:00
parent 2de46f545f
commit 3b092f28c3
3 changed files with 52 additions and 1 deletions

View File

@@ -19,6 +19,7 @@ PlatformIO Core 4.0
- Added support for `PVS-Studio <https://docs.platformio.org/page/plus/check-tools/pvs-studio.html>`__ static code analyzer - Added support for `PVS-Studio <https://docs.platformio.org/page/plus/check-tools/pvs-studio.html>`__ static code analyzer
* Control debug flags and optimization level with a new `debug_build_flags <https://docs.platformio.org/page/projectconf/section_env_debug.html#debug-build-flags>`__ option * Control debug flags and optimization level with a new `debug_build_flags <https://docs.platformio.org/page/projectconf/section_env_debug.html#debug-build-flags>`__ option
* Added support for "pythonPackages" in `platform.json <https://docs.platformio.org/page/platforms/creating_platform.html#manifest-file-platform-json>`__ manifest (PlatformIO Package Manager will install dependent Python packages from PyPi registry automatically when dev-platform is installed)
* Handle project configuration (monitor, test, and upload options) for PIO Remote commands (`issue #2591 <https://github.com/platformio/platformio-core/issues/2591>`_) * Handle project configuration (monitor, test, and upload options) for PIO Remote commands (`issue #2591 <https://github.com/platformio/platformio-core/issues/2591>`_)
* Updated SCons tool to 3.1.2 * Updated SCons tool to 3.1.2
* Made package ManifestSchema compatible with marshmallow >= 3 (`issue #3296 <https://github.com/platformio/platformio-core/issues/3296>`_) * Made package ManifestSchema compatible with marshmallow >= 3 (`issue #3296 <https://github.com/platformio/platformio-core/issues/3296>`_)

2
docs

Submodule docs updated: a430de3311...cfc5eed060

View File

@@ -17,6 +17,7 @@
import base64 import base64
import os import os
import re import re
import subprocess
import sys import sys
from os.path import basename, dirname, isdir, isfile, join from os.path import basename, dirname, isdir, isfile, join
@@ -86,6 +87,8 @@ class PlatformManager(BasePkgManager):
# don't cleanup packages or install them after update # don't cleanup packages or install them after update
# we check packages for updates in def update() # we check packages for updates in def update()
if after_update: if after_update:
p.install_python_packages()
p.on_installed()
return True return True
p.install_packages( p.install_packages(
@@ -95,6 +98,8 @@ class PlatformManager(BasePkgManager):
silent=silent, silent=silent,
force=force, force=force,
) )
p.install_python_packages()
p.on_installed()
return self.cleanup_packages(list(p.packages)) return self.cleanup_packages(list(p.packages))
def uninstall(self, package, requirements=None, after_update=False): def uninstall(self, package, requirements=None, after_update=False):
@@ -109,6 +114,8 @@ class PlatformManager(BasePkgManager):
p = PlatformFactory.newPlatform(pkg_dir) p = PlatformFactory.newPlatform(pkg_dir)
BasePkgManager.uninstall(self, pkg_dir, requirements) BasePkgManager.uninstall(self, pkg_dir, requirements)
p.uninstall_python_packages()
p.on_uninstalled()
# don't cleanup packages or install them after update # don't cleanup packages or install them after update
# we check packages for updates in def update() # we check packages for updates in def update()
@@ -594,6 +601,10 @@ class PlatformBase(PlatformPackagesMixin, PlatformRunMixin):
packages[name].update({"version": version.strip(), "optional": False}) packages[name].update({"version": version.strip(), "optional": False})
return packages return packages
@property
def python_packages(self):
return self._manifest.get("pythonPackages")
def get_dir(self): def get_dir(self):
return dirname(self.manifest_path) return dirname(self.manifest_path)
@@ -699,6 +710,45 @@ class PlatformBase(PlatformPackagesMixin, PlatformRunMixin):
return [dict(name=name, path=path) for path, name in storages.items()] return [dict(name=name, path=path) for path, name in storages.items()]
def on_installed(self):
pass
def on_uninstalled(self):
pass
def install_python_packages(self):
if not self.python_packages:
return None
click.echo(
"Installing Python packages: %s"
% ", ".join(list(self.python_packages.keys())),
)
args = [proc.get_pythonexe_path(), "-m", "pip", "install", "--upgrade"]
for name, requirements in self.python_packages.items():
if any(c in requirements for c in ("<", ">", "=")):
args.append("%s%s" % (name, requirements))
else:
args.append("%s==%s" % (name, requirements))
try:
return subprocess.call(args) == 0
except Exception as e: # pylint: disable=broad-except
click.secho(
"Could not install Python packages -> %s" % e, fg="red", err=True
)
def uninstall_python_packages(self):
if not self.python_packages:
return
click.echo("Uninstalling Python packages")
args = [proc.get_pythonexe_path(), "-m", "pip", "uninstall", "--yes"]
args.extend(list(self.python_packages.keys()))
try:
subprocess.call(args) == 0
except Exception as e: # pylint: disable=broad-except
click.secho(
"Could not install Python packages -> %s" % e, fg="red", err=True
)
class PlatformBoardConfig(object): class PlatformBoardConfig(object):
def __init__(self, manifest_path): def __init__(self, manifest_path):