-
Notifications
You must be signed in to change notification settings - Fork 0
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
docs: 📝 add examples to user facing functions #982
Conversation
Based on the work by @martonvago in 498e1b9.
… to `dict` internally
# Set global path for the example | ||
os.environ["SPROUT_GLOBAL"] = ".storage/" | ||
|
||
# sp.path_package_database(package_id=1) |
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.
Commented out bc there is no package database in the current setup. This function will soon be removed altogether #980
```{python} | ||
#| output: false | ||
#| echo: false | ||
import os | ||
|
||
import seedcase_sprout.core as sp | ||
from seedcase_sprout.core.write_json import write_json | ||
|
||
# Set global path for the example | ||
os.environ["SPROUT_GLOBAL"] = ".storage/" | ||
|
||
edited_properties = sp.edit_package_properties( | ||
path=sp.path_package_properties(package_id=1), | ||
properties=sp.PackageProperties( | ||
name="new-package-name", | ||
title="New Package Title", | ||
description="This is a package description", | ||
), | ||
).compact_dict | ||
|
||
write_json(edited_properties, path=sp.path_package_properties(package_id=1)) | ||
``` |
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.
Had to add this bc write_resource_properties()
would fail otherwise bc the existing properties/data-package.json
are missing required fields (name, description, title)
But it won't be showed (output and echo is false)
Examples: | ||
```{python} | ||
#| output: false | ||
#| echo: false | ||
f = open(".storage/packages/1/resources/1/data.parquet", "x") | ||
``` |
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.
Added this so there was a data file to get the path for.
```{python} | ||
#| echo: false | ||
f = open(".storage/packages/1/resources/1/raw/file1.csv", "x") | ||
f = open(".storage/packages/1/resources/1/raw/file2.csv", "x") | ||
``` |
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.
Added these so the example wouldn't just return an empty list.
So the examples will run correctly. If `create_resource_properties` is run before `create_resource_structure` the example will fail bc the resource structure doesn't exist yet.
There's no output of this code chunk, so it's not needed.
By moving `write_resource_properties` down.
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.
Nice start! I didn't finish reviewing it since the main thing to resolve here is that example code should be self-contained. It's a good exercise for us to identify what functions depend on others to run without anything else involved.
# TODO: Add data to resource | ||
# sp.write_resource_data_to_raw( | ||
# package_id=1, | ||
# resource_id=1, | ||
# data="path/to/data.csv") | ||
|
||
# sp.write_resource_parquet( | ||
# raw_files=sp.path_resource_raw_files(package_id=1, resource_id=1), | ||
# path=sp.path_resource_data(package_id=1, resource_id=1)) | ||
|
||
# Get the path to the resource data | ||
# sp.path_resource_data(package_id=1, resource_id=1) |
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.
Some examples, such as this one, requires functionality that doesn't exist yet, so I have commented it out and added a TODO item.
# TODO: Write package properties that passes checks | ||
# Write package properties | ||
# sp.write_package_properties( | ||
# path=temp_dir / "1" / "datapackage.json", | ||
# package_properties=sp.PackageProperties( | ||
# title="New Package Title", | ||
# name="new-package-name", | ||
# description="New Description", | ||
# ), | ||
|
||
# Write resource properties | ||
# sp.write_resource_properties( | ||
# path=temp_dir / "1" / "datapackage.json", | ||
# resource_properties=sp.ResourceProperties( | ||
# name="new-resource-name", | ||
# title="New resource name", | ||
# description="This is a new resource", | ||
# path="data.parquet", | ||
# ), | ||
# ) | ||
``` | ||
""" |
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.
Same here. Currently, we can't write resource properties on a newly created package bc the (package) properties are missing required fields.
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.
Super nice!!! 🤩
## Description This PR adds docstrings to the modules with multiple/many functions/classes. Note that this is stacked on #982 <!-- Select quick/in-depth as necessary --> This PR needs an in-depth review. ## Checklist - [X] Updated documentation - [X] Ran `just run-all` --------- Co-authored-by: Luke W. Johnston <[email protected]>
Description
This PR adds examples in the docstrings of user facing functions.
Closes #951
This PR needs an in-depth review.
Checklist
just run-all