Skip to content

Commit 8eb5939

Browse files
committed
Fix activated python script path in windows
1 parent e15d6e5 commit 8eb5939

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

.mg.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@ def uvx_ipython(not_windows=True, version=""):
7474
venv_dir = ".venv"
7575
argument = ""
7676
if os.path.exists(venv_dir):
77-
version = get_python_version(not_windows, venv_dir)
78-
if verbose:
79-
print("virtual environment found: " + venv_dir)
80-
print("python version: " + version)
77+
if not version:
78+
version = get_python_version(not_windows, venv_dir)
79+
if verbose:
80+
print("virtual environment found: " + venv_dir)
81+
print("python version: " + version)
8182
argument = " --no-python-downloads --python " + version
8283
print("You may want to load virtual environment libs by:")
8384
print("```py")
@@ -115,7 +116,7 @@ def without_manage_py():
115116
not_windows
116117
or "--uv" in args
117118
or "--uvx" in args
118-
or "fast" in capture_output("uvx tool list")
119+
or "fast" in capture_output("uv tool list")
119120
)
120121
if is_venv():
121122
msg = "ipython not installed. "
@@ -129,7 +130,17 @@ def without_manage_py():
129130
tip = "uv " + tip
130131
print(" " + tip)
131132
raise
132-
version = "" if not_windows else sys.executable
133+
if not_windows:
134+
version = ""
135+
else:
136+
version = sys.executable
137+
cwd = os.getcwd()
138+
try:
139+
version = os.path.relpath(version, cwd)
140+
except ValueError:
141+
if "--verbose" in args:
142+
msg = "{version} is not relative path of {cwd}"
143+
print(msg.format(version=version, cwd=cwd))
133144
command = (
134145
uvx_ipython(not_windows, version=version)
135146
if prefer_uvx

0 commit comments

Comments
 (0)