Is there a way to discover Jython modules inside a package at runtime, if they are inside a Java .jar in the form of compiled .py$class files?
Suppose I have a module foo
containing function frobify
. Someone else on my team is providing a package bar
with modules in it:
bar/
__init__.py
tweedledee.py
tweedledum.py
walrus.py
carpenter.py
and they use Jython to compile each of these into a .py$class
file, and then turn the bar
directory including all .py$class
files into bar.jar
Then we run Jython and execute the following:
import foo
import bar
foo.frobify(bar)
where I want to write frobify()
to do this:
def frobify(package):
for module in get_modules(package):
do_something_with(module)
How could I implement get_modules()
so that it returns a list of the modules inside the provided package? I would rather take this approach than having to force my customers to pass in a list of modules explicitly.