Is it possible to include subdirectories using dist utils (setup.py) as part of package data?

前端 未结 6 1563
礼貌的吻别
礼貌的吻别 2021-01-03 17:54

Basically my python package is setup like:

module
\\_examples
  \\_folder1
     \\_file1.py
     \\_file2.py
  \\_folder2
    \\_file1.py
    \\_file2.py
         


        
6条回答
  •  独厮守ぢ
    2021-01-03 18:52

    None of the suggested answers worked for me in a similar situation.

    I needed to make a distribution with my package, which included several sub-modules in a sub-directory, so that these were the files I needed to go into sdist:

    ipyexperiments/*py
    ipyexperiments/utils/*py
    

    and no matter what I tried, the subdir utils's modules were not getting included in sdist.

    What worked for me is leaving config.py's default:

    # config.py
    from setuptools import setup, find_packages
    [...]
    setup(
        packages = find_packages(),
        [...]
    )
    

    but adding to MANIFEST.in:

    # MANIFEST.in
    graft ipyexperiments
    

    and everything under ipyexperiments was included.

    If you don't already have MANIFEST.in, create it at the same directory as config.py.

    I also added to MANIFEST.in

    prune tests
    global-exclude *.py[co]
    

    to exclude all of tests directory and any unwanted *pyc and *.pyo files anywhere.

提交回复
热议问题