meta_package_manager.managers.winget module¶
- class meta_package_manager.managers.winget.WinGet[source]¶
Bases:
PackageManagerMicrosoft’s official Windows package manager.
mpm reads inventory from
winget list --details, whoseKey: Valueblocks carry the installed version and anAvailable Upgradessection, and readssearchfrom winget’s fixed-width column table.Note
installedandoutdatedkeep only rows whoseOrigin Sourceiswinget, dropping packages winget merely tracks (sideloaded, portable or Microsoft Store). Store entries still surface insearch, but their real version cannot be queried throughwinget, so mpm tags them with anmsstoresentinel version and sorts them below winget-native ones.Warning
Two Windows-only, process-level workarounds keep winget from taking the calling process down with it:
winget is spawned with
DETACHED_PROCESS. Its COM server and installer children callGenerateConsoleCtrlEventas they shut down, broadcasting aCTRL_C_EVENTto every process sharing their console: detaching removes winget from that console, so the signal never reaches the caller.WindowsPackageManagerServer.exeis killed by image name after each call. This COM server is activated out-of-process, so it never inherits mpm’s pipes and is never reaped bycommunicate().
Initialize
cli_errorslist.- homepage_url: str | None = 'https://github.com/microsoft/winget-cli'¶
Home page of the project, only used in documentation for reference.
- brewfile_entry_type: ClassVar[str | None] = 'winget'¶
Name of the Brewfile DSL entry type this manager maps to, or
Noneif the manager has no Brewfile equivalent.Set by the subset of managers Homebrew Bundle’s DSL covers, and consumed by
meta_package_manager.brewfilewhen rendering the output ofmpm dump --brewfile. Which manager maps to which entry is tabulated from these declarations in Snapshot and export, section “Brewfile”, where the export’s own quirks are documented too.
- platforms: frozenset[Platform] | Group | Platform | Iterable[Platform | Group] = frozenset({Platform(id='windows', name='Windows')})¶
List of platforms supported by the manager.
Allows for a mishmash of platforms and groups of platforms. Will be normalized into a
frozensetofPlatforminstances at instantiation.
- requirement: str | None = '>=1.28.190'¶
Version requirement specifier.
Supports a comma-separated range of constraints (e.g.
">=1.20.0,<2.0.0"). A bare version string like"1.20.0"is treated as>=1.20.0.Parsed by
meta_package_manager.version.VersionRange.Defaults to
None, which deactivates version check entirely.
- post_args: tuple[str, ...] = ('--accept-source-agreements', '--disable-interactivity')¶
--accept-source-agreements:Used to accept the source license agreement, and avoid the following prompt:
> winget list The "msstore' source requires that you view the following agreements before using. Terms of Transaction: https://aka.ms/microsoft-store-terms-of-transaction The source requires the current machine's 2-letter geographic region to be sent to the backend service to function prope rly (ex. "US"). Do you agree to all the source agreements terms? [Y] Yes [N] No:
--disable-interactivity:Disable interactive prompts.
Todo
Add the
--no-progressoption once it is available in the stable release:
- windows_creation_flags: int = 0¶
Detach winget from the calling process’s console.
When winget runs, the Windows COM infrastructure activates
WindowsPackageManagerServer.exeas a separate process. Installer EXEs launched bywinget upgradeorwinget installare also spawned as grandchildren. Both the COM server and any installer EXEs callGenerateConsoleCtrlEvent(0)during their own shutdown, which broadcasts aCTRL_C_EVENTto every process sharing the same console — including the Python test runner — causing it to exit with code 1 even after all tests pass.DETACHED_PROCESSbreaks the shared-console link: winget has no console, so neither the COM server nor any installer EXE can broadcast console events that reach us. Output is still captured because stdout and stderr are redirected to pipes, which are independent of console attachment.
- windows_processes_to_cleanup: tuple[str, ...] = ('WindowsPackageManagerServer.exe',)¶
Kill winget’s COM server after each call.
WindowsPackageManagerServer.exeis activated by the Windows COM infrastructure when winget runs, not as a direct child process. It therefore does not inherit our pipe handles and is not reaped bycommunicate(). Kill it by image name after each call to avoid accumulating orphan COM server processes.
- property installed: Iterator[Package]¶
Fetch installed packages.
> winget list --details --accept-source-agreements --disable-interactivity (1/7) CCleaner [CCleaner] Version: 6.08 Publisher: Piriform Software Ltd Local Identifier: ARP\Machine\X64\CCleaner Product Code: CCleaner Installer Category: exe Installed Scope: Machine Installed Architecture: X64 Installed Locale: en-US Origin Source: winget Available Upgrades: (2/7) Git [Git.Git] Version: 2.37.3 Publisher: The Git Development Community Origin Source: winget
Only returns packages with Origin Source: winget to exclude packages installed via other sources (e.g., sideload, portable).
- property outdated: Iterator[Package]¶
Fetch outdated packages.
> winget list --upgrade-available --details --accept-source-agreements --disable-interactivity (1/4) Git [Git.Git] Version: 2.37.3 Publisher: The Git Development Community Origin Source: winget Available Upgrades: winget [2.45.1] (2/4) Microsoft Edge [Microsoft.Edge] Version: 109.0.1518.70 Publisher: Microsoft Origin Source: winget Available Upgrades: winget [125.0.2535.51]
Only returns packages with Origin Source: winget to exclude packages installed via other sources (e.g., sideload, portable).
- search(query, extended, exact)[source]¶
Fetch matching packages.
> winget search --query vscode --accept-source-agreements --disable-interactivity Name Id Version Match Source --------------------------------------------------------------------------------------------------------- Microsoft Visual Studio Code Microsoft.VisualStudioCode 1.89.1 Moniker: vscode winget MrCode zokugun.MrCode 1.82.0.23253 Tag: vscode winget VSCodium Insiders VSCodium.VSCodium.Insiders 1.88.0.24095 Tag: vscode winget VSCodium VSCodium.VSCodium 1.89.1.24130 Tag: vscode winget Upgit pluveto.Upgit 0.2.18 Tag: vscode winget vscli michidk.vscli 0.3.0 Tag: vscode winget Huawei QuickApp IDE Huawei.QuickAppIde 14.0.1 Tag: vscode winget TheiaBlueprint EclipseFoundation.TheiaBlueprint 1.44.0 Tag: vscode winget Codium Alex313031.Codium 1.86.2.24053 Tag: vscode winget Cursor Editor CursorAI,Inc.Cursor latest Tag: vscode winget Microsoft Visual Studio Code CLI Microsoft.VisualStudioCode.CLI 1.89.1 Moniker: vscode-cli winget
> winget search --query vscode --exact --accept-source-agreements --disable-interactivity Name Id Version Match Source ------------------------------------------------------------------------------------------------- Microsoft Visual Studio Code Microsoft.VisualStudioCode 1.89.1 Moniker: vscode winget MrCode zokugun.MrCode 1.82.0.23253 Tag: vscode winget VSCodium Insiders VSCodium.VSCodium.Insiders 1.88.0.24095 Tag: vscode winget VSCodium VSCodium.VSCodium 1.89.1.24130 Tag: vscode winget Upgit pluveto.Upgit 0.2.18 Tag: vscode winget vscli michidk.vscli 0.3.0 Tag: vscode winget Huawei QuickApp IDE Huawei.QuickAppIde 14.0.1 Tag: vscode winget TheiaBlueprint EclipseFoundation.TheiaBlueprint 1.44.0 Tag: vscode winget Codium Alex313031.Codium 1.86.2.24053 Tag: vscode winget Cursor Editor CursorAI,Inc.Cursor latest Tag: vscode winget
> winget search --id VSCodium.VSCodium --accept-source-agreements --disable-interactivity Name Id Version Source ---------------------------------------------------------------- VSCodium Insiders VSCodium.VSCodium.Insiders 1.88.0.24095 winget VSCodium VSCodium.VSCodium 1.89.1.24130 winget
> winget search --name Codium --accept-source-agreements --disable-interactivity Name Id Version Source ---------------------------------------------------------------- Codium Alex313031.Codium 1.86.2.24053 winget VSCodium Insiders VSCodium.VSCodium.Insiders 1.88.0.24095 winget VSCodium VSCodium.VSCodium 1.89.1.24130 winget
> winget search --id VSCodium.VSCodium --exact --accept-source-agreements --disable-interactivity Name Id Version Source ---------------------------------------------- VSCodium VSCodium.VSCodium 1.89.1.24130 winget
> winget search --name Codium --exact --accept-source-agreements --disable-interactivity Name Id Version Source -------------------------------------------- Codium Alex313031.Codium 1.86.2.24053 winget
- install(package_id, version=None)[source]¶
Install one package.
> winget install --id Microsoft.PowerToys --accept-package-agreements --accept-source-agreements --disable-interactivity Found Power Toys [Microsoft.PowerToys] Version 0.15.2 This application is licensed to you by its owner. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages. Successfully verified installer hash Starting package install... ██████████████████████████████ 100% Successfully installed
- Return type:
- cli_names: tuple[str, ...] = ('winget',)¶
List of CLI names the package manager is known as.
This list of recognized CLI names is ordered by priority. That way we can influence the search of the right binary.
- ..hint::
This was helpful in the case of the Python transition from 2.x to 3.x, where multiple versions of the same executable were named
pythonorpython3.
By default, this property’s value is derived from the manager’s ID (see the
MetaPackageManager.__init__method above).
- id: str = 'winget'¶
Package manager’s ID.
Derived by defaults from the lower-cased class name in which underscores
_are replaced by dashes-.This ID must be unique among all package manager definitions and lower-case, as they’re used as feature flags for the mpm CLI.
- upgrade_all_cli()[source]¶
Generates the CLI to upgrade all outdated packages.
> winget update --all --accept-package-agreements --accept-source-agreements --disable-interactivity Name Id Version Available Source ------------------------------------------------------------------------------------------------ Microsoft Edge Microsoft.Edge 109.0.1518.70 125.0.2535.51 winget Microsoft Edge WebView2 Runtime Microsoft.EdgeWebView2Runtime 109.0.1518.70 125.0.2535.51 winget Python Launcher Python.Launchez < 3.12.0 3.12.0 winget Microsoft Visual C++ (x86)... Microsoft.VCRedist.2015+.X86 14.34.31931.0 14.38.33135.0 winget 4 upgrades available. Installing dependencies: This package requires the following dependencies: - Packages Microsoft.UI.Xaml.2.8 [>= 8.2306.22001.0] (1/3) Found Microsoft Edge WebView2 Runtime [Microsoft.EdgeWebView2Runtime] Version 125. 0.2535.51 This application is licensed to you by its owner. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages. Downloading https://msedge.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/e5dd841e-17ff-43b7-a2c0-ff759f55c202/MicrosoftEdgeWebView2RuntimeInstallerARM64.exe ██████████████████████████████ 166 MB / 166 MB Successfully verified installer hash Starting package install... Successfully installed (...)
- virtual: bool = False¶
Should we expose the package manager to the user?
Virtual package manager are just skeleton classes used to factorize code among managers of the same family.
- upgrade_one_cli(package_id, version=None)[source]¶
Generates the CLI to upgrade the provided package.
> winget install --id Git.Git --accept-package-agreements --accept-source-agreements --disable-interactivity Found Git [Git.Git] Version 2.45.1 This application is licensed to you by its owner. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages. Downloading https://github.com/git-for-windows/git/releases/download/v2.45.1.windows.1/Git-2.45.1-64-bit.exe ██████████████████████████████ 64.7 MB / 64.7 MB Successfully verified installer hash Starting package install... Successfully installed
Todo
Automatically uninstall the package if the technology is different:
> winget upgrade --id Microsoft.Edge A newer version was found, but the install technology is different from the current version installed. Please uninstall the package and install the newer version.
- remove(package_id)[source]¶
Remove one package.
> winget uninstall --id Microsoft.PowerToys --source winget --accept-source-agreements --disable-interactivity Found PowerToys (Preview) [Microsoft.PowerToys] Starting package uninstall... ██████████████████████████████ 100% Successfully uninstalled
- Return type: