将console_scripts创建为entry_points时,如何访问包中的数据文件(package_data)?
setup(
# other stuff
entry_points={
'console_scripts': [
'runme = mypackage.a_py_file:a_function_within_the_py_file',
]
}
)
目录结构:
├── mypackage
│ ├── __init__.py
│ └── a_py_file.py
├── requirements.txt
├── setup.py
└── data
├── a.data
└── b.data
用于处理console_scripts的Python文件:
# a_py_file.py
def a_function_within_the_py_file:
# HOW TO READ a.data FILE HERE
解决方法:
改变cwd怎么样?
import os
os.chdir(__file__)
conftest.py听起来像个好地方.或者附加到测试命令的文件.