Skip to content

Commit 8853efd

Browse files
committed
feat: generate env.bat for Windows CMD and restricted PowerShell environments
1 parent 8d47089 commit 8853efd

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ source ~/.claude/redmatter/python/env.sh
5959
. "$env:USERPROFILE\.claude\redmatter\python\env.ps1"
6060
```
6161

62+
> [!NOTE]
63+
> If your system blocks PowerShell scripts (`running scripts is disabled on this system`), use
64+
> `install.bat` instead of `install.ps1`, and source the environment with `call` instead of dot-sourcing:
65+
>
66+
> ```bat
67+
> install.bat -Prefix "%USERPROFILE%\.claude\redmatter\python" -MinPython "3.10" -UvEnv "REDMATTER_UV" -PythonEnv "REDMATTER_PYTHON"
68+
> call "%USERPROFILE%\.claude\redmatter\python\env.bat"
69+
> ```
70+
>
71+
> To remove the restriction permanently, run in an elevated PowerShell prompt:
72+
> `Set-ExecutionPolicy -Scope CurrentUser RemoteSigned`
73+
6274
**Scripted install (quiet mode):**
6375
6476
```bash
@@ -116,6 +128,7 @@ exec "$PYTHON" script.py
116128
Scripts/python.exe # Windows
117129
env.sh # exports env vars + conditional PATH (bash)
118130
env.ps1 # exports env vars + conditional PATH (PowerShell)
131+
env.bat # exports env vars + conditional PATH (CMD / restricted PS)
119132
distro.toml # source version record + [install] options
120133
```
121134

setup.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,39 @@ def _write_env_ps1(prefix: Path, uv_env: str, python_env: str, distro_version: s
208208
_ok("env.ps1")
209209

210210

211+
# ── env.bat ───────────────────────────────────────────────────────────────────
212+
213+
def _write_env_bat(prefix: Path, uv_env: str, python_env: str, distro_version: str) -> None:
214+
if not _IS_WINDOWS:
215+
return
216+
217+
uv_exe = prefix / "uv.exe"
218+
venv_py = prefix / "venv" / "Scripts" / "python.exe"
219+
bin_dir = prefix / "bin"
220+
221+
add_to_path, notes = _path_decision(bin_dir)
222+
223+
lines: list[str] = [
224+
f"@echo off",
225+
f":: managed-python v{distro_version} -- generated by setup.py",
226+
":: Do not edit manually; re-run install to regenerate",
227+
"",
228+
":: Env vars (always set -- these are the reliable contract)",
229+
f'SET {uv_env}={uv_exe}',
230+
f'SET {python_env}={venv_py}',
231+
"",
232+
]
233+
234+
if add_to_path:
235+
lines += [f":: {n}" for n in notes]
236+
lines.append(f'SET PATH={bin_dir};%PATH%')
237+
else:
238+
lines += [f":: {n}" for n in notes]
239+
240+
(prefix / "env.bat").write_text("\r\n".join(lines) + "\r\n", encoding="utf-8")
241+
_ok("env.bat")
242+
243+
211244
# ── distro.toml ───────────────────────────────────────────────────────────────
212245

213246
def _write_installed_distro_toml(
@@ -299,6 +332,7 @@ def main() -> None:
299332
_create_bin(prefix)
300333
_write_env_sh(prefix, args.uv_env, args.python_env, distro_version)
301334
_write_env_ps1(prefix, args.uv_env, args.python_env, distro_version)
335+
_write_env_bat(prefix, args.uv_env, args.python_env, distro_version)
302336
_write_installed_distro_toml(
303337
script_dir, prefix, args.min_python, args.uv_env, args.python_env, args.shell_profile
304338
)
@@ -312,6 +346,7 @@ def main() -> None:
312346
print()
313347
if _IS_WINDOWS:
314348
print(f' . "{prefix / "env.ps1"}"')
349+
print(f' or (if scripts are restricted): call "{prefix / "env.bat"}"')
315350
else:
316351
print(f' source "{prefix / "env.sh"}"')
317352
print()

0 commit comments

Comments
 (0)