Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions builder/frameworks/espidf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2097,8 +2097,20 @@ def _get_uv_exe():
return get_executable_path(str(Path(PLATFORMIO_DIR) / "penv"), "uv")


def install_python_deps():
def _get_python_deps():
"""Get the required Python dependencies for ESP-IDF"""
return {
# https://github.com/platformio/platform-espressif32/issues/635
"cryptography": "~=44.0.0",
"pyparsing": ">=3.1.0,<4",
"idf-component-manager": "~=2.4.8",
"esp-idf-kconfig": "~=3.7.0"
}


def install_python_deps(deps=None):
UV_EXE = _get_uv_exe()
deps = deps or _get_python_deps()

def _get_installed_uv_packages(python_exe_path):
result = {}
Expand All @@ -2120,14 +2132,6 @@ def _get_installed_uv_packages(python_exe_path):
if os.path.isfile(skip_python_packages):
return

deps = {
# https://github.com/platformio/platform-espressif32/issues/635
"cryptography": "~=44.0.0",
"pyparsing": ">=3.1.0,<4",
"idf-component-manager": "~=2.4.6",
"esp-idf-kconfig": "~=2.5.0"
}

python_exe_path = get_python_exe()
installed_packages = _get_installed_uv_packages(python_exe_path)
packages_to_install = []
Expand Down Expand Up @@ -2185,7 +2189,12 @@ def _get_idf_venv_python_version():
print("Failed to extract Python version from IDF virtual env!")
return None

def _is_venv_outdated(venv_data_file):
def _get_deps_hash(deps_dict):
import hashlib
deps_str = json.dumps(deps_dict, sort_keys=True)
return hashlib.sha256(deps_str.encode()).hexdigest()

def _is_venv_outdated(venv_data_file, current_deps):
try:
with open(venv_data_file, "r", encoding="utf8") as fp:
venv_data = json.load(fp)
Expand All @@ -2203,6 +2212,11 @@ def _is_venv_outdated(venv_data_file):
" differs from the current Python!"
)
return True
if venv_data.get("deps_hash", "") != _get_deps_hash(current_deps):
print(
"Warning! Python dependencies have changed!"
)
return True
return False
except (OSError, ValueError):
return True
Expand Down Expand Up @@ -2235,15 +2249,19 @@ def _create_venv(venv_dir):
sys.stderr.write("Error: Failed to create a proper virtual environment. Missing the Python executable!\n")
env.Exit(1)

# Define deps here so we can track changes
deps = _get_python_deps()

venv_dir = get_idf_venv_dir()
venv_data_file = str(Path(venv_dir) / "pio-idf-venv.json")
if not os.path.isfile(venv_data_file) or _is_venv_outdated(venv_data_file):
if not os.path.isfile(venv_data_file) or _is_venv_outdated(venv_data_file, deps):
_create_venv(venv_dir)
install_python_deps()
install_python_deps(deps)
with open(venv_data_file, "w", encoding="utf8") as fp:
venv_info = {
"version": IDF_ENV_VERSION,
"python_version": _get_idf_venv_python_version()
"python_version": _get_idf_venv_python_version(),
"deps_hash": _get_deps_hash(deps)
}
json.dump(venv_info, fp, indent=2)

Expand Down