NiceLib
NiceLib copied to clipboard
Don't pollute the working directory with lextab and yacctab
Currently, whenever we use pycparser
(either directly or indirectly via cffi
), lextab.py
and yacctab.py
files are generated in the working directory. Instead, we should generate them in a temp directory.
Unfortunately, cffi
doesn't currently support setting this directory, though pycparser
does. As a hacky workaround, you can instantiate your own CParser
which will use a temp directory, then set it as the global parser instance in pycparser
.
See the pco
driver in Instrumental
for a working example of this.
My understanding now is that this is only happening for me b/c I'm using a local development version of pycparser
. An ordinary release version installed via pip
should not have this issue.
Some strange behaviour when installing from pip (pip install nicelib) _build_tables.py does not run on setup. Hence every time nicelib is imported it creates the tables. Only python setup.py install creates the tables every time.
pip install NiceLib/ -v
Output:
Build the lexing/parsing tables creating build/bdist.macosx-10.9-x86_64/wheel/NiceLib-0.7.dev0.dist-info/WHEEL creating '/private/var/folders/5m/vlz3kp392gx3ztcx3mxxzmy00000gn/T/pip-wheel-goa862fg/NiceLib-0.7.dev0-py2.py3-none-any.whl' and adding 'build/bdist.macosx-10.9-x86_64/wheel' to it adding 'nicelib/__about__.py' adding 'nicelib/__init__.py' adding 'nicelib/build.py' adding 'nicelib/nicelib.py' adding 'nicelib/platform.py' adding 'nicelib/process.py' adding 'nicelib/util.py' adding 'nicelib/parser/__init__.py' adding 'nicelib/parser/_build_tables.py' adding 'nicelib/parser/cpp_generator.py' adding 'nicelib/parser/cpp_lexer.py' adding 'nicelib/parser/cpp_parser.py' adding 'NiceLib-0.7.dev0.dist-info/LICENSE' adding 'NiceLib-0.7.dev0.dist-info/METADATA' adding 'NiceLib-0.7.dev0.dist-info/WHEEL' adding 'NiceLib-0.7.dev0.dist-info/top_level.txt' adding 'NiceLib-0.7.dev0.dist-info/RECORD' removing build/bdist.macosx-10.9-x86_64/wheel done
If it is run a second time then the tables are generated, so the behavoir is quite strange.
Build the lexing/parsing tables creating build/bdist.macosx-10.9-x86_64/wheel/NiceLib-0.7.dev0.dist-info/WHEEL creating '/private/var/folders/5m/vlz3kp392gx3ztcx3mxxzmy00000gn/T/pip-wheel-goa862fg/NiceLib-0.7.dev0-py2.py3-none-any.whl' and adding 'build/bdist.macosx-10.9-x86_64/wheel' to it adding 'nicelib/__about__.py' adding 'nicelib/__init__.py' adding 'nicelib/build.py' adding 'nicelib/nicelib.py' adding 'nicelib/platform.py' adding 'nicelib/process.py' adding 'nicelib/util.py' adding 'nicelib/parser/__init__.py' adding 'nicelib/parser/_build_tables.py' adding 'nicelib/parser/cpp_generator.py' adding 'nicelib/parser/cpp_lexer.py' adding 'nicelib/parser/cpp_parser.py' adding 'nicelib/parser/lextab.py' adding 'nicelib/parser/yacctab.py' adding 'NiceLib-0.7.dev0.dist-info/LICENSE' adding 'NiceLib-0.7.dev0.dist-info/METADATA' adding 'NiceLib-0.7.dev0.dist-info/WHEEL' adding 'NiceLib-0.7.dev0.dist-info/top_level.txt' adding 'NiceLib-0.7.dev0.dist-info/RECORD' removing build/bdist.macosx-10.9-x86_64/wheel done
I am able to reproduce this, I'l look into it.
Considering yacctab.py and lextab.py are generated by pycparser on installation can we not just link to these files? Seems just changing lines 16 and 17 of cpp_parser.py to
class CPPParser(CParser):
def __init__(self, **kwds):
kwds['lexer'] = CPPLexer
kwds['lextab'] = 'pycparser.lextab'
kwds['yacctab'] = 'pycparser.yacctab'
CParser.__init__(self, **kwds)
works.
This still happens for me.