-
-
Notifications
You must be signed in to change notification settings - Fork 656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] Accessing absolute directory of the executed file as a config variable #1277
Comments
Yes. this is documented in the basic tutorial here. |
Hey @omry, So for example, when I execute my file from some outside directory like this: python some/path/main.py I want to access global absolute path of Can this be done with some specialised variable in config similar to Also, my real use case is that I want the hydra logs to be always next to my |
What if your main.py is in a Python wheel (maybe even in a zipped wheel?) You can try:
I don't think it's possible right now. |
I have a similar issue. I have a txt file along with a module file and I want to load the content of the text file in the module. I wrote the code like:
but when I run the code, the module tries to find the file on some path under the output directory. I think hydra should not break the meaning of |
|
Thank you for your clarification. I misunderstand the problem. I move the code to the module level and it runs successfully. And thanks for the suggested material. Learned a lot from them. |
I'm not sure if this solves your problem but I used this in a recent project
which I think could be customized for what you need, then I was able to refer to files like:
which gets me a path that is relative to the file that is being executed
Probably won't work in this case though I think |
Reading this issue again, I am not sure this makes sense to me:
The configs being relative to the file with I don't think that you suggestion to add I am closing this for now, feel free to followup if you want to discuss this. |
How does python execute a zipped wheel? Presumably it has to decompress it right? |
No. it can do it directly from the wheel. The correct way to access resources is using a dedicated API like importlib_resources and not relative to |
create a zip file with a file called print("Hello from ", __file__) Run the zip with Python:
|
I'll have to look into this more but according to pep 427 part of installing a wheel is extracting it: https://www.python.org/dev/peps/pep-0427/#installing-a-wheel-distribution-1-0-py32-none-any-whl I know about importlib but I forget the details, there might be a way to include it in the interpolation I wrote to make something more universal |
🚀 Feature Request
I would like to access absolute directory of my main file. Usually I do it like this:
But hydra changes working directory so this doesn't work anymore.
hydra.utils.get_original_cwd() gives me working directory the app was executed from, which is not what I need.
It would be best if I could access absolute directory of my main file like this:
Motivation
This is important if user wants to make execution independent of working directory the app was executed from.
(I have paths in my config that I always want to be relative to placement of my executed file, so I want to join them with absolute path of directory of executed file)
Suggestion
Maybe there could be some new special variables available in hydra like the ${hydra:runtime.cwd}? For example:
The text was updated successfully, but these errors were encountered: