@@ -1343,11 +1343,37 @@ def get_idf_venv_dir():
1343
1343
1344
1344
def ensure_python_venv_available ():
1345
1345
1346
+ def _get_idf_venv_python_version ():
1347
+ try :
1348
+ version = subprocess .check_output (
1349
+ [
1350
+ get_python_exe (),
1351
+ "-c" ,
1352
+ "import sys;print('{0}.{1}.{2}-{3}.{4}'.format(*list(sys.version_info)))"
1353
+ ], text = True
1354
+ )
1355
+ return version .strip ()
1356
+ except subprocess .CalledProcessError as e :
1357
+ print ("Failed to extract Python version from IDF virtual env!" )
1358
+ return None
1359
+
1346
1360
def _is_venv_outdated (venv_data_file ):
1347
1361
try :
1348
1362
with open (venv_data_file , "r" , encoding = "utf8" ) as fp :
1349
1363
venv_data = json .load (fp )
1350
1364
if venv_data .get ("version" , "" ) != IDF_ENV_VERSION :
1365
+ print (
1366
+ "Warning! IDF virtual environment version changed!"
1367
+ )
1368
+ return True
1369
+ if (
1370
+ venv_data .get ("python_version" , "" )
1371
+ != _get_idf_venv_python_version ()
1372
+ ):
1373
+ print (
1374
+ "Warning! Python version in the IDF virtual environment"
1375
+ " differs from the current Python!"
1376
+ )
1351
1377
return True
1352
1378
return False
1353
1379
except :
@@ -1387,8 +1413,13 @@ def _create_venv(venv_dir):
1387
1413
venv_data_file = os .path .join (venv_dir , "pio-idf-venv.json" )
1388
1414
if not os .path .isfile (venv_data_file ) or _is_venv_outdated (venv_data_file ):
1389
1415
_create_venv (venv_dir )
1416
+
1417
+ install_python_deps ()
1390
1418
with open (venv_data_file , "w" , encoding = "utf8" ) as fp :
1391
- venv_info = {"version" : IDF_ENV_VERSION }
1419
+ venv_info = {
1420
+ "version" : IDF_ENV_VERSION ,
1421
+ "python_version" : _get_idf_venv_python_version ()
1422
+ }
1392
1423
json .dump (venv_info , fp , indent = 2 )
1393
1424
1394
1425
@@ -1407,11 +1438,10 @@ def get_python_exe():
1407
1438
1408
1439
1409
1440
#
1410
- # ESP-IDF requires Python packages with specific versions in a virtual environment
1441
+ # Ensure Python environment contains everything required for IDF
1411
1442
#
1412
1443
1413
1444
ensure_python_venv_available ()
1414
- install_python_deps ()
1415
1445
1416
1446
# ESP-IDF package doesn't contain .git folder, instead package version is specified
1417
1447
# in a special file "version.h" in the root folder of the package
0 commit comments