prusnak / micropython-extmod-generator

Generator for Micropython external modules written in C
MIT License
21 stars 6 forks source link

Input module needs to be on PYTHONPATH #4

Open SpotlightKid opened 8 years ago

SpotlightKid commented 8 years ago

Maybe the path of the input module should be added to sys.path in the generate script?

$ ./micropython-extmod-generator/generate testmod1
Looking for module "testmod1":
Traceback (most recent call last):
  File "./micropython-extmod-generator/generate", line 241, in <module>
    main()
  File "./micropython-extmod-generator/generate", line 234, in main
    module = Module(sys.argv[1])
  File "./micropython-extmod-generator/generate", line 66, in __init__
    self.module = importlib.import_module(name)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named 'testmod1'

$ PYTHONPATH=. ./micropython-extmod-generator/generate testmod1
Looking for module "testmod1":
Found <module 'testmod1' from '/[...]/testmod1.py'>
Parsed OK ... loaded 1 functions and 1 classes with 1 methods
Generating source code:
Done
Saved source as modtestmod1.c
Saved qstrdefs as modtestmod1-qstrdefs.h
prusnak commented 8 years ago

Should be fixed in a935645cb2e662955fc9744c015bca0da0630c75

Running ./micropython-extmod-generator/extmod-generator example works correctly for me.

SpotlightKid commented 8 years ago

But this doesn't work:

./micropython-extmod-generator/extmod-generator testmod1

... where testmod1.py is in the working directory, i.e the parent directory of the dir extmod-generate is in. You example only works, because example.py is in the directory extmod-generate is in, because the directory containing the running script is added to the Python path.