eliben/pycparser

fake_libc_include not included in distributed version of library

inglesp opened this issue · 9 comments

The fake_libc_include directory is not included in the version of the library installed from PyPI with pip.

This means that I cannot do something like:

pycparser_path = os.path.basename(pycparser.__file__)
include_path = os.path.join(pycparser_path, 'utils', 'fake_libc_include')
ast = parse_file(filename, use_cpp=True, cpp_args=rf'-I{include_path}')

Instead I have to vendor fake_libc_include (which is not the end of the world!).

Would you consider a patch to fix this?

s/consider/consider accepting/

It's listed here: https://github.com/eliben/pycparser/blob/master/MANIFEST.in#L4

And I do see it in the distribution tarball -- are you sure pip doesn't install it?

I'm pretty sure... I've pip installed the libary into a fresh virtualenv, and it's not there:

~/.pyenv/versions/pycparser-test/lib/python3.6/site-packages/pycparser $ tree
.
├── __init__.py
├── __pycache__
│   ├── __init__.cpython-36.pyc
│   ├── _ast_gen.cpython-36.pyc
│   ├── _build_tables.cpython-36.pyc
│   ├── ast_transforms.cpython-36.pyc
│   ├── c_ast.cpython-36.pyc
│   ├── c_generator.cpython-36.pyc
│   ├── c_lexer.cpython-36.pyc
│   ├── c_parser.cpython-36.pyc
│   ├── lextab.cpython-36.pyc
│   ├── plyparser.cpython-36.pyc
│   └── yacctab.cpython-36.pyc
├── _ast_gen.py
├── _build_tables.py
├── _c_ast.cfg
├── ast_transforms.py
├── c_ast.py
├── c_generator.py
├── c_lexer.py
├── c_parser.py
├── lextab.py
├── ply
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-36.pyc
│   │   ├── cpp.cpython-36.pyc
│   │   ├── ctokens.cpython-36.pyc
│   │   ├── lex.cpython-36.pyc
│   │   ├── yacc.cpython-36.pyc
│   │   └── ygen.cpython-36.pyc
│   ├── cpp.py
│   ├── ctokens.py
│   ├── lex.py
│   ├── yacc.py
│   └── ygen.py
├── plyparser.py
└── yacctab.py

3 directories, 35 files

I'm using pip 9.0.1 and Python 3.6.0:

$ pip --version
pip 9.0.1 from /Users/inglesp/.pyenv/versions/3.6.0/envs/pycparser-test/lib/python3.6/site-packages (python 3.6)

This SO answer suggests that pip ignores top-level "non-package" directories, and that a solution would be to move the utils directory inside the pycparser directory.

But moving it would break compatibility for projects that rely on it being there :)

I'd say I'm not too excited about making this change, to be completely honest. It's easy enough to distribute this directory with pycparser in some way, I don't know if I'd force it to be installed since it's not strictly necessary for the package (pycparser really wants to see preprocessed source code -- this dir is used by the preprocessor, not pycparser)

Sounds reasonable! Thanks for taking the time to respond.

If I submit a Pull Request for this feature, would you be willing to add it? I feel like I can add it without breaking anything since its not there to begin with. You'd have to make additions to setup.py as my understanding, the MANIFEST.in is just for the sdist packaging.

@drebbe-intrepid I think I prefer not installing it. pycparser itself doesn't need or use it.

For anyone still strugling I found this to work for me:

fake_libc_path = files('pycparser').joinpath('utils/fake_libc_include')
ast = parse_file(filename, use_cpp=True,
                 cpp_path='gcc',
                 cpp_args=['-E', r'-I{}'.format(fake_libc_path)])

Hope this helps. Also this only worked on Linux (Mac C libraries seemed to conflict

For anyone still strugling I found this to work for me:

fake_libc_path = files('pycparser').joinpath('utils/fake_libc_include')
ast = parse_file(filename, use_cpp=True,
                 cpp_path='gcc',
                 cpp_args=['-E', r'-I{}'.format(fake_libc_path)])

Hope this helps. Also this only worked on Linux (Mac C libraries seemed to conflict

I don't know what files does, but even so fake_libc_include is not present on my system. #413

A quick solution for me was this:
https://pypi.org/project/pycparser-fake-libc/