Skip to content
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

feat: add quarto cheat sheet setup to docs build actions #528

Merged
merged 42 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
eed0e05
feat: add quarto cheatsheet action to docs build
Revathyvenugopal162 Jul 31, 2024
7ad5d3c
Merge branch 'main' into feat/add-quarto-pyansys-actions
Revathyvenugopal162 Jul 31, 2024
5b89510
fix: update the cheatsheet
Revathyvenugopal162 Jul 31, 2024
15a37f2
Merge branch 'main' into feat/add-quarto-pyansys-actions
Revathyvenugopal162 Aug 7, 2024
7d67c10
fix: test cheatsheet
Revathyvenugopal162 Aug 7, 2024
227473f
Merge branch 'feat/add-quarto-pyansys-actions' of https://github.com/…
Revathyvenugopal162 Aug 7, 2024
61e039c
fix: test cheatsheet
Revathyvenugopal162 Aug 7, 2024
f35cc94
fix: test cheatsheet with actions
Revathyvenugopal162 Aug 7, 2024
35c6ac6
test: add popler package
Revathyvenugopal162 Aug 8, 2024
e211294
fix: change the branch of theme
Revathyvenugopal162 Aug 8, 2024
b30c869
Merge branch 'main' into feat/add-quarto-pyansys-actions
Revathyvenugopal162 Aug 9, 2024
45e633b
Merge branch 'main' into feat/add-quarto-pyansys-actions
Revathyvenugopal162 Aug 12, 2024
39fe39c
fix: codestyle
Revathyvenugopal162 Aug 12, 2024
56e6806
Merge branch 'main' into feat/add-quarto-pyansys-actions
Revathyvenugopal162 Aug 12, 2024
987708c
fix: test with upfdated branch
Revathyvenugopal162 Aug 12, 2024
0b958b1
fix: test quarto version
Revathyvenugopal162 Aug 12, 2024
58ce360
Merge branch 'main' into feat/add-quarto-pyansys-actions
Revathyvenugopal162 Aug 12, 2024
508f834
fix: install quarto
Revathyvenugopal162 Aug 12, 2024
2ec5f3e
fix: install quarto
Revathyvenugopal162 Aug 12, 2024
a57f1f9
fix: install quarto
Revathyvenugopal162 Aug 12, 2024
e34b76d
fix: install quarto without path
Revathyvenugopal162 Aug 12, 2024
d66fac6
fix: install quarto without path
Revathyvenugopal162 Aug 12, 2024
cc3eeb8
fix: install jupyter
Revathyvenugopal162 Aug 12, 2024
1d0f7b4
fix: install quarto
Revathyvenugopal162 Aug 12, 2024
5a661d5
fix: initial jinja template
Revathyvenugopal162 Aug 12, 2024
f47e552
fix: the jinja template
Revathyvenugopal162 Aug 13, 2024
05f06eb
fix: templates and conf.py
Revathyvenugopal162 Aug 13, 2024
c53c1ba
docs: add the docstrings
Revathyvenugopal162 Aug 13, 2024
c997c07
Apply suggestions from code review
Revathyvenugopal162 Aug 13, 2024
ef4d1fa
Apply suggestions from code review
Revathyvenugopal162 Aug 13, 2024
af2a2e2
docs: add the docstrings
Revathyvenugopal162 Aug 13, 2024
506dacb
Update doc/source/cheat_sheet.jinja
Revathyvenugopal162 Aug 14, 2024
fdc7c73
Merge branch 'feat/add-quarto-pyansys-actions' of https://github.com/…
Revathyvenugopal162 Aug 14, 2024
a0ccdde
docs: update the gitignore
Revathyvenugopal162 Aug 14, 2024
1a2a598
Merge branch 'main' into feat/add-quarto-pyansys-actions
jorgepiloto Aug 14, 2024
ffb634a
docs: update the actions for windows and references
Revathyvenugopal162 Aug 14, 2024
285c458
Merge branch 'feat/add-quarto-pyansys-actions' of https://github.com/…
Revathyvenugopal162 Aug 14, 2024
f278b05
Merge branch 'main' into feat/add-quarto-pyansys-actions
Revathyvenugopal162 Aug 19, 2024
51df518
Merge branch 'main' into feat/add-quarto-pyansys-actions
Revathyvenugopal162 Aug 26, 2024
d2b2f08
fix: updated the dependencies
Revathyvenugopal162 Aug 26, 2024
6acdf5c
Merge branch 'feat/add-quarto-pyansys-actions' of https://github.com/…
Revathyvenugopal162 Aug 26, 2024
7b97016
Merge branch 'main' into feat/add-quarto-pyansys-actions
Revathyvenugopal162 Aug 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ jobs:
skip-install: true
python-version: ${{ env.MAIN_PYTHON_VERSION }}
use-python-cache: false
needs-quarto: true

