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

Mechanical stubs to sphinx documentation #1

Merged
merged 5 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
19 changes: 14 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
repos:

klmcadams marked this conversation as resolved.
Show resolved Hide resolved
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
# - repo: https://github.com/psf/black
# rev: 23.7.0
# hooks:
# - id: black

- repo: https://github.com/adamchainz/blacken-docs
rev: 1.16.0
Expand All @@ -15,6 +15,7 @@ repos:
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black"]

# - repo: https://github.com/PyCQA/flake8
# rev: 6.1.0
Expand All @@ -24,4 +25,12 @@ repos:
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
hooks:
- id: codespell
- id: codespell

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-merge-conflict
- id: debug-statements
- id: check-yaml
- id: trailing-whitespace
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,38 @@ autocomplete.

# Documentation

1. Install Mechanical 2023 R2 onto your computer.
1. Install Mechanical 2023 R2 onto your computer.

Ensure the environment variable, AWP_ROOT232, is set to the location of
Mechanical 2023 R2 (C:\Program Files\Ansys Inc\v232).

2. Run main.py to generate the stubs from Mechanical 232.

python main.py
```python main.py```

Note: There may be an Unhandled Exception when the stubs are done running.
If the message, "Done creating all Mechanical stubs" appears, proceed
If the message, "Done creating all Mechanical stubs" appears, proceed
to the next step.

3. Next, create a virtual environment and activate it:

python -m venv .venv
```python -m venv .venv```

Windows:
.venv\Scripts\activate.bat
```.venv\Scripts\activate.bat```

Linux:
source .venv/bin/activate
```source .venv/bin/activate```

4. Navigate to the package directory and install mechanical-stubs

cd package && pip install -e .
```cd package && pip install -e .```

5. Navigate to the doc directory and make the Sphinx documentation

cd doc && make html
```cd doc && make html```

Note: Warning messages can be ignored for now.
Note: Warning messages can be ignored for now.


# Quickstart
Expand Down
28 changes: 24 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@
import System # isort: skip


def resolve():
def get_version():
install_dir = os.environ["AWP_ROOT232"] # Change this back to AWP_ROOTDV_DEV
version = int(install_dir[-3:])

return install_dir, version


def resolve():
install_dir, version = get_version()
platform_string = "winx64" if os.name == "nt" else "linx64"
sys.path.append(os.path.join(install_dir, "aisol", "bin", platform_string))
klmcadams marked this conversation as resolved.
Show resolved Hide resolved
version = int(install_dir[-3:])
clr.AddReference("Ansys.Mechanical.Embedding")
import Ansys
klmcadams marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -54,17 +60,31 @@ def is_type_published(mod_type: "System.RuntimeType"):


def make():
install_dir, version = get_version() # 232
version = str(version)
version = version[:2] + "." + version[2:]
major_minor = version.split(".")
major = major_minor[0]
minor = major_minor[1]

outdir.mkdir(parents=True, exist_ok=True)

for assembly in ASSEMBLIES:
gen.make(outdir, assembly, type_filter=is_type_published)

