Week 12: Add API support to the GUI

Just the final week things! 😦

As planned for Week 12, an API support has been added to the GUI of the gr_modtool. The work on the GUI is in progress but it can still be used an alternative for the CLI commands since the API has been integrated. The work on the GUI can be followed in my GitHub repository, modtool_gui.

The push-button, run, on every command’s tab firstly calls the functional definition for the setup of the common parameters like directory, --skip-lib, scm-mode, and then instantiate an object of the corresponding API class with these parameters. After that, the class members in the __init__ take their values from the user input and the method run of the particular class is executed.

I have also tried to enhance the code quality by splitting the QtDesigner generated code into several functional definitions.

Next Task

This might be the final blog post on this website but there will be another blog post with the condensed work of the entire GSoC period soon on the GNU Radio website.

I would still like to contribute to the gr-modtool, the magical tool that enhanced my knowledge of python multiple folds. I will try to complete the GUI with decent code quality as soon as possible. I will also try my level best to sort out the issues that come up with the code I produced, or modtool in general.

Acknowledgement

I knew very little about Python and the idiosyncrasies with its versions when I started off with the programme but with the immense support of my mentors, Sebastian Koslowski and Nicolas Cuervo, I was able to cope-up with the project demands. I learnt about several awesome python libraries and the methodology of writing good quality python code. I would like to thank my mentors for such high degree of support throughout the GSoC programme.

I would also like to thank Marcus Müller for reviewing the PRs and briefing me about the first issue that I can work on. I would also like to thank Martin Braun for reviewing the PRs as well as the GSoC proposal. I would also like to thank Andrej Rode for helping me with the branch rebase on GitHub and providing me with the rights for editing the GNU Radio wiki. I would also like to thank Håkon Vågsether for helping me with the XML to YAML conversion. I would also like to thank Kartik Patel for suggesting me to work with the GNU Radio Community this summer. I would also like to thank Felix Wunsch for providing me the overall GSoC updates.

I would like to thank Ben Hilburn and the GNU Radio Community for inviting me to the GNU Radio Conference 2018. A special vote of thanks to Ben Hilburn for booking my flight tickets, Derek Kozel for booking the hotel for my stay, and Neel Pandeya for his support during the VISA application.

Thank You!

 

 

Week 11: Updated GUI

GUI begins!

As planned for Week 11, I have created a GUI for the modtool​.  Currently, the GUI has not been integrated with the API. The design for GUI has been updated to make it more user interactive. There is a proper space for common parameters​, logger output​, and auto-completion candidates.

Here are some of the images of the modtool GUI:

Screenshot from 2018-07-28 22-36-19.png

Screenshot from 2018-07-28 22-36-35.png

Screenshot from 2018-07-28 22-36-08.png

Any kind of suggestion or feedback will be highly helpful!


Tasks for Week 12

  1. Add an API support to the modtool GUI.
  2. Work on logger output and candidates auto-completion for the GUI.
  3. Bug fixes of the PR, if any.

The code for the GUI can be followed in my repository modtool_gui.

Week 10: Mock GUI

As planned for Week 10, I have created a mock GUI for the modtool. I have also added the commits from the branch yaml, which contained the cli and core modules for the XML to YAML conversion, into the branch swapnil_next​. I have also condensed all the remaining work of the other PRs into the main PR.

I have designed the GUI for the modtool using the QtDesigner. In the current design, the screen is split into 3 vboxes. The first contains the commands for the modtool, the second contains the user_input window while the third contains the candidates for auto-completion, if any. The second vbox is totally dependent on the first, while the third  vbox is totally dependent on the input field of the second vbox. There is a space for logger output in the second vbox. The GUI looks like:-

Screenshot from 2018-07-20 19-25-19.png

Note: Block Candidates is just for mock display.

Now, the branch swapnil_next contains the most recent version of modtool including the option for XML to YAML conversion.


Tasks for Week 11

  1. Complete the GUI with basic features.
  2. Bug fixes of the PR, if any.

I have updated the GitHub project and the code can be followed in the forked repository swapnil_next branch.

Week 9: XML to YAML Converter

As planned for Week 9, an XML to YAML generator has been added to the modtool. A new CLI command, update, has been added to the existing modtool commands that serves the purpose of conversion of XML scripts to YAML scripts. The functionality can also be achieved through the API class, ModToolUpdate. I would like to thank my mentors and Håkon Vågsether for helping me throughout.

