Skip to content

Commit

Permalink
Merge pull request #1 from lsst-dm/u/ktl/initial
Browse files Browse the repository at this point in the history
Initial repo and CSC setup.
  • Loading branch information
ktlim committed Apr 10, 2023
2 parents 539efab + 461e9a7 commit 829175d
Show file tree
Hide file tree
Showing 14 changed files with 267 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: 3.9

- name: Install
run: pip install -r <(curl https://raw.githubusercontent.com/lsst/linting/main/requirements.txt)
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ pytest_session.txt
.cache/
.pytest_cache
.coverage
.pre-commit-config.yaml
.flake8
.isort.cfg
.mypy.ini
6 changes: 6 additions & 0 deletions .ts_pre_commit_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
check-yaml: true
check-xml: true
black: true
flake8: true
isort: true
mypy: true
1 change: 1 addition & 0 deletions COPYRIGHT
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Copyright 2023 Association of Universities for Research in Astronomy, Inc. (AURA)
Copyright 2023 The Board of Trustees of the Leland Stanford Junior University, through SLAC National Accelerator Laboratory
2 changes: 2 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@Library('JenkinsShared')_
DevelopPipeline(name: "consdb", module_name: "lsst.consdb", idl_names: ["ConsDB"])
2 changes: 2 additions & 0 deletions Jenkinsfile.conda
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@Library('JenkinsShared')_
CondaPipeline(["consdb_config"], "consdb", "lsst.consdb")
4 changes: 1 addition & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
consdb
######



.. Add a brief (few sentence) description of what this package provides.
This CSC listens for SAL events, executes EFD queries when they arrive, and writes results to columns in relational database tables in the Consolidated Database.
55 changes: 55 additions & 0 deletions conda/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{% set data= load_setup_py_data() %}
package:
name: consdb
version: {{ data.get('version') }}

source:
path: ../

build:
noarch: python
script: {{ PYTHON }} -m pip install --no-deps --ignore-installed .
script_env:
- PATH
- PYTHONPATH
- LD_LIBRARY_PATH
- OSPL_HOME
- PYTHON_BUILD_VERSION
- PYTHON_BUILD_LOCATION
- LSST_DDS_DOMAIN
# Replace with csc configuration repo directory, i.e. TS_CONFIG_ATTCS_DIR for athexapod

test:
requires:
- ts-conda-build
- ts-dds
- ts-idl {{ idl_version }}
- ts-salobj {{ salobj_version }}
source_files:
- python
- bin
- tests
- schema
- setup.cfg
- pyproject.toml
commands:
- pytest

requirements:
host:
- python {{ python }}
- pip
- setuptools_scm
- setuptools
- pytest-runner
build:
- python {{ python }}
- setuptools_scm
- setuptools
- ts-conda-build =0.3
run:
- python {{ python }}
- setuptools
- setuptools_scm
- ts-salobj
- ts-idl
5 changes: 2 additions & 3 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
https://developer.lsst.io/stack/building-single-package-docs.html
"""

from documenteer.conf.pipelinespkg import *

from documenteer.conf.pipelinespkg import * # type: ignore # noqa

project = "consdb"
html_theme_options["logotext"] = project
html_theme_options["logotext"] = project # type: ignore # noqa
html_title = project
html_short_title = project
36 changes: 36 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[build-system]
requires = ["setuptools>=45", "setuptools-scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"

[project]
name = "consdb"
description = "consdb is a Commandable SAL Component for the `Vera C. Rubin Observatory <https://lsst.org>`_."
license = { text = "GPL" }
dependencies = ["pymodbus"]
readme = "README.rst"
urls = { documentation = "https://consdb.lsst.io", source_code = "https://github.com/lsst-dm/consdb"}
dynamic = ["version"]

[tool.setuptools.dynamic]
version = { attr = "setuptools_scm.get_version" }

[tool.setuptools.packages.find]
where = [ "python" ]

[project.scripts]
run_consdb = "lsst.consdb.cli:execute_csc"

[tool.setuptools_scm]
write_to = "python/lsst/consdb/version.py"
write_to_template = """
# Generated by setuptools_scm
__all__ = ["__version__"]
__version__ = "{version}"
"""

[tool.pytest.ini_options]
log_level = "DEBUG"
asyncio_mode = "auto"

[project.optional-dependencies]
dev = ["pytest"]
5 changes: 4 additions & 1 deletion python/lsst/consdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from .version import * # Generated by sconsUtils
try:
from .version import * # Generated by sconsUtils
except ImportError:
__version__ = "?"
148 changes: 148 additions & 0 deletions python/lsst/consdb/consdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# This file is part of consdb.
#
# Developed for the LSST Telescope and Site Systems.
# This product includes software developed by the LSST Project
# (https://www.lsst.org).
# See the COPYRIGHT file at the top-level directory of this distribution
# for details of code ownership.
#
# 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 <https://www.gnu.org/licenses/>.

__all__ = ["ConsDB", "run_consdb"]

import asyncio
import types

import yaml
from lsst.ts import salobj

from . import __version__

CONFIG_SCHEMA = yaml.safe_load(
"""
$schema: http://json-schema.org/draft-07/schema#
$id: https://github.com/lsst/consdb/blob/main/schema/ConsDB.yaml
title: ConsDB v1
Description: Schema for ConsDB configuration files
type: object
properties:
instances:
type: array
description: Configuration for each trigger event
minItem: 1
items:
type: object
properties:
trigger:
type: string
description: name of SAL event to trigger on
tables:
type: array
description: List of ConsDB tables to update
minItem: 1
items:
type: object
properties:
table:
type: string
description: ConsDB table to insert/update
key:
type: string
description: Name of primary key column in ConsDB table
columns:
type: array
description: List of ConsDB columns to insert/update
minItem: 1
items:
type: object
properties:
column:
type: string
description: Name of ConsDB column to insert/update
query:
type: string
description: EFD query to execute
required:
- column
- query
additionalProperties: false
required:
- table
- columns
additionalProperties: false
required:
- trigger
- tables
additionalProperties: false
"""
)


class ConsDB(salobj.ConfigurableCsc):
"""CSC to populate the Consolidated Database.
Parameters
----------
config_dir: `str`, optional
Directory of configuration files (for unit testing).
initial_state: `salobj.State`, optional
The initial state of the CSC. This is provided for unit testing.
override: `str`, optional
Configuration override file to appliy if ``initial_state`` is
`salobj.State.DISABLED` or `salobj.State.ENABLED`.
simulation_mode: `int` (optional)
Simulation mode (default = 0, do not simulate).
Raises
------
ValueError
If ``config_dir`` is not a directory or ``initial_state`` is invalid.
salobj.ExpectedError
If ``simulation_mode`` is invalid.
"""

valid_simulation_modes = (0, 1)
version = __version__

def __init__(
self,
config_dir: str | None = None,
initial_state: salobj.State = salobj.State.STANDBY,
override: str = "",
simulation_mode: int = 0,
):
super().__init__(
"ConsDB",
index=None,
config_schema=CONFIG_SCHEMA,
config_dir=config_dir,
initial_state=initial_state,
override=override,
simulation_mode=simulation_mode,
)

@classmethod
def get_config_pkg(cls) -> str:
return "consdb_config"

async def configure(self, config: types.SimpleNamespace) -> None:
pass

async def handle_summary_state(self) -> None:
pass


def run_consdb() -> None:
"""Run the ConsDB CSC."""
asyncio.run(ConsDB.amain())
6 changes: 1 addition & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ max-doc-length = 79
ignore = E133, E226, E228, N802, N803, N806, N812, N813, N815, N816, W503
exclude =
bin,
doc/conf.py,
doc,
**/*/__init__.py,
**/*/version.py,
tests/.tests

[tool:pytest]
addopts = --flake8
flake8-ignore = E133 E226 E228 N802 N803 N806 N812 N813 N815 N816 W503
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import setuptools
import setuptools_scm

setuptools.setup(version=setuptools_scm.get_version())

0 comments on commit 829175d

Please sign in to comment.