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

前端 未结 6 1570
礼貌的吻别
礼貌的吻别 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:54

    Introduction

    I came across this post and spent some time figuring out how to add specific sub-modules to my package, so I will post my solution here.

    Solution

    In my package root folder, I have a setup.py file see doc
    In this file, I have the following code:

    from setuptools import setup
    
    with open("README.md", "r") as fh:
        long_description = fh.read()
    
    setup(
        name='package name',
        version='0.4.1',
        description='short description',
        long_description=long_description,
        long_description_content_type="text/markdown",
        url='repository url',
        author='My name',
        author_email='my@e.mail',
        license='MIT',
        packages=['PackageName','PackageName.SubModule'],
        zip_safe=False,
        install_requires=[
            'dependecy1',
        ],
        classifiers=[
            'Development Status :: 3 - Alpha',
            'License :: OSI Approved :: MIT License',
            'Programming Language :: Python :: 3.7'
        ]
    )
    
    

    The interesting part to answer the question, here is : packages=['PackageName','PackageName.SubModule'],

    By following this syntax, you can include sub-modules to your main package distribution.

    More info about all the others arguments can be found in the doc.

提交回复
热议问题