mailgun / flanker

Python email address and Mime parsing library
http://www.mailgun.com
Apache License 2.0
1.63k stars 204 forks source link

Suppress unreachable symbol warnings; don't write cached tables #250

Closed mikebveil closed 1 year ago

mikebveil commented 3 years ago

Address two outstanding issues that are especially a problem when using flanker in a frozen application (i.e. using pyinstaller).

231 Disable warnings on first run

When addresslib is first imported, the yacc parser gets run and logs a bunch of warnings about missing symbols. This pollutes the stdout (or maybe stderr) of the application using it. And when freezing with pyInstaller, the directory with cached tables is removed between runs, so this happens on every run. I have no idea if these warnings are themselves a bug, but they shouldn't be exposed like this and setting check_recursion=False suppresses them.

208 Don't generate cached parser tables

When running in a read-only filesystem, yacc will fail to write out the cached parser tables. This affects, for example, AWS Lambda and pyInstaller builds. It's not fatal, but it does generate an error in the application output each time.

There is a cost to write_tables=False, since we will have to re-parse on the next startup. But it's worth noting that the next version of the yacc module will do away with caching entirely, and the author considers it of negligible performance benefit:

PLY no longer writes cached table files. Honestly, the use of the cached files made more sense when I was developing PLY on my 200Mhz PC in 2001. It's not as much as an issue now. For small to medium sized grammars, PLY should be almost instantaneous. If you're working with a large grammar, you can arrange to pickle the associated grammar instance yourself if need be.

Testing

Have verified no regressions in nosetests.

mailgun-ci commented 3 years ago

Can one of the admins verify this patch?

Torxed commented 1 year ago

If this PR isn't what the authors would want, at least do:

log = logging.getLogger(__name__)
+ log.level = logging.ERROR

in https://github.com/mailgun/flanker/blob/551813cfa4ca3fb29c63ec322d1aa10de138a044/flanker/addresslib/_parser/parser.py#L7-L9

We're 2 years in to this PR, and the WARNING: Symbol '...' is unreachable is still at large.

Torxed commented 1 year ago

Due to age and by popular community request I will merge this. However I am not a python maintainer and have not vetted this PR.

Thank you! Our logs and storage are forever in your debt! ^^

danielkauffman commented 1 year ago

Thank you! This should resolve https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1033714

danielkauffman commented 1 year ago

Is there a release schedule for flanker? Would be great to get this package into Debian Bookworm, which is currently approaching release.

danielkauffman commented 7 months ago

Is there a release schedule for flanker? Would be great to see this patch released and in Debian.