Skip to content

Commit

Permalink
Tools: Fix esptool wrappers by avoiding importing the module
Browse files Browse the repository at this point in the history
Importing esptool in wrappers could cause importing the wrapper itself.
Updating the PATH is not reliable. For example, os.path.realpath()
changes the Windows driver letter to uppercase therefore, misses the
right path for users with small device letters in their PATH. Removing
paths without considering cases could also lead to errors.

This fix invokes esptool scripts as modules without the need to
importing them.

Closes #9861

Closes espressif/vscode-esp-idf-extension#791
  • Loading branch information
dobairoland committed Nov 11, 2022
1 parent 6bb28c4 commit 43deee5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 39 deletions.
15 changes: 2 additions & 13 deletions components/esptool_py/esptool/espefuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,8 @@
# SPDX-License-Identifier: Apache-2.0
#

import os
import subprocess
import sys

try:
sys.path.remove(os.path.dirname(os.path.realpath(__file__))) # do not import this script
except ValueError:
pass

try:
import espefuse
except ImportError:
raise ModuleNotFoundError('No module named "espefuse" please install espefuse.py by running '
'the install and export scripts.')

if __name__ == '__main__':
espefuse._main() # type: ignore
sys.exit(subprocess.run([sys.executable, '-m', 'espefuse'] + sys.argv[1:]).returncode)
15 changes: 2 additions & 13 deletions components/esptool_py/esptool/espsecure.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,8 @@
# SPDX-License-Identifier: Apache-2.0
#

import os
import subprocess
import sys

try:
sys.path.remove(os.path.dirname(os.path.realpath(__file__))) # do not import this script
except ValueError:
pass

try:
import espsecure
except ImportError:
raise ModuleNotFoundError('No module named "espsecure" please install espsecure.py by running '
'the install and export scripts.')

if __name__ == '__main__':
espsecure._main() # type: ignore
sys.exit(subprocess.run([sys.executable, '-m', 'espsecure'] + sys.argv[1:]).returncode)
15 changes: 2 additions & 13 deletions components/esptool_py/esptool/esptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,8 @@
# SPDX-License-Identifier: Apache-2.0
#

import os
import subprocess
import sys

try:
sys.path.remove(os.path.dirname(os.path.realpath(__file__))) # do not import this script
except ValueError:
pass

try:
import esptool
except ImportError:
raise ModuleNotFoundError('No module named "esptool" please install esptool.py by running '
'the install and export scripts.')

if __name__ == '__main__':
esptool._main() # type: ignore
sys.exit(subprocess.run([sys.executable, '-m', 'esptool'] + sys.argv[1:]).returncode)

0 comments on commit 43deee5

Please sign in to comment.