ansys / ansys/pyoptislang

Allow more control to environment variables at start of OSL

Open
#240 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
24
Forks
5
Avg merge
3d 14h
Merged PRs (30d)
12

Description

### 📝 Description of the feature

Currently, when started out of a Python session, OSL will use the same set of environment variables as the parent Python session sees. The Optislang class [exposes the argument env_vars](https://github.com/ansys/pyoptislang/blob/e2fda4a4fad28165f6084afba848f7bb94481c54/src/ansys/optislang/core/optislang.py#L205) which can be used to add new environment variables, or to modify/overwrite existing environment variables. However, in certain configurations more control over the environment variables for the Optislang session is required. One example is the PYTHONPATH variable, which might be required for the parent session and can have unwanted effects to the OSL session (potentially resulting in dependency conflicts of different python environments).

Example: The "outside" application runs in the default Python installation on the computer and sets certain paths referring to that Python installation in the PYTHONPATH variable (required for the "outside" app to work properly). When OSL is then started through PyOSL, the PYTHONPATH from the parent app will be used to initialize the Python environment used for OSL (which is using the Ansys/OSL Python env). This scenario can lead to various dependency/version conflicts in the "inner" (OSL) Python session.

To offer more control, different approaches would be possible, e.g., for the Optislang class,
- expose an option "env_override" to fully set/overwrite all environment variables
- expose an option to clear the environment variables before OSL start (default True)
- expose an option to clear/delete selected environment variables before OSL start

### 💡 Steps for implementing the feature

_No response_

### 🔗 Useful links and references

_No response_

Contributor guide

Open the contributing guide

Research direction

Start in src/ansys/optislang/core/optislang.py at the Optislang env_vars argument and trace how the environment is passed when OSL starts. Clarify which override or clearing behavior is required, then define completion around isolated, predictable environment handling without unwanted parent-session variables.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.