Examples: query, "exact match", wildcard*, wild?ard, wild*rd
Fuzzy search: cake~ (finds cakes, bake)
Term boost: "red velvet"^4, chocolate^2
Field grouping: tags:(+work -"fun-stuff")
Escaping: Escape characters +-&|!(){}[]^"~*?:\ with \, e.g. \+
Range search: properties.timestamp:[1587729413488 TO *] (inclusive), properties.title:{A TO Z}(excluding A and Z)
Combinations: chocolate AND vanilla, chocolate OR vanilla, (chocolate OR vanilla) NOT "vanilla pudding"
Field search: properties.title:"The Title" AND text
Answered
Hi, I Am Trying To Setup The Path To Trains.Conf File Programatically And Having Trouble.. We Tried Using Os.Environ['Trains_Config_File'] = Path, And Also Other Variations Of Overriding The Trains.Backend_Config.Defs But Nothing Seem To Work.. When Creat

Hi, I am trying to setup the path to trains.conf file programatically and having trouble..
we tried using os.environ['TRAINS_CONFIG_FILE'] = path, and also other variations of overriding the trains.backend_config.defs but nothing seem to work.. when creating a task the default path is still there.. any answer \ reference will be appreciated, Thanks

  
  
Posted 3 years ago
Votes Newest

Answers 17


Hi RipeGoose2

when creating a task the default path is still there

What do you mean by "PATH" do you want to provide path for the config file? is it for trains manual execution or the agent ?

  
  
Posted 3 years ago

thanks!

  
  
Posted 3 years ago

The problem is, the configuration is loaded at import time, so there is no "time" to pass anything other than environment variable.
That said if the only difference is server config you can use
Task.set_credentials

  
  
Posted 3 years ago

Programmatically before , importing the package, set os.environ['TRAINS_CONFIG_FILE']='~/my_new_trains.conf'
BTW: What's the use case for doing so?

thanks for helping again

My pleasure :)

  
  
Posted 3 years ago

I'll try to go with this option, I think its actually perfect for my needs

  
  
Posted 3 years ago

AgitatedDove14 the option you mentioned just before sounds much better for me, I must admit I find the name of the method confusing. I came across it before but thought its only relevant for credentials

  
  
Posted 3 years ago

Hi RipeGoose2

when I'm using the set_credentials approach does it mean the trains.conf is redundant? if

Yes this means there is no need for trains.conf , all the important stuff (i.e. server + credentials you provide from code).
BTW: When you execute the same code (i.e. code with set_credentials call) the agent's coniguration will override what you have there, so you will be able to run the Task later either on prem/cloud without needing to change the code itself 🙂

  
  
Posted 3 years ago

I came across it before but thought its only relevant for credentials

We are working on improving the docs, hopefully it will get clearer 😉

  
  
Posted 3 years ago

I didn't get to test it on the cloud yet and trying to make final adjustments

  
  
Posted 3 years ago

AgitatedDove14 The use case is conditional choice of a server config, when ran locally or on the cloud..
I was trying to do exactly as you mentioned setting the environment variable before any trains import but it didn't work (and also its a mess in terms of my code).. I was hoping there is another way to go about it.. if not I'll try to create a minimal reproducible example..

  
  
Posted 3 years ago

I was trying to do exactly as you mentioned setting the environment variable 

before

 any trains import but it didn't work

In your entry point script, (even if you do not call trains/ Task.init ) add:
import os os.environ['TRAINS_CONFIG_FILE']='~/my_new_trains.conf' import trainsThen when you actually import trains, everything is already set and it will not read the configuration again.
Make sense ?

  
  
Posted 3 years ago

hi AgitatedDove14 , when I'm using the set_credentials approach does it mean the trains.conf is redundant? if the file doesn't exists on the machine, will it be an issue? if not, so what defaults should I assume for the rest of the values?

  
  
Posted 3 years ago

AgitatedDove14 it does, and it did, but for some reason I couldn't make it to work this way..
I require some additional imports before to infer the config path dynamically.. but even when I stripped down the code and made sure there is no other trains imports anywhere it still didn't work..

  
  
Posted 3 years ago

thanks for helping again 🙂

  
  
Posted 3 years ago

I'll try to go with this option, I think its actually perfect for my needs

Great!

  
  
Posted 3 years ago

Hi AgitatedDove14 , path to the config file for trains manual execution

  
  
Posted 3 years ago
1K Views
17 Answers
3 years ago
one year ago
Tags