renatahodovan / grammarinator

ANTLR v4 grammar-based test generator
Other
340 stars 61 forks source link

Example failing - ImportError: cannot import name 'UnparserRuleContext' from 'grammarinator.runtime' #213

Closed ZuseZ4 closed 4 months ago

ZuseZ4 commented 7 months ago

After running pip install grammarinator I failed to run my own grammar (missing class error), so I tried to run the example, which unfortunately also failed. Were there any breaking changes?

➜  prog git clone git@github.com:renatahodovan/grammarinator.git
Cloning into 'grammarinator'...
remote: Enumerating objects: 2509, done.
remote: Counting objects: 100% (998/998), done.
remote: Compressing objects: 100% (312/312), done.
remote: Total 2509 (delta 727), reused 913 (delta 677), pack-reused 1511
Receiving objects: 100% (2509/2509), 662.74 KiB | 6.69 MiB/s, done.
Resolving deltas: 100% (1690/1690), done.
➜  prog cd grammarinator 
➜  grammarinator git:(master) ls
docs  examples  grammarinator  LICENSE.rst  MANIFEST.in  pyproject.toml  README.rst  RELNOTES.rst  setup.cfg  tests  tox.ini
➜  grammarinator git:(master) ls
docs  examples  grammarinator  LICENSE.rst  MANIFEST.in  pyproject.toml  README.rst  RELNOTES.rst  setup.cfg  tests  tox.ini
➜  grammarinator git:(master) grammarinator-process examples/grammars/HTMLLexer.g4 examples/grammars/HTMLParser.g4 \
  -o examples/fuzzer/
        The farthest rule from 'htmlDocument' is 'ATTCHAR' (8 steps).
        3 rule(s) unreachable from 'htmlDocument': 'EOF', 'TAG_WHITESPACE', 'HEXDIGIT'
➜  grammarinator git:(master) ✗ grammarinator-generate HTMLCustomGenerator.HTMLCustomGenerator -r htmlDocument -d 20 \
  -o examples/tests/test_%d.html -n 100 \
  -s HTMLGenerator.html_space_serializer \
  --sys-path examples/fuzzer/
Traceback (most recent call last):
  File "/home/manuel/.local/bin/grammarinator-generate", line 8, in <module>
    sys.exit(execute())
  File "/home/manuel/.local/lib/python3.10/site-packages/grammarinator/generate.py", line 148, in execute
    process_args(args)
  File "/home/manuel/.local/lib/python3.10/site-packages/grammarinator/generate.py", line 36, in process_args
    args.generator = import_object(args.generator)
  File "/home/manuel/.local/lib/python3.10/site-packages/inators/imp.py", line 24, in import_object
    return getattr(importlib.import_module('.'.join(steps[0:-1])), steps[-1])
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/manuel/prog/grammarinator/examples/fuzzer/HTMLCustomGenerator.py", line 13, in <module>
    from grammarinator.runtime import UnlexerRule, UnparserRuleContext
ImportError: cannot import name 'UnparserRuleContext' from 'grammarinator.runtime' (/home/manuel/.local/lib/python3.10/site-packages/grammarinator/runtime/__init__.py)
renatahodovan commented 6 months ago

Hi @ZuseZ4 !

The problem with your use case is that you installed the latest release of Grammarinator from PyPI but you tried to execute the example from the latest master, which contains a lot of new features. To execute the examples you need to install the latest Grammarinator: pip install . from the root of Grammarinator.

If you have further issues with your own grammar, please share the details here and I try to help!

renatahodovan commented 4 months ago

I hope that it solved the issue. If it still persist, then please feel free to reopen.