Zac-HD / hypothesmith

Hypothesis strategies for generating Python programs, something like CSmith
https://pypi.org/project/hypothesmith/
Mozilla Public License 2.0
95 stars 9 forks source link

hypothesmith on PyPI breaks with FileNotFoundError when importing from_grammar or from_node #27

Closed jakkdl closed 1 year ago

jakkdl commented 1 year ago

Repro:

  1. create a clean virtualenv
  2. pip install hypothesmith
  3. open python prompt (3.10.8)
  4. any of the following doesn't work:
    • from hypothesmith import from_grammar
    • from hypothesmith import from_node

Error:

$ python          
Python 3.10.8 (main, Nov  1 2022, 14:18:21) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from hypothesmith import grammar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/test_hypothesmith/.virtualenv/test_hypothesmith-dgeh/lib/python3.10/site-packages/hypothesmith/__init__.py", line 3, in <module>
    from hypothesmith.cst import from_node
  File "/tmp/test_hypothesmith/.virtualenv/test_hypothesmith-dgeh/lib/python3.10/site-packages/hypothesmith/cst.py", line 24, in <module>
    from hypothesmith.syntactic import identifiers
  File "/tmp/test_hypothesmith/.virtualenv/test_hypothesmith-dgeh/lib/python3.10/site-packages/hypothesmith/syntactic.py", line 21, in <module>
    LARK_GRAMMAR = read_text("hypothesmith", "python.lark")
  File "/usr/lib/python3.10/importlib/resources.py", line 103, in read_text
    with open_text(package, resource, encoding, errors) as fp:
  File "/usr/lib/python3.10/importlib/resources.py", line 82, in open_text
    open_binary(package, resource), encoding=encoding, errors=errors
  File "/usr/lib/python3.10/importlib/resources.py", line 46, in open_binary
    return reader.open_resource(resource)
  File "/usr/lib/python3.10/importlib/abc.py", line 433, in open_resource
    return self.files().joinpath(resource).open('rb')
  File "/usr/lib/python3.10/pathlib.py", line 1119, in open
    return self._accessor.open(self, mode, buffering, encoding, errors,
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/test_hypothesmith/.virtualenv/test_hypothesmith-dgeh/lib/python3.10/site-packages/hypothesmith/python.lark'

I assume it's related to the recent lark/lark-parser snafus

jakkdl commented 1 year ago

See https://github.com/Zac-HD/flake8-trio/actions/runs/3584245303/jobs/6030668423 for a CI job failing with it

Zac-HD commented 1 year ago

Ooh, I think this is because the file name changed in 0.2.1, so it's not packaged up properly anymore. Which still works with editable installs only... oops.

Zac-HD commented 1 year ago

Fixed by 148dc61c46d2f9d20eb4c11911ebb11ad3f6a5f0, which is released as version 0.2.3 😅