Search code examples
setuptoolsdistutilspython-packaging

how can setup.py sdist dereference symbolic links?


The setup.cfg section data_files contains a directory with symbolic links. When running python setup.py sdist, the resulting distribution does not contain the symbolic links, they are ignored. Here is the content of setup.py, based on pbr:

#!/usr/bin/env python

from setuptools import setup

setup(
    setup_requires=['pbr'],
    pbr=True,
)

It would be fine to dereference the symbolic links and include the actual file instead. The distribution would be bigger because files are duplicated, but it would be complete.

Looking at the sdist sources it is looks like the symbolic links are always ignored:

$ python setup.py sdist
...
'molecule/debops' not a regular file -- skipping
...

Is there a workaround to convince sdist to dereference the symbolic links?


Solution

  • The MANIFEST.in graft command is unfortunately not in the python 3 documentation, but can be found in the sources. It calls include_pattern and findall which follows symbolic links. It is therefore enough to add the following line to MANIFEST.in:

    graft molecule/
    

    to ensure the molecule/ tree is included in the distribution and that all symbolic links will be followed. This indeed leads to duplicate content but the result is complete.

    The root cause of the symbolic link suppression is that (unlike to sdist) pbr walks the directories mentionned in data_files without following symbolic links. It will therefore create a list of paths in the SOURCES.txt file that contain symbolic links. And they will be ignored by sdist and never make it to the distribution.