Skip to content

operations.util.packaging: Extend PkgInfo for winget#1447

Merged
Fizzadar merged 2 commits intopyinfra-dev:3.xfrom
rod7760:make-packaging-util-support-winget
Sep 16, 2025
Merged

operations.util.packaging: Extend PkgInfo for winget#1447
Fizzadar merged 2 commits intopyinfra-dev:3.xfrom
rod7760:make-packaging-util-support-winget

Conversation

@rod7760
Copy link
Contributor

@rod7760 rod7760 commented Sep 6, 2025

Background

I'm hoping to utilize the existing ensure_packages utility in `pyinfra-windows'.

The utility currently makes some assumptions that don't work with winget. Namely, that all package managers support the following syntax:

apt install package1=version1 package2=version2

# does not work in winget
winget install package1=version1 package2=version2

You must do the following:

winget install package1 —version version1; winget install package2 —version version2;

This PR introduces Pkginfo.inst_vers_template to customize the creation PkgInfo.inst_vers.
The default template works from programs that support the {name}{operator}{version} syntax.

winget overides the template to do '{name} {operator} {version};'.format("winget install Notepad++.Notepad++", "—version", "8.5")

Notes

This PR does change the shlex.quote behavior slightly, and I have left the failing tests for now.
Do you think this new quoting behavior is ok?

# example failing test
--> COMMANDS OUTPUT:
[
    "pip install pyinfra==1.1 pytask another'>'1"
]
--> TEST WANTS:
[
    "pip install pyinfra==1.1 pytask 'another>1'"
]

If you don't want to support this here, I totally understand. I will duplicate some of the code.

  • Pull request is based on the default branch (3.x at this time)
  • Pull request includes tests for any new/updated operations/facts
  • Pull request includes documentation for any new/updated operations/facts
  • Tests pass (see scripts/dev-test.sh)
  • Type checking & code style passes (see scripts/dev-lint.sh)

Copy link
Member

@Fizzadar Fizzadar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big fan of using this in other packages, think extending here is a great call.

@Fizzadar Fizzadar force-pushed the make-packaging-util-support-winget branch from 6767ca7 to dc70773 Compare September 16, 2025 18:32
Copy link
Member

@Fizzadar Fizzadar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great add, thank you @rod7760!

@Fizzadar Fizzadar merged commit 04468c2 into pyinfra-dev:3.x Sep 16, 2025
106 of 134 checks passed
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