Skip to content

Commit

Permalink
First version of PPDB classes and CLI tools.
Browse files Browse the repository at this point in the history
The main purpose of this package id to implement management tools for
PDDB, including tools for migration of APDB data to PPDB. Regular clients
will access PDDB either via SQL or using TAP services.

What is implemented on thi ticket:
- Added base Ppdb class with factory methods, and its SQL implementation.
- Two CLI tools - `ppdb-cli` for general commands and `ppdb-replication`
  for replication-related stuff.
- Efficient bulk insert methods for Postgres.
  • Loading branch information
andy-slac committed Apr 12, 2024
1 parent b78bfa5 commit f80bc33
Show file tree
Hide file tree
Showing 33 changed files with 2,042 additions and 27 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/formatting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Check Python formatting

Check warning on line 1 in .github/workflows/formatting.yaml

View workflow job for this annotation

GitHub Actions / call-workflow / yamllint

1:1 [document-start] missing document start "---"

on:

Check warning on line 3 in .github/workflows/formatting.yaml

View workflow job for this annotation

GitHub Actions / call-workflow / yamllint

3:1 [truthy] truthy value should be one of [false, true]
push:
branches:
- main
pull_request:

jobs:
call-workflow:
uses: lsst/rubin_workflows/.github/workflows/formatting.yaml@main
24 changes: 9 additions & 15 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
name: lint

Check warning on line 1 in .github/workflows/lint.yaml

View workflow job for this annotation

GitHub Actions / call-workflow / yamllint

1:1 [document-start] missing document start "---"

on:

Check warning on line 3 in .github/workflows/lint.yaml

View workflow job for this annotation

GitHub Actions / call-workflow / yamllint

3:1 [truthy] truthy value should be one of [false, true]
- push
- pull_request
push:
branches:
- main
pull_request:

jobs:
lint:
call-workflow:
uses: lsst/rubin_workflows/.github/workflows/lint.yaml@main
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Install
run: pip install -r <(curl https://raw.githubusercontent.com/lsst/linting/main/requirements.txt)

- name: Run linter
run: flake8
- uses: actions/checkout@v3
- uses: chartboost/ruff-action@v1
11 changes: 11 additions & 0 deletions .github/workflows/mypy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Run mypy

Check warning on line 1 in .github/workflows/mypy.yaml

View workflow job for this annotation

GitHub Actions / call-workflow / yamllint

1:1 [document-start] missing document start "---"

on:

Check warning on line 3 in .github/workflows/mypy.yaml

View workflow job for this annotation

GitHub Actions / call-workflow / yamllint

3:1 [truthy] truthy value should be one of [false, true]
push:
branches:
- main
pull_request:

jobs:
call-workflow:
uses: lsst/rubin_workflows/.github/workflows/mypy.yaml@main
1 change: 0 additions & 1 deletion .github/workflows/rebase_checker.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
name: Check that 'main' is not merged into the development branch

Check warning on line 1 in .github/workflows/rebase_checker.yaml

View workflow job for this annotation

GitHub Actions / call-workflow / yamllint

1:1 [document-start] missing document start "---"

on: pull_request

Check warning on line 3 in .github/workflows/rebase_checker.yaml

View workflow job for this annotation

GitHub Actions / call-workflow / yamllint

3:1 [truthy] truthy value should be one of [false, true]
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Lint YAML Files

Check warning on line 1 in .github/workflows/yamllint.yaml

View workflow job for this annotation

GitHub Actions / call-workflow / yamllint

1:1 [document-start] missing document start "---"

on:
push:
branches:
- main
pull_request:

jobs:
call-workflow:
uses: lsst/rubin_workflows/.github/workflows/yamllint.yaml@main
28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
repos:

Check warning on line 1 in .pre-commit-config.yaml

View workflow job for this annotation

GitHub Actions / call-workflow / yamllint

1:1 [document-start] missing document start "---"
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-yaml
args:
- "--unsafe"
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.2.0
hooks:
- id: black
# It is recommended to specify the latest version of Python
# supported by your project here, or alternatively use
# pre-commit's default_language_version, see
# https://pre-commit.com/#top_level-default_language_version
language_version: python3.11
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.3.1
hooks:
- id: ruff
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
dax_ppdb
########


``dax_ppdb`` is a package in the `LSST Science Pipelines <https://pipelines.lsst.io>`_.

.. Add a brief (few sentence) description of what this package provides.
1 change: 1 addition & 0 deletions bin.src/SConscript
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- python -*-
from lsst.sconsUtils import scripts

scripts.BasicSConscript.shebang()
6 changes: 6 additions & 0 deletions bin.src/ppdb-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env python

from lsst.dax.ppdb.cli import ppdb_cli

if __name__ == "__main__":
ppdb_cli.main()
6 changes: 6 additions & 0 deletions bin.src/ppdb-replication
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env python

from lsst.dax.ppdb.cli import ppdb_replication

if __name__ == "__main__":
ppdb_replication.main()
28 changes: 28 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[mypy]
ignore_errors = False
warn_unused_configs = True
warn_redundant_casts = True
ignore_missing_imports = False
disallow_untyped_defs = True
disallow_incomplete_defs = True

[mypy-astropy.*]
ignore_missing_imports = True

[mypy-lsst.daf.*]
ignore_missing_imports = True

[mypy-lsst.sphgeom]
ignore_missing_imports = True

[mypy-lsst.dax.ppdb.*]
ignore_missing_imports = False
ignore_errors = False
disallow_untyped_defs = True
disallow_incomplete_defs = True
strict_equality = True
warn_unreachable = True
warn_unused_ignores = True

[mypy-lsst.dax.ppdb.version]
ignore_errors = True
111 changes: 111 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
[build-system]
requires = ["setuptools", "lsst-versions >= 1.3.0"]
build-backend = "setuptools.build_meta"

[project]
name = "lsst-dax-ppdb"
description = "Prompt Products Database for LSST AP pipeline."
license = {text = "GPLv3+ License"}
readme = "README.md"
authors = [
{name="Rubin Observatory Data Management", email="[email protected]"},
]
classifiers = [
"Intended Audience :: Science/Research",
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering :: Astronomy",
]
keywords = ["lsst"]
dependencies = [
"astropy",
"numpy",
"pandas",
"pyyaml >= 5.1",
"sqlalchemy",
"felis",
"lsst-utils",
"lsst-resources",
"lsst-dax-apdb",
]
dynamic = ["version"]

[project.urls]
"Homepage" = "https://github.com/lsst/dax_ppdb"

[project.optional-dependencies]
test = [
"pytest >= 3.2",
"pytest-openfiles >= 0.5.0"
]

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

[tool.setuptools]
zip-safe = true
license-files = ["COPYRIGHT", "LICENSE"]

[tool.setuptools.package-data]
"lsst.dax.ppdb" = ["py.typed"]

[tool.setuptools.dynamic]
version = { attr = "lsst_versions.get_lsst_version" }

[tool.black]
line-length = 110
target-version = ["py311"]

[tool.isort]
profile = "black"
line_length = 110

[tool.lsst_versions]
write_to = "python/lsst/dax/ppdb/version.py"

[tool.ruff]
exclude = [
"__init__.py",
"doc/conf.py",
]
line-length = 110
target-version = "py311"

[tool.ruff.lint]
ignore = [
"N802",
"N803",
"N806",
"N812",
"N815",
"N816",
"N999",
"D107",
"D105",
"D102",
"D104",
"D100",
"D200",
"D205",
"D400",
]
select = [
"E", # pycodestyle
"F", # pycodestyle
"N", # pep8-naming
"W", # pycodestyle
"D", # pydocstyle
]
extend-select = [
"RUF100", # Warn about unused noqa
]

[tool.ruff.lint.pycodestyle]
max-doc-length = 79

[tool.ruff.lint.pydocstyle]
convention = "numpy"
1 change: 1 addition & 0 deletions python/lsst/dax/ppdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
# 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 .ppdb import *
from .version import * # Generated by sconsUtils
110 changes: 110 additions & 0 deletions python/lsst/dax/ppdb/_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# This file is part of dax_ppdb
#
# Developed for the LSST Data Management System.
# 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/>.

from __future__ import annotations

__all__ = ["config_type_for_name", "ppdb_type", "ppdb_type_for_name"]

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from .config import PpdbConfig
from .sql import PpdbSql


def ppdb_type(config: PpdbConfig) -> type[PpdbSql]:
"""Return Ppdb class matching Ppdb configuration type.
Parameters
----------
config : `PpdbConfig`
Configuration object, sub-class of PpdbConfig.
Returns
-------
type : `type` [`Ppdb`]
Subclass of `Ppdb` class.
Raises
------
TypeError
Raised if type of ``config`` does not match any known types.
"""
from .sql import PpdbSqlConfig

if type(config) is PpdbSqlConfig:
from .sql import PpdbSql

return PpdbSql

raise TypeError(f"Unknown type of config object: {type(config)}")


def ppdb_type_for_name(type_name: str) -> type[PpdbSql]:
"""Return Ppdb class matching type name.
Parameters
----------
type_name : `str`
Short type name of Ppdb implement, for now only "sql" is supported.
Returns
-------
type : `type` [`Ppdb`]
Subclass of `Ppdb` class.
Raises
------
TypeError
Raised if ``type_name`` does not match any known types.
"""
if type_name == "sql":
from .sql import PpdbSql

return PpdbSql

raise TypeError(f"Unknown type name: {type_name}")


def config_type_for_name(type_name: str) -> type[PpdbConfig]:
"""Return PpdbConfig class matching type name.
Parameters
----------
type_name : `str`
Short type name of Ppdb implement, for now only "sql" is supported.
Returns
-------
type : `type` [`Ppdb`]
Subclass of `PpdbConfig` class.
Raises
------
TypeError
Raised if ``type_name`` does not match any known types.
"""
if type_name == "sql":
from .sql import PpdbSqlConfig

return PpdbSqlConfig

raise TypeError(f"Unknown type name: {type_name}")
Empty file.
Loading

0 comments on commit f80bc33

Please sign in to comment.