with open(os.path.join(outdir, "Ansys", "__init__.py"), "w") as f:
f.write(
'''try:
f'''try:
import importlib.metadata as importlib_metadata
except ModuleNotFoundError: # pragma: no cover
import importlib_metadata # type: ignore
__version__ = importlib_metadata.version("ansys-mechanical-stubs")
patch = importlib_metadata.version("ansys-mechanical-stubs")

# major, minor, patch
version_info = {major}, {minor}, patch

# Format version
__version__ = ".".join(map(str, version_info))
"""Mechanical Scripting version"""
'''
)
Expand Down
1 change: 0 additions & 1 deletion package/doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ help:

clean:
rm -rf $(BUILDDIR)/*
rm -rf source/examples/gallery_examples
find . -type d -name "_autosummary" -exec rm -rf {} +

pdf:
Expand Down
51 changes: 24 additions & 27 deletions package/doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

from datetime import datetime
import os
from datetime import datetime

from Ansys import __version__
from ansys_sphinx_theme import (
ansys_favicon,
ansys_logo_white,
Expand All @@ -17,31 +18,31 @@
)
from sphinx.builders.latex import LaTeXBuilder

from Ansys import __version__

LaTeXBuilder.supported_image_types = ["image/png", "image/pdf", "image/svg+xml"]

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

# Project information
project = "ansys-mechanical-stubs"
project = "ansys-mechanical-scripting"
copyright = f"(c) {datetime.now().year} ANSYS, Inc. All rights reserved"
author = "ANSYS, Inc."
release = version = __version__
cname = os.getenv("DOCUMENTATION_CNAME", default="scripting.mechanical.docs.pyansys.com")
switcher_version = get_version_match(__version__)
release = version = __version__
cname = os.getenv(
"DOCUMENTATION_CNAME", default="scripting.mechanical.docs.pyansys.com"
)
switcher_version = get_version_match(__version__)

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
'sphinx.ext.intersphinx',
'sphinx.ext.autodoc',
'sphinx.ext.viewcode',
'numpydoc',
'sphinx.ext.autosummary',
'sphinx.ext.inheritance_diagram',
"sphinx.ext.intersphinx",
"sphinx.ext.autodoc",
"sphinx.ext.viewcode",
"numpydoc",
"sphinx.ext.autosummary",
"sphinx.ext.inheritance_diagram",
"sphinx_jinja",
"autoapi.extension",
]
Expand All @@ -58,7 +59,7 @@
"special-members",
]
autoapi_template_dir = "_autoapi_templates"
suppress_warnings = ["autoapi.python_import_resolution"]
suppress_warnings = ["autoapi.python_import_resolution", "epub.duplicated_toc_entry"]
exclude_patterns.append("_autoapi_templates/index.rst")
autoapi_python_use_implicit_namespaces = True

Expand All @@ -70,7 +71,7 @@
"imageio": ("https://imageio.readthedocs.io/en/stable", None),
"pandas": ("https://pandas.pydata.org/pandas-docs/stable", None),
"pytest": ("https://docs.pytest.org/en/stable", None),
}
}

# Numpydoc config
numpydoc_use_plots = True
Expand Down Expand Up @@ -103,10 +104,10 @@
html_favicon = ansys_favicon

# The suffix(es) of source filenames.
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "sphinx"
Expand All @@ -121,7 +122,7 @@
# Select desired logo, theme, and declare the html title
html_logo = pyansys_logo_black
html_theme = "ansys_sphinx_theme"
html_short_title = html_title = "Mechanical Stubs"
html_short_title = html_title = "Ansys Mechanical Scripting"

# specify the location of your github repo
html_context = {
Expand All @@ -143,14 +144,10 @@
"use_edit_page_button": True,
"additional_breadcrumbs": [
("PyAnsys", "https://docs.pyansys.com/"),
],
"icon_links": [
{
"name": "Support",
"url": "https://github.com/ansys/mechanical-stubs/discussions",
"icon": "fa fa-comment fa-fw",
},
("PyMechanical", "https://mechanical.docs.pyansys.com/"),
(
"Mechanical Scripting",
"https://mechanical.docs.pyansys.com/version/stable/user_guide_scripting/index.html",
),
],
}


4 changes: 2 additions & 2 deletions package/doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
contain the root `toctree` directive.

Mechanical API Documentation
======================================
============================

This documentation lists the APIs used in Ansys Mechanical 2023R2.
This documentation lists the APIs used in Ansys Mechanical 2023R2.

.. toctree::
:maxdepth: 2
Expand Down
2 changes: 1 addition & 1 deletion package/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "flit_core.buildapi"
[project]
# Check https://flit.readthedocs.io/en/latest/pyproject_toml.html for all available sections
name = "ansys-mechanical-stubs"
version = "0.1.dev0"
version = "0"
description = "PyMechanical scripting API stubs."
readme = "README.rst"
requires-python = ">=3.9"
Expand Down