-
Notifications
You must be signed in to change notification settings - Fork 36
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
Automate examples in documentation (#603) #625
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
aa58e3b
Update CONTRIBUTING.md to reference the correct branch (2.x)
7ffeff0
Automate examples in documentation for issue #603
71961cb
Merge pull request #1 from srinitha709/update-contributing-docs
srinitha709 600be54
Update CONTRIBUTING.md
srinitha709 fcc3a18
Update conf.py
srinitha709 267fa5e
Update conf.py
srinitha709 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
Empty file.
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 |
---|---|---|
|
@@ -9,3 +9,4 @@ pyproject.toml | |
.idea/ | ||
.DS_Store | ||
schema/*/build/ | ||
workflows/ |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Examples | ||
======== | ||
|
||
.. code-block:: python | ||
|
||
.. code-block:: python | ||
|
||
>>> multiply(2, 3) |
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,10 @@ | ||
|
||
def multiply(a, b): | ||
""" | ||
Multiply two numbers together. | ||
|
||
Example: | ||
>>> multiply(2, 3) | ||
6 | ||
""" | ||
return a * b |
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,45 @@ | ||
import os | ||
|
||
def extract_examples(file_path): | ||
"""Extract examples from source files.""" | ||
examples = [] | ||
with open(file_path, 'r') as f: | ||
for line in f: | ||
if line.strip().startswith(">>>"): | ||
examples.append(line.strip()) | ||
return examples | ||
|
||
def update_docs(doc_path, examples): | ||
"""Insert updated examples into documentation.""" | ||
print(f"Reading from: {doc_path}") # Debugging output | ||
with open(doc_path, 'r') as f: | ||
content = f.readlines() | ||
|
||
updated_content = [] | ||
inside_placeholder = False | ||
for line in content: | ||
if line.strip() == "# Examples will be dynamically updated here.": | ||
inside_placeholder = True | ||
updated_content.append(".. code-block:: python\n\n") | ||
for example in examples: | ||
updated_content.append(f" {example}\n") | ||
elif inside_placeholder and line.strip() == "": | ||
inside_placeholder = False | ||
elif not inside_placeholder: | ||
updated_content.append(line) | ||
|
||
with open(doc_path, 'w') as f: | ||
f.writelines(updated_content) | ||
print(f"Updated {doc_path} with new examples.") # Debugging output | ||
|
||
# Example usage | ||
source_file_path = 'examples/example.py' # Path to the source code file | ||
doc_file_path = 'docs/source/examples.rst' # Path to the documentation file | ||
|
||
print(f"Extracting examples from: {source_file_path}") # Debugging output | ||
examples = extract_examples(source_file_path) # Pass the actual file path here | ||
print(f"Extracted examples: {examples}") # Debugging output | ||
|
||
print(f"Updating documentation: {doc_file_path}") # Debugging output | ||
update_docs(doc_file_path, examples) | ||
print("Documentation updated successfully!") # Final success message |
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.
So I believe we would like to use our validation models that are defined here as the source and update the example section that corresponds to that model in docs/source/concepts.
For example, CopyNumberCount validation model would generate the docs example here. We'd want the docs example to also add the
id
field which is theout.ga4gh_identify
field in the validation model.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.
Thank you for the clarification! I will use the validation models as the source for generating the documentation examples. specifically I will extract the relevant data from each model, including the out.ga4gh_identify field and update the example section in docs/source/concepts. I’ll proceed with implementing this and updating the documentation accordingly.