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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
generate docs when running gradio cc build
#7109
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ec6a309
add docs command to build
pngwn c53af26
add changeset
gradio-pr-bot f405941
add changeset
gradio-pr-bot 997861f
add arg to disable
pngwn a4039fb
add changeset
gradio-pr-bot b835a77
tweaks
pngwn b2b2a6e
tweaks
pngwn 25d56ad
tweaks
pngwn bd7ad74
add changeset
gradio-pr-bot File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
"gradio": minor | ||
--- | ||
|
||
feat:generate docs when running `gradio cc build` |
This file contains 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 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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
import importlib | ||
from pathlib import Path | ||
from typing import Optional | ||
from typing import Any, Optional | ||
|
||
import requests | ||
import tomlkit as toml | ||
|
@@ -77,69 +77,114 @@ def _docs( | |
|
||
with open(_component_dir / "pyproject.toml") as f: | ||
data = toml.loads(f.read()) | ||
with open(_demo_path) as f: | ||
demo = f.read() | ||
|
||
name = get_deep(data, ["project", "name"]) | ||
|
||
if not isinstance(name, str): | ||
raise ValueError("Name not found in pyproject.toml") | ||
|
||
pypi_exists = requests.get(f"https://pypi.org/pypi/{name}/json").status_code | ||
run_command( | ||
live=live, | ||
name=name, | ||
suppress_demo_check=suppress_demo_check, | ||
pyproject_toml=data, | ||
generate_space=generate_space, | ||
generate_readme=generate_readme, | ||
type_mode="simple", | ||
_demo_path=_demo_path, | ||
_demo_dir=_demo_dir, | ||
_readme_path=_readme_path, | ||
space_url=space_url, | ||
_component_dir=_component_dir, | ||
) | ||
|
||
pypi_exists = pypi_exists == 200 or False | ||
|
||
local_version = get_deep(data, ["project", "version"]) | ||
description = str(get_deep(data, ["project", "description"]) or "") | ||
repo = get_deep(data, ["project", "urls", "repository"]) | ||
space = space_url if space_url else get_deep(data, ["project", "urls", "space"]) | ||
def run_command( | ||
live: LivePanelDisplay, | ||
name: str, | ||
pyproject_toml: dict[str, Any], | ||
suppress_demo_check: bool, | ||
generate_space: bool, | ||
generate_readme: bool, | ||
type_mode: str, | ||
_demo_path: Path, | ||
_demo_dir: Path, | ||
_readme_path: Path, | ||
space_url: str | None, | ||
_component_dir: Path, | ||
simple: bool = False, | ||
): | ||
with open(_demo_path) as f: | ||
demo = f.read() | ||
|
||
if not local_version and not pypi_exists: | ||
raise ValueError( | ||
f"Cannot find version in pyproject.toml or on PyPI for [orange3]{name}[/].\nIf you have just published to PyPI, please wait a few minutes and try again." | ||
) | ||
pypi_exists = requests.get(f"https://pypi.org/pypi/{name}/json").status_code | ||
|
||
module = importlib.import_module(name) | ||
(docs, type_mode) = extract_docstrings(module) | ||
pypi_exists = pypi_exists == 200 or False | ||
|
||
local_version = get_deep(pyproject_toml, ["project", "version"]) | ||
description = str(get_deep(pyproject_toml, ["project", "description"]) or "") | ||
repo = get_deep(pyproject_toml, ["project", "urls", "repository"]) | ||
space = ( | ||
space_url | ||
if space_url | ||
else get_deep(pyproject_toml, ["project", "urls", "space"]) | ||
) | ||
|
||
if not local_version and not pypi_exists: | ||
raise ValueError( | ||
f"Cannot find version in pyproject.toml or on PyPI for [orange3]{name}[/].\nIf you have just published to PyPI, please wait a few minutes and try again." | ||
) | ||
module = importlib.import_module(name) | ||
(docs, type_mode) = extract_docstrings(module) | ||
|
||
if generate_space: | ||
if generate_space: | ||
if not simple: | ||
live.update(":computer: [blue]Generating space.[/]") | ||
|
||
source = make_space( | ||
docs=docs, | ||
name=name, | ||
description=description, | ||
local_version=local_version | ||
if local_version is None | ||
else str(local_version), | ||
demo=demo, | ||
space=space if space is None else str(space), | ||
repo=repo if repo is None else str(repo), | ||
pypi_exists=pypi_exists, | ||
suppress_demo_check=suppress_demo_check, | ||
) | ||
source = make_space( | ||
docs=docs, | ||
name=name, | ||
description=description, | ||
local_version=local_version | ||
if local_version is None | ||
else str(local_version), | ||
demo=demo, | ||
space=space if space is None else str(space), | ||
repo=repo if repo is None else str(repo), | ||
pypi_exists=pypi_exists, | ||
suppress_demo_check=suppress_demo_check, | ||
) | ||
|
||
with open(_demo_dir / "space.py", "w") as f: | ||
f.write(source) | ||
with open(_demo_dir / "space.py", "w") as f: | ||
f.write(source) | ||
if not simple: | ||
live.update( | ||
f":white_check_mark: Space created in [orange3]{_demo_dir}/space.py[/]\n" | ||
) | ||
with open(_demo_dir / "css.css", "w") as f: | ||
f.write(css) | ||
with open(_demo_dir / "css.css", "w") as f: | ||
f.write(css) | ||
|
||
if generate_readme: | ||
if generate_readme: | ||
if not simple: | ||
live.update(":pencil: [blue]Generating README.[/]") | ||
readme = make_markdown( | ||
docs, name, description, local_version, demo, space, repo, pypi_exists | ||
) | ||
readme = make_markdown( | ||
docs, name, description, local_version, demo, space, repo, pypi_exists | ||
) | ||
|
||
with open(_readme_path, "w") as f: | ||
f.write(readme) | ||
with open(_readme_path, "w") as f: | ||
f.write(readme) | ||
if not simple: | ||
live.update( | ||
f":white_check_mark: README generated in [orange3]{_readme_path}[/]" | ||
) | ||
if simple: | ||
short_readme_path = Path(_readme_path).relative_to(_component_dir) | ||
short_demo_path = Path(_demo_path).relative_to(_component_dir) | ||
live.update( | ||
f":white_check_mark: Documention generated in [orange3]{short_demo_path}[/] and [orange3]{short_readme_path}[/]. Pass --no-generate-docs to disable auto documentation." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed! |
||
) | ||
|
||
if type_mode == "simple": | ||
print( | ||
live.update( | ||
"\n:orange_circle: [red]The docs were generated in simple mode. Updating python to a version greater than 3.9 will result in richer documentation.[/]" | ||
) |
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.
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.
The warning about python 3.9 needs to be printed with
live
otherwise it's out of order: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.
I would maybe skip the "Generating documentation" and just print the "Documentation generated..." but something like
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.
I kinda wanted it to be not in the live panel because there isn't actually an issue with the doc gen, just a note. But I can put it at the bottom with some space.
Will update the message.
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.
Looks great! My bad, I think we should remove the backticks around --no-generate-docs since they don't change. how it renders