-
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-25030 make an import butler subcommand #293
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1531a17
do not cache commands
n8pease 137581d
add a Mocker unit test
n8pease 1720f7d
improve error reporting
n8pease 0713e09
fix test case name
n8pease 07dadaf
remove unneeded setup and teardown
n8pease 80c408b
move transfer option from obs_base
n8pease 00be48a
add a click argument help generator
n8pease 669c711
add directory argument
n8pease 8190bd2
add butler import command
n8pease b1587d3
add a unit test help msg generator
n8pease f659eed
use the click argument help generator
n8pease 51fc113
fix --help for Options that take multiple vals
n8pease 1be7e7f
accept path or file-like object
n8pease 3eaaa8a
add test for file-like object
n8pease 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
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
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,51 @@ | ||
# 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/>. | ||
|
||
|
||
import click | ||
|
||
from ..utils import addArgumentHelp | ||
|
||
|
||
class directory_argument: # noqa: N801 | ||
"""Decorator to add a directory argument to a click command. | ||
|
||
Parameters | ||
---------- | ||
required : `bool`, optional | ||
Indicates if the caller must pass this argument to the command, by | ||
default True. | ||
help : `str`, optional | ||
The help text for this argument to append to the command's help text. | ||
If None or '' then nothing will be appended to the help text (in which | ||
case the command should document this argument directly in its help | ||
text). By default, the value of directory_argument.default_help | ||
""" | ||
|
||
default_help = "DIRECTORY is the folder containing dataset files." | ||
|
||
def __init__(self, required=False, help=default_help): | ||
self.required = required | ||
self.helpText = help | ||
|
||
def __call__(self, f): | ||
f.__doc__ = addArgumentHelp(f.__doc__, self.helpText) | ||
return click.argument("directory", required=self.required)(f) |
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,38 @@ | ||
# 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/>. | ||
|
||
|
||
import click | ||
|
||
allowed_types = ["auto", "link", "symlink", "hardlink", "copy", "move", "relsymlink"] | ||
|
||
|
||
class transfer_option: # noqa: N801 | ||
def __init__(self, required=False, help=None): | ||
self.required = required | ||
self.help = "The external data transfer mode." if help is None else help | ||
|
||
def __call__(self, f): | ||
return click.option("-t", "--transfer", | ||
default="auto", | ||
type=click.Choice(allowed_types), | ||
required=self.required, | ||
help=self.help)(f) |
Oops, something went wrong.
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.
One other option that may be less prone to scaling problems could be to define a dict that maps from "import" to "butler_import" and then automatically generate the inverse dict. Then in these two functions you do the equivalent of:
(I understand that my dict name there is non-optimal)
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.
I thought about making some kind of data structure like that, but if I'm going to do even that much work I wanted to take a moment to figure out the best way to solve the problem. I think it might involve the plugin system, but I didn't want to spent that much time on it or add complexity, yet.