Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an environment variable for server config
Browse files Browse the repository at this point in the history
dhirving committed Oct 30, 2023
1 parent 403d76f commit ccd0f67
Showing 2 changed files with 49 additions and 3 deletions.
46 changes: 46 additions & 0 deletions python/lsst/daf/butler/remote_butler/server/_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This file is part of daf_butler.
#
# Developed for the LSST Data Management System.
# This product includes software developed by the LSST Project
# (http://www.lsst.org).
# See the COPYRIGHT file at the top-level directory of this distribution
# for details of code ownership.
#
# This software is dual licensed under the GNU General Public License and also
# under a 3-clause BSD license. Recipients may choose which of these licenses
# to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
# respectively. If you choose the GPL option then the following text applies
# (but note that there is still no warranty even if you opt for BSD instead):
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import os
from dataclasses import dataclass

__all__ = ("Config", "get_config_from_env")


@dataclass(frozen=True)
class Config:
butler_root: str


def get_config_from_env() -> Config:
butler_root = os.getenv("BUTLER_SERVER_BUTLER_ROOT")
if butler_root is None:
raise Exception(
"The environment variable BUTLER_SERVER_BUTLER_ROOT "
"must point to a Butler configuration to be used by the server"
)
return Config(butler_root=butler_root)
6 changes: 3 additions & 3 deletions python/lsst/daf/butler/remote_butler/server/_server.py
Original file line number Diff line number Diff line change
@@ -37,10 +37,9 @@
from fastapi.middleware.gzip import GZipMiddleware
from lsst.daf.butler import Butler

from ._config import get_config_from_env
from ._factory import Factory

BUTLER_ROOT = "ci_hsc_gen3/DATA"

log = logging.getLogger(__name__)

app = FastAPI()
@@ -49,7 +48,8 @@

@cache
def _make_global_butler() -> Butler:
return Butler.from_config(BUTLER_ROOT)
config = get_config_from_env()
return Butler.from_config(config.butler_root)


def factory_dependency() -> Factory:

0 comments on commit ccd0f67

Please sign in to comment.