Skip to content

Commit 6fd56ef

Browse files
authored
Merge pull request #11 from lsst-dm/tickets/DM-36468
DM-36468: Enable db-auth.yaml credentials use
2 parents 0808028 + 919e737 commit 6fd56ef

18 files changed

+169
-153
lines changed

.github/workflows/build.yaml

+11-7
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,28 @@ on:
88

99
jobs:
1010
build_and_test:
11-
# runs-on: ubuntu-latest
12-
# Need >= 20.04 for modern sqlite. Can switch to latest when
13-
# github change
14-
runs-on: ubuntu-20.04
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ["3.10"]
15+
1516
steps:
16-
- uses: actions/checkout@v2
17+
- uses: actions/checkout@v3
18+
with:
19+
# Need to clone everything for the git tags.
20+
fetch-depth: 0
1721

1822
- uses: conda-incubator/setup-miniconda@v2
1923
with:
20-
python-version: 3.8
24+
python-version: ${{ matrix.python-version }}
2125
channels: conda-forge,defaults
2226
channel-priority: strict
2327
show-channel-urls: true
2428

2529
- name: Update pip/wheel infrastructure
2630
shell: bash -l {0}
2731
run: |
28-
conda install -y -q pip wheel
32+
conda install -y -q "pip<22" wheel
2933
3034
- name: Install dependencies
3135
shell: bash -l {0}

.github/workflows/formatting.yaml

+3-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: check Python formatting
1+
name: Check Python formatting
22

33
on:
44
push:
@@ -7,21 +7,5 @@ on:
77
pull_request:
88

99
jobs:
10-
lint:
11-
runs-on: ubuntu-latest
12-
steps:
13-
- uses: actions/checkout@v2
14-
15-
- name: Set up Python
16-
uses: actions/setup-python@v2
17-
with:
18-
python-version: 3.8
19-
20-
- name: Install isort and black
21-
run: pip install isort black
22-
23-
- name: Run isort
24-
run: isort --diff --check-only python/ tests/
25-
26-
- name: Run black
27-
run: black --check --verbose --diff python/ tests/
10+
call-workflow:
11+
uses: lsst/rubin_workflows/.github/workflows/formatting.yaml@main

.github/workflows/lint.yaml

+6-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
11
name: lint
22

33
on:
4-
- push
5-
- pull_request
4+
push:
5+
branches:
6+
- main
7+
pull_request:
68

79
jobs:
8-
lint:
9-
runs-on: ubuntu-latest
10-
steps:
11-
- uses: actions/checkout@v2
12-
13-
- name: Set up Python
14-
uses: actions/setup-python@v2
15-
with:
16-
python-version: 3.8
17-
18-
- name: Install
19-
run: pip install -r <(curl https://raw.githubusercontent.com/lsst/linting/main/requirements.txt)
20-
21-
- name: Run linter
22-
run: flake8
10+
call-workflow:
11+
uses: lsst/rubin_workflows/.github/workflows/lint.yaml@main

.github/workflows/mypy.yaml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Run mypy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
mypy:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Setup Python
17+
uses: actions/setup-python@v3
18+
with:
19+
python-version: "3.10.6"
20+
cache: "pip"
21+
22+
- name: Install
23+
run: pip install mypy pydantic
24+
25+
- name: Install types dependencies
26+
run: |
27+
if [ -e types.txt ]
28+
then
29+
pip install -r types.txt
30+
fi
31+
- name: Install lsst dependencies
32+
run: |
33+
if [ -e requirements.txt ]
34+
then
35+
pip install -r requirements.txt
36+
fi
37+
- name: Run mypy
38+
run: |
39+
prefix="python/lsst"
40+
echo "__all__ = ['__version__']" > "${prefix}/daf/butler_migrate/version.py"
41+
echo "__version__ = '0.0.1'" >> "${prefix}/daf/butler_migrate/version.py"
42+
mypy "${prefix}"

.pre-commit-config.yaml

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v2.3.0
3+
rev: v4.3.0
44
hooks:
55
- id: check-yaml
66
- id: end-of-file-fixer
@@ -13,9 +13,13 @@ repos:
1313
# supported by your project here, or alternatively use
1414
# pre-commit's default_language_version, see
1515
# https://pre-commit.com/#top_level-default_language_version
16-
language_version: python3.8
16+
language_version: python3.10
1717
- repo: https://github.com/pycqa/isort
1818
rev: 5.10.1
1919
hooks:
2020
- id: isort
2121
name: isort (python)
22+
- repo: https://github.com/PyCQA/flake8
23+
rev: 4.0.1
24+
hooks:
25+
- id: flake8

bin.src/SConscript

-3
This file was deleted.

pyproject.toml

+59-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,65 @@
1+
[build-system]
2+
requires = ["setuptools", "lsst-versions >= 1.3.0"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "lsst-daf-butler-migrate"
7+
description = "Tooling for migrating schemas in butler repositories."
8+
license = {text = "GPLv3+ License"}
9+
readme = "README.md"
10+
authors = [
11+
{name="Rubin Observatory Data Management", email="[email protected]"},
12+
]
13+
classifiers = [
14+
"Intended Audience :: Science/Research",
15+
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
16+
"Operating System :: OS Independent",
17+
"Programming Language :: Python :: 3",
18+
"Programming Language :: Python :: 3.10",
19+
"Topic :: Scientific/Engineering :: Astronomy",
20+
]
21+
keywords = ["lsst"]
22+
dependencies = [
23+
"lsst-utils",
24+
"lsst-resources",
25+
"lsst-daf-butler",
26+
"click",
27+
"sqlalchemy",
28+
"alembic"
29+
]
30+
dynamic = ["version"]
31+
32+
[project.urls]
33+
"Homepage" = "https://github.com/lsst-dm/daf_butler_migrate"
34+
35+
[project.optional-dependencies]
36+
test = [
37+
"pytest >= 3.2",
38+
"flake8 >= 3.7.5",
39+
"pytest-flake8 >= 1.0.4",
40+
"pytest-openfiles >= 0.5.0"
41+
]
42+
43+
[tool.setuptools.packages.find]
44+
where = ["python"]
45+
46+
[tool.setuptools]
47+
zip-safe = true
48+
license-files = ["COPYRIGHT", "LICENSE"]
49+
50+
[tool.setuptools.package-data]
51+
"lsst.daf.butler_migrate" = []
52+
53+
[tool.setuptools.dynamic]
54+
version = { attr = "lsst_versions.get_lsst_version" }
55+
156
[tool.black]
257
line-length = 110
3-
target-version = ["py38"]
58+
target-version = ["py310"]
459

560
[tool.isort]
661
profile = "black"
762
line_length = 110
63+
64+
[tool.lsst_versions]
65+
write_to = "python/lsst/daf/butler_migrate/version.py"

python/lsst/daf/butler_migrate/database.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828

2929
import sqlalchemy
3030
from alembic.runtime.migration import MigrationContext
31-
from lsst.daf.butler import ButlerConfig
32-
from lsst.daf.butler.core.repoRelocation import replaceRoot
31+
from lsst.daf.butler import ButlerConfig, RegistryConfig
3332

3433
from . import revision
3534

@@ -59,7 +58,7 @@ class Database:
5958
dimensions_config_manager = "dimensions-config"
6059
"""Name of the special dimensions-config pseudo-manager (`str`)"""
6160

62-
def __init__(self, db_url: str, schema: Optional[str] = None):
61+
def __init__(self, db_url: sqlalchemy.engine.url.URL, schema: Optional[str] = None):
6362
self._db_url = db_url
6463
self._schema = schema
6564

@@ -74,11 +73,10 @@ def from_repo(cls, repo: str) -> Database:
7473
"butler.yaml" file.
7574
"""
7675
butlerConfig = ButlerConfig(repo)
77-
if "root" in butlerConfig:
78-
butlerRoot = butlerConfig["root"]
79-
else:
80-
butlerRoot = butlerConfig.configDir
81-
db_url = replaceRoot(butlerConfig["registry", "db"], butlerRoot)
76+
registryConfig = RegistryConfig(butlerConfig)
77+
butlerRoot = butlerConfig.get("root", butlerConfig.configDir)
78+
registryConfig.replaceRoot(butlerRoot)
79+
db_url = registryConfig.connectionString
8280
schema: Optional[str] = None
8381
try:
8482
schema = butlerConfig["registry", "namespace"]
@@ -91,7 +89,7 @@ def from_repo(cls, repo: str) -> Database:
9189
@property
9290
def db_url(self) -> str:
9391
"""URL for registry database (`str`)"""
94-
return self._db_url
92+
return str(self._db_url)
9593

9694
@property
9795
def schema(self) -> Optional[str]:

python/lsst/daf/butler_migrate/script/migrate_revision.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ def _migrate_revision_one_shot(mig_path: str, tree_name: str, manager_class: str
131131
assert len(bases) == 1
132132

133133
# Base revision has a random ID but its branch label is "<tree>"
134-
branches = scripts.get_revision(bases[0]).branch_labels
134+
revision_script = scripts.get_revision(bases[0])
135+
assert revision_script is not None, "Script for a known base must exist"
136+
branches = revision_script.branch_labels
135137
assert len(branches) == 1
136138
manager = branches.pop()
137139

python/lsst/daf/butler_migrate/script/migrate_trees.py

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def migrate_trees(mig_path: str, verbose: bool, one_shot: bool) -> None:
5454
bases_map: Dict[str, Script] = {}
5555
for name in bases:
5656
revision = scripts.get_revision(name)
57+
assert revision is not None, "Script for a known base must exist"
5758
# Base revision has a random ID but its branch label is "<tree>"
5859
branches = revision.branch_labels
5960
if not branches:
@@ -93,6 +94,7 @@ def _migrate_trees_one_shot(mig_path: str, verbose: bool) -> None:
9394
if bases:
9495
assert len(bases) == 1
9596
revision = scripts.get_revision(bases[0])
97+
assert revision is not None, "Script for a known base must exist"
9698
print(revision.log_entry)
9799
else:
98100
print(entry)

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
click >7.0
2-
sqlalchemy >= 1.3
2+
sqlalchemy >= 1.4
33
alembic
44
lsst-daf-butler
55
lsst-utils

setup.cfg

-40
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,3 @@
1-
[metadata]
2-
name = lsst_butler_migrate
3-
description = Tooling for migrating schemas in butler repositories.
4-
author = Rubin Observatory Data Management
5-
url = https://github.com/lsst-dm/daf_butler_migrate
6-
classifiers =
7-
Intended Audience :: Science/Research
8-
License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
9-
Operating System :: OS Independent
10-
Programming Language :: Python :: 3
11-
Programming Language :: Python :: 3.8
12-
Topic :: Scientific/Engineering :: Astronomy
13-
14-
[options]
15-
zip_safe = True
16-
package_dir=
17-
=python
18-
packages=find:
19-
setup_requires =
20-
setuptools >=46.0
21-
install_requires =
22-
click >7.0
23-
sqlalchemy >= 1.3
24-
alembic >= 1.7
25-
lsst-resources
26-
lsst-utils
27-
lsst-daf-butler
28-
tests_require =
29-
pytest >= 3.2
30-
flake8 >= 3.7.5
31-
pytest-flake8 >= 1.0.4
32-
pytest-openfiles >= 0.5.0
33-
34-
[options.packages.find]
35-
where=python
36-
371
[flake8]
382
max-line-length = 110
393
max-doc-length = 79
@@ -46,7 +10,3 @@ exclude =
4610
tests/.tests
4711
per-file-ignores =
4812
migrations/**:F401,W505
49-
50-
[tool:pytest]
51-
addopts = --flake8
52-
flake8-ignore = E133 E226 E228 N802 N803 N806 N812 N813 N815 N816 W503 E203

setup.py

-32
This file was deleted.

0 commit comments

Comments
 (0)