I have a python cli app that we're migrating to pa...
# general
l
I have a python cli app that we're migrating to pants. It writes logs to a directory named "logs" at the top-level of the project directory tree. This is currently accomplished by using a path relative to
__file__
in one of the files in the project's root. We do it this way in order to avoid being sensitive to the working directory the command is run from, and to avoid making any assumptions about where the code lives on a user's file system. But unsurprisingly, when I run this as a pex, it now writes to a directory under
~/.pex/user_code
, which is not what I want. Is there a good pattern for figuring out a directory outside the pex build, without being sensitive to the current working directory?
g
Option (1): pass it as an arg to the application Option (2): when you
pants run
, it'll use the workspace as working directory by default Option (3): use something like
platformdirs
to resolve a place to log to
Not very helpfully, we use all three contextually in our codebase, depending on the type of things we want to write. Logs always go to
platformdirs.user_log_dir()
(or similar), direct artifacts to cwd, other workspaces passed by path.
l
Option (2): when you
pants run
, it'll use the workspace as working directory by default
This is what I was missing, and I think it makes the most sense in this case. But all of these options are helpful and I can see them being useful for different things. Thanks very much!