Search code examples
pythongithubgitignore

Github python gitignore, why is c extension ignored? Is there a better way to use C in Python?


Recently I pushed a Python package to github, and I noticed that all .so files are not uploaded.

And in the default .gitignore, I found out

# C extensions
*.so

Why?

I'm not familiar with C++, and I was told that the .so files are created with pybind.

Does this mean that there is a better way to use C++ code in python?


Solution

  • Any file that can be re-generated after cloning your repository should be ignored.
    (and they are indeed ignored by a python-based .gitignore)

    This is not limited to *.so files, but applies also to any file in distribution folder (dist/) or cache folder (__pycache__/)

    That promotes a source dependencies (meaning you include the C sources in your repository, as well as a Makefile allowing to quickly rebuild the C artifact)