Skip to content

Commit

Permalink
Avoid overwriting original Python executable.
Browse files Browse the repository at this point in the history
  • Loading branch information
emeryberger committed Dec 16, 2023
1 parent 7071e75 commit 75154f4
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions scalene/redirect_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import stat
import sys

from typing import List


def redirect_python(preface: str, cmdline: str, python_alias_dir: pathlib.Path) -> None:
# Likely names for the Python interpreter.
base_python_extension = ".exe" if sys.platform == "win32" else ""
Expand All @@ -14,20 +11,10 @@ def redirect_python(preface: str, cmdline: str, python_alias_dir: pathlib.Path)
"python" + str(sys.version_info.major) + base_python_extension,
"python" + str(sys.version_info.major) + "." + str(sys.version_info.minor) + base_python_extension
]
if sys.platform == "win32":
base_python_name = re.sub(r'\.exe$', '', os.path.basename(sys.executable))
else:
base_python_name = sys.executable
all_python_names.extend([
base_python_name + base_python_extension,
base_python_name + str(sys.version_info.major) + base_python_extension,
base_python_name
+ str(sys.version_info.major)
+ "."
+ str(sys.version_info.minor)
+ base_python_extension,
])
# print(all_python_names)
# if sys.platform == "win32":
# base_python_name = re.sub(r'\.exe$', '', os.path.basename(sys.executable))
# else:
# base_python_name = sys.executable

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

# Don't show commands on Windows; regular shebang for
# shell scripts on Linux/OS X
Expand All @@ -48,6 +35,7 @@ def redirect_python(preface: str, cmdline: str, python_alias_dir: pathlib.Path)
with open(fname, "w") as file:
file.write(payload)
os.chmod(fname, stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR)

# Finally, insert this directory into the path.
sys.path.insert(0, str(python_alias_dir))
os.environ["PATH"] = (
Expand Down

0 comments on commit 75154f4

Please sign in to comment.