今天我创建了一个 setup.py 文件,发现一个工作脚本和两个无工作场景。在两个非工作场景package_data
中,构建中缺少 after。我用python setup.py sdist
.
为什么方案 2 和 3 不包含我的包裹数据?
方案 1 工作:
import os
from distutils.core import setup
def find_packages(path):
package_path = os.path.join(os.path.dirname(__file__), path)
packages = []
for f in os.walk(package_path):
directory_name = f[0]
if directory_name.endswith('egg-info') or directory_name.endswith('path'):
continue
directory_name = directory_name.replace(package_path, '').replace('/', '.').strip()
if not len(directory_name):
continue
if directory_name.startswith('.'):
directory_name = directory_name.replace('.', '', 1)
packages.append(directory_name)
return packages
setup (
name = 'mypkg',
packages = find_packages('src'),
package_dir = {'mypkg': 'src/mypkg'},
include_package_data = True,
package_data = {
'': ['*.txt'],
'mypkg': ['data/*.dat'],
}
)
方案 2,不起作用:
from setuptools import setup #, find_packages
from setuptools.command import sdist
setup (
name = 'mypkg',
packages = ['mypkg'],
package_dir = {'mypkg': 'src/mypkg'},
include_package_data = True,
package_data = {
'': ['*.txt'],
'mypkg': ['data/*.dat'],
}
)
场景 3 也不起作用:
from setuptools import find_packages
from setuptools.command import sdist
setup (
name = 'mypkg',
packages = find_packages('src'),
package_dir = {'mypkg': 'src/mypkg'},
include_package_data = True,
package_data = {
'': ['*.txt'],
'mypkg': ['data/*.dat'],
}
)