1

I have used gr_modtool to add custom blocks in python to an OOT module. It appears that all the source python I write must reside in the gr-my_oot_module/python directory. I will be writing a lot of code spread over many python files. I would like to organize those files into sub-directories (presumably) under gr-my_oot_module/python. Simply creating those directories and putting code there does not lead to a successful installation.

What is the correct approach to organizing the python files I write for this module into sub-directories?

More specifically:

  1. I added a block via gr_modtool. The associated python file with put in the python directory.
  2. I then moved that .py file into a sub-directory (sub_dir) under python/.
  3. I modified init.py and CMakeLists.txt under the python directory to reflect the sub-directory location and then did the install.

The block appears in GRC. When I try to use it, it complains

File "/home/my_name/devel/gnuradio3_8/lib/python3.6/dist-packages/my_module/__init__.py"
 from .sub_dir.sub_dir_test_blk import sub_dir_test_blk
 ModuleNotFoundError: No module named 'my_module.sub_dir' –
Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
rhz
  • 960
  • 14
  • 29

1 Answers1

0

You're right, Python code resides under python/. Then, you should use gr_modtool add to add GNU Radio python blocks. That will also add them to the CMakeLists.txt, which will in turn make sure they get installed during installation.

No, just putting files in subdirectories doesn't make them part of the installed module. That is not different than for any other python code. If you want things to be part of a module, you need to have them in an __init__.py. The python.org tutorial is your friend!

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
  • please put all that information into your question instead of into a comment here! – Marcus Müller Jan 01 '20 at 11:08
  • Done--Question details have been expanded. – rhz Jan 02 '20 at 17:46
  • Upon further experimentation, it seems that the following works: 1) create a new block via gr_modtool in the usual way 2) move the associated .py into the desired sub-directory under python/ 3) update the CMakeLists.txt file in the python/ directory to contain the sub-directory associated with the new .py file 4) install as usual – rhz Jan 03 '20 at 00:18