Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a `console_scripts` access file from `package_data`

When create a console_scripts as an entry_points, how do you access a data file (package_data) within the package?

setup(
    # other stuff
    entry_points={
        'console_scripts': [
            'runme = mypackage.a_py_file:a_function_within_the_py_file',
        ]
    }
)

Directory structure:

├── mypackage
│   ├── __init__.py
│   └── a_py_file.py
├── requirements.txt
├── setup.py
└── data 
    ├── a.data
    └── b.data

Python file to handle console_scripts:

# a_py_file.py
def a_function_within_the_py_file:
    # HOW TO READ a.data FILE HERE
like image 281
Sam R. Avatar asked Sep 08 '26 07:09

Sam R.


1 Answers

How about changing cwd?

import os
os.chdir(__file__)

conftest.py sounds like a good place to do this. Or the file which is attached to your test command.

like image 87
Dušan Maďar Avatar answered Sep 09 '26 21:09

Dušan Maďar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!