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

BUG: Extension manager seems to move files from venv instead of copying #5744

Open
2 tasks done
svandenb-dev opened this issue Feb 7, 2025 · 3 comments
Open
2 tasks done
Assignees
Labels
bug Something isn't working

Comments

@svandenb-dev
Copy link
Collaborator

Before submitting the issue

  • I have searched among the existing issues
  • I am using a Python virtual environment

Description of the bug

Extension manager seems to delete python script files instead of copying.

Steps To Reproduce

NA

Which Operating System are you using?

Windows

Which Python version are you using?

3.11

Installed packages

NA

@svandenb-dev svandenb-dev added the bug Something isn't working label Feb 7, 2025
@SMoraisAnsys
Copy link
Collaborator

@Marwane-20 here's one of the tasks I'd like you to tackle. The content is light so I expect you to have a look at the documentation first and ask questions later. Any question should be directed to me.

@Marwane-20
Copy link

@SMoraisAnsys i will start looking at the documentation, and keep you posted. Thanks.

@Marwane-20
Copy link

Hello @SMoraisAnsys, here is what i think is causing the problem:

Shared Virtual Environment

In src/ansys/aedt/core/workflows/installer/extension_manager.py, the function add_custom_toolkit creates a virtual environment using:

src/ansys/aedt/core/workflows/customize_automation_tab.py:

command = [base_venv, "-m", "venv", venv_dir, "--system-site-packages"]  

The --system-site-packages flag means this venv shares site-packages with the system/global environment.
When pip uninstall is called in that shared venv, it can remove packages from the actual environment rather than an isolated copy.


pip uninstall Removing Shared Packages

Still in add_custom_toolkit, before installing or updating a toolkit, the code calls:

command = [pip_exe, "uninstall", "--yes", toolkit_info["pip"]]  
run_command(command, desktop_object)  

Because of --system-site-packages, this uninstall step can delete files in the shared site-packages folder.
From a user’s perspective, it looks like files are “moved” or have disappeared from the venv.


Docstring incorrect

In add_script_to_menu (also used by the extension manager), the docstring says:

“The script will be moved to Personal Lib,”

but the code actually uses:

shutil.copy2(script_file, dest_script_path)  

So it’s actually a copy, not a move.
The real cause is the uninstall step noted above, not a direct move operation.


Suggested Fixes

1. Remove --system-site-packages

Instead of:

command = [base_venv, "-m", "venv", venv_dir, "--system-site-packages"]  

Use:

command = [base_venv, "-m", "venv", venv_dir]  

This ensures the extension manager’s venv is isolated.
It will no longer uninstall packages from the global environment.


2. Clarify the Docstring - Just a doc fix

Update the docstring in add_script_to_menu to say “copied” instead of “moved.”


3. Double-Check Logs

If packages still appear to vanish, confirm via pip logs that uninstalls are only affecting the isolated venv (once the above changes are made).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants