Pex_config configs now know where they are

dm-dev
Tags: #<Tag:0x00007f61a3686b70>

(Tim Jenness) #1

A discussion on Slack prompted @erykoff to wonder why he could not use __file__ inside a pex_config configuration file given that they are python files. I looked at the code and it turned out to be easy to add support for this and this morning I merged it.

The main use case is the case where you want to load a secondary config from the same directory. At the moment our config files look like this:

import os.path
from lsst.utils import getPackageDir

config.load(os.path.join(getPackageDir("obs_lsst"), "config", "latiss", "latiss.py"))

but now you can do something more explicitly requesting the latiss.py from the same directory:

import os.path
config.load(os.path.join(os.path.dirname(__file__), "latiss.py"))

Before making any changes it’s important to understand that the two approaches are different. The first one allows you to reference another config location through a setup package and that location might be unrelated to where the original file is situated (which can happen if you have forgotten to setup a local package and then get confused when it picks up the second file from an installed stack location). The second option absolutely requires that you treat the collection of configs as a self-consistent unit that should move around together and that should be kept in sync together.


(Paul Price) #2

I also expect the use of __file__ will be faster, since you’re not incurring eups overheads.