Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable yacc write_tables to prevent warnings/errors down the line #63

Merged
merged 1 commit into from
Dec 7, 2020

Conversation

sochotnicky
Copy link

When djangoql is used within an application which gets installed in a system location (unwritable by
the application itself), yacc command fails with a traceback:

  File "/usr/lib/python3.9/site-packages/djangoql/queryset.py", line 36, in apply_search
    ast = DjangoQLParser().parse(search)
  File "/usr/lib/python3.9/site-packages/djangoql/parser.py", line 39, in __init__
    self.yacc = yacc.yacc(module=self, **kwargs)
  File "/usr/lib/python3.9/site-packages/ply/yacc.py", line 3488, in yacc
    errorlog.warning("Couldn't create %r. %s" % (tabmodule, e))
  File "/usr/lib/python3.9/site-packages/ply/yacc.py", line 118, in warning
    self.f.write('WARNING: ' + (msg % args) + '\n')
BrokenPipeError: [Errno 32] Broken pipe

This because yacc tries to write to this location:

  File "/usr/lib/python3.9/site-packages/ply/yacc.py", line 3484, in yacc
    lr.write_table(tabmodule, outputdir, signature)
  File "/usr/lib/python3.9/site-packages/ply/yacc.py", line 2734, in write_table
    f = open(filename, 'w')
PermissionError: [Errno 13] Permission denied: '/usr/lib/python3.9/site-packages/djangoql/parsetab.py'

Adding write_tables=False will disable this behaviour making the error go away

When djangoql is used within an application which gets installed in a system location (unwritable by
the application itself), yacc command fails with a traceback:

  File "/usr/lib/python3.9/site-packages/djangoql/queryset.py", line 36, in apply_search
    ast = DjangoQLParser().parse(search)
  File "/usr/lib/python3.9/site-packages/djangoql/parser.py", line 39, in __init__
    self.yacc = yacc.yacc(module=self, **kwargs)
  File "/usr/lib/python3.9/site-packages/ply/yacc.py", line 3488, in yacc
    errorlog.warning("Couldn't create %r. %s" % (tabmodule, e))
  File "/usr/lib/python3.9/site-packages/ply/yacc.py", line 118, in warning
    self.f.write('WARNING: ' + (msg % args) + '\n')
BrokenPipeError: [Errno 32] Broken pipe

This because yacc tries to write to this location:
  File "/usr/lib/python3.9/site-packages/ply/yacc.py", line 3484, in yacc
    lr.write_table(tabmodule, outputdir, signature)
  File "/usr/lib/python3.9/site-packages/ply/yacc.py", line 2734, in write_table
    f = open(filename, 'w')
PermissionError: [Errno 13] Permission denied: '/usr/lib/python3.9/site-packages/djangoql/parsetab.py'

Adding write_tables=False will disable this behaviour making the error go away
@sochotnicky
Copy link
Author

If this change is unwanted for general use case - I can make this overridable and keep the default to write the tables of course

@vkrizan
Copy link
Contributor

vkrizan commented Dec 4, 2020

See also #53

@stebunovd stebunovd merged commit fcb6bb9 into ivelum:master Dec 7, 2020
@stebunovd
Copy link
Member

thank you for the PR!

I've also replaced parsetab.py with the latest version compatible with PLY 3.11. So for users of the latest PLY version, the parser will be initialized slightly faster. I suppose it should be the majority of users. And for others, it'll at least not crash, thanks to the write_tables option.

I plan to release it to PyPI soon, together with one more bugfix. It'll be v0.14.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants