Skip to content
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

DM-30985: Change schema file discovery to use environment variables and expandvars #19

Merged
merged 1 commit into from
Jul 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions python/lsst/dax/apdb/apdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import lsst.afw.table as afwTable
import lsst.pex.config as pexConfig
from lsst.pex.config import Field, ChoiceField, ListField
from lsst.utils import getPackageDir
import sqlalchemy
from sqlalchemy import (func, sql)
from sqlalchemy.pool import NullPool
Expand Down Expand Up @@ -124,7 +123,7 @@ def _ansi_session(engine):
def _data_file_name(basename):
"""Return path name of a data file.
"""
return os.path.join(getPackageDir("dax_apdb"), "data", basename)
return os.path.join("${DAX_APDB_DIR}", "data", basename)


class ApdbConfig(pexConfig.Config):
Expand Down
4 changes: 4 additions & 0 deletions python/lsst/dax/apdb/apdbSchema.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

from collections import namedtuple
import logging
import os
import yaml

import sqlalchemy
Expand Down Expand Up @@ -234,6 +235,7 @@ def __init__(self, engine, dia_object_index, dia_object_nightly,
self.visits = None

if column_map:
column_map = os.path.expandvars(column_map)
_LOG.debug("Reading column map file %s", column_map)
with open(column_map) as yaml_stream:
# maps cat column name to afw column name
Expand Down Expand Up @@ -494,13 +496,15 @@ def _buildSchemas(self, schema_file, extra_schema_file=None, afw_schemas=None):
Mapping of table names to `TableDef` instances.
"""

schema_file = os.path.expandvars(schema_file)
_LOG.debug("Reading schema file %s", schema_file)
with open(schema_file) as yaml_stream:
tables = list(yaml.load_all(yaml_stream, Loader=yaml.SafeLoader))
# index it by table name
_LOG.debug("Read %d tables from schema", len(tables))

if extra_schema_file:
extra_schema_file = os.path.expandvars(extra_schema_file)
_LOG.debug("Reading extra schema file %s", extra_schema_file)
with open(extra_schema_file) as yaml_stream:
extras = list(yaml.load_all(yaml_stream, Loader=yaml.SafeLoader))
Expand Down