Skip to content

Commit 79b8540

Browse files
authored
fix serverless docs, pin statsmodels (#331)
Co-authored-by: viseshrp <[email protected]>
1 parent 836aa61 commit 79b8540

14 files changed

+86
-185
lines changed

doc/source/serverless/caveats.rst

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,19 @@ Example: Threading with Serverless ADR
8787
for t in threads:
8888
t.join()
8989
90-
Common Pitfalls and Solutions
91-
-----------------------------
92-
93-
- **Error: "ADR has not been set up" in worker processes**
94-
95-
_Cause_: ``ADR.setup()`` was not called in the worker process.
96-
97-
_Solution_: Call ``adr.setup()`` early in each new process, as shown above.
98-
99-
- **Race conditions or inconsistent state due to multiple ``setup()`` calls**
100-
101-
_Cause_: Concurrent calls to ``setup()`` from multiple threads.
90+
Serverless ADR Usage Within Django Apps
91+
--------------------------------------
10292

103-
_Solution_: Call ``setup()`` only once in the main thread before spawning workers.
93+
- Serverless ADR internally configures Django settings and environment variables at the
94+
process level during ``ADR.setup()``.
95+
- Because Django settings are designed to be configured once per process, **attempting
96+
to initialize Serverless ADR inside an existing Django application causes conflicts.**
97+
- Specifically, setting up Serverless ADR tries to configure Django a second time, which
98+
is unsupported and results in errors or unpredictable behavior.
99+
- This means **embedding or using Serverless ADR as a Django app within another Django
100+
project is not currently supported and strongly discouraged.**
101+
- If you require integration, consider separating Serverless ADR usage into a dedicated
102+
process or microservice to avoid Django settings conflicts.
104103

105104
Summary and Best Practices
106105
--------------------------
@@ -109,7 +108,8 @@ Summary and Best Practices
109108
- In multiprocessing scenarios, call ``setup()`` separately in each spawned process.
110109
- Avoid calling ``setup()`` multiple times or concurrently within the same process.
111110
- Share the ADR instance across threads within a process after setup completes.
111+
- Avoid embedding Serverless ADR within other Django apps due to Django configuration conflicts.
112112
- If unsure whether setup is needed, check ``adr.is_setup`` before calling.
113113

114114
By following these guidelines, you ensure stable and consistent Serverless ADR usage
115-
in complex multi-threaded or multi-process environments.
115+
in complex multi-threaded or multi-process environments without risking Django conflicts.

doc/source/serverless/configuration.rst

Lines changed: 18 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,15 @@ The primary configuration options for the ``ADR`` class constructor are:
6363
Environment Variables
6464
=====================
6565

66-
Serverless ADR supports several environment variables to configure its runtime behavior,
67-
database connections, security settings, and media/static file handling. These variables
68-
can be used for legacy configurations or advanced deployments.
66+
.. warning::
67+
68+
**Use of environment variables for Serverless ADR configuration is strongly discouraged.**
69+
Environment variables represent a legacy configuration method and can lead to hidden,
70+
hard-to-debug issues, security risks (such as leaking secrets), and inconsistent behavior
71+
especially in multi-instance or containerized deployments.
72+
73+
It is highly recommended to use explicit constructor parameters and configuration files
74+
for all setup and runtime options instead.
6975

7076
Core Variables
7177
--------------
@@ -86,17 +92,11 @@ Core Variables
8692
URL prefix used to access media files remotely. Must start and end with a slash, e.g., ``/media/``.
8793
Corresponds to the ``media_url`` constructor parameter.
8894

89-
- **CEI_NEXUS_LOCAL_ALLOW_REMOTE_ACCESS**
90-
If set to any value, allows remote access to a local database server (use cautiously).
91-
92-
- **CEI_NEXUS_SERVE_STATIC_FILES**
93-
If ``True``, enables Django’s built-in static and media file serving (not recommended for production).
94-
9595
Database Connection Variables
9696
-----------------------------
9797

9898
- **CEI_NEXUS_DB_ENGINE**
99-
Database engine string (e.g., ``django.db.backends.postgresql_psycopg2``). Defaults to PostgreSQL.
99+
Database engine. Defaults to SQLite.
100100

101101
- **CEI_NEXUS_DB_DATABASE_NAME**
102102
Name of the database to connect to. Defaults to ``nexus_database``.
@@ -108,78 +108,29 @@ Database Connection Variables
108108
Password for the database user. Default is ``cei``.
109109

110110
- **CEI_NEXUS_DB_HOSTNAME**
111-
Database server hostname or IP address. Defaults to ``127.0.0.1``.
111+
Database server hostname or IP address. Defaults to the path to the SQLite database file.
112112

113113
- **CEI_NEXUS_DB_PORT**
114-
Database server port number. Default is ``5432``.
114+
Database server port number. Default is not set for SQLite.
115115

116-
Security and Server Variables
117-
-----------------------------
118-
119-
- **CEI_NEXUS_SERVER_NAME**
120-
Human-readable name of the server. Defaults to ``mixed``.
116+
Security Variables
117+
------------------
121118

122119
- **CEI_NEXUS_SECRET_KEY**
123120
Django secret key used internally. If not provided, a built-in default key is used (not recommended for production).
124121

125-
- **CEI_NEXUS_ALLOWED_HOSTS**
126-
Comma-separated list of allowed hostnames for accessing the server (e.g., ``localhost,127.0.0.1``).
127-
128-
- **CEI_NEXUS_TRUSTED_ORIGINS**
129-
List of trusted origins for unsafe requests like POST, supporting wildcards (e.g., ``https://*.example.com``).
130-
131-
- **CEI_NEXUS_HTTPS_SECURED**
132-
Boolean flag to indicate if the server runs behind HTTPS only. Enables security headers.
133-
134-
- **CEI_NEXUS_HSTS_SECURED**
135-
Enables HTTP Strict Transport Security (HSTS) headers.
136-
137-
- **CEI_NEXUS_HSTS_SECONDS**
138-
Duration in seconds for HSTS policy enforcement. Use with caution to avoid locking out clients.
139-
140-
- **CEI_NEXUS_X_FRAME_OPTIONS**
141-
Sets the HTTP X-Frame-Options header globally for protection against clickjacking.
142-
143122
Advanced / Optional Variables
144123
-----------------------------
145124

146125
- **CEI_NEXUS_ENABLE_ACLS**
147126
Enables per-category Access Control Lists (ACLs). Experimental and not recommended for general use.
148127

149-
- **CEI_NEXUS_ACLS_NGINX_LOCATION**
150-
NGINX internal location directive for permission-protected media files. Default is ``/media_secured``.
151-
152-
Remote Session Configuration
153-
----------------------------
154-
155-
- **CEI_NEXUS_REMOTE_WEBSOCKETURL**
156-
URL to the NGINX server proxying to the websocket server.
157-
158-
- **CEI_NEXUS_REMOTE_WS_PORT**
159-
Port used by the websocket server for WS protocol communication.
160-
161-
- **CEI_NEXUS_REMOTE_HTML_PORT**
162-
Port used by the websocket server for HTTP REST communication.
163-
164-
- **CEI_NEXUS_REMOTE_VNCPASSWORD**
165-
Password for VNC server sessions.
166-
167128
Usage Notes
168129
-----------
169130

170-
- When running a non-debug local server, use the following command to enable static file serving:
171-
172-
.. code-block:: bash
131+
- Constructor parameters take precedence over environment variables. If both are set, constructor values will be used.
173132

174-
python manage.py runserver --insecure 0.0.0.0:8000
175-
176-
- Environment variables override constructor parameters if both are set.
177-
178-
- Always set secure secret keys in production environments to protect sensitive data.
179-
180-
- Configure ``CEI_NEXUS_ALLOWED_HOSTS`` and ``CEI_NEXUS_TRUSTED_ORIGINS`` to restrict server access.
181-
182-
- When enabling HTTPS and HSTS, be cautious with duration settings to avoid client lockout.
133+
- Always set secure secret keys in production environments to protect sensitive data. If you do not set a key, a default will be used.
183134

184135
Example: Setting environment variables in Linux shell:
185136

@@ -189,8 +140,6 @@ Example: Setting environment variables in Linux shell:
189140
export CEI_NEXUS_LOCAL_MEDIA_DIR="/var/data/adr_media"
190141
export CEI_NEXUS_MEDIA_URL_PREFIX="/media/"
191142
export CEI_NEXUS_SECRET_KEY="a-very-secure-secret-key"
192-
export CEI_NEXUS_ALLOWED_HOSTS="localhost,127.0.0.1"
193-
export CEI_NEXUS_HTTPS_SECURED="True"
194143
195144
Example: Passing variables via ``opts`` parameter:
196145

@@ -206,14 +155,6 @@ Example: Passing variables via ``opts`` parameter:
206155
adr = ADR(ansys_installation="/opt/ansys", opts=opts)
207156
adr.setup()
208157
209-
Summary
210-
-------
211-
212-
Proper use of environment variables allows flexible deployment and integration of Serverless ADR
213-
into diverse environments, including containerized, cloud, or on-premises infrastructures.
214-
215-
See also the :doc:`configuration` and :doc:`setup` guides for comprehensive initialization instructions.
216-
217158
**Note: Prefer constructor parameters for new projects. Environment variables remain supported primarily for legacy compatibility.**
218159

219160
Best Practices
@@ -252,50 +193,6 @@ Examples
252193
)
253194
adr.setup(collect_static=True)
254195
255-
**Multi-database PostgreSQL and SQLite setup:**
256-
257-
.. code-block:: python
258-
259-
database_config = {
260-
"default": {
261-
"ENGINE": "postgresql",
262-
"NAME": "adr_db",
263-
"USER": "adr_user",
264-
"PASSWORD": "password",
265-
"HOST": "localhost",
266-
"PORT": "5432",
267-
},
268-
"sqlite_local": {
269-
"ENGINE": "sqlite3",
270-
"NAME": r"C:\Reports\DB\local.sqlite3",
271-
},
272-
}
273-
274-
adr = ADR(
275-
ansys_installation=r"/opt/ansys",
276-
databases=database_config,
277-
media_directory=r"/opt/reports/media",
278-
static_directory=r"/opt/reports/static",
279-
media_url="/media/",
280-
static_url="/static/",
281-
)
282-
adr.setup()
283-
284-
**Docker-based Ansys installation:**
285-
286-
.. code-block:: python
287-
288-
adr = ADR(
289-
ansys_installation="docker",
290-
docker_image="ghcr.io/ansys-internal/nexus_dev",
291-
db_directory=r"C:\Reports\DB",
292-
media_directory=r"C:\Reports\Media",
293-
static_directory=r"C:\Reports\Static",
294-
media_url="/media/",
295-
static_url="/static/",
296-
)
297-
adr.setup()
298-
299196
Troubleshooting
300197
---------------
301198

@@ -312,11 +209,5 @@ Troubleshooting
312209
Summary
313210
-------
314211

315-
Proper configuration of Serverless ADR ensures seamless database connections, media management, and web serving of report assets. Follow best practices for setup and environment initialization to avoid common issues.
316-
317-
Next Steps
318-
----------
319-
320-
See the :doc:`setup` guide for detailed startup and initialization instructions.
321-
322-
See the :doc:`media_and_static` guide for managing static and media files in your reports.
212+
Proper configuration of Serverless ADR ensures seamless database connections, media management, and web serving of report assets.
213+
Follow best practices for setup and environment initialization to avoid common issues.

doc/source/serverless/copying_objects.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Best Practices
134134
--------------
135135

136136
- Ensure the target database is properly configured and accessible before copying.
137-
- Copy related sessions and datasets automatically by copying items or templates.
137+
- Copy related sessions and datasets automatically by copying items.
138138
- Always use ``test=True`` initially to preview the number of objects to be copied.
139139
- Ensure media directories have sufficient space and permissions.
140140
- Use descriptive ADR query strings to limit copy scope.

doc/source/serverless/embedding_reports.rst

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Generating Embed-Ready HTML
2121
---------------------------
2222

2323
Use the ``render_report()`` method of the ADR instance to render a complete
24-
report or a subset of it as HTML.
24+
report.
2525

2626
.. code-block:: python
2727
@@ -42,8 +42,6 @@ You can also render individual report items using their ``render()`` method:
4242
.. code-block:: python
4343
4444
item = adr.create_item(String, name="summary_text", content="Summary content here.")
45-
item.save()
46-
4745
html_snippet = item.render(context={"plotly": 0})
4846
4947
Embedding Partial Templates or Sections
@@ -63,7 +61,7 @@ Integration Tips
6361

6462
- Make sure your embedded HTML includes references to static and media URLs
6563
configured during ADR setup so that assets like images and stylesheets
66-
load correctly.
64+
load correctly and your web server is configured to serve them.
6765

6866
- Use the ``context`` parameter to pass additional context variables
6967
needed for rendering.
@@ -81,15 +79,14 @@ Example with Flask:
8179

8280
.. code-block:: python
8381
82+
from ansys.dynamicreporting.core.serverless import ADR
8483
from flask import Flask, render_template_string
8584
8685
app = Flask(__name__)
8786
8887
8988
@app.route("/embedded-report")
9089
def embedded_report():
91-
from ansys.dynamicreporting.core.serverless import ADR
92-
9390
adr = ADR.get_instance()
9491
my_app_html = "<!-- Your app's HTML here -->"
9592
html = adr.render_report(name="My Simulation Report")
@@ -112,7 +109,7 @@ Security Considerations
112109

113110
- Validate and sanitize any dynamic input used in filters or templates
114111
to avoid injection attacks.
115-
- Limit exposure of internal data by controlling which templates or items
112+
- Limit exposure of data by controlling which templates or items
116113
are accessible for embedding.
117114

118115
Summary

doc/source/serverless/examples.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Examples
2+
========
3+

doc/source/serverless/index.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ want to:
1919

2020
- Create, manage, and render reports locally using Python
2121
- Avoid setting up a centralized ADR service or HTTP connection
22-
- Maintain full fidelity with the ADR schema (items, templates, layout logic)
23-
- Output HTML content and media assets for web apps, automation, or
24-
documentation pipelines
22+
- Maintain full fidelity with the ADR schema (items, templates, etc.)
23+
- Output HTML content and media assets for web and desktop apps.
2524

2625
Serverless ADR is ideal for:
2726

2827
- Local, file-based workflows (e.g., building offline reports)
28+
- Embedding reports in web or desktop applications
2929
- Use in batch scripts, Python notebooks, or simulations
30-
- Building and verifying templates before pushing to production ADR services
3130

3231
Key features
3332
============

doc/source/serverless/items.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ Items automatically link to the current default session and dataset unless speci
4141
content="This simulation demonstrates fluid flow around a wing.",
4242
tags="section=summary project=wing_sim",
4343
)
44-
string_item.save()
4544
4645
# Create a table item with data
4746
data = np.array(
@@ -71,7 +70,10 @@ Item Properties and Metadata
7170

7271
Items support several useful properties and metadata fields:
7372

73+
- **guid**: Unique identifier for the item, automatically generated.
7474
- **name**: Unique identifier for the item within the dataset.
75+
- **type**: The item type (e.g., `string`, `table`, etc.).
76+
- **date**: Timestamp indicating when the item was created.
7577
- **content**: The primary payload of the item, type-dependent.
7678
- **tags**: A space-separated string of key or key=value tags for querying and filtering.
7779
- **source**: String to track the data origin or generating process.
@@ -94,7 +96,6 @@ Example: Creating and saving an image item
9496
content="path/to/wing_profile.png",
9597
tags="section=images project=wing_sim",
9698
)
97-
image_item.save()
9899
99100
After saving, the file is copied into the configured media directory. You can access the uploaded file's storage path using the `file_path` property:
100101

@@ -106,7 +107,8 @@ After saving, the file is copied into the configured media directory. You can ac
106107
This path points to the location within the media directory configured during ADR setup.
107108
You can use this path for verification, further processing, or serving the media file in your application.
108109

109-
When rendering reports or templates that include media items, the HTML references media files using relative URLs, typically prefixed by the configured media URL (default is `/media/`):
110+
When rendering reports or templates that include media items, the HTML references media files using relative URLs,
111+
typically prefixed by the configured media URL (default is `/media/`):
110112

111113
.. code-block:: html
112114

@@ -118,7 +120,10 @@ Ensure your web server is configured to serve these media URLs from the media di
118120
Summary:
119121
- Set the `content` of file-based items to the local file path before saving.
120122
- After saving, `file_path` gives the full path to the uploaded media file.
123+
- When the item is loaded again from the database, `content` will be the relative path to the media file.
121124
- Rendered reports use relative media URLs; configure your web server accordingly.
125+
- Use the `media_url` property to get the URL prefix for serving media files.
126+
- The media URL is typically `/media/` by default.
122127

123128
Rendering Items
124129
---------------

0 commit comments

Comments
 (0)