-
Notifications
You must be signed in to change notification settings - Fork 33
Built-in BIDS support for dandi upload
#1011
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
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
46bcdb1
Built-in BIDS support for `dandi upload`
TheChymera d508c7b
fixed logic for None input
TheChymera 5531d3c
not using return value
TheChymera db3379c
Code improvements as suggested by jwodder
TheChymera 0890e0a
Code style and no SystemExit in library function.
TheChymera 7ba78d5
Corrected return type
TheChymera 9ae2218
Fixed typing
TheChymera d698804
Better user prompt
TheChymera 953f7b4
Validation return typing and docstring
TheChymera adf2605
Allowing upload of BIDS datasets relative to input path
TheChymera e10c8ea
No click usage outside of CLI library
TheChymera 0492dbb
Not computing list if errors are suppressed
TheChymera d079d9c
Typing
TheChymera 540923a
docstring fix
TheChymera a3b89dc
Separating validation evaluation logic from reporting
TheChymera c59bae2
fix typing
TheChymera 358d2f2
Improve function naming
TheChymera 62cf170
Testing data
TheChymera 044ee28
Fixed typing
TheChymera ac37533
testing bids upload
TheChymera 306b2f9
using shutil instead of deprecated distutils
TheChymera 4847cbb
fixing copytree parameter
TheChymera 9f82246
improved bids upload testing
TheChymera c230d26
Creating changes file
TheChymera bf3aba7
allowing existing directory
TheChymera 7f58c05
boilerplate copytree
TheChymera 50092ea
Check asset upload
TheChymera 427a136
Testing upload with validation ignore
TheChymera 2864c77
simplified path processing in BIDS lookup
TheChymera 8139966
docstring formatting
TheChymera File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,77 @@ | ||
| from .utils import pluralize | ||
|
|
||
|
|
||
| def is_valid( | ||
| validation_result: dict, | ||
| allow_invalid_filenames: bool = False, | ||
| allow_missing_files: bool = False, | ||
| ) -> bool: | ||
| """Determine whether a dataset validation result marks it as valid. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| validation_result: dict | ||
| Dictionary as returned by `dandi.bids_validator_xs.validate_bids()`. | ||
| allow_missing_files: bool, optional | ||
| Whether to consider the dataset invalid if any mandatory files are not present. | ||
| allow_invalid_filenames: bool, optional | ||
| Whether to consider the dataset invalid if any filenames inside are invalid. | ||
|
|
||
| Returns | ||
| ------- | ||
| bool: whether the dataset validation result marks it as valid. | ||
|
|
||
| """ | ||
|
|
||
| if allow_invalid_filenames and allow_missing_files: | ||
| return True | ||
TheChymera marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| missing_files = [ | ||
| i["regex"] for i in validation_result["schema_tracking"] if i["mandatory"] | ||
| ] | ||
| invalid_filenames = validation_result["path_tracking"] | ||
|
|
||
| if missing_files and not allow_missing_files: | ||
| return False | ||
| if invalid_filenames and not allow_invalid_filenames: | ||
| return False | ||
| else: | ||
| return True | ||
|
|
||
|
|
||
| def report_errors( | ||
| validation_result: dict, | ||
| ) -> None: | ||
| import click | ||
|
|
||
| missing_files = [ | ||
| pattern["regex"] | ||
| for pattern in validation_result["schema_tracking"] | ||
| if pattern["mandatory"] | ||
| ] | ||
| error_list = [] | ||
| if missing_files: | ||
| error_substring = ( | ||
| f"{pluralize(len(missing_files), 'filename pattern')} required " | ||
| "by BIDS could not be found" | ||
| ) | ||
| error_list.append(error_substring) | ||
| if validation_result["path_tracking"]: | ||
| error_substring = ( | ||
| f"{pluralize(len(validation_result['path_tracking']), 'filename')} " | ||
| "did not match any pattern known to BIDS" | ||
| ) | ||
| error_list.append(error_substring) | ||
| if error_list: | ||
| error_string = " and ".join(error_list) | ||
| error_string = f"Summary: {error_string}." | ||
| click.secho( | ||
| error_string, | ||
| bold=True, | ||
| fg="red", | ||
| ) | ||
| else: | ||
| click.secho( | ||
| "All filenames are BIDS-valid and no mandatory files are missing.", | ||
| bold=True, | ||
| fg="green", | ||
| ) | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.