Open zflat opened 1 year ago
@RobertBlakeAnderson Thanks for adding the ability to specify modules to use in the python eval
launch substitution in https://github.com/ros2/launch/pull/655! I'm wondering if you considered the case that I mention in this issue and if you have any thoughts on how to address the issue?
Bug report
Required Info:
Steps to reproduce issue
I want to use the
eval
python substitution with a module that is within a package or parent module. For example, when I addos.path
as a module to import, then I should be able to use a function from that module in the pythoneval
substitution. However, sincepath
in this case is a submodule ofos
, the parent moduleos
is not available for performing substitutions when only passing"os.path"
as the second argument toeval
.Here is a failing test case where only
"os.path"
is passed. (added tolaunch/test/launch/frontend/test_substitutions.py
)Here is a passing test case where
"os, os.path"
is passed.Expected behavior
I should be able to pass
"os.path"
as the second argument toeval
to use methods fromos.path
.Actual behavior
I must pass
"os, os.path"
as the second argument toeval
to use methods fromos.path
. Otherwise I get an error:Additional information
Feature request
Feature description
I don't know if importing all parent modules is desired, but the error I get when only providing "os.path" is not easy to understand. I think the feature of being able to specify submodule will be easier to use if we import and add the parent modules of a specified submodule.
Implementation considerations
Update
launch/launch/substitutions/python_expression.py
classPythonExpression
methodperform
to build out a list of all modules and parent modules fromself.python_modules
. So if "os.path" is given, then the list of modules to import usingimportlib.import_module
would be["os", "os.path"]
.