python setuptools构建多个文件

时间:2018-09-27 20:04:18

标签: python build setuptools distutils

我想做的是编译多个文件,并且它们的输出是一个模块。

项目:

ModuleA
|
+--file1.py
|
+--file2.py
|
+--setup.py

setup.py

from setuptools import setup

setup(
    name='example',
    version='1.0',
    url='',
    license='MIT',
    author='Francisco',
    author_email='',
    description='',
    package_dir={'ModuleA':'./*'},
    py_modules=['file1','file2'],
    zip_safe=False,
    include_package_data=True,
    platforms='any',
)

我需要的输出是 python setup.py install

site-packages
|
+--ModuleA
   |
   +--file1.py
   +--file2.py

1 个答案:

答案 0 :(得分:0)

ModuleA从技术上讲是package。我建议您使用setuptools中的find_packages实用工具:

from setuptools import setup, find_packages

setup(
    name='example',
    version='1.0',
    url='',
    license='MIT',
    author='Francisco',
    author_email='',
    description='',
    packages=find_packages(),
    zip_safe=False,
    include_package_data=True,
    platforms='any',
)

目录结构:

$ tree
.
...
├── ModuleA
│   ├── file1.py
│   ├── file2.py
│   └── __init__.py
└── setup.py

现在构建软件包:

$ python setup.py bdist_wheel
....
$ unzip -l dist/example-1.0-py2-none-any.whl 
Archive:  dist/example-1.0-py2-none-any.whl
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2018-09-27 21:53   ModuleA/file2.py
        0  2018-09-27 21:53   ModuleA/file1.py
        0  2018-09-27 21:53   ModuleA/__init__.py
       10  2018-09-27 21:53   example-1.0.dist-info/DESCRIPTION.rst
      305  2018-09-27 21:53   example-1.0.dist-info/metadata.json
        8  2018-09-27 21:53   example-1.0.dist-info/top_level.txt
       92  2018-09-27 21:53   example-1.0.dist-info/WHEEL
      163  2018-09-27 21:53   example-1.0.dist-info/METADATA
      693  2018-09-27 21:53   example-1.0.dist-info/RECORD
---------                     -------
     1271                     9 files