From 43deee5374eff87d485de89cb7de62b09995ef1c Mon Sep 17 00:00:00 2001 From: Roland Dobai Date: Fri, 11 Nov 2022 12:51:33 +0100 Subject: [PATCH] Tools: Fix esptool wrappers by avoiding importing the module 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 https://github.com/espressif/esp-idf/issues/9861 Closes https://github.com/espressif/vscode-esp-idf-extension/issues/791 --- components/esptool_py/esptool/espefuse.py | 15 ++------------- components/esptool_py/esptool/espsecure.py | 15 ++------------- components/esptool_py/esptool/esptool.py | 15 ++------------- 3 files changed, 6 insertions(+), 39 deletions(-) diff --git a/components/esptool_py/esptool/espefuse.py b/components/esptool_py/esptool/espefuse.py index 78e23980ac3..507de8bf2a3 100644 --- a/components/esptool_py/esptool/espefuse.py +++ b/components/esptool_py/esptool/espefuse.py @@ -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) diff --git a/components/esptool_py/esptool/espsecure.py b/components/esptool_py/esptool/espsecure.py index 68b03256500..3979e83eaa1 100644 --- a/components/esptool_py/esptool/espsecure.py +++ b/components/esptool_py/esptool/espsecure.py @@ -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) diff --git a/components/esptool_py/esptool/esptool.py b/components/esptool_py/esptool/esptool.py index 3063556d4d4..828129e6d6d 100644 --- a/components/esptool_py/esptool/esptool.py +++ b/components/esptool_py/esptool/esptool.py @@ -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)