Skip to content
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

Added possible_values() #3212

Merged
merged 7 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion reference/conanfile/attributes/binary_model.inc
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,31 @@ If you want to do a safe check of settings values, you could use the ``get_safe(
# Will be the default version if the return is None
build_type = self.settings.get_safe("build_type", default="Release")

The ``get_safe()`` method will return ``None`` if that setting or sub-setting doesn't
The ``get_safe()`` method returns ``None`` if that setting or sub-setting doesn't
franramirez688 marked this conversation as resolved.
Show resolved Hide resolved
exist and there is no default value assigned.

It's also feasible to check the possible values defined for any setting/sub-setting using the ``possible_values()``
method:

.. code-block:: python

def generate(self):
# Print if Android exists as OS in the whole settings.yml
is_android = "Android" in self.settings.possible_values()["os"]
self.output.info(f"Android in settings.yml: {is_android}")
# Print the available compiler versions given your host profile
compiler_versions = self.settings.compiler.version.possible_values()
self.output.info(f"[HOST] Versions for {str(self.settings.compiler)}: {', '.join(compiler_versions)}")
# Print the available compiler versions given your build profile
compiler_versions = self.settings_build.compiler.version.possible_values()
self.output.info(f"[BUILD] Versions for {str(self.settings.compiler)}: {', '.join(compiler_versions)}")


As you can see above, doing ``self.settings.possible_values()`` returns the
whole :ref:`reference_config_files_settings_yml` as a Python dict-like object, and doing
``self.settings.compiler.version.possible_values()`` for instance returns the available versions for the compiler
used by the consumer.

If you want to do a safe deletion of settings, you could use the ``rm_safe()`` method.
For example, in the ``configure()`` method a typical pattern for a C library would be:

Expand All @@ -86,8 +108,10 @@ For example, in the ``configure()`` method a typical pattern for a C library wou
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")


.. seealso::

- :ref:`reference_config_files_settings_yml`.
- Removing settings in the ``package_id()`` method. <MISSING PAGE>


Expand Down
3 changes: 2 additions & 1 deletion reference/config_files/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ It looks like this:
WindowsStore:
version: ["8.1", "10.0"]
WindowsCE:
platform: ANY
platform: [ANY]
version: ["5.0", "6.0", "7.0", "8.0"]
Linux:
iOS:
Expand Down Expand Up @@ -140,6 +140,7 @@ to distribute an unified *settings.yml* file you can use the :ref:`conan config
.. seealso::

- :ref:`creating_packages_configure_options_settings`
- :ref:`conan_conanfile_properties_settings`


Operating systems
Expand Down