Skip to content

Commit 13bc84f

Browse files
committed
Update 2 code files
Modified: • src/omnipkg/dispatcher.c (+28/-22 lines) • src/omnipkg/isolation/worker_daemon.py (+16/-22 lines) [gitship-generated]
1 parent c811fd4 commit 13bc84f

2 files changed

Lines changed: 41 additions & 41 deletions

File tree

src/omnipkg/dispatcher.c

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -973,29 +973,35 @@ static void fallback_to_python_v(const char *self_dir, char **argv,
973973
char py[MAX_PATH];
974974
int found = 0;
975975

976-
/* 1. Try the config first */
977-
if (read_self_config(self_dir, py, sizeof(py)) && file_exists(py)) {
978-
found = 1;
979-
} else {
980-
/* 2. Try common names in both the current directory AND the parent directory */
981-
const char *names[] = {"python3.11", "python3.10", "python3.9",
982-
"python3", "python", "python.exe", NULL};
983-
984-
/* We check the current dir (self_dir) and the parent dir (self_dir/..) */
985-
const char *search_paths[] = {self_dir, NULL}; // We will handle parent manually for safety
986-
987-
for (int i = 0; names[i]; i++) {
988-
// Try current directory: .../Scripts/python.exe
989-
snprintf(py, sizeof(py), "%s/%s", self_dir, names[i]);
990-
if (file_exists(py)) { found = 1; break; }
991-
992-
// Try parent directory: .../Scripts/../python.exe
993-
snprintf(py, sizeof(py), "%s/../%s", self_dir, names[i]);
994-
if (file_exists(py)) { found = 1; break; }
976+
/* 1. Try local / parent search (works for venvs) */
977+
const char *names[] = {"python3.11", "python3.10", "python3.9", "python3", "python", "python.exe", NULL};
978+
for (int i = 0; names[i]; i++) {
979+
snprintf(py, sizeof(py), "%s/%s", self_dir, names[i]);
980+
if (file_exists(py)) { found = 1; break; }
981+
snprintf(py, sizeof(py), "%s/../%s", self_dir, names[i]);
982+
if (file_exists(py)) { found = 1; break; }
983+
}
984+
985+
/* 2. CROSS-DRIVE FIX: If still not found, ask Windows where 'python' is */
986+
if (!found) {
987+
FILE *fp = _popen("where python", "r");
988+
if (fp) {
989+
if (fgets(py, sizeof(py), fp)) {
990+
// Remove newline characters
991+
py[strcspn(py, "\r\n")] = 0;
992+
if (file_exists(py)) {
993+
found = 1;
994+
}
995+
}
996+
_pclose(fp);
995997
}
996998
}
997999

9981000
if (!found) {
1001+
fprintf(stderr, "omnipkg: cannot find host Python for fallback\n");
1002+
fprintf(stderr, " Self Dir: %s\n", self_dir);
1003+
exit(1);
1004+
}
9991005
/* VERBOSE DIAGNOSTICS: Tell the user EXACTLY where we looked */
10001006
fprintf(stderr, "omnipkg: cannot find host Python for fallback\n");
10011007
fprintf(stderr, " Checked directory: %s\n", self_dir);

src/omnipkg/isolation/worker_daemon.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -332,29 +332,23 @@ def _ensure_worker_config(python_exe: str, site_packages: str, multiversion_base
332332
OMNIPKG_TEMP_DIR = os.path.join(tempfile.gettempdir(), "omnipkg")
333333

334334
def _get_venv_temp_dir() -> str:
335-
"""
336-
Return a temp dir scoped to the current virtual environment.
337-
This exactly mirrors ConfigManager._get_env_id() so that the daemon
338-
and the core Omnipkg application share the same namespace.
339-
"""
340-
import hashlib
341-
import platform
342-
343-
# 1. Respect the override if set (used by ConfigManager)
344-
env_id = os.environ.get("OMNIPKG_ENV_ID_OVERRIDE")
335+
# 1. Check for the override first (Symmetry with ConfigManager)
336+
override = os.environ.get("OMNIPKG_ENV_ID_OVERRIDE")
337+
if override:
338+
venv_hash = override
339+
else:
340+
# Fallback to the original hash logic
341+
import hashlib
342+
identity = sys.prefix
343+
try:
344+
project_root = Path(__file__).resolve().parent.parent.parent
345+
if (project_root / "pyproject.toml").exists():
346+
identity = f"{sys.prefix}:{project_root}"
347+
except Exception:
348+
pass
349+
venv_hash = hashlib.sha1(identity.encode()).hexdigest()[:10]
345350

346-
# 2. Replicate _canonical_path_str from ConfigManager
347-
if not env_id:
348-
venv_path = Path(sys.prefix)
349-
if platform.system() == "Windows":
350-
canonical = str(venv_path.resolve()).lower()
351-
else:
352-
canonical = str(venv_path.resolve())
353-
354-
env_id = hashlib.md5(canonical.encode()).hexdigest()[:8]
355-
356-
# Store daemon files cleanly in a shared env directory
357-
d = os.path.join(OMNIPKG_TEMP_DIR, f"env_{env_id}")
351+
d = os.path.join(OMNIPKG_TEMP_DIR, venv_hash)
358352
os.makedirs(d, exist_ok=True)
359353
return d
360354

0 commit comments

Comments
 (0)