fixed symlinc resolving

This commit is contained in:
Elara 2025-07-29 20:32:16 +02:00
parent d968795628
commit 8036dc33b3
2 changed files with 20 additions and 11 deletions

View File

@ -8,6 +8,7 @@ import argparse
from .responses import compile_config
from .static import IS_VENV, VENV_DIRECTORY, CONFIG_DIRECTORY, COMPILED_CONFIG_FILE_NAME
from ntpath import devnull
logging.basicConfig(
format='%(message)s',
@ -108,12 +109,11 @@ def write_compile_config(local: bool):
(VENV_DIRECTORY / COMPILED_CONFIG_FILE_NAME).unlink(missing_ok=True)
def wrap_interpreter(path: Path):
def wrap_interpreter(path: Path, symlink_target: Path):
mommy_logger.info("mommy found a symlink to an interpreter~ %s", str(path))
serious_logger.info("interpreter symlink found at %s", str(path))
inner_symlink = path.parent / ("inner_" + path.name)
symlink_target = path.resolve()
if inner_symlink.exists():
raise Exception("inner symlink somehow already exists. This shouldn't happen because of prior checks")
@ -203,6 +203,11 @@ def mommify_venv():
mommy_logger.info("mommy looks in %s to mess your system up~ <33", str(bin_path))
serious_logger.info("scanning binary directory of venv at %s", str(bin_path))
resolved_symlinks = {}
for path in list(bin_path.iterdir()):
if path.is_symlink():
resolved_symlinks[path.name] = path.resolve()
for path in list(bin_path.iterdir()):
name = path.name
@ -213,10 +218,10 @@ def mommify_venv():
if name.startswith("inner_"):
continue
if subprocess.run([str(path), '-c', '"exit(0)"']).returncode != 0:
if subprocess.run([str(path), '-c', '"exit(0)"'], stdout=sys.devnull).returncode != 0:
continue
wrap_interpreter(path)
wrap_interpreter(path, resolved_symlinks[path.name])
else:
# could be pip

View File

@ -28,7 +28,7 @@ ADDITIONAL_ENV_VARS = {
def _load_config_file(config_file: Path) -> Dict[str, List[str]]:
with config_file.open("r") as f:
data = toml.load(f)
result = {}
for key, value in data.items():
if isinstance(value, str):
@ -43,7 +43,7 @@ ADDITIONAL_PROGRAM_PREFIXES = [
"cargo", # only as fallback if user already configured cargo
]
def _get_env_var_names(name: str):
def _get_env_var_names(name: str):
BASE = PREFIX + "_" + name.upper()
yield "PYTHON_" + BASE
yield BASE
@ -56,23 +56,27 @@ def _get_env_value(name: str) -> Optional[str]:
val = os.environ.get(key)
if val is not None:
return val
for key in _get_env_var_names(name):
val = os.environ.get(key)
if val is not None:
return val
def compile_config(disable_requests: bool = False) -> dict:
global RESPONSES_FILE, RESPONSES_URL
data = json.loads(RESPONSES_FILE.read_text())
if not disable_requests:
mommy_logger.info("mommy downloads newest responses for her girl~ %s", RESPONSES_URL)
serious_logger.info("downloading cargo mommy responses: %s", RESPONSES_URL)
r = requests.get(RESPONSES_URL)
data = r.json()
try:
r = requests.get(RESPONSES_URL)
data = r.json()
except requests.exceptions.ConnectionError:
mommy_logger.info("mommy couldn't fetch the url~")
serious_logger.info("couldnt fetch the url")
config_definition: Dict[str, dict] = data["vars"]
mood_definitions: Dict[str, dict] = data["moods"]