Python设置工具在子文件夹中维护文本文件引用?

2024-04-26 17:32:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个应用程序,当没有传递命令行参数时,默认为文件夹./wordlists中的默认文件。这在主机文件夹中运行得很好,但是一旦我运行setup.py install,应用程序就会丢失引用,我不确定为什么。你知道吗

这是我现在的工作设置.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并尝试运行应用程序之后,它会丢失到单词列表的链接。你知道吗

这就是我一直试图加入我的设置.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/


Tags: installpytxt应用程序package列表dataos
1条回答
网友
1楼 · 发布于 2024-04-26 17:32:37

setup.py和您的包中的问题:

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

要修复:添加py_modules=['VHostScan.py']。你知道吗

  1. 目录wordlists不是Python包,因此find_packages找不到它,因此package_data文件不包括在内。你知道吗

我有两种解决方法:

a)使目录wordlists成为Python包(添加一个空的__init__.py

b)将package_data应用于lib包:

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

相关问题 更多 >