EnviousStarfish54 you can use Use Task.set_credentials
Notice that OS environment or trains.conf will override the programmatic credentials
https://allegro.ai/docs/task.html#trains.task.Task.set_credentials
You can add something like:
import os from trains.backend_config.defs import LOCAL_CONFIG_FILES if not os.path.exists(LOCAL_CONFIG_FILES[0]): Task.set_offline(offline_mode=True)
notice that LOCAL_CONFIG_FILES is a list
if the conf file doesnt exists, turn on offline mode (will save you task locally).
currently I do it in a hacky way. I call trains.backend_api Session, and check if 'demoapp' in web server URL.
Hi EnviousStarfish54 ,
You can add environment vars in you code, and trains will use those (no configuration file is needed)
import os os.environ["TRAINS_API_HOST"] = "YOUR API HOST " os.environ["TRAINS_WEB_HOST"] = "YOUR WEB HOST " os.environ["TRAINS_FILES_HOST"] = "YOUR FILES HOST "
Can this do the trick?
I need this as I want to write a wrapper for internal use.
I need to block the default behavior that link to public server automatically when user has no configuration file.
I mean, once I add environment variable, can trains.conf overwrite it? I am guessing environment variable will have a higher hierarchy.
The things that I want to achieve is:
Block user to access to public server If they configure trains.conf, then it's fine
import os os.environ["TRAINS_API_HOST"] = "YOUR API HOST " os.environ["TRAINS_WEB_HOST"] = "YOUR WEB HOST " os.environ["TRAINS_FILES_HOST"] = "YOUR FILES HOST "
is it possible to overwrite if trains.conf did exist
This will cause a redundant Trains session, I guess.
I don't want to mess with the standard setup.
I just need a way to check if the web/app host is configured.
If yes, go ahead. If not, offline/throw an error
AgitatedDove14 Thanks! This seems to be a more elegant solution
So if you have ~/trains.conf
work with it, if you don't, work offline?
I want a reliable way, so I don't want to hardcode to check if trains.conf exist in a certain path
is it possible to overwrite if trains.conf did exist
Yes, you can choose specific configuration file with TRAINS_CONFIG_FILE
environment var.