Skip to content

Commit

Permalink
better handling of cache.json with multiple solvers using the same ex…
Browse files Browse the repository at this point in the history
…ecutable
  • Loading branch information
karmacoma-eth committed Nov 13, 2024
1 parent 21f29b6 commit a0721f9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
25 changes: 19 additions & 6 deletions src/jsi/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ def reaper_thread():
# Skip PID 1 check if we're running in a container
# (when running interactively, the parent shell can have PID 1)
skip_pid1 = is_in_container()
if skip_pid1:
logger.debug("containerized environment detected, skipping PID 1 check")

def check_parent():
while True:
Expand Down Expand Up @@ -364,20 +366,21 @@ def main(args: list[str] | None = None) -> int:
return 1

with timer("find_available_solvers"):
# maps solver name to executable path
# maps executable name to executable path
available_solvers = load_solvers(solver_definitions, config)
if not available_solvers:
available_solvers = find_solvers(solver_definitions, config)
save_solvers(available_solvers, config)

if not available_solvers:
stderr.print("error: no solvers found on PATH")
stderr.print("see https://github.com/a16z/jsi?tab=readme-ov-file#tips for help")
return 1

# build the commands to run the solvers
# run the solvers in the specified sequence, or fallback to the default order
defs = solver_definitions
enabled_solvers = [solver for solver in available_solvers if defs[solver].enabled]
enabled_solvers = [solver for solver in defs if defs[solver].enabled]

if not enabled_solvers:
n = len(available_solvers)
Expand All @@ -387,14 +390,24 @@ def main(args: list[str] | None = None) -> int:
if config.solver_versions:
import subprocess

executables: set[str] = set(defs[x].executable for x in enabled_solvers)
for executable in executables:
done: set[str] = set()
for solver_name in enabled_solvers:
executable_name = solver_definitions[solver_name].executable
if executable_name not in available_solvers:
continue

executable_path = available_solvers[executable_name]
if executable_name in done:
continue

done.add(executable_name)

output = subprocess.run(
[executable, "--version"],
[executable_path, "--version"],
capture_output=True,
text=True,
).stdout
print(f"{executable}: {extract_version(output)}")
print(f"{executable_name}: {extract_version(output)}")

return 0

Expand Down
18 changes: 8 additions & 10 deletions src/jsi/config/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,26 +143,24 @@ def find_solvers(
config: Config,
) -> dict[str, str]:
stderr = config.stderr
if config.verbose:
stderr.print("looking for solvers available on PATH:")
stderr.print("looking for solvers available on PATH:")

paths: dict[str, str] = {}

import shutil

for solver_name, solver_def in solver_definitions.items():
path = shutil.which(solver_def.executable) # type: ignore
executables = set(d.executable for d in solver_definitions.values())
for executable in executables:
path = shutil.which(executable) # type: ignore

if path is None:
stderr.print(f"{solver_name:>12} not found")
stderr.print(f"[yellow]{'N/A':>6}[/yellow] {executable}")
continue

paths[solver_name] = path
stderr.print(f"{solver_name:>12} [green]OK[/green]")

if config.verbose:
stderr.print()
paths[executable] = path
stderr.print(f"[green]{'OK':>6}[/green] {executable}")

stderr.print()
return paths


Expand Down
6 changes: 5 additions & 1 deletion src/jsi/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,11 @@ def base_commands(
if not solver_def:
raise RuntimeError(f"unknown solver: {solver_name}")

executable_path = available_solvers[solver_name]
executable_name = solver_def.executable
executable_path = available_solvers.get(executable_name)
if not executable_path:
continue

args = [executable_path]

# append the model option if requested
Expand Down

0 comments on commit a0721f9

Please sign in to comment.