-
Notifications
You must be signed in to change notification settings - Fork 12
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-31367: Add butler register-dataset-type
subcommand
#558
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add ``butler register-dataset-type`` command to register a new dataset type. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# 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 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/>. | ||
from __future__ import annotations | ||
|
||
__all__ = ("register_dataset_type",) | ||
|
||
from typing import Tuple | ||
|
||
from .. import Butler | ||
from ..core import DatasetType | ||
|
||
|
||
def register_dataset_type(repo: str, dataset_type: str, storage_class: str, | ||
dimensions: Tuple[str, ...], is_calibration: bool = False) -> bool: | ||
"""Register a new dataset type. | ||
|
||
Parameters | ||
---------- | ||
repo : `str` | ||
URI string of the Butler repo to use. | ||
dataset_type : `str` | ||
The name of the new dataset type. | ||
storage_class : `str` | ||
The name of the storage class associated with this dataset type. | ||
dimensions : `tuple` [`str`] | ||
Dimensions associated with this dataset type. Can be empty. | ||
is_calibration : `bool` | ||
If `True` this dataset type may be included in calibration | ||
collections. | ||
|
||
Returns | ||
------- | ||
inserted : `bool` | ||
`True` if the dataset type was added; `False` if it was already | ||
there. | ||
|
||
Raises | ||
------ | ||
ValueError | ||
Raised if an attempt is made to register a component dataset type. | ||
Component dataset types are not real dataset types and so can not | ||
be created by this command. They are always derived from the composite | ||
dataset type. | ||
""" | ||
|
||
butler = Butler(repo, writeable=True) | ||
|
||
composite, component = DatasetType.splitDatasetTypeName(dataset_type) | ||
if component: | ||
raise ValueError("Component dataset types are created automatically when the composite is created.") | ||
|
||
# mypy does not think that Tuple[str, ...] is allowed for DatasetType | ||
# constructor so we have to do the conversion here. | ||
graph = butler.registry.dimensions.extract(dimensions) | ||
|
||
datasetType = DatasetType(dataset_type, graph, storage_class, | ||
parentStorageClass=None, | ||
isCalibration=is_calibration, | ||
universe=butler.registry.dimensions) | ||
|
||
return butler.registry.registerDatasetType(datasetType) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"no" instead of "not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The convention is
--x
to enable and--no-x
to disable and that seems to be what click uses elsewhere. I think I could leave off the negating option but then you'd have no way to set it explicitly rather than letting it be the default.