Skip to content

Conversation

@AshokThangavel
Copy link
Contributor

Overview

This PR introduces a robust Python library management system for the IPM (InterSystems Package Manager). It transitions the system to a state-aware lifecycle manager that tracks library ownership, handles local wheel files, and ensures a clean environment during module uninstallation.

fixed: #1006

Key Implementations

  • -with-py Modifier: New opt-in flag for uninstall. By default, Python libraries are preserved. Physical removal only occurs when -with-py is explicitly called.
  • Reference Counting: Created %IPM.Storage.PythonReference to track library usage across the instance.
  • RefCount - Prevents "Dependency Breaking": A library is only physically uninstalled when its RefCount reaches 0, meaning no other installed module requires it.
  • Physical pip uninstall triggers only when RefCount reaches 1 (the final module using it).

Execution Sample (Verbose Mode)

zpm:USER>uninstall demo-module2 -with-py -v

[USER|demo-module2]     Clean START
[USER|demo-module2]     Unconfigure START
[USER|demo-module2]     Unconfigure SUCCESS
[USER|demo-module2]     Evaluating Python dependencies for removal...
Detecting pip caller
Attempting to find flexible python... 
Attempting to find python3 or python...Success!

Running command=$lb("python3","-m","pip","uninstall","-y","regex","--break-system-packages")
Found existing installation: regex 2025.11.3
Uninstalling regex-2025.11.3:
  Successfully uninstalled regex-2025.11.3

Running command=$lb("python3","-m","pip","uninstall","-y","six","--break-system-packages")
Found existing installation: six 1.17.0
Uninstalling six-1.17.0:
  Successfully uninstalled six-1.17.0

[USER|demo-module2]     Clean SUCCESS

Additionally fixed the <UNDEFINED>InstallOrDownloadPythonRequirem+64^%IPM.Lifecycle.Base.1 error

zpm:USER>load /usr/irissys/mgr/user/mmm

Building dependency graph...Done.
[USER|demo-module1]     Initialize START
[USER|demo-module1]     Initialize SUCCESS
[USER|demo-module1]     Reload START (/usr/irissys/mgr/user/mmm/)
[demo-module1]  Reload FAILURE
ERROR! ObjectScript error: <UNDEFINED>InstallOrDownloadPythonRequirem+64^%IPM.Lifecycle.Base.1 *processType

to

zpm:USER>load /usr/irissys/mgr/user/mmm

Building dependency graph...Done.
[USER|demo-module1]     Initialize START
[USER|demo-module1]     Initialize SUCCESS
[USER|demo-module1]     Reload START (/usr/irissys/mgr/user/mmm/)
[USER|demo-module1]      FAILURE
[demo-module1]  Reload FAILURE
ERROR! Python general error 'Embedded Python is not available in this instance.

- Added %IPM.Storage.PythonReference to track library metadata (SourceType, Version, WheelPath).
- Added '-with-py' modifier to the 'uninstall' command to allow conditional physical removal via pip.
- Created %IPM.Utils.Python for centralized environment gating and version retrieval.
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.

Support for Python dependency cleanup during uninstall

1 participant