Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ jobs:
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}
check-links: false
sphinxopts: '-j auto'

package:
name: Package library
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/nightly-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}
check-links: false
sphinxopts: '-j auto'

docs_upload:
needs: docs_build
Expand Down
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

# Intersphinx mapping
intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
"python": ("https://docs.python.org/3.11", None),
# kept here as an example
# "scipy": ("https://docs.scipy.org/doc/scipy/reference", None),
# "numpy": ("https://numpy.org/devdocs", None),
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ requires = [

[project]
name = "ansys-dynamicreporting-core"
version = "0.6.0.dev0"
version = "0.6.1.dev0"
authors = [
{name = "ANSYS, Inc.", email = "pyansys.core@ansys.com"},
]
Expand Down
126 changes: 125 additions & 1 deletion src/ansys/dynamicreporting/core/adr_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
my_report.visualize()
"""
import sys
from typing import Optional
import webbrowser

from ansys.dynamicreporting.core.adr_utils import in_ipynb
Expand Down Expand Up @@ -182,7 +183,7 @@ def get_iframe(self, width: int = 1000, height: int = 800):
import ansys.dynamicreporting.core as adr
adr_service = adr.Service(ansys_installation = r'C:\\Program Files\\ANSYS Inc\\v232')
ret = adr_service.connect()
my_report = adr_service.get_report(report_name = "My Top Report"
my_report = adr_service.get_report(report_name = "My Top Report")
report_iframe = my_report.get_iframe()
"""
if "IPython.display" in sys.modules:
Expand All @@ -191,3 +192,126 @@ def get_iframe(self, width: int = 1000, height: int = 800):
else:
iframe = None
return iframe

def export_pdf(
self,
file_name: str = "",
query: Optional[dict] = None,
page: Optional[list] = None,
delay: Optional[int] = None,
) -> bool:
"""
Export report as PDF. Currently works only with a local ADR installation, and
not a docker image.

Parameters
----------
file_name : str
Path and filename for the PDF file to export.
query : dict, optional
Dictionary for query parameters to apply to report template before export. Default: None
page : list, optional
List of integers that represents the size of the exported pdf. Default: None, which
corresponds to A4 size
delay : int, optional
Seconds to delay the start of the pdf export operation. Default: None, which
corresponds to no delay

Returns
-------
bool
Success status of the PDF export: True if it worked, False otherwise

Examples
--------
::

import ansys.dynamicreporting.core as adr
adr_service = adr.Service(ansys_installation = r'C:\\Program Files\\ANSYS Inc\\v232')
ret = adr_service.connect()
my_report = adr_service.get_report(report_name = "My Top Report")
succ = my_report.export_pdf(file_name=r'D:\\tmp\\myreport.pdf')
"""
success = False # pragma: no cover
if self.service is None: # pragma: no cover
self.service.logger.error("No connection to any report")
return ""
if self.service.serverobj is None: # pragma: no cover
self.service.logger.error("No connection to any server")
return ""
try:
if query is None:
query = {}
self.service.serverobj.export_report_as_pdf(
report_guid=self.report.guid,
file_name=file_name,
query=query,
page=page,
parent=None,
delay=delay,
exec_basis=self.service._ansys_installation,
ansys_version=self.service._ansys_version,
)
success = True
except Exception as e: # pragma: no cover
self.service.logger.error(f"Can not export pdf report: {str(e)}")
return success

def export_html(
self,
directory_name: str = "",
query: Optional[dict] = None,
filename: Optional[str] = "index.html",
no_inline_files: Optional[bool] = False,
) -> bool:
"""
Export report as static HTML.

Parameters
----------
directory_name : str
....
query : dict, optional
Dictionary for query parameters to apply to report template before export. Default: None
filename : str, optional
Filename for the exported static HTML file. Default: index.html
no_inline_files : bool, optional
If True, the information is exported as stand alone files instead of in line content
in the static HTML. Default: False

Returns
-------
bool
Success status of the HTML export: True if it worked, False otherwise

Examples
--------
::

import ansys.dynamicreporting.core as adr
adr_service = adr.Service(ansys_installation = r'C:\\Program Files\\ANSYS Inc\\v232')
ret = adr_service.connect()
my_report = adr_service.get_report(report_name = "My Top Report")
succ = my_report.export_html(directory_name = r'D:\\tmp')
"""
success = False
if self.service is None: # pragma: no cover
self.service.logger.error("No connection to any report")
return ""
if self.service.serverobj is None: # pragma: no cover
self.service.logger.error("No connection to any server")
return ""
try:
if query is None:
query = {}
self.service.serverobj.export_report_as_html(
report_guid=self.report.guid,
directory_name=directory_name,
query=query,
filename=filename,
no_inline_files=no_inline_files,
)
success = True
except Exception as e: # pragma: no cover
self.service.logger.error(f"Can not export static HTML report: {str(e)}")
return success
9 changes: 8 additions & 1 deletion test_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
"tests/test_data/viewer_test/",
]
dir_list.extend(
["tests/test_data/ansys", "tests/test_data/media", "tests/test_data/webfonts/", "htmltest/"]
[
"tests/test_data/ansys",
"tests/test_data/media",
"tests/test_data/webfonts/",
"htmltest/",
"htmltest_again/",
]
)
dir_list.append("tests/test_data/create_delete/")
dir_list.append("tests/test_data/create_twice/")
Expand All @@ -32,6 +38,7 @@
file_list.extend(glob.glob("tests/outfile*.txt"))
file_list.append("mypresentation")
file_list.append("mytest.pdf")
file_list.append("again_mytest")
for i_file in file_list:
try:
os.remove(i_file)
Expand Down
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def adr_service_query(request, pytestconfig: pytest.Config) -> Service:
use_local = pytestconfig.getoption("use_local_launcher")
local_db = os.path.join("test_data", "query_db")
db_dir = os.path.join(request.fspath.dirname, local_db)
tmp_docker_dir = os.path.join(
os.path.join(request.fspath.dirname, "test_data"), "tmp_docker_query"
)
if use_local:
ansys_installation = pytestconfig.getoption("install_path")
else:
Expand All @@ -83,6 +86,7 @@ def adr_service_query(request, pytestconfig: pytest.Config) -> Service:
ansys_installation=ansys_installation,
docker_image=DOCKER_DEV_REPO_URL,
db_directory=db_dir,
data_directory=tmp_docker_dir,
port=8000 + int(random() * 4000),
)
tmp_service.start(create_db=False, exit_on_close=True, delete_db=False)
Expand Down
29 changes: 29 additions & 0 deletions tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,32 @@ def test_unit_no_url(request) -> bool:
if "No connection to any server" in line:
err_msg = True
assert err_msg


@pytest.mark.ado_test
def test_save_as_pdf(adr_service_query, request, get_exec) -> bool:
exec_basis = get_exec
if exec_basis:
success = False
try:
my_report = adr_service_query.get_report(report_name="My Top Report")
pdf_file = os.path.join(request.fspath.dirname, "again_mytest")
success = my_report.export_pdf(file_name=pdf_file)
except Exception:
success = False
adr_service_query.stop()
else: # If no local installation, then skip this test
success = True
assert success is True


@pytest.mark.ado_test
def test_save_as_html(adr_service_query) -> bool:
success = False
try:
my_report = adr_service_query.get_report(report_name="My Top Report")
success = my_report.export_html(directory_name="htmltest_again")
except Exception:
success = False
adr_service_query.stop()
assert success is True