Skip to content

Commit 783e8a9

Browse files
committed
Better handling of Python deps for IDF
1 parent 6660f2c commit 783e8a9

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

builder/frameworks/espidf.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import subprocess
2626
import sys
2727
import os
28+
import pkg_resources
2829

2930
import click
3031
import semantic_version
@@ -49,6 +50,9 @@
4950
mcu = board.get("build.mcu", "esp32")
5051
idf_variant = mcu.lower()
5152

53+
# Required until Arduino switches to v5
54+
IDF5 = platform.get_package_version(
55+
"framework-espidf").split(".")[1].startswith("5")
5256
FRAMEWORK_DIR = platform.get_package_dir("framework-espidf")
5357
TOOLCHAIN_DIR = platform.get_package_dir(
5458
"toolchain-%s" % ("riscv32-esp" if mcu == "esp32c3" else ("xtensa-%s" % mcu))
@@ -585,6 +589,7 @@ def _fix_component_relative_include(config, build_flags, source_index):
585589
build_flags = build_flags.replace("..", os.path.dirname(source_file_path) + "/..")
586590
return build_flags
587591

592+
588593
def prepare_build_envs(config, default_env, debug_allowed=True):
589594
build_envs = []
590595
target_compile_groups = config.get("compileGroups")
@@ -1073,15 +1078,15 @@ def _get_installed_pip_packages():
10731078
# https://github.com/platformio/platform-espressif32/issues/635
10741079
"cryptography": ">=2.1.4,<35.0.0",
10751080
"future": ">=0.15.2",
1076-
"pyparsing": ">=3"
1077-
if platform.get_package_version("framework-espidf")
1078-
.split(".")[1]
1079-
.startswith("5")
1080-
else ">=2.0.3,<2.4.0",
1081+
"pyparsing": ">=2.0.3,<2.4.0",
10811082
"kconfiglib": "==13.7.1",
10821083
"idf-component-manager": "~=1.0",
10831084
}
10841085

1086+
if IDF5:
1087+
# Remove specific versions for IDF5 as not required
1088+
deps = {dep: "" for dep in deps}
1089+
10851090
installed_packages = _get_installed_pip_packages()
10861091
packages_to_install = []
10871092
for package, spec in deps.items():
@@ -1096,21 +1101,34 @@ def _get_installed_pip_packages():
10961101
env.Execute(
10971102
env.VerboseAction(
10981103
(
1099-
'"$PYTHONEXE" -m pip install -U --force-reinstall '
1100-
+ " ".join(['"%s%s"' % (p, deps[p]) for p in packages_to_install])
1104+
'"$PYTHONEXE" -m pip install -U '
1105+
+ " ".join(
1106+
[
1107+
'"%s%s"' % (p, deps[p])
1108+
for p in packages_to_install
1109+
]
1110+
)
11011111
),
11021112
"Installing ESP-IDF's Python dependencies",
11031113
)
11041114
)
11051115

1106-
# a special "esp-windows-curses" python package is required on Windows for Menuconfig
1107-
if "windows" in get_systype():
1108-
import pkg_resources
1116+
if "windows" in get_systype() and "windows-curses" not in installed_packages:
1117+
env.Execute(
1118+
env.VerboseAction(
1119+
"$PYTHONEXE -m pip install windows-curses",
1120+
"Installing windows-curses package",
1121+
)
1122+
)
11091123

1110-
if "esp-windows-curses" not in {pkg.key for pkg in pkg_resources.working_set}:
1124+
# A special "esp-windows-curses" python package is required on Windows
1125+
# for Menuconfig on IDF <5
1126+
if not IDF5 and "esp-windows-curses" not in {
1127+
pkg.key for pkg in pkg_resources.working_set
1128+
}:
11111129
env.Execute(
11121130
env.VerboseAction(
1113-
'$PYTHONEXE -m pip install "file://%s/tools/kconfig_new/esp-windows-curses" windows-curses'
1131+
'$PYTHONEXE -m pip install "file://%s/tools/kconfig_new/esp-windows-curses"'
11141132
% FRAMEWORK_DIR,
11151133
"Installing windows-curses package",
11161134
)

0 commit comments

Comments
 (0)