-
Notifications
You must be signed in to change notification settings - Fork 10
Doc style #113
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
Doc style #113
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c25fd4a
makes src modules public
bcalford 13f239b
adds docstring to more files
bcalford 7852e69
doc strings for all public modules besides options mixin
bcalford 04a2674
Merge branch 'main' into doc_style
christian-oreilly f687db6
Update src/ipyniivue/options_mixin.py
christian-oreilly 2517aa7
Update src/ipyniivue/constants.py
christian-oreilly ecef668
Update src/ipyniivue/constants.py
christian-oreilly 43cbc23
Update src/ipyniivue/utils.py
christian-oreilly 6f121d9
Update src/ipyniivue/constants.py
christian-oreilly a629553
Update src/ipyniivue/constants.py
christian-oreilly 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
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,33 +1,77 @@ | ||
| """Defines some utily functions for reuse across the package.""" | ||
| """ | ||
| Important utilities needed to work data between Python and JavaScript code. | ||
|
|
||
| It includes a class to convert from snake to camel case as well as multiple | ||
| classes the serialize data to work with JS. | ||
| """ | ||
|
|
||
| import enum | ||
| import pathlib | ||
| import typing | ||
|
|
||
|
|
||
| def snake_to_camel(snake_str: str): | ||
| """Convert a string from snake case to camel case.""" | ||
| """ | ||
| Convert the Python typical snake case to JS typical camel case. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| snake_str : str | ||
| The snake case string to be converted. | ||
|
|
||
| Returns | ||
| ------- | ||
| camel_string : str | ||
| The parameter string converted to camel case. | ||
| """ | ||
| components = snake_str.split("_") | ||
| return components[0] + "".join(x.title() for x in components[1:]) | ||
|
|
||
|
|
||
| def file_serializer(instance: typing.Union[pathlib.Path, str], widget: object): | ||
| """Serialize file paths.""" | ||
| """ | ||
| Serialize a file to be transferred and read by the JS side. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| instance : typing.Union[pathLib.Path, str] | ||
| The path to a file to be serialized. | ||
| widget : object | ||
| The NiiVue widget the instance is a part of. | ||
| """ | ||
| if isinstance(instance, str): | ||
| # make sure we have a pathlib.Path instance | ||
| # Make sure we have a pathlib.Path instance | ||
| instance = pathlib.Path(instance) | ||
| return {"name": instance.name, "data": instance.read_bytes()} | ||
|
|
||
|
|
||
| def mesh_layers_serializer(instance: list, widget: object): | ||
| """Serialize meshes.""" | ||
| """ | ||
| Serialize each layer of a mesh instance. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| instance : list | ||
| The mesh instance containing the layers. | ||
| widget : object | ||
| The NiiVue widget the instance is a part of. | ||
| """ | ||
| return [ | ||
| {**mesh_layer, "path": file_serializer(mesh_layer["path"], widget)} | ||
| for mesh_layer in instance | ||
| ] | ||
|
|
||
|
|
||
| def serialize_options(instance: dict, widget: object): | ||
| """Serialize options.""" | ||
| # serialize enums as their value | ||
| """ | ||
| Serialize the options for a NiiVue instance. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| instance : dict | ||
| The list of options to be serialized. | ||
| widget : object | ||
| The NiiVue widget the instance is a part of. | ||
| """ | ||
| # Serialize enums as their value | ||
| return {k: v.value if isinstance(v, enum.Enum) else v for k, v in instance.items()} |
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
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.