Skip to content

Commit

Permalink
Merge pull request OpenMDAO#520 from crecine/try-glue2
Browse files Browse the repository at this point in the history
Try glue2
  • Loading branch information
jkirk5 authored Nov 18, 2024
2 parents 07ca01e + 82782f6 commit 7a7703f
Show file tree
Hide file tree
Showing 37 changed files with 1,337 additions and 218 deletions.
3 changes: 3 additions & 0 deletions aviary/docs/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ parts:
- file: developer_guide/unit_tests
- file: developer_guide/contributing_guidelines
- file: developer_guide/how_to_contribute_docs
sections:
- file: developer_guide/doctape.ipynb
- file: developer_guide/doctape_examples.ipynb
- file: developer_guide/debugging_env_from_github

- caption: Miscellaneous Resources
Expand Down
6 changes: 3 additions & 3 deletions aviary/docs/developer_guide/codebase_overview.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"outputs": [],
"source": [
"from aviary.docs.tests.utils import Markdown, glue_variable\n",
"from aviary.utils.doctape import glue_variable\n",
"\n",
"structure = {\n",
" 'docs':'contains the doc files for Aviary',\n",
Expand All @@ -31,7 +31,7 @@
"\n",
"# change display to False to prevent displaying the results when running cells directly\n",
"# (Does not change the generated book)\n",
"glue_variable('folder_structure', Markdown(bulleted_list), display=True)\n"
"glue_variable('folder_structure', bulleted_list, display=True)\n"
]
},
{
Expand Down Expand Up @@ -62,7 +62,7 @@
"# Testing Cell\n",
"import os\n",
"from aviary.utils.functions import get_path\n",
"from aviary.docs.tests.utils import check_contains\n",
"from aviary.utils.doctape import check_contains\n",
"\n",
"folder = get_path('docs').parent\n",
"subfolders = [ f.name for f in os.scandir(folder) ]\n",
Expand Down
6 changes: 3 additions & 3 deletions aviary/docs/developer_guide/coding_standards.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
"source": [
"# Testing Cell\n",
"import aviary.api as av\n",
"from aviary.docs.tests.utils import get_attribute_name, glue_variable\n",
"from aviary.utils.doctape import get_attribute_name, get_variable_name, glue_variable\n",
"Verbosity = av.Verbosity;\n",
"\n",
"verbosity = get_attribute_name(av.Settings,av.Settings.VERBOSITY)\n",
"glue_variable('VERBOSITY',verbosity, md_code=True)\n",
"glue_variable(f'{Verbosity=}'.split('=')[0], md_code=True)\n",
"glue_variable(get_variable_name(Verbosity), md_code=True)\n",
"glue_variable('QUIET',av.Verbosity.QUIET.name, md_code=True)\n",
"glue_variable('BRIEF',av.Verbosity.BRIEF.name, md_code=True)\n",
"glue_variable(f'{Verbosity.BRIEF=}'.split('=')[0], md_code=True)\n",
"glue_variable(get_variable_name(Verbosity.BRIEF), md_code=True)\n",
"glue_variable('VERBOSE',av.Verbosity.VERBOSE.name, md_code=True)\n",
"glue_variable('DEBUG',av.Verbosity.DEBUG.name, md_code=True)"
]
Expand Down
212 changes: 212 additions & 0 deletions aviary/docs/developer_guide/doctape.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# DocTAPE\n",
"\n",
"DocTAPE (Documentation Testing and Automated Placement of Expressions) is a collection of utility functions (and wrappers for [Glue](https://myst-nb.readthedocs.io/en/latest/render/glue.html)) that are useful\n",
"for automating the process of building and testing documentation to ensure that documentation doesn't get stale.\n",
"\n",
"Our standard practice it to include a comment (`# Testing Cell`) at the begining of code cells as well as make use of the `remove-cell` tag.\n",
"\n",
"> \"metadata\": { \"tags\": [ \"remove-cell\" ] },\n",
"\n",
"<details><summary>More info about adding cell tags</summary>\n",
"\n",
"- [Jupyter Book](https://jupyterbook.org/en/stable/content/metadata.html)\n",
"- [Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-toolsai.vscode-jupyter-cell-tags)\n",
"</details>\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
"# Testing Cell\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
"# Testing Cell\n",
"\n",
"from aviary.utils import doctape\n",
"import inspect\n",
"\n",
"imported_functions = {k:v for k,v in inspect.getmembers(doctape, inspect.isfunction) if v.__module__ == doctape.__name__}\n",
"imported_classes = {k:v for k,v in inspect.getmembers(doctape, inspect.isclass) if v.__module__ == doctape.__name__}\n",
"\n",
"custom_classes = {\n",
" \"expected_error\": \"is an execption that can be used in try/except blocks to allow desired errors to pass while still raising unexpected errors.\",\n",
"}\n",
"testing_functions = {\n",
" \"check_value\": \"is a simple function for comparing two values\",\n",
" \"check_contains\": \"confirms that all the elements of one iterable are contained in the other\",\n",
" \"check_args\": \"gets the signature of a function and compares it to the arguments you are expecting\",\n",
" \"run_command_no_file_error\": \"executes a CLI command but won't fail if a FileNotFoundError is raised\",\n",
"}\n",
"glue_functions = {\n",
" \"glue_variable\": \"Glue a variable for later use in markdown cells of notebooks (can auto format for code)\",\n",
" \"glue_keys\": \"recursively glue all of the keys from a dict of dicts\",\n",
"}\n",
"utility_functions = {\n",
" \"gramatical_list\": \"combines the elements of a list into a string with proper punctuation\",\n",
" \"get_variable_name\": \"returns the name of the variable passed to the function as a string\",\n",
" \"get_previous_line\": \"returns the previous line of code as a string\",\n",
" \"get_attribute_name\": \"gets the name of an object's attribute based on it's value\",\n",
" \"get_all_keys\": \"recursively get all of the keys from a dict of dicts\",\n",
" \"get_value\": \"recursively get a value from a dict of dicts\",\n",
"}\n",
"\n",
"doctape.check_value(imported_classes.keys(),custom_classes.keys())\n",
"doctape.check_value(imported_functions.keys(), {\n",
" **testing_functions, **glue_functions, **utility_functions}.keys())\n",
"\n",
"class_list = ''\n",
"for key,val in custom_classes.items():\n",
" doctape.glue_variable(key, md_code=True)\n",
" class_list += f'- `{key}` {val}\\n'\n",
"\n",
"# testing_list = ''\n",
"# for key,val in testing_functions.items():\n",
"# testing_list += f'- `{key}` {val}\\n'\n",
"\n",
"utility_list = '```{eval-rst}\\n'\n",
"for key in utility_functions:\n",
" doctape.glue_variable(key, md_code=True)\n",
" utility_list += ' '*4+f'.. autofunction:: aviary.utils.doctape.{key}\\n{\" \"*8}:noindex:\\n\\n'\n",
"utility_list += '```'\n",
"\n",
"# testing_list = '```{eval-rst}\\n'\n",
"# for key in testing_functions:\n",
"# utils.glue_variable(key, md_code=True)\n",
"# testing_list += ' '*4+f'.. autofunction:: aviary.utils.doctape.{key}\\n{\" \"*8}:noindex:\\n\\n'\n",
"# testing_list += '```'\n",
"\n",
"# testing_list = '<details>\\n\\n<summary>Function Docs</summary>\\n\\n'\n",
"testing_list = '```{eval-rst}\\n'\n",
"for key in testing_functions:\n",
" doctape.glue_variable(key, md_code=True)\n",
" testing_list += ' '*4+f'.. autofunction:: aviary.utils.doctape.{key}\\n{\" \"*8}:noindex:\\n\\n'\n",
"testing_list += '```'\n",
"# testing_list += '\\n\\n</details>'\n",
"\n",
"# glue_list = ''\n",
"# for key,val in glue_functions.items():\n",
"# glue_list += f'- `{key}` {key}\\n'\n",
"\n",
"# glue_list = ''\n",
"# for key in glue_functions:\n",
"# # doc_str = inspect.getdoc(imported_functions[key])\n",
"# doc_str = imported_functions[key].__doc__.split('\\n')[1]\n",
"# # doc_str = '\\n'.join([s+' ' for s in imported_functions[key].__doc__.split('\\n')])\n",
"# print(doc_str)\n",
"# glue_list += f'- `{key}`: {doc_str}\\n'\n",
"\n",
"glue_list = '```{eval-rst}\\n'\n",
"for key in glue_functions:\n",
" doctape.glue_variable(key, md_code=True)\n",
" glue_list += ' '*4+f'.. autofunction:: aviary.utils.doctape.{key}\\n{\" \"*8}:noindex:\\n\\n'\n",
"glue_list += '```'\n",
"\n",
"doctape.glue_variable('class_list', class_list)\n",
"doctape.glue_variable('utility_list', utility_list)\n",
"doctape.glue_variable('testing_list', testing_list)\n",
"doctape.glue_variable('glue_list', glue_list)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Classes\n",
"```{glue:md} class_list\n",
":format: myst\n",
"```\n",
"\n",
"## Testing Functions\n",
"\n",
"Functions that raise an error provide the option to specify an error type to use instead of the default. This allows users to change the error type that is raised which can be useful in try/except blocks, especially when combined with the {glue:md}`expected_error` class.\n",
"\n",
"```{glue:md} testing_list\n",
":format: myst\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
"# Testing Cell\n",
"import myst_nb\n",
"from aviary.utils.doctape import glue_variable\n",
"\n",
"glue_variable(myst_nb.__name__)\n",
"glue_variable(myst_nb.glue.__name__, md_code=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Glue Functions\n",
"\n",
"The glue functions provide a wrapper for the {glue:md}`myst_nb` {glue:md}`glue` function that provides a simplified interface.\n",
"\n",
"```{glue:md} glue_list\n",
":format: myst\n",
"```\n",
"\n",
"## Utility Functions\n",
"\n",
"Utility functions are provided that the user may find useful for generating or testing their documentation.\n",
"\n",
"```{glue:md} utility_list\n",
":format: myst\n",
"```"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "latest_env",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 7a7703f

Please sign in to comment.