Python setuptools - 在子文件夹中维护文本文件引用?

Python setuptools - maintain text file reference in a subfolder?

我有一个应用程序,当未传递命令行参数时,默认使用文件夹 ./wordlists 中的默认文件。这在主机文件夹外工作正常,但是一旦我 运行 setup.py install 应用程序丢失了引用,我不确定为什么。

这是我现在的 setup.py:

from setuptools import find_packages, setup


def dependencies(file):
    with open(file) as f:
        return f.read().splitlines()

with open("README.md") as f:
    setup(
        name="<redacted>",
        license="<redacted>",
        description="<redacted>",
        long_description=f.read(),
        author="<redacted>",
        author_email="<redacted>",
        url="<redacted>",
        packages=find_packages(exclude=('tests')),
        package_data={'wordlists': ['*.txt', './wordlists/*.txt']},
        scripts=['<redacted>'],
        install_requires=dependencies('requirements.txt'),
        tests_require=dependencies('test-requirements.txt'),
        include_package_data=True)

如前所述,我可以 运行 我的目录中的应用程序使用:

python ./VHostScan.py -t <target>

然后它将默认为单词表:

./wordlists/virtual-host-scanning.txt

然而,在使用 ./setup.py install 然后尝试 运行 应用程序后,它失去了 link 到单词列表。

这是我试图添加到我的 setup.py 中的内容,但我猜我需要在此处进行更改,或者在词表引用所在的位置进行更改:

package_data={'wordlists': ['*.txt', './wordlists/*.txt']},

这是我引用默认单词表文件的方式:

DEFAULT_WORDLIST_FILE = os.path.join(
    os.path.dirname(os.path.abspath(__file__)),
    'wordlists',
    'virtual-host-scanning.txt'
)

如有需要,可在此处获取完整的代码库:https://github.com/codingo/VHostScan/

setup.py和你的包裹有问题:

  1. 您在顶部有一个模块 VHostScan.py,但未在 setup.py 中列出;因此它没有安装,也没有包含在二进制发行版中。

修复:添加 py_modules=['VHostScan.py'].

  1. 目录 wordlists 不是 Python 包,因此 find_packages 找不到它,因此不包含 package_data 个文件。

我看到了 2 种修复方法:

a) 将目录 wordlists 设为 Python 包(添加一个空的 __init__.py);

b) 将 package_data 应用于 lib 包:

package_data={'lib': ['../wordlists/*.txt']},