<Comment on #20206 How To Run a Python Source That...
# github-notifications
c
Comment on #20206 How To Run a Python Source That Uses Files In Repo Subdirectory Discussion answered by justicefreed Wrapping my service inside another python script that also changes the working directory seems to satisfactorily do everything I need to here. Thanks @huonw for the assistance. For others, what I now have is the below files:
repo_name/projects/myservice/dev-main-wrapper.py
Copy code
"""Simple wrapper function to run src/main.py in the right context"""
import os
from src.main import main

os.chdir("./components/MTConnectClient")

main()
`repo_name/projects/myservice/BUILD`:
Copy code
python_requirements(
    name="reqs",
    source="requirements.txt",
)

pex_binary(
    name="pex_binary",
    entry_point="src/main.py",
    dependencies=[":reqs"]
)

python_source(
    name="runner",
    source="dev-main-wrapper.py",
    dependencies=[":reqs"]
)
This works well it seems, and packaging via PEX loads the file as expected too, and all the dependencies get loaded correctly. pantsbuild/pants