Skip to content

package_manager version support added #18517

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

Open
wants to merge 13 commits into
base: develop2
Choose a base branch
from

Conversation

davidsanfal
Copy link
Contributor

@davidsanfal davidsanfal commented Jun 24, 2025

Changelog: Feature: Added support to the system_package tool for defining the system package version to be installed
Changelog: Fix: Fixed an issue that caused APT packages without a defined architecture to be detected if one with the same name was installed for a different architecture.

Docs: conan-io/docs#4170

Close #17744
Close #18569

  • Refer to the issue that supports this Pull Request.
  • If the issue has missing info, explain the purpose/use case/pain/need that covers this Pull Request.
  • I've read the Contributing guide.
  • I've followed the PEP8 style guides for Python code.
  • I've opened another PR in the Conan docs repo to the develop branch, documenting this one.

@davidsanfal davidsanfal requested a review from memsharded June 24, 2025 09:44
Copy link
Member

@memsharded memsharded left a comment

Choose a reason for hiding this comment

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

Looking good

@memsharded memsharded modified the milestone: 2.18.0 Jun 24, 2025
@davidsanfal davidsanfal marked this pull request as ready for review July 16, 2025 11:13
@@ -25,8 +25,6 @@ def system_requirements(self):
print("missing:", not_installed)
""")})
client.run("create . --name=test --version=1.0 -s:b arch=armv8 -s:h arch=x86")
assert "dpkg-query: no packages found matching non-existing1:i386" in client.out
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed these lines because dpkg -l doesn't print anything if it doesn't find any package with the search pattern

@davidsanfal davidsanfal requested review from jcar87 and memsharded July 16, 2025 11:23
Copy link
Member

@memsharded memsharded left a comment

Choose a reason for hiding this comment

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

Looks good to me!

install_command = "{sudo}{tool} install -y {recommends}{packages}"
update_command = "{sudo}{tool} update"
check_command = "dpkg-query -W -f='${{Status}}' {package} | grep -q \"ok installed\""
check_command = "dpkg -l | grep -q -E \"^ii\\s+\\b{package}\\s+\\b\""
Copy link
Member

Choose a reason for hiding this comment

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

Does the change to check_command solve issues of the previous one, or is this change more to align it with the check_version_command?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is necessary to fix a false positive issue we had before. It is also to align with the way of checking the version of a package.

If your package had a default architecture that was implicit and the others were explicit, the old check found the default package substring within an installation for another architecture:

For example: foo and foo:armv8. The old check said that foo was already installed if it found foo:armv8.

Copy link
Contributor

Choose a reason for hiding this comment

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

https://man7.org/linux/man-pages/man1/dpkg-query.1.html
the query can be tailored to show the architecture as well -

I'm famously incapable to parse regex - so if we could keep a more readable thing that would be great. if the PR is fixing a pre-existing issue that is not aligned with the PR objective, it helps the review to mention it in the description

Copy link
Contributor

@czoido czoido Aug 19, 2025

Choose a reason for hiding this comment

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

Checking this again, I'm not sure I understand this change. If we are passing always the architecture now, can't we keep the check_command as it was with dpkg-query?

@memsharded memsharded added this to the 2.19.0 milestone Jul 16, 2025
arch_name=arch_name,
version="",
version_separator="")
if version and self.check_version_command:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should we output a warning message when we are specifying versions but the package manager does not support that?

Copy link
Contributor

@jcar87 jcar87 left a comment

Choose a reason for hiding this comment

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

just one comment, but PR LGTM otherwise

@pytest.mark.parametrize("tool_class, result", [
(Apk, 'apk info -e package'),
(Apt, 'dpkg-query -W -f=\'${Status}\' package | grep -q "ok installed"'),
(Apt, 'dpkg -l | grep -q -E "^ii\\s+\\bpackage\\s+\\b"'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Curiosity, but what is the reasoning behind this change? a regular expression is a tad harder to parse -

the code as it was was added to address an issue
#3033
#3032

just want to make sure we don't introduce regressions

also note that you can do for example dpkg-query -W -f='${version}' libudev-dev to get the version of a package
it can be combined with other things like ${Status}

changes are dpkg -l is fine, but may need to consider whether it causes performance issues due to repeated calls on systems that have many packages installed (dpkg -l gives you the list of all packages, dpkg-query can be tailored to output info of a specific package

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is to verify that the arch of the installed package is correct. for example:

If you want the foo packge and you have foo:arm64 installed, searching for foo using the current option find it as installed. With the second option, when checking that the name is strictly foo and has nothing else in front of the name, it doesn't find the wrong package and installs it.

install_command = "{sudo}{tool} install -y {recommends}{packages}"
update_command = "{sudo}{tool} update"
check_command = "dpkg-query -W -f='${{Status}}' {package} | grep -q \"ok installed\""
check_command = "dpkg -l | grep -q -E \"^ii\\s+\\b{package}\\s+\\b\""
check_version_command = "dpkg -l | grep -E \"^ii\\s+\\b{package}\\s+\\b\" | grep -q \"{version}\""
Copy link
Contributor

@czoido czoido Aug 19, 2025

Choose a reason for hiding this comment

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

Isn't this doable with something like this?

check_version_command = "dpkg-query -W -f='${Version}\n' {package} | grep -qx '{version}'"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we will have the same problem I mentioned above, there will be no discrimination based on architecture, so we will have false positives. (issues/18569)

@czoido czoido self-requested a review August 19, 2025 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants