Skip to content

Commit

Permalink
Fix installation of simforge in subprocess
Browse files Browse the repository at this point in the history
Signed-off-by: Andrej Orsula <orsula.andrej@gmail.com>
  • Loading branch information
AndrejOrsula committed Jan 1, 2025
1 parent 1a56b5c commit 49a8bec
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions simforge/core/generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,24 +278,33 @@ def __subprocess_ensure_sf_installed(cls):
if cls.__IS_SUBPROC_SF_ENSURED:
return
cls.__IS_SUBPROC_SF_ENSURED = True

extras = (
f"[{cls.SUBPROC_INSTALL_SF_EXTRAS}]"
if cls.SUBPROC_INSTALL_SF_EXTRAS
else ""
)
for src_path in simforge.__path__:
project_path = Path(src_path).parent
if project_path.joinpath("pyproject.toml").exists():
is_editable = True
install_target = project_path.as_posix()
install_args = (
"-e",
project_path.as_posix() + extras,
)
break
else:
is_editable = False
install_target = f'simforge=={importlib.metadata.version("simforge")}'
install_args = (
"simforge" + extras + f'=={importlib.metadata.version("simforge")}',
)

expr = [
"from importlib.util import find_spec",
'exit(0) if find_spec("simforge") else ()',
"from subprocess import check_call",
"from sys import executable",
'check_call([executable,"-m","pip","install","--no-input","--no-cache-dir",'
+ ('"-e",' if is_editable else "")
+ f'"{install_target}[{cls.SUBPROC_INSTALL_SF_EXTRAS}]"])',
'check_call([executable,"-m","pip","install","--no-input","--no-cache-dir","-I",'
+ ",".join(f'"{arg}"' for arg in install_args)
+ "])",
]

cls.__subprocess_run(expr)
Expand Down

0 comments on commit 49a8bec

Please sign in to comment.