Skip to content

Commit ad9915c

Browse files
committed
Allow Python to choose generator interpreter using shutil parameter to generators.
1 parent 74a4fa1 commit ad9915c

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

doc/source/user/build_system/generators.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Key Description
6868
===================== ===========
6969
command The command to run (relative to the core root) to invoke the generator. FuseSoC will pass a yaml configuration file as the first argument when calling the command.
7070
interpreter If the command requires an interpreter (e.g. python or perl), this will be used called, with the string specified in `command` as the first argument, and the yaml file as the second argument.
71+
shutil If `true`, use Python's `shutil.which` to find the path to the interpreter instead of the system `PATH`. Ignored if no `interpreter`.
7172
cache_type If the result of the generator should be considered cacheable. Legal values are `none`, `input` or `generator`.
7273
file_input_parameters All parameters that are file inputs to the generator. This option can be used when `cache_type` is set to `input` if fusesoc should track if these files change.
7374
===================== ===========

fusesoc/capi2/json_schema.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,13 @@
317317
"type": "string"
318318
},
319319
"interpreter": {
320-
"description": "If the command needs a custom interpreter (such as python) this will be inserted as the first argument before command when calling the generator. The interpreter needs to be on the system PATH.",
320+
"description": "If the command needs a custom interpreter (such as python) this will be inserted as the first argument before command when calling the generator. If shutil is not true, the interpreter needs to be on the system PATH.",
321321
"type": "string"
322322
},
323+
"shutil": {
324+
"description": "If an interpreter is set, use the Python interpreter's shutil.which module to find it.",
325+
"type": "boolean"
326+
},
323327
"cache_type": {
324328
"description": "If the result of the generator should be considered cacheable. Legal values are *none*, *input* or *generator*.",
325329
"type": "string",

fusesoc/edalizer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,11 @@ def _run(self, generator_cwd):
601601
]
602602

603603
if "interpreter" in self.generator:
604-
args[0:0] = [self.generator["interpreter"]]
604+
if self.generator.get("shutil", False):
605+
genpath = shutil.which(self.generator["interpreter"])
606+
args[0:0] = [genpath]
607+
else:
608+
args[0:0] = [self.generator["interpreter"]]
605609

606610
Launcher(args[0], args[1:], cwd=generator_cwd).run()
607611

0 commit comments

Comments
 (0)