IDEMSInternational / rapidpro-flow-toolkit

Toolkit for using spreadsheets to create and modify RapidPro flows
GNU Lesser General Public License v2.1
3 stars 1 forks source link

ModuleNotFoundError: No module named 'tests.input' #101

Closed ronna closed 7 months ago

ronna commented 9 months ago

Hi, I am currently working on using the Rapid Flow Toolkit by creating flows using the example files and commands from https://libraries.io/pypi/rapidpro-flow-tools. However, I have encountered an error and would be grateful for your help resolving this issue. Thank you very much for considering my request.

ronald@x200 ~/Documents/Github/rapidpro-flow-toolkit $ rpft create_flows \ --output flows.json \ --datamodels=tests.input.example1.nestedmodel \ --format=csv \ src/rpft/tests/input/example1/content_index.csv Traceback (most recent call last): File "/home/ronald/.local/bin/rpft", line 8, in sys.exit(main()) File "/home/ronald/.local/lib/python3.10/site-packages/rpft/cli.py", line 11, in main create_flows( File "/home/ronald/.local/lib/python3.10/site-packages/rpft/converters.py", line 11, in create_flows parser = ContentIndexParser( File "/home/ronald/.local/lib/python3.10/site-packages/rpft/parsers/creation/contentindexparser.py", line 33, in init self.user_models_module = importlib.import_module(user_data_model_module_name) File "/usr/lib/python3.10/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1050, in _gcd_import File "", line 1027, in _find_and_load File "", line 992, in _find_and_load_unlocked File "", line 241, in _call_with_frames_removed File "", line 1050, in _gcd_import File "", line 1027, in _find_and_load File "", line 992, in _find_and_load_unlocked File "", line 241, in _call_with_frames_removed File "", line 1050, in _gcd_import File "", line 1027, in _find_and_load File "", line 1004, in _find_and_load_unlocked ModuleNotFoundError: No module named 'tests.input'

ronna commented 9 months ago

checking the help file:

--datamodels DATAMODELS Module defining models for data sheets e.g. if the definitions reside in ./myfolder/mysubfolder/mymodelsfile.py, then this argument should be myfolder.mysubfolder.mymodelsfile

The syntax is correct. I tried using the full file path and still received the same error. Omitting the --datamodels option throws an error, as required in the test file row 5.

geoo89 commented 8 months ago

Hi Ronald, I assume you are using the packaged library from pypi?

I believe the tests are not part of the packaged library (@istride to confirm), and thus this particular file (tests/input/example1/nestedmodel.py) in not part of the package, which would probably explain this. @istride maybe you can confirm and propose how to present usage examples going forward.

As a quick fix, I think you can download the file from here https://github.com/IDEMSInternational/rapidpro-flow-toolkit/blob/main/tests/input/example1/nestedmodel.py, put it in a subfolder of your project, and adjust the module path in the --datamodels parameter accordingly.

istride commented 8 months ago

Thanks for raising this issue. It's true that the tests are no longer part of the rpft package and I don't think that they should be. The way to access the example files would be to clone the repository, or to individually download example files from the repository, as suggested above.

The README file should explain this more clearly. I am happy to update the README myself, but I would also accept a PR if you wanted to make the change yourself, @ronna .

ronna commented 8 months ago

Hi @geoo89

Hi Ronald, I assume you are using the packaged library from pypi?

yes, I am using the packaged libary.

I believe the tests are not part of the packaged library (@istride to confirm), and thus this particular file (tests/input/example1/nestedmodel.py) in not part of the package, which would probably explain this. @istride maybe you can confirm and propose how to present usage examples going forward.

As a quick fix, I think you can download the file from here https://github.com/IDEMSInternational/rapidpro-flow-toolkit/blob/main/tests/input/example1/nestedmodel.py, put it in a subfolder of your project, and adjust the module path in the --datamodels parameter accordingly.

I have tried this and still get the same error.

ronna commented 8 months ago

Hi @istride

Thanks for raising this issue.

Thank you for your kind expression of gratitude.

It's true that the tests are no longer part of the rpft package and I don't think that they should be. The way to access the example files would be to clone the repository, or to individually download example files from the repository, as suggested above.

I'm looking to expand my knowledge on building Rapidpro flows with Excel. While I have a basic understanding of creating flows with the editor's drag-and-drop feature, incorporating Excel will enable me to build more elaborate flows quickly and effectively. I've attempted to comprehend the example Excel and CSV files on the repository, but I'm having some difficulty. My objective is to convert the example files into a Rapidpro JSON format, upload and test them in the flow editor using the simulator, and ideally, determine the purpose of each column in the Excel/CSV files.

Do you have documentation similar to ODK ecosystem's XLSForm - https://xlsform.org/en?/

The README file should explain this more clearly. I am happy to update the README myself, but I would also accept a PR if you wanted to make the change yourself, @ronna .

Once I have mastered everything, I'm happy to contribute to documentation.

istride commented 8 months ago

As a quick workaround, to get the example to work, you may alter the PYTHONPATH environment variable to help Python to find the data models.

  1. Copy the directory tests/input/example1 to a temporary directory e.g. /tmp/example1
  2. Change directory to your temporary directory - cd /tmp
  3. Run the toolkit (using Excel files instead of CSV):
    PYTHONPATH=. rpft create_flows --output flows.json --datamodels=example1.nestedmodel --format=xlsx example1/content_index.xlsx

At the moment, there isn't such polished documentation as that for XLSForm. The best available is this Google Doc, plus the unit tests in the repo. @fagiothree @geoo89 Let us know if there is better documentation out there.

istride commented 7 months ago

The README has been updated with an example that actually works and links to the best documentation we currently have - which, admittedly, needs improvement.

I believe this issue is resolved, so I will close it.