-
Notifications
You must be signed in to change notification settings - Fork 4
Added and integrated a configuration model #164
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
35 commits
Select commit
Hold shift + click to select a range
99332ad
Merge pull request #161 from con/reduce_codecov_spam
CodyCBakerPhD f05d58d
chore: add back blurb for consistency
CodyCBakerPhD c15fb79
Merge branch 'main' into add_config
CodyCBakerPhD 882dc59
Apply suggestion from @CodyCBakerPhD
CodyCBakerPhD a64f7ad
Merge branch 'main' into add_config
CodyCBakerPhD 8aa0692
chore: fix bad merges
CodyCBakerPhD 4028e5d
chore: fix bad merge
CodyCBakerPhD 8b49a36
feat: redefine private attributes as properties and adjust their type…
candleindark 0091975
feat: default `run_id` through default factory and remove `None` type…
candleindark 649415e
feat: default `cache_directory` through default factory and remove `N…
candleindark 60fa15d
feat: default `bids_directory` through default factory and remove `No…
candleindark 7db118e
feat: default `file_mode` through default factory and remove its `"au…
candleindark 74b2be2
feat: modify `_validate_existing_directory_as_bids` into a field vali…
candleindark 27f6ad8
feat: filter values of CLI arguments to set `RunConfig`
candleindark 4e58190
fix: ensure `dataset_description.json` is a file
candleindark 7d1c0ce
fix: handle situation that `dataset_description.json` is not a valid …
candleindark ca5ff77
style: add parentheses to make intent explicit
candleindark e74ecf1
Merge pull request #175 from candleindark/add_config_revise_config_model
CodyCBakerPhD 10492ef
Merge branch 'main' into add_config
CodyCBakerPhD 6f3d586
feat: make RunConfig immutable; restore previous style; move helpers …
CodyCBakerPhD 8f1928b
Merge branch 'add_config' of https://github.com/con/nwb2bids into add…
CodyCBakerPhD 38185c7
Merge branch 'main' into add_config
CodyCBakerPhD 3656ebf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 83c7b85
Merge branch 'main' into add_config
CodyCBakerPhD f32822c
fix: some pr suggestions
CodyCBakerPhD fa0d615
Update src/nwb2bids/_core/_validate_existing_bids.py
CodyCBakerPhD 2702a2a
fix: some pr suggestions
CodyCBakerPhD 47d3030
Merge branch 'add_config' of https://github.com/con/nwb2bids into add…
CodyCBakerPhD 1f88ecd
Update src/nwb2bids/_converters/_dataset_converter.py
CodyCBakerPhD 1b9bf4c
fix: update datalad tests
CodyCBakerPhD ea37a3b
Merge branch 'add_config' of https://github.com/con/nwb2bids into add…
CodyCBakerPhD 9a568df
fix: update datalad tests
CodyCBakerPhD f0e4eba
fix: update datalad tests
CodyCBakerPhD 0dbead2
fix: update datalad tests
CodyCBakerPhD 365f1ef
Simplify notification check in CLI
CodyCBakerPhD 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
Some comments aren't visible on the classic Files Changed page.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,97 +1,19 @@ | ||
| import abc | ||
| import json | ||
| import pathlib | ||
| import tempfile | ||
| import typing | ||
|
|
||
| import pydantic | ||
|
|
||
| from ._run_config import RunConfig | ||
|
|
||
|
|
||
| class BaseConverter(pydantic.BaseModel, abc.ABC): | ||
| run_config: RunConfig = pydantic.Field( | ||
| description="The configuration for this conversion run.", default_factory=RunConfig | ||
| ) | ||
|
|
||
| @abc.abstractmethod | ||
| def extract_metadata(self) -> None: | ||
| """ | ||
| Extract essential metadata used by the BIDS standard from the source NWB files. | ||
| """ | ||
| message = f"The `extract_metadata` method has not been implemented by the `{self.__class__.__name__}` class." | ||
| raise NotImplementedError(message) | ||
|
|
||
| def _handle_bids_directory(self, bids_directory: str | pathlib.Path | None = None) -> pathlib.Path: | ||
| """ | ||
| Handle the BIDS directory path. | ||
|
|
||
| If the directory does not exist, create it. | ||
| If it exists, validate that it is a valid BIDS dataset. | ||
| """ | ||
| if bids_directory is None: | ||
| bids_directory = pathlib.Path.cwd() | ||
| bids_directory = pathlib.Path(bids_directory) | ||
|
|
||
| if bids_directory.exists(): | ||
| self._validate_existing_directory_as_bids(bids_directory=bids_directory) | ||
| else: | ||
| bids_directory.mkdir(exist_ok=True) | ||
| self.extract_metadata() | ||
|
|
||
| return bids_directory | ||
|
|
||
| @staticmethod | ||
| def _validate_existing_directory_as_bids(bids_directory: pathlib.Path) -> None: | ||
| """ | ||
| Validate that the existing directory is a valid BIDS dataset. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| bids_directory : pathlib.Path | ||
| The path to the directory to validate. | ||
| """ | ||
| dataset_description_file_path = bids_directory / "dataset_description.json" | ||
|
|
||
| current_directory_contents = { | ||
| path.stem for path in bids_directory.iterdir() if not path.name.startswith(".") | ||
| } - {"README", "CHANGES", "derivatives", "dandiset"} | ||
| if len(current_directory_contents) == 0: | ||
| default_dataset_description = {"BIDSVersion": "1.10"} | ||
| with dataset_description_file_path.open(mode="w") as file_stream: | ||
| json.dump(obj=default_dataset_description, fp=file_stream, indent=4) | ||
| return | ||
|
|
||
| if not dataset_description_file_path.exists(): | ||
| message = ( | ||
| f"The directory ({bids_directory}) exists and is not empty, but is not a valid BIDS dataset: " | ||
| "missing 'dataset_description.json'." | ||
| ) | ||
| raise ValueError(message) | ||
|
|
||
| with dataset_description_file_path.open(mode="r") as file_stream: | ||
| dataset_description = json.load(fp=file_stream) | ||
| if dataset_description.get("BIDSVersion", None) is None: | ||
| message = ( | ||
| f"The directory ({bids_directory}) exists but is not a valid BIDS dataset: " | ||
| "missing 'BIDSVersion' in 'dataset_description.json'." | ||
| ) | ||
| raise ValueError(message) | ||
|
|
||
| @staticmethod | ||
| def _handle_file_mode( | ||
| file_mode: typing.Literal["move", "copy", "symlink", "auto"] = "auto", | ||
| ) -> typing.Literal["move", "copy", "symlink"]: | ||
| if file_mode != "auto": | ||
| return file_mode | ||
|
|
||
| with tempfile.TemporaryDirectory(prefix="nwb2bids-") as temp_dir_str: | ||
| temp_dir_path = pathlib.Path(temp_dir_str) | ||
|
|
||
| # Create a test file | ||
| test_file_path = temp_dir_path / "test_file.txt" | ||
| test_file_path.touch() | ||
|
|
||
| try: | ||
| # Create a symlink to the test file | ||
| (temp_dir_path / "test_symlink.txt").symlink_to(target=test_file_path) | ||
| except (OSError, PermissionError, NotImplementedError): # Windows can sometimes have trouble with symlinks | ||
| # TODO: log a INFO message here when logging is set up | ||
| return "copy" | ||
| else: | ||
| # If symlink creation was successful, return "symlink" | ||
| return "symlink" |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.