Skip to content

Commit a7df5d3

Browse files
committed
bugfix: Adjust wrapper scripts to not import themselves
1 parent 54bbf62 commit a7df5d3

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

espefuse.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
# Linux/macOS: remove current script directory to avoid importing this file
1919
# as a module; we want to import the installed espefuse module instead
2020
with contextlib.suppress(ValueError):
21-
if sys.path[0].endswith("/bin"):
22-
sys.path.pop(0)
23-
sys.path.remove(os.path.dirname(sys.executable))
21+
executable_dir = os.path.dirname(sys.executable)
22+
sys.path = [
23+
path
24+
for path in sys.path
25+
if not path.endswith(("/bin", "/sbin")) and path != executable_dir
26+
]
2427

2528
# Linux/macOS: delete imported module entry to force Python to load
2629
# the module from scratch; this enables importing espefuse module in

espsecure.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
# Linux/macOS: remove current script directory to avoid importing this file
1919
# as a module; we want to import the installed espsecure module instead
2020
with contextlib.suppress(ValueError):
21-
if sys.path[0].endswith("/bin"):
22-
sys.path.pop(0)
23-
sys.path.remove(os.path.dirname(sys.executable))
21+
executable_dir = os.path.dirname(sys.executable)
22+
sys.path = [
23+
path
24+
for path in sys.path
25+
if not path.endswith(("/bin", "/sbin")) and path != executable_dir
26+
]
2427

2528
# Linux/macOS: delete imported module entry to force Python to load
2629
# the module from scratch; this enables importing espsecure module in

esptool.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
# Linux/macOS: remove current script directory to avoid importing this file
1919
# as a module; we want to import the installed esptool module instead
2020
with contextlib.suppress(ValueError):
21-
if sys.path[0].endswith("/bin"):
22-
sys.path.pop(0)
23-
sys.path.remove(os.path.dirname(sys.executable))
21+
executable_dir = os.path.dirname(sys.executable)
22+
sys.path = [
23+
path
24+
for path in sys.path
25+
if not path.endswith(("/bin", "/sbin")) and path != executable_dir
26+
]
2427

2528
# Linux/macOS: delete imported module entry to force Python to load
2629
# the module from scratch; this enables importing esptool module in

0 commit comments

Comments
 (0)