From 57e909e7909b5a11024fe630c506ba166243a68c Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Mon, 1 May 2023 15:57:57 +1200 Subject: [PATCH] Only pre-install libraries in docker images (#4766) --- docker/Dockerfile | 2 +- script/platformio_install_deps.py | 20 +++++++++++++++----- script/setup | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 21c8f2a0ae..720241242f 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -63,7 +63,7 @@ RUN \ COPY requirements.txt requirements_optional.txt script/platformio_install_deps.py platformio.ini / RUN \ pip3 install --no-cache-dir -r /requirements.txt -r /requirements_optional.txt \ - && /platformio_install_deps.py /platformio.ini + && /platformio_install_deps.py /platformio.ini --libraries # ======================= docker-type image ======================= diff --git a/script/platformio_install_deps.py b/script/platformio_install_deps.py index 2340410161..ed133ecb47 100755 --- a/script/platformio_install_deps.py +++ b/script/platformio_install_deps.py @@ -2,12 +2,22 @@ # This script is used to preinstall # all platformio libraries in the global storage +import argparse import configparser import subprocess -import sys config = configparser.ConfigParser(inline_comment_prefixes=(";",)) -config.read(sys.argv[1]) + +parser = argparse.ArgumentParser(description="") +parser.add_argument("file", help="Path to platformio.ini", nargs=1) +parser.add_argument("-l", "--libraries", help="Install libraries", action="store_true") +parser.add_argument("-p", "--platforms", help="Install platforms", action="store_true") +parser.add_argument("-t", "--tools", help="Install tools", action="store_true") + +args = parser.parse_args() + +config.read(args.file) + libs = [] tools = [] @@ -15,7 +25,7 @@ platforms = [] # Extract from every lib_deps key in all sections for section in config.sections(): conf = config[section] - if "lib_deps" in conf: + if "lib_deps" in conf and args.libraries: for lib_dep in conf["lib_deps"].splitlines(): if not lib_dep: # Empty line or comment @@ -28,10 +38,10 @@ for section in config.sections(): continue libs.append("-l") libs.append(lib_dep) - if "platform" in conf: + if "platform" in conf and args.platforms: platforms.append("-p") platforms.append(conf["platform"]) - if "platform_packages" in conf: + if "platform_packages" in conf and args.tools: for tool in conf["platform_packages"].splitlines(): if not tool: # Empty line or comment diff --git a/script/setup b/script/setup index 5acd1a9f13..656e95eba6 100755 --- a/script/setup +++ b/script/setup @@ -15,4 +15,4 @@ pip3 install --no-use-pep517 -e . pre-commit install -script/platformio_install_deps.py platformio.ini +script/platformio_install_deps.py platformio.ini --libraries --tools --platforms