Fix platformio monkey patch (#768)

This commit is contained in:
Otto Winter 2019-10-18 15:33:30 +02:00 committed by GitHub
parent aed7b3fbb2
commit b78b28ea0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,27 +12,18 @@ from esphome.util import run_external_command, run_external_process
_LOGGER = logging.getLogger(__name__)
def is_platformio4():
from platformio import VERSION
return VERSION[0] >= 4
def patch_structhash():
# Patch platformio's structhash to not recompile the entire project when files are
# removed/added. This might have unintended consequences, but this improves compile
# times greatly when adding/removing components and a simple clean build solves
# all issues
# pylint: disable=no-member,no-name-in-module,import-error
from platformio.commands import run
from platformio import util
if is_platformio4():
from platformio.project.helpers import get_project_dir
else:
from platformio.util import get_project_dir
from platformio.commands.run import helpers, command
from os.path import join, isdir, getmtime
from os import makedirs
def patched_clean_build_dir(build_dir, *args):
from platformio import util
from platformio.project.helpers import get_project_dir
platformio_ini = join(get_project_dir(), "platformio.ini")
# if project's config is modified
@ -43,10 +34,8 @@ def patch_structhash():
makedirs(build_dir)
# pylint: disable=protected-access
if is_platformio4():
run.helpers.clean_build_dir = patched_clean_build_dir
else:
run._clean_build_dir = patched_clean_build_dir
helpers.clean_build_dir = patched_clean_build_dir
command.clean_build_dir = patched_clean_build_dir
def run_platformio_cli(*args, **kwargs):