tests:
name: "Tests"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ instance/

# Sphinx documentation
doc/_build/
doc/source/cheat_sheet.qmd

# PyBuilder
.pybuilder/
Expand Down
26 changes: 26 additions & 0 deletions _doc-build-linux/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ inputs:
required: true
type: boolean

needs-quarto:
description: |
Whether to add a Quarto cheatsheet to the documentation. Default value is
``false``.
default: false
required: false
type: boolean


runs:
using: "composite"
Expand Down Expand Up @@ -155,6 +163,24 @@ runs:
run: |
sudo apt-get install -y texlive-latex-extra latexmk

- name: Install Quarto
if: ${{ inputs.needs-quarto == 'true' }}
uses: quarto-dev/quarto-actions/setup@v2
with:
tinytex: true

- name: Check Quarto Version
if: ${{ inputs.needs-quarto == 'true' }}
shell: bash
run: |
quarto --version

- name: "Install Poppler for PDF to PNG conversion"
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y poppler-utils

- name: "Check if requirements.txt file exists"
shell: bash
run: |
Expand Down
34 changes: 34 additions & 0 deletions _doc-build-windows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ inputs:
required: true
type: boolean

needs-quarto:
description: |
Whether to add a Quarto cheatsheet to the documentation. Default value is
``false``.
default: false
required: false
type: boolean


runs:
using: "composite"
Expand Down Expand Up @@ -164,6 +172,12 @@ runs:
choco install miktex -y
echo "C:\Program Files\MiKTeX\miktex\bin\x64" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8

- name: "Install Poppler for PDF to PNG conversion"
shell: powershell
run: |
choco install poppler -y
echo "C:\Program Files\poppler\bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8

# ------------------------------------------------------------------------

- uses: ansys/actions/_logging@main
Expand All @@ -179,6 +193,26 @@ runs:

# ------------------------------------------------------------------------

- uses : ansys/actions/_logging@main
with:
level: "INFO"
message: >
Setup quarto to build the cheatsheet.

- name: Install Quarto
if: ${{ inputs.needs-quarto == 'true' }}
uses: quarto-dev/quarto-actions/setup@v2
with:
tinytex: true

- name: Check Quarto Version
if: ${{ inputs.needs-quarto == 'true' }}
shell: bash
run: |
quarto --version

# ------------------------------------------------------------------------

- uses: ansys/actions/_logging@main
with:
level: "INFO"
Expand Down
9 changes: 9 additions & 0 deletions doc-build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ inputs:
required: false
type: boolean

needs-quarto:
description: >
Whether to add a Quarto cheatsheet to the documentation. Default value is
``false``.
default: false
required: false
type: boolean

runs:
using: "composite"
Expand Down Expand Up @@ -199,6 +206,7 @@ runs:
skip-json-build: ${{ inputs.skip-json-build }}
check-links: ${{ inputs.check-links }}
add-pdf-html-docs-as-assets: ${{ inputs.add-pdf-html-docs-as-assets }}
needs-quarto: ${{ inputs.needs-quarto }}

# ------------------------------------------------------------------------

Expand All @@ -222,3 +230,4 @@ runs:
skip-json-build: ${{ inputs.skip-json-build }}
check-links: ${{ inputs.check-links }}
add-pdf-html-docs-as-assets: ${{ inputs.add-pdf-html-docs-as-assets }}
needs-quarto: ${{ inputs.needs-quarto }}
1 change: 1 addition & 0 deletions doc/source/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.quarto/
43 changes: 43 additions & 0 deletions doc/source/cheat_sheet.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
title: Ansys Actions
format: cheat_sheet-pdf
version: {{ version }}
footer: Getting started with Ansys Actions
footerlinks:
- urls: 'https://actions.docs.ansys.com/version/stable/'
text: Ansys Actions documentation
- urls: 'https://github.com/ansys/actions/'
text: Ansys Actions GitHub
execute:
# output: false
eval: false

latex-clean: true
jupyter:
jupytext:
text_representation:
extension: .qmd
format_name: quarto
format_version: '1.0'
jupytext_version: 1.16.1
kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
---
{%- for action_name, action_data in actions.items() %}
# {{ action_name | capitalize }}
{% for example in action_data.examples_for_cheatsheet %}

**{{ example.title | capitalize }}**

```{yml}
{{ example.code }}
```

{% if example.reference_url -%}
***Ref***: [{{ example.title }}]({{ example.reference_url }})
{% endif -%}
{% endfor -%}

{% endfor -%}
63 changes: 60 additions & 3 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
project = "Ansys Actions"
copyright = f"(c) 2022-{datetime.today().year} ANSYS, Inc. and/or its affiliates."
author = "ANSYS, Inc."
cname = os.getenv("DOCUMENTATION_CNAME", "nocname.com")
cname = os.getenv("DOCUMENTATION_CNAME", "actions.docs.ansys.com")

# Read version from VERSION file in base root directory
source_dir = pathlib.Path(__file__).parent.resolve().absolute()
Expand All @@ -40,6 +40,7 @@
actions_version = (
"main" if __version__.endswith("dev0") else f"v{get_version_match(__version__)}"
)
switcher_version = get_version_match(__version__)

html_theme = "ansys_sphinx_theme"
html_favicon = ansys_favicon
Expand All @@ -63,14 +64,18 @@
],
"switcher": {
"json_url": f"https://{cname}/versions.json",
"version_match": get_version_match(__version__),
"version_match": switcher_version,
},
"use_meilisearch": {
"api_key": os.getenv("MEILISEARCH_PUBLIC_API_KEY", ""),
"index_uids": {
f"actions-v{get_version_match(__version__).replace('.', '-')}": "Ansys-actions",
f"actions-v{switcher_version.replace('.', '-')}": "Ansys-actions",
},
},
"cheatsheet": {
"file": "cheat_sheet.qmd",
"title": "Actions cheat sheet",
},
}

# Specify Sphinx extensions to use
Expand Down Expand Up @@ -338,3 +343,55 @@ def load_file_lines_as_list(file_path):
jinja_contexts["check-vulnerabilities"]["ignored_safety"] = load_file_lines_as_list(
IGNORED_SAFETY
)


def get_example_content_for_cheatsheet(example_file):
"""Get the content of an example file for the cheatsheet.

Parameters
----------
example_file : ~pathlib.Path
The ``Path`` for the example file.

Returns
-------
str
A string representing the content of the example file.
"""
with open(example_file, "r") as yaml_file:
file_content = yaml.safe_load(yaml_file)
first_key = next(iter(file_content))
file_content = file_content[first_key]["steps"]
return yaml.dump(file_content, default_flow_style=False)


def get_docs_link_for_action(action_file, action_name):
"""Get the link to the documentation for a specific action."""
return f"https://{cname}/version/{switcher_version}/{action_file.parent.parent.name}/index.html#{action_name}-action"


# Generate the cheatsheet content
actions_cheatsheet_jinja_contexts = {
action_dir.name.replace("-", " ").casefold(): {
"examples_for_cheatsheet": [
{
"name": action_dir.name.replace("-", " "),
"title": get_example_file_title(file),
"code": get_example_content_for_cheatsheet(file),
"reference_url": get_docs_link_for_action(file, action_dir.name),
}
for file in collect_examples_from_action_name(action_dir.name)
]
}
for action_dir in public_actions
}

jinja2_env = jinja2.Environment(loader=jinja2.FileSystemLoader(source_dir))
template = jinja2_env.get_template("cheat_sheet.jinja")

content = template.render(
version=actions_version, actions=actions_cheatsheet_jinja_contexts
)
with open("cheat_sheet.qmd", "w") as cheat_sheet_file_rendered:
cheat_sheet_file_rendered.write(content)
cheat_sheet_file_rendered.close()
2 changes: 2 additions & 0 deletions requirements/requirements_doc.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
ansys-sphinx-theme==1.0.7
jupyter==1.0.0
nbformat==5.10.4
pyyaml==6.0.2
Sphinx==8.0.2
sphinx-copybutton==0.5.2
Expand Down
Loading