# -*- python -*-

import lsst.sconsUtils
import os

# scons steals our environment away, so we have to reinstate it
env = lsst.sconsUtils.env.Clone()
for name in ("PYTHONPATH", "LD_LIBRARY_PATH",
             "DYLD_LIBRARY_PATH", "PATH"):
    if name in os.environ:
        env.AppendENVPath(name, os.environ[name])

# we may need an explicit library load path specified in the command
libpathstr = lsst.sconsUtils.utils.libraryLoaderEnvironment()

# We always run these commands with an explicit python rather than relying on
# the shebang
python = "{} python".format(libpathstr)

pipe_tasks_dir = lsst.sconsUtils.env.ProductDir('pipe_tasks')
data_dir = lsst.sconsUtils.env.ProductDir('obs_lsst_data')
command = (f"{python} {pipe_tasks_dir}/bin/ingestCuratedCalibs.py latiss/CALIB/ {data_dir}/latiss/defects "
           "--calib latiss/CALIB --config clobber=True")
commandInst = env.Command('CALIB/calibRegistry.sqlite3', [], command)
env.Depends(commandInst, lsst.sconsUtils.targets["python"])
env.Depends(commandInst, "../policy/latiss.yaml")
