创建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
答案 0 :(得分:2)
如何更改cwd
?
import os
os.chdir(__file__)
conftest.py
听起来像个好地方。或者附加到test
命令的文件。
答案 1 :(得分:2)
所以这就是我所做的并且有效:
import os
import pkg_resources
os.chdir(pkg_resources.get_distribution('mypackage').location)
# running as if the script is invoked from project's root