billions-bear-56484
08/26/2022, 2:38 PM- ./pants
- src
- python
- shared
- BUILD
- logging
- BUILD
- config.json
- accounts
- BUILD
- api
- server.py
- ...
What I want to do is to include the config.json
into the accounts package to be able to use a shared logging configuration.
This is the BUILD file in src/python/shared/logging
resource(
name="config",
source="config.json",
)
This is my pex_binary
in src/python/accounts/BUILD
where I want to use the config.json
pex_binary(
name="serve",
restartable=True,
dependencies=[
"src/python/shared/logging:config",
":sources",
],
entry_point="api/server.py",
shebang="/usr/bin/env python3",
)
```
If I got it right from documentation I should be able to set the path relative from the source root. In my case I have the `api/server.py` where I’m launching a uvicorn server with the following command:
```if __name__ == "__main__":
uvicorn.run(
get_app(),
host="0.0.0.0",
port=8000,
log_config="config.json",
)
What is the source root in that case? Currently I always get the error FileNotFoundError: [Errno 2] No such file or directory: 'config.json'
.
Thanks in advance ☀️bitter-ability-32190
08/26/2022, 2:40 PMsrc/python
) use shared/logging/config.json
.__file__
f"{__file__}/../../shared/logging/config.json
(or whatever the right path is)billions-bear-56484
08/26/2022, 2:46 PMNotADirectoryError: [Errno 20] Not a directory: '…/.pants.d/tmpi03th7ds/src/python/accounts/api/server.py/../../shared/logging/config.json'
bitter-ability-32190
08/26/2022, 2:48 PMpathlib
I suppose is our friendstr(pathlib.PurePath(__file__, "../../shared/logging/config.json").resolve())
billions-bear-56484
08/26/2022, 2:52 PMbitter-ability-32190
08/26/2022, 3:06 PMbillions-bear-56484
08/26/2022, 3:07 PMstr(pathlib.PurePath(__file__, "../../shared/logging/config.json").resolve())
bitter-ability-32190
08/26/2022, 3:07 PMbillions-bear-56484
08/26/2022, 3:12 PMbitter-ability-32190
08/26/2022, 3:20 PMbillions-bear-56484
08/26/2022, 3:25 PMbitter-ability-32190
08/26/2022, 3:33 PMbillions-bear-56484
08/26/2022, 3:58 PM