Skip to content

PowerShell profile: Invalid syntax when accessing environment variable _IDF.PY_COMPLETE (ESPTOOL-1321) #1164

Description

@heheshizu

Operating System

Win11

Esptool Version

ESP-IDF v6.0.1

Python Version

Python 3.11.9

Full Esptool Command Line that Was Run

No manual esptool command executed. Error occurs automatically when launching IDF terminal via EIM, while loading PowerShell profile script.

Esptool Output

C:\Espressif\tools\Microsoft.v6.0.1.PowerShell_profile.ps1:82 字符: 21
+         $previous = $env:'_IDF.PY_COMPLETE'
+                     ~~~~~
变量引用无效。':' 后面的变量名称字符无效。请考虑使用 ${} 分隔名称。
所在位置 C:\Espressif\tools\Microsoft.v6.0.1.PowerShell_profile.ps1:82 字符: 26
+         $previous = $env:'_IDF.PY_COMPLETE'
+                          ~~~~~~~~~~~~~~~~~~
表达式或语句中包含意外的标记“'_IDF.PY_COMPLETE'”。
所在位置 C:\Espressif\tools\Microsoft.v6.0.1.PowerShell_profile.ps1:83 字符: 9
+         $env:'_IDF.PY_COMPLETE' = 'powershell_source'
+         ~~~~~
变量引用无效。':' 后面的变量名称字符无效。请考虑使用 ${} 分隔名称。
所在位置 C:\Espressif\tools\Microsoft.v6.0.1.PowerShell_profile.ps1:83 字符: 14
+         $env:'_IDF.PY_COMPLETE' = 'powershell_source'
+              ~~~~~~~~~~~~~~~~~~
表达式或语句中包含意外的标记“'_IDF.PY_COMPLETE'”。
所在位置 C:\Espressif\tools\Microsoft.v6.0.1.PowerShell_profile.ps1:91 字符: 13
+             $env:'_IDF.PY_COMPLETE' = $previous
+             ~~~~~
变量引用无效。':' 后面的变量名称字符无效。请考虑使用 ${} 分隔名称。
所在位置 C:\Espressif\tools\Microsoft.v6.0.1.PowerShell_profile.ps1:91 字符: 18
+             $env:'_IDF.PY_COMPLETE' = $previous
+                  ~~~~~~~~~~~~~~~~~~
表达式或语句中包含意外的标记“'_IDF.PY_COMPLETE'”。
所在位置 C:\Espressif\tools\Microsoft.v6.0.1.PowerShell_profile.ps1:83 字符: 14
+         $env:'_IDF.PY_COMPLETE' = 'powershell_source'
+              ~~~~~~~~~~~~~~~~~~
赋值表达式无效。赋值运算符输入必须是能够接受赋值的对象,例如变量或属性。
所在位置 C:\Espressif\tools\Microsoft.v6.0.1.PowerShell_profile.ps1:91 字符: 18
+             $env:'_IDF.PY_COMPLETE' = $previous
+                  ~~~~~~~~~~~~~~~~~~
赋值表达式无效。赋值运算符输入必须是能够接受赋值的对象,例如变量或属性。
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : InvalidVariableReferenceWithDrive

What is the Expected Behaviour?

Launching IDF terminal via EIM should load PowerShell profile normally without parser errors, and enable idf.py tab completion correctly.

More Information

Root Cause

The script uses invalid PowerShell syntax: $env:'_IDF.PY_COMPLETE'.
PowerShell does not allow single quotes directly after env:. Since the environment variable name contains dot ., it must be wrapped with ${} to parse correctly.

Temporary Fix

Replace all instances of:
$env:'_IDF.PY_COMPLETE'

With:
${env:_IDF.PY_COMPLETE}

After manual modification, the terminal launches successfully and all functions work as expected.

Other Steps to Reproduce

(I'm sorry I'm not sure but I just believe what I have doen is as below, so I think it may be reproduced by below three steps:)

  1. On Windows 11, install ESP-IDF v6.0.1 with default tools.
  2. Open IDF terminal by clicking related button in EIM.
  3. PowerShell loads Microsoft.v6.0.1.PowerShell_profile.ps1 and throws the parser errors above.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions