Is your feature request related to a problem? Please describe.
I use mcstas-pygen to turn an .instr file into a .py script so it can be wrapped in a python package to add a complex detector geometry. The generated script creates a make() function that instantiates McStas_instr with only hardcoded parameters.
The problem is that my package expects custom local components, so McStasScript needs to know where they are (input_path) right at instantiation time. Because make() takes no arguments, I'm forced to manually edit the generated python file to add input_path to the function signature and constructor call each time the base instrument file is edited and the python file is regenerated.
Describe the solution you'd like
It would be great if mcstas-pygen generated the make function with a default parameter: def make(input_path=None):.
This would pass input_path directly to McStas_instr(..., input_path=input_path). Since the constructor signature defaults to input_path=None (resolving to "." internally (see: here)), I expet this change to be completely backward-compatible and won't break any existing scripts calling make() with no arguments.
Describe alternatives you've considered
My alternative is to continue manually editing or to automate overriding :)
Additional context
Looking at the source code, I hope this would be a very quick change in mccode/src/pygen.c:
#if MCCODE_PROJECT == 1 /* neutron */
cout("# Python McStas instrument description");
cout("def make(input_path=None):");
coutf(" instr = ms.McStas_instr(\"%s_generated\", author = \"McCode Py-Generator\", origin = \"ESS DMSC\", input_path=input_path)",instr->name);
#elif MCCODE_PROJECT == 2 /* xray */
cout("# Python McXtrace instrument description");
cout("def make(input_path=None):");
coutf(" instr = ms.McXtrace_instr(\"%s_generated\", author = \"McCode Py-Generator\", origin = \"ESS DMSC\", input_path=input_path)",instr->name);
#endif
Note:
I wouldn't mind having other McStas_instr arguments as well (I manually add output_path and NeXus, but these can be modified through .settings() after the initialisation, so they are not really important)
Is your feature request related to a problem? Please describe.
I use
mcstas-pygento turn an.instrfile into a.pyscript so it can be wrapped in a python package to add a complex detector geometry. The generated script creates amake()function that instantiatesMcStas_instrwith only hardcoded parameters.The problem is that my package expects custom local components, so McStasScript needs to know where they are (
input_path) right at instantiation time. Becausemake()takes no arguments, I'm forced to manually edit the generated python file to addinput_pathto the function signature and constructor call each time the base instrument file is edited and the python file is regenerated.Describe the solution you'd like
It would be great if
mcstas-pygengenerated themakefunction with a default parameter:def make(input_path=None):.This would pass
input_pathdirectly toMcStas_instr(..., input_path=input_path). Since the constructor signature defaults toinput_path=None(resolving to"."internally (see: here)), I expet this change to be completely backward-compatible and won't break any existing scripts callingmake()with no arguments.Describe alternatives you've considered
My alternative is to continue manually editing or to automate overriding :)
Additional context
Looking at the source code, I hope this would be a very quick change in
mccode/src/pygen.c:Note:
I wouldn't mind having other McStas_instr arguments as well (I manually add output_path and NeXus, but these can be modified through
.settings()after the initialisation, so they are not really important)