Repository: conan-io/conan
Pull request #15026 (2023-10-29 12:49:37)

package_manager: handle linux mint
Changelog: (Fix): Default to apt-get package manager in Linux Mint
Docs: https://github.com/conan-io/docs/pull/3440

- [ ] Refer to the issue that supports this Pull Request.
- [X] If the issue has missing info, explain the purpose/use case/pain/need that covers this Pull Request.
- [X] I've read the [Contributing guide](https://github.com/conan-io/conan/blob/develop/.github/CONTRIBUTING.md).
- [X] I've followed the PEP8 style guides for Python code.
- [X] I've opened another PR in the Conan docs repo to the ``develop`` branch, documenting this one.

Linux Mint, being based on Ubuntu, should default to using the apt-get package manager. Being a decently popular OS for Linux beginners, ideally Conan should work on it with as little configuration from the user as possible, and the tool name is one such configuration that can be preset.

Right now it fails to install system packages even with sudo=True and mode=install in the global.conf file, as it doesn't know which package manager to use.

CLAassistant: [![CLA assistant check](https://cla-assistant.io/pull/badge/not_signed)](https://cla-assistant.io/conan-io/conan?pullRequest=15026) <br/>Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our [Contributor License Agreement](https://cla-assistant.io/conan-io/conan?pullRequest=15026) before we can accept your contribution.<br/><sub>You have signed the CLA already but the status is still pending? Let us [recheck](https://cla-assistant.io/check/conan-io/conan?pullRequest=15026) it.</sub>
RMZeroFour: There should probably be a helpful error or at least a warning on systems where the default package manager cannot be found and the user hasn't set one, right now Conan only prints out the name of the package not found, with no indication for why (no package manager). I'd be willing to contribute another commit for raising said error, if someone would be kind enough to point me to where might be the best place for this. 

Will the run() method below be a suitable place to raise an error, if self._active_tool is not set?
memsharded: > There should probably be a helpful error or at least a warning on systems where the default package manager cannot be found and the user hasn't set one

Sounds that the ``_SystemPackageManagerTool.get_default_tool`` would be a good place, ``run()`` might be too noisy. 
Also, it shouldn't be a warning, because it is very common that recipes define some system packages for Linux that are not necessary neither in Windows or in OSX, but recipes do not explicitly check for this. So it shouldn't be a warning in Windows or OSX, for example. But some informational message, like "A default system package manager couldn't be found for XXX, system packages will not be installed" could be good.
RMZeroFour: > > There should probably be a helpful error or at least a warning on systems where the default package manager cannot be found and the user hasn't set one
> 
> Sounds that the `_SystemPackageManagerTool.get_default_tool` would be a good place, `run()` might be too noisy. Also, it shouldn't be a warning, because it is very common that recipes define some system packages for Linux that are not necessary neither in Windows or in OSX, but recipes do not explicitly check for this. So it shouldn't be a warning in Windows or OSX, for example. But some informational message, like "A default system package manager couldn't be found for XXX, system packages will not be installed" could be good.

Gotcha, that makes sense. A self._conanfile.output.info at the end of the get_default_tool function should work right? Please have a look.
memsharded: Sounds good, approved, it will be merged for next 2.0.14 release, thanks again!

Patch:
diff --git a/conan/tools/system/package_manager.py b/conan/tools/system/package_manager.py
index 5a40478e6..6b8cb8877 100644
--- a/conan/tools/system/package_manager.py
+++ b/conan/tools/system/package_manager.py
@@ -39,7 +39,7 @@ class _SystemPackageManagerTool(object):
             os_name = distro.id() or os_name
         elif os_name == "Windows" and self._conanfile.conf.get("tools.microsoft.bash:subsystem") == "msys2":
             os_name = "msys2"
-        manager_mapping = {"apt-get": ["Linux", "ubuntu", "debian", "raspbian"],
+        manager_mapping = {"apt-get": ["Linux", "ubuntu", "debian", "raspbian", "linuxmint"],
                            "apk": ["alpine"],
                            "yum": ["pidora", "scientific", "xenserver", "amazon", "oracle", "amzn",
                                    "almalinux", "rocky"],
@@ -61,6 +61,11 @@ class _SystemPackageManagerTool(object):
             for d in distros:
                 if d in os_name:
                     return tool
+                
+        # No default package manager was found for the system,
+        # so notify the user
+        self._conanfile.output.info("A default system package manager couldn't be found for {}, "
+                                    "system packages will not be installed.".format(os_name))
 
     def get_package_name(self, package, host_package=True):
         # Only if the package is for building, for example a library,


Test patch:
diff --git a/conans/test/integration/tools/system/package_manager_test.py b/conans/test/integration/tools/system/package_manager_test.py
index 669d25927..de65d8f44 100644
--- a/conans/test/integration/tools/system/package_manager_test.py
+++ b/conans/test/integration/tools/system/package_manager_test.py
@@ -45,6 +45,7 @@ def test_msys2():
 @pytest.mark.parametrize("distro, tool", [
     ("ubuntu", "apt-get"),
     ("debian", "apt-get"),
+    ("linuxmint", "apt-get"),
     ("pidora", "yum"),
     ("rocky", "yum"),
     ("fedora", "dnf"),