The feature of XML to YAML conversion of grc scripts has been achieved by using the existing grc converter. The conversion utilises the functional definition load_block_xml of the class Converter of the grc converter.

The command update also comes with a special option --all that converts all the existing XML scripts to YAML. There is also a feature for auto-completion of candidates for conversion. The list of candidates is generated by traversing the grc directory of the module. There are proper checks on the existence of blockname entered by the user. The blockname is a mandatory argument unless --all option is specified (there are no checks on the blockname in this particular case). The mandatory changes in the CMakeLists.txt is also handled by the core ModTool class ModToolUpdate​ with proper warnings on more than 1 or 0 substitutions.

In the meantime, I also worked on learning PyQt5 for the GUI of the modtool. I learned about the various QtWidgets​, layouts, setting up connections, creating menu bar, etc.  I also worked on the basic GUI design on paper.


Tasks for Week 10

  1. Work on the GUI of the ModTool.
  2. Bug fixes of the PR, if any.

I have updated the GitHub project and the code can be followed in the forked repository yaml branch.

Week 8: Add YAML Generator

As planned for Week 8, YAML Generator has been added to the ModTool and the basic grc_xml template has been replaced with the grc_yaml template.

Since, the branch next contains YAML only, the grc_xml_generator has been replaced with a grc_yaml_generator. The CLI command has been changed from makexml to makeyaml. Similarly, the API or the core class has been changed from ModToolMakeXML to ModToolMakeYAML​. The python library pyyaml has been used to dump the dictionary into YAML data​. The generated YAML scripts are in strict correspondence to the existing YAML files in the next.

Since it is not possible to manage the order of entries using the traditional dictionary which stores the entries in the sorted manner according to the keys​, I have used an OrderedDict to manage the dictionary entries. For implementing an OrderedDict with pyyaml, I have added a special representer to the traditional Dumper. The data_flow_style has been kept as False​.

The template grc_xml has been replaced with the template grc_yml which gives the brief description of the YAML file that needs to be added for grc support.

Moreover, I have slightly modified the CMakeLists and the directory structure. The modtool configuration file has been moved to the base modtool folder. The CMakeLists.txt of the base modtool folder adds the sub_directories for the installation. The README.modtool has also been updated.

I have also replaced all possible %s, %d with str.format() in the python modules of the core as well as tools.

The entire work for gr_modtool overhaul has been rebased to the branch next from  the branch python3 and the pull request with current work status has been made.


Tasks for Week 9

  1. Bug fixes of the PR (if any).
  2. Create an XML to YAML converter (CLI option as well as API support).
  3. Start working on the GUI.

I have updated the GitHub project and the code can be followed in the forked repository swapnil_next branch.

Week 7: Logger Colors and Pylint Tests

As planned for week 7, the logger has been updated with ANSI colors, the modtool tests have been updated with Pylint tests (currently errors only) and the issue with the rename module has been solved (PR has been submitted).

ModTool tests for the API classes ModToolNewModule and ModToolAdd have been updated with the Pylint tests. They use the function py_run of the module epylint of the pylint package. To silence the configuration file alert as well as silently run the tests, the pylint_stderr is stored but not printed. For verbose testing, it can also be printed (not aware of the use case).  Currently, only the error messages of the pylint_stdout are printed as stdout for testing the ModTool generated scripts. The only issue is that the Pylint tests usually take a lot of time.

The logger gnuradio.modtool is now equipped with ANSI colors. The work has been done by overriding the StreamHandler class method emit. Even the input statements have ANSI colors. Now, there is a separate ModToolException for the CLI modules which raises the exception in red​ color. The redundancy in similar styling of input has been sorted with a separate function cli_input in the base CLI module. The colors are emitted using click.style which comes with an optional dependency colorama. So, no colors appear if colorama is not installed.

The issue regarding the renaming of the regex pattern instead of the entire blockname has been sorted by generating a list of block candidates for renaming. A special feature of alternative suggestions has been added so that the user faces minimum difficulty. The pull request also includes the py3k compatible Sequence Completion of the blocknames for the modules rename, rm​, makexml and disable.

I have also made a pull request regarding the lint fixes in the generated python scripts and a pull request for relative import of modules in python scripts. All the PRs have been moved to the next.

In the meantime, I also read about YAML serialization​ and also went through some of the blocks in the next for clear understanding.


