Add version attributes up_to_1, up_to_2, up_to_3 (#38410)

Making them also available in spec format string
This commit is contained in:
Jordan Galby 2025-01-15 13:07:17 +01:00 committed by GitHub
parent 976f1c2198
commit c504304d39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 6 deletions

View File

@ -456,14 +456,13 @@ For instance, the following config options,
tcl: tcl:
all: all:
suffixes: suffixes:
^python@3: 'python{^python.version}' ^python@3: 'python{^python.version.up_to_2}'
^openblas: 'openblas' ^openblas: 'openblas'
will add a ``python-3.12.1`` version string to any packages compiled with will add a ``python3.12`` to module names of packages compiled with Python 3.12, and similarly for
Python matching the spec, ``python@3``. This is useful to know which all specs depending on ``python@3``. This is useful to know which version of Python a set of Python
version of Python a set of Python extensions is associated with. Likewise, the extensions is associated with. Likewise, the ``openblas`` string is attached to any program that
``openblas`` string is attached to any program that has openblas in the spec, has openblas in the spec, most likely via the ``+blas`` variant specification.
most likely via the ``+blas`` variant specification.
The most heavyweight solution to module naming is to change the entire The most heavyweight solution to module naming is to change the entire
naming convention for module files. This uses the projections format naming convention for module files. This uses the projections format

View File

@ -869,6 +869,12 @@ def test_spec_formatting(self, default_mock_concretization):
("{namespace=namespace}", "namespace=", "namespace", lambda spec: spec), ("{namespace=namespace}", "namespace=", "namespace", lambda spec: spec),
("{compiler.name}", "", "name", lambda spec: spec.compiler), ("{compiler.name}", "", "name", lambda spec: spec.compiler),
("{compiler.version}", "", "version", lambda spec: spec.compiler), ("{compiler.version}", "", "version", lambda spec: spec.compiler),
(
"{compiler.version.up_to_1}",
"",
"up_to_1",
lambda spec: spec.compiler.version.up_to(1),
),
("{%compiler.name}", "%", "name", lambda spec: spec.compiler), ("{%compiler.name}", "%", "name", lambda spec: spec.compiler),
("{@compiler.version}", "@", "version", lambda spec: spec.compiler), ("{@compiler.version}", "@", "version", lambda spec: spec.compiler),
("{architecture.platform}", "", "platform", lambda spec: spec.architecture), ("{architecture.platform}", "", "platform", lambda spec: spec.architecture),

View File

@ -490,6 +490,21 @@ def up_to(self, index: int) -> "StandardVersion":
""" """
return self[:index] return self[:index]
@property
def up_to_1(self):
"""The version truncated to the first component."""
return self.up_to(1)
@property
def up_to_2(self):
"""The version truncated to the first two components."""
return self.up_to(2)
@property
def up_to_3(self):
"""The version truncated to the first three components."""
return self.up_to(3)
_STANDARD_VERSION_TYPEMIN = StandardVersion("", ((), (ALPHA,)), ("",)) _STANDARD_VERSION_TYPEMIN = StandardVersion("", ((), (ALPHA,)), ("",))