Skip to content

Commit 401a1d4

Browse files
jorgepilotopre-commit-ci[bot]RobPasMue
authored
doc: getting started layout (#830)
* doc: getting started layout * doc: complete prerequisites * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * doc: use datatables * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * doc: install * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * doc: additional targets * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * doc: offline * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * doc: wheelhouse * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: remove unnecessary files * fix: links * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: links * fix: add link to pypi * fix: typo * fix: avoid using will * fix: missing function docstrings * fix: remove unnecessary CSS and JS * fix: logic for extracting metadata * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: ignore link to customer portal * fix: ignore links * fix: broken link * fix: lincheck issues --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Roberto Pastor Muela <[email protected]>
1 parent 9d79068 commit 401a1d4

File tree

11 files changed

+456
-283
lines changed

11 files changed

+456
-283
lines changed

doc/source/conf.py

Lines changed: 113 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from ansys_sphinx_theme import ansys_favicon, get_version_match
1010
import github
11-
import jinja2
1211
from PIL import Image
1312
import requests
1413
import sphinx
@@ -89,15 +88,77 @@
8988

9089
metadata = Path(__file__).parent.parent.parent / "projects.yaml"
9190

91+
92+
def read_dependencies_from_pyproject():
93+
"""Read the dependencies declared in the project file."""
94+
pyproject = Path(__file__).parent.parent.parent / "pyproject.toml"
95+
if not pyproject.exists():
96+
raise ValueError(f"The file {pyproject} does not exist.")
97+
98+
pyproject_content = toml.loads(pyproject.read_text(encoding="utf-8"))
99+
dependencies = pyproject_content["project"]["dependencies"]
100+
return {pkg.split("==")[0]: pkg.split("==")[1] for pkg in dependencies}
101+
102+
103+
def read_optional_dependencies_from_pyproject():
104+
"""Read the extra dependencies declared in the project file."""
105+
pyproject = Path(__file__).parent.parent.parent / "pyproject.toml"
106+
if not pyproject.exists():
107+
raise ValueError(f"The file {pyproject} does not exist.")
108+
109+
pyproject_content = toml.loads(pyproject.read_text(encoding="utf-8"))
110+
exclude_targets = ["doc"]
111+
optional_dependencies = {
112+
target: {pkg.split("==")[0]: pkg.split("==")[1] for pkg in deps}
113+
for target, deps in pyproject_content["project"]["optional-dependencies"].items()
114+
if target not in exclude_targets
115+
}
116+
return optional_dependencies
117+
118+
119+
def get_last_metapackage_release():
120+
"""Retrieve the last release of the metapackage."""
121+
# Get the PyAnsys metapackage repository
122+
g = github.Github(os.getenv("GITHUB_TOKEN", None))
123+
repository = g.get_repo("ansys/pyansys")
124+
125+
# Get the last release
126+
last_release = repository.get_latest_release()
127+
128+
return last_release.tag_name
129+
130+
131+
jinja_globals = {
132+
"LAST_RELEASE": get_last_metapackage_release(),
133+
"VERSION": version,
134+
"SUPPORTED_PYTHON_VERSIONS": ["3.10", "3.11", "3.12"],
135+
"SUPPORTED_PLATFORMS": ["Windows", "macOS", "Linux"],
136+
}
92137
jinja_contexts = {
93-
"project_context": {"projects": yaml.safe_load(metadata.read_text(encoding="utf-8"))}
138+
"project_context": {"projects": yaml.safe_load(metadata.read_text(encoding="utf-8"))},
139+
"dependencies": {"dependencies": read_dependencies_from_pyproject()},
140+
"optional_dependencies": {"optional_dependencies": read_optional_dependencies_from_pyproject()},
141+
"wheelhouse": {
142+
"wheelhouse": {
143+
platform: icon
144+
for platform, icon in zip(["Windows", "macOS", "Linux"], ["windows", "apple", "linux"])
145+
}
146+
},
94147
}
95148

96149
html_context = {
97150
"github_user": "ansys",
98151
"github_repo": "pyansys",
99152
"github_version": "main",
100153
"doc_path": "doc/source",
154+
"page_assets": {
155+
"getting-started/prerequisites": {
156+
"needs_datatables": True,
157+
},
158+
"getting-started/install": {
159+
"needs_datatables": True,
160+
},
161+
},
101162
}
102163

103164
html_theme_options = {
@@ -153,9 +214,11 @@
153214

154215
# Ignore certain URLs
155216
linkcheck_ignore = [
156-
r"https://www.ansys.com/.*",
217+
r"https://www.ansys.com.*",
157218
rf"https://pypi.org/project/pyansys/{switcher_version}.*",
158219
r"https://ansunits.docs.*",
220+
r"https://download.ansys.com/.*",
221+
r"https://github.com/ansys/pyansys/releases/download/*",
159222
]
160223

161224
# User agent
@@ -179,37 +242,6 @@
179242
# file for the minor versions of the PyAnsys metapackage release branches.
180243

181244

182-
def generate_rst_files(versions: list[str], tables: dict[str, list[str]]):
183-
"""Generate the .rst files for the package versions."""
184-
# Create Jinja2 environment
185-
jinja_env = jinja2.Environment(loader=jinja2.BaseLoader())
186-
187-
# Compile the template
188-
template = jinja_env.from_string(VERSIONS_TEMPLATE)
189-
190-
# Generate an .rst file for each version entry
191-
for version in versions:
192-
# Generate the content of the .rst file using the Jinja template
193-
rendered_content = template.render(
194-
version=version,
195-
table=tables[version],
196-
)
197-
198-
# Define the output path for the generated file
199-
output_filename = GENERATED_DIR / f"version_{version}.rst"
200-
201-
# Write the rendered content to the file
202-
output_filename.write_text(rendered_content, encoding="utf-8")
203-
204-
# Generate the index.rst file
205-
index_template = jinja_env.from_string(INDEX_TEMPLATE)
206-
rendered_index = index_template.render(versions=versions)
207-
208-
# Write the rendered content to the file
209-
output_filename = GENERATED_DIR / "index.rst"
210-
output_filename.write_text(rendered_index, encoding="utf-8")
211-
212-
213245
def get_documentation_link_from_pypi(library: str, version: str) -> str:
214246
"""Get the documentation link from PyPI for a specific library and version."""
215247
# Get the PyPI metadata for the library
@@ -341,31 +373,6 @@ def build_versions_table(branch: str) -> list[str]:
341373
return table
342374

343375

344-
def get_release_branches_in_metapackage():
345-
"""Retrieve the release branches in the PyAnsys metapackage."""
346-
# Get the PyAnsys metapackage repository
347-
g = github.Github(os.getenv("GITHUB_TOKEN", None))
348-
github_repo = g.get_repo("ansys/pyansys")
349-
350-
# Get the branches
351-
branches = github_repo.get_branches()
352-
353-
# Get the branches that are release branches + main
354-
release_branches = []
355-
versions = []
356-
for branch in branches:
357-
if branch.name.startswith("release"):
358-
release_branches.append(branch.name)
359-
versions.append(branch.name.split("/")[-1])
360-
361-
# Sort the release branches and versions: from newest to oldest
362-
release_branches.reverse()
363-
versions.reverse()
364-
365-
# Return the dev/main branch and the release branches (and versions)
366-
return ["main"] + release_branches, ["dev"] + versions
367-
368-
369376
###########################################################################
370377
# Adapting thumbnails to the documentation
371378
###########################################################################
@@ -440,15 +447,6 @@ def revert_thumbnails(app: sphinx.application.Sphinx, exception):
440447
subprocess.run(["git", "checkout", "--", thumbnail_dir])
441448

442449

443-
def package_versions_table(app: sphinx.application.Sphinx):
444-
"""Generate the package_versions directory."""
445-
branches, versions = get_release_branches_in_metapackage()
446-
generate_rst_files(
447-
versions,
448-
{version: build_versions_table(branch) for version, branch in zip(versions, branches)},
449-
)
450-
451-
452450
def convert_yaml_to_json(app: sphinx.application.Sphinx):
453451
"""
454452
Convert a YAML file to a JSON file.
@@ -475,6 +473,52 @@ def convert_yaml_to_json(app: sphinx.application.Sphinx):
475473
print(f"JSON file successfully written to {json_path}")
476474

477475

476+
def fetch_release_branches_and_python_limits(app: sphinx.application.Sphinx):
477+
"""Retrieve the release branches in the PyAnsys metapackage."""
478+
# Get the PyAnsys metapackage repository
479+
g = github.Github(os.getenv("GITHUB_TOKEN", None))
480+
repository = g.get_repo("ansys/pyansys")
481+
482+
# Get the branches
483+
branches = repository.get_branches()
484+
485+
supported_python_versions_by_metapackage_version = []
486+
for branch in branches:
487+
if not branch.name.startswith("release") and not branch.name.startswith("main"):
488+
continue
489+
490+
# Inspect the pyproject.toml file to get the Python limits
491+
pyproject = repository.get_contents("pyproject.toml", ref=branch.name)
492+
content = toml.loads(pyproject.decoded_content.decode("utf-8"))
493+
494+
# Extract the latest version and the Python limits
495+
branch_name = branch.name
496+
metapackage_version = branch_name.split("/")[-1]
497+
try:
498+
pypi_version = content["project"]["version"]
499+
python_limits = content["project"]["requires-python"].split(",")
500+
except KeyError:
501+
pypi_version = content["tool"]["poetry"]["version"]
502+
python_limits = content["tool"]["poetry"]["dependencies"]["python"].split(",")
503+
504+
if pypi_version.split(".")[-1].startswith("dev"):
505+
link = repository.html_url
506+
else:
507+
link = f"https://pypi.org/project/pyansys/{pypi_version}"
508+
509+
supported_python_versions_by_metapackage_version.append(
510+
{
511+
"version": metapackage_version,
512+
"python": {"lower": python_limits[0], "upper": python_limits[1]},
513+
"link": link,
514+
}
515+
)
516+
517+
print(supported_python_versions_by_metapackage_version)
518+
519+
jinja_contexts["releases"] = {"table_data": supported_python_versions_by_metapackage_version}
520+
521+
478522
def setup(app: sphinx.application.Sphinx):
479523
"""Run different hook functions during the documentation build.
480524
@@ -486,7 +530,7 @@ def setup(app: sphinx.application.Sphinx):
486530
# At the beginning of the build process - update the version in cheatsheet
487531
app.connect("builder-inited", convert_yaml_to_json)
488532
app.connect("builder-inited", resize_thumbnails)
489-
app.connect("builder-inited", package_versions_table)
533+
app.connect("builder-inited", fetch_release_branches_and_python_limits)
490534

491535
# Reverting the thumbnails - no local changes
492536
app.connect("build-finished", revert_thumbnails)

doc/source/getting-started.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Getting started
2+
===============
3+
4+
This page helps you quickly get started with PyAnsys. It lists all the
5+
prerequisites and guides you step by step to install the project on your
6+
platform.
7+
8+
.. grid:: 1 1 3 3
9+
10+
.. grid-item-card:: :fa:`info-circle` About PyAnsys
11+
:link: getting-started/about
12+
:link-type: doc
13+
:padding: 2 2 2 2
14+
15+
Learn more about PyAnsys and its ecosystem
16+
17+
.. grid-item-card:: :fa:`tasks` Prerequisites
18+
:link: getting-started/prerequisites
19+
:link-type: doc
20+
:padding: 2 2 2 2
21+
22+
What you need prior installing PyAnsys
23+
24+
.. grid-item-card:: :fa:`download` Install
25+
:link: getting-started/install
26+
:link-type: doc
27+
:padding: 2 2 2 2
28+
29+
Guidelines on how to install PyAnsys in your system
30+
31+
.. toctree::
32+
:maxdepth: 3
33+
:hidden:
34+
35+
About<getting-started/about>
36+
Prerequisites<getting-started/prerequisites>
37+
Install<getting-started/install>
38+

doc/source/getting-started/about.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
About
2+
#####
3+
4+
PyAnsys is a collection of Python libraries and tools developed by `ANSYS,
5+
Inc.`_ It provides access to `Ansys products`_ by using a Python interface,
6+
enabling users to perform engineering simulations, data processing, and
7+
automation tasks.
8+
9+
To ease the installation of the libraries and tools, PyAnsys provides a Python
10+
metapackage. This ensures compatibility between its projects.
11+
12+
Key features of PyAnsys
13+
=======================
14+
15+
PyAnsys shines in the following areas:
16+
17+
- **Automation of workflows:** PyAnsys enables users to automate repetitive or
18+
complex simulation tasks.
19+
20+
- **Integration with the Python ecosystem:** users can leverage the Python
21+
ecosystem.
22+
23+
- **Cross-product functionality:** PyAnsys provides Python APIs for various
24+
Ansys services and products. By allowing users to interact with multiple
25+
products in a single environment, PyAnsys enables users to streamline their
26+
workflows.
27+
28+
The PyAnsys ecosystem
29+
=====================
30+
31+
PyAnsys libraries can be classified into wrappers and tools.
32+
33+
**Wrappers** are Python libraries that provide direct access to Ansys products.
34+
Communication between the product and the library is performed via `gRPC
35+
<grpc_>`_. Therefore, users can have the product installed remotely and connect
36+
to that remote instance.
37+
38+
**Tools** are Python libraries that provide additional functionality to the
39+
wrappers.

0 commit comments

Comments
 (0)