Tasks for Week 8

  1. Add a YAML generator as a CLI command.
  2. Bug fixes, if any.

I have updated the GitHub project and the code can be followed in the forked repository core_cli branch.

Week 6: Modify API, Add logger

As planned for Week 6, the modtool tests have been added in-tree and all the print statements have been replaced by the logger. A major change to the API structure has also been made. All the raw open() statements have been replaced by with open(filename) as f.  The CLI modules have been modified to enhance the developer readability as well as the user experience.

API

Now, the ModTool API does not have any mandatory positional arguments for any of the in-tree modules. In the function __init__, the parameters are assigned the values passed by the user without any validation. The user has the liberty to pass the values later. The validation of values occur when the run method of a class is called. The run method calls the validate  method followed by the assign method (if required) of the particular class. The validate method initially calls the _validate method of the base module, except for the classes ModToolInfo and ModToolNewModule, for the validation of common parameters and then validates the parameters for the particular modules. The _assign method of the base module and the assign method of other modules assign the values of arguments based on the user input (eg:- fullblockname). The _assign method also calls required methods of the base module. For the CLI commands, the methods _validate and _assign are called from the  __init__ function itself.

The ModTool tests have also been changed as per the above-mentioned changes with tests on API calls via list-unpacking as well as object instantiation. They have been pushed in-tree.

A global logger gnuradio.modtool has been configured in the base module. All the loggers in the core as well as tools are created based on their respective module’s name. Since all the modules are packaged in the package gnuradio.modtool​, they inherit the configuration of the logger in the base module. Currently, the logger level has been set to info for the CLI commands whereas error for the API calls.

The CLI modules have been changed to facilitate the developer experience while changing a particular portion of the CLI interface. Moreover, until the value of block name or the module name is not specified, the user is prompted to fill its value which is followed by the usual regex check.

I have updated the pull request for the grc_xml_generator.


Tasks for Week 7

  1. Run pylint against the generated modules. This involves fixing of current pylint issues in the templates.
  2. Add ANSI colors to the logger as well as the CLI. This involves configuring the logger such that it works differently for the commands through different interfaces.
  3. Fix the issue with the core rename module.
  4. Read for adding a YAML generator in-tree plugin.

I have updated the GitHub project and the code is available at the forked repository core_cli branch.

 

 

Week 5: Expose API and API tests

The API!

As planned for week 5, the work on proper exposure of API has been completed with the help of thorough guidance by the mentors. Moreover, the modules have been separated among core, cli, tools, and templates. Here is the link to the forked repository working branch. Moreover, the modtool tests for the core modules newmod, add, rename, rm (remove) have been written. Here is the link to the GitHub repository.

API

Regarding the core modules, the setup function has been removed and all the arguments get their values in the __init__ itself. Moreover, proper checks like check on boolean values and improper arguments have been made in a separate validate function which does not run for arguments passed through CLI because of the checks in the CLI modules themselves. The checks in the CLI modules are same as the ones that existed earlier and have not been moved to the core modules considering the fact that the code should break just after an incorrect argument is passed rather than breaking after all the arguments have been passed for the convenience of the user. Thus, validation for CLI commands does not take place twice. The common parameters get initialized in the  __init__ function of the base module class Modtool. Moreover, the ModTool.__init__ does not run completely for commands newmod and info because that is not necessary and also assumes an existing module. So, if type(self).__name__ in ['ModToolInfo', 'ModToolNewModule'] the code breaks after initializing the arguments. All the imports for module classes or functional definitions have been made relative. Some of the protected members of the modtool classes have been made public for the access of CLI modules and for the simplicity of the user.

The tools like code_generator, grc_xml_generator​ have been moved to a separate directory tools which is accessible to both CLI and Core modules (the CLI modules utilize some of the util_functions). The templates, gr_newmod and templates.py, have been moved to a separate templates directory. The prefix modtool_ has been removed from the core modules since the helper modules have been moved to a separate directory.

Modtool Tests

The modtool testing begins with the creation of a new temporary directory in setUpClass function which runs before the actual testing begins and ends with the deletion of that directory in tearDownClass function which runs after the entire testing is complete.

Before test for any module, a setUp function runs the commands for creation of new module in the temporary directory and then adds a block if the previous command ran without raising an exception. After that, the specific tests for the module are run. The tests are skipped if the command necessary for their execution has already failed (like remove will be skipped if add fails in the setUp​).

The tests for the API classes ModToolNewModule, ModToolAdd, ModToolRename, and ModToolRemove have been written. The testing includes the raising of particular exceptions for class instantiation and the assertion for the existence or non-existence of a particular directory or module. For the class ModToolRemove, there are tests for asserting that the incorrect files are not removed. The reason for the exceptions has been mentioned before most of the assertRasises statements as a comment.

Moreover, I found a redundant patch of code in the class ModToolRemove of the master branch. Here is the link to the pull request.


Tasks for Week 6

  1. Enhance the tests and add the source in-tree.
  2. Bug fixes for the API (if any).
  3. Add a logger and use it instead of print statements.
  4. Split long functions.
  5. Make the nested functions without the need of closure as global.

Link to forked repository working branch (core_cli)

Link to the repository containing modtool tests.

Link to the updated GitHub project.

Week 4: Core/CLI split

The Core and the CLI splits!

As planned for week 4, the Core and the CLI portions of the modtool have been separated so the modtool becomes scriptable from python scripts. The work is done on the forked repository module_sep branch. Moreover, I have also worked on the enhancement of python3 branch.

The CLI portion of the modtool still holds the same functionality for all the commands. The entire click portion and the user CLI interaction is placed in the CLI modules whereas the core functionality of modtool that can be exposed as an API is in the Core modules. All the print statements in the core are only executed if the user has used the command through the command line interface. Moreover, since the setup function of the core becomes redundant for the CLI calls, it will only be executed for the API calls. The entire code has been thoroughly tested.

Currently, the user needs to call the run function from the imported module with the options and arguments passed as a dictionary. For example:-

>>> from gnuradio.modtool.core import *
>>> ModToolNewModule().run({‘directory’:’/home/swapnil/Documents/modtool’, ‘module_name’:’square_ff’})
>>> ModToolAdd().run({‘blockname’:’test_block’, ‘directory’:’/home/swapnil/Documents/modtool/gr-square_ff’, ‘lang’:’cpp’, ‘block_type’:’general’, ‘add_cpp_qa’: True})

works absolutely awesome.

Similarly, all the commands except for gr_modtool info work from the python scripts.

There is a slight problem with the ModToolException as it is giving traceback for the exceptions raised.

There was a problem with the grc_xml_generator for python3 compatibility. Here is the link to the pull request.
Here is the link to another enhancement pull request for modtool_newmod.py.


Tasks for Week 5

  • Bug fixes and enhancement of the current work on the module_sep branch
  • Completely expose the API for the modtool
  • Complete modtool testing for the API

Link to forked repository module_sep branch.

Link to the updated Github project.

Week 3: Enhancement, Documentation, Separation of Modules (started)

The first major pull request!

As planned for Week 3, the modtool has been rewritten as plug-in architecture with the external plug-ins working absolutely fine (thanks to awesome guidance by the mentors). The pull request has been made from the forked repository modtool branch. I have also worked on documenting the click plug-in architecture. Here is the link to the documentation. I have also started working on separation of modules on the forked repository module_sep branch.

Initially, I worked on making the external plug-ins work for the modtool. The only mistake that I was committing was I was installing the external plug-in inside a virtual environment so the modtool was not able to load the package through the entry_point (I tried several things to make that work though). After that, I worked on refactoring the code and also made the suggested changes by the mentors.

The documentation part was an awesome experience. It was my first experience on writing a technical blog.

The unit-testing portion also seems exciting. In between, I slightly learned about writing  unit tests, including setup and teardown functions as well as classes that can be beneficial for modtool testing (I slightly read about mocking too, not really beneficial here!).

The work on separation of modules is already in progress. I have already separated the entire click portion from the core without changing the current functionality of the modtool. Now, I need to shift the CLI portion of various other functions so that the core remains unaware of the CLI.

There were slight problems with the cmake, the modified code was not being updated at the dist-packages directory from where it was called during execution on running make and make install. Actually, I never specified the prefix while re-building GNU Radio. The problem was sorted out with the guidance of the mentors.


Tasks for Week 4

  1.  Bug fixes of the current modtool branch, if any.
  2.  Work on separation of modules (major task).
  3.  Work on modtool testing.

Link to the updated Github Project.

Link to the forked repository working branch (separation of modules).

Link to the forked repository modtool branch (plug-in stuff).