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

Custom subprocess environment variables for Python embedded #989

Merged
merged 2 commits into from
Sep 12, 2022

Conversation

lmbelo
Copy link
Contributor

@lmbelo lmbelo commented Jul 19, 2022

Python embedded might not have environment variables set to Python paths and host application might not want to change its own environment settings.

For example (Android):

env = { 
  "LD_LIBRARY_PATH": shared_library_path,
  "PYTHONHOME": python_home,
  "PATH": python_executable_path,
  "TMPDIR": tmp
}
debugpy.configure(subProcessEnv=env)

Tested on Windows, Linux, MacOS (Intel and M1) and Android.

@sonarcloud
Copy link

sonarcloud bot commented Jul 19, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@int19h
Copy link
Contributor

int19h commented Aug 1, 2022

Can you clarify the scenario for this? The name of the new property is subProcessEnv, but from the code, it is applied not to subprocesses in the debuggee (which the "subProcess" property corresponds too), but rather specifically to the debug adapter process. What's the purpose of the debug adapter using environment variables different from the debug server that spawned it?

@lmbelo
Copy link
Contributor Author

lmbelo commented Aug 1, 2022

Can you clarify the scenario for this? The name of the new property is subProcessEnv, but from the code, it is applied not to subprocesses in the debuggee (which the "subProcess" property corresponds too), but rather specifically to the debug adapter process. What's the purpose of the debug adapter using environment variables different from the debug server that spawned it?

The debug server might be an executable that embeds Python, then It might not contain the necessary Python's initialization paths on its environment paths. Once the subprocess would be a Python process, we need to initialize it with all required paths.
Did I clarify it? I will try to share some sample.

@int19h
Copy link
Contributor

int19h commented Aug 2, 2022

Ah, I see, so this is basically a companion for the "python" configuration property then? I think calling it "pythonEnv" would make this clearer.

Out of curiosity, does setting the requisite variables directly in os.environ before doing listen() not work? I thought that any changes there would be automatically inherited by subprocesses.

@lmbelo
Copy link
Contributor Author

lmbelo commented Aug 2, 2022

Ah, I see, so this is basically a companion for the "python" configuration property then? I think calling it "pythonEnv" would make this clearer.

Out of curiosity, does setting the requisite variables directly in os.environ before doing listen() not work? I thought that any changes there would be automatically inherited by subprocesses.

Yes, I can change the host variables and it would be inherited by the subprocess, but maybe we don't want to change the host environment variables. It makes sense if i can launch the new process with custom variables. It worth mentioning that the host process can be a Delphi, or C# or whatever application language made, but not the Python executable itself. Then it wont have the Python environment paths settings.

@lmbelo
Copy link
Contributor Author

lmbelo commented Aug 2, 2022

Ah, I see, so this is basically a companion for the "python" configuration property then? I think calling it "pythonEnv" would make this clearer.
Out of curiosity, does setting the requisite variables directly in os.environ before doing listen() not work? I thought that any changes there would be automatically inherited by subprocesses.

Yes, I can change the host variables and it would be inherited by the subprocess, but maybe we don't want to change the host environment variables. It makes sense if i can launch the new process with custom variables. It worth mentioning that the host process can be a Delphi, or C# or whatever application language made, but not the Python executable itself. Then it wont have the Python environment paths settings.

I totally agree to call it PythonEnv, though.

@lmbelo
Copy link
Contributor Author

lmbelo commented Aug 28, 2022

Changed!

@sonarcloud
Copy link

sonarcloud bot commented Aug 28, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@int19h int19h merged commit 1d7443e into microsoft:main Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants