Open frankeverdij opened 1 month ago
Shorter reproducer:
Spack version 0.23.0.dev0
Python 3.11.5, Linux x86_64
>>> from spack.spec import Spec
>>> s = Spec("zlib-ng").concretized()
>>> s.format("{variants}")
'+compat+new_strategies+opt+pic+shared build_system=autotools'
>>> s.format("{variants.compat}")
Traceback (most recent call last):
File "/home/culpo/PycharmProjects/spack/lib/spack/spack/spec.py", line 3905, in format_attribute
current = getattr(current, part)
^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'VariantMap' object has no attribute 'compat'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/culpo/PycharmProjects/spack/lib/spack/spack/spec.py", line 3941, in format
return SPEC_FORMAT_RE.sub(format_attribute, format_string).strip()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/culpo/PycharmProjects/spack/lib/spack/spack/spec.py", line 3910, in format_attribute
raise SpecFormatStringError(m)
spack.spec.SpecFormatStringError: Attempted to format attribute variants.compat.Spec variants has no attribute compat
The only place I found where we explicitly mention this feature is the docstring of Spec.format
:
Steps to reproduce
After a discussion in (Slack) about changes in allowed characters with respect to module file generation with variants in the name, i tested this with various Slack versions.
==> Error: Attempted to format attribute variants.pic.name.Spec variants has no attribute pic
$ spack -d module lmod refresh -y
==> [2024-07-19-13:06:37.016605] Reading config from file /tmp/spack/etc/spack/defaults/config.yaml ==> [2024-07-19-13:06:37.043014] Imported module from built-in commands ==> [2024-07-19-13:06:37.045784] Imported module from built-in commands
==> [2024-07-19-13:06:37.046775] DATABASE LOCK TIMEOUT: 60s
==> [2024-07-19-13:06:37.046830] PACKAGE LOCK TIMEOUT: No timeout
==> [2024-07-19-13:06:37.047645] Reading config from file /tmp/spack/etc/spack/defaults/repos.yaml ==> [2024-07-19-13:06:37.049472] Reading config from file /tmp/spack/etc/spack/defaults/packages.yaml ==> [2024-07-19-13:06:37.078849] Reading config from file /tmp/spack/etc/spack/defaults/modules.yaml
==> [2024-07-19-13:06:37.088935] Reading config from file /tmp/spack/etc/spack/defaults/linux/modules.yaml ==> [2024-07-19-13:06:37.090516] Reading config from file /home/sup-feverdij/.spack/modules.yaml ==> [2024-07-19-13:06:37.261392] SpecFormatStringError: Attempted to format attribute variants.pic.name.Spec variants has no attribute pic ==> [2024-07-19-13:06:37.261455] Error: Attempted to format attribute variants.pic.name.Spec variants has no attribute pic Traceback (most recent call last): File "/tmp/spack/lib/spack/spack/spec.py", line 4535, in format_attribute current = getattr(current, part) AttributeError: 'VariantMap' object has no attribute 'pic'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/tmp/spack/lib/spack/spack/main.py", line 1070, in main return _main(argv) File "/tmp/spack/lib/spack/spack/main.py", line 1023, in _main return finish_parse_and_run(parser, cmd_name, args, env_format_error) File "/tmp/spack/lib/spack/spack/main.py", line 1053, in finish_parse_and_run return _invoke_command(command, parser, args, unknown) File "/tmp/spack/lib/spack/spack/main.py", line 650, in _invoke_command return_val = command(parser, args) File "/tmp/spack/lib/spack/spack/cmd/module.py", line 26, in module _subcommands[args.module_command](parser, args) File "/tmp/spack/lib/spack/spack/cmd/modules/init.py", line 388, in modules_cmd callbacks[args.subparser_name](module_type, specs, args) File "/tmp/spack/lib/spack/spack/cmd/modules/init.py", line 321, in refresh file2writer[item.layout.filename].append(item) File "/tmp/spack/lib/spack/spack/modules/lmod.py", line 279, in filename f"{self.use_name}.{self.extension}", # file name File "/tmp/spack/lib/spack/spack/modules/common.py", line 588, in use_name name = self.spec.format_path(projection) File "/tmp/spack/lib/spack/spack/spec.py", line 4624, in format_path fs.polite_filename(self.format(part)) for part in input_path_components File "/tmp/spack/lib/spack/spack/spec.py", line 4624, in
fs.polite_filename(self.format(part)) for part in input_path_components
File "/tmp/spack/lib/spack/spack/spec.py", line 4567, in format
return SPEC_FORMAT_RE.sub(format_attribute, format_string).strip()
File "/tmp/spack/lib/spack/spack/spec.py", line 4540, in format_attribute
raise SpecFormatStringError(m)
spack.spec.SpecFormatStringError: Attempted to format attribute variants.pic.name.Spec variants has no attribute pic