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

Don't pollute the working directory with lextab and yacctab #2

Open
natezb opened this issue Feb 8, 2017 · 5 comments
Open

Don't pollute the working directory with lextab and yacctab #2

natezb opened this issue Feb 8, 2017 · 5 comments

Comments

@natezb
Copy link
Collaborator

natezb commented Feb 8, 2017

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.

@natezb
Copy link
Collaborator Author

natezb commented Apr 5, 2017

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.

@natezb natezb closed this as completed Apr 5, 2017
@superted6851
Copy link

superted6851 commented May 15, 2020

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

@natezb
Copy link
Collaborator Author

natezb commented May 18, 2020

I am able to reproduce this, I'l look into it.

@natezb natezb reopened this May 18, 2020
@superted6851
Copy link

superted6851 commented May 18, 2020

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.

@Tillsten
Copy link
Contributor

Tillsten commented Feb 9, 2022

This still happens for me.

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

No branches or pull requests

3 participants