Skip to content

depends_on does not support default_args for languages #45488

@adamjstewart

Description

@adamjstewart

Steps to reproduce

  1. Apply the following patch:
diff --git a/var/spack/repos/builtin/packages/zlib/package.py b/var/spack/repos/builtin/packages/zlib/package.py
index 32a40fb31d..66c334ce1d 100644
--- a/var/spack/repos/builtin/packages/zlib/package.py
+++ b/var/spack/repos/builtin/packages/zlib/package.py
@@ -52,8 +52,9 @@ class Zlib(MakefilePackage, Package):
         deprecated=True,
     )
 
-    depends_on("c", type="build")  # generated
-    depends_on("cxx", type="build")  # generated
+    with default_args(type="build"):
+        depends_on("c")  # generated
+        depends_on("cxx")  # generated
 
     build_system("makefile", conditional("generic", when="platform=windows"), default="makefile")
  1. Run any command that uses the zlib package:
> spack info zlib

Error message

> spack -d info zlib
==> [2024-07-29-12:38:14.909114] Reading config from file /Users/Adam/spack/etc/spack/defaults/config.yaml
==> [2024-07-29-12:38:14.936495] Imported info from built-in commands
==> [2024-07-29-12:38:14.936830] Imported info from built-in commands
==> [2024-07-29-12:38:14.937131] Reading config from file /Users/Adam/spack/etc/spack/defaults/repos.yaml
==> [2024-07-29-12:38:14.938110] Reading config from file /Users/Adam/spack/etc/spack/defaults/packages.yaml
==> [2024-07-29-12:38:14.949809] Reading config from file /Users/Adam/spack/etc/spack/defaults/darwin/packages.yaml
==> [2024-07-29-12:38:14.955454] Reading config from file /Users/Adam/.spack/packages.yaml
==> [2024-07-29-12:38:14.988284] RepoError: cannot load package 'zlib' from the 'builtin' repository: _language() got an unexpected keyword argument 'type'
==> [2024-07-29-12:38:14.988340] Error: cannot load package 'zlib' from the 'builtin' repository: _language() got an unexpected keyword argument 'type'
Traceback (most recent call last):
  File "/Users/Adam/spack/lib/spack/spack/repo.py", line 1261, in get_pkg_class
    module = importlib.import_module(fullname)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Adam/spack/opt/spack/darwin-sonoma-m2/apple-clang-15.0.0/python-3.11.6-7kc3atdlybs3ishfi7zhmy3zhjvulalv/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/Adam/spack/var/spack/repos/builtin/packages/zlib/package.py", line 19, in <module>
    """A free, general-purpose, legally unencumbered lossless
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Adam/spack/var/spack/repos/builtin/packages/zlib/package.py", line 57, in Zlib
    depends_on("cxx")  # generated
    ^^^^^^^^^^^^^^^
  File "/Users/Adam/spack/lib/spack/spack/directives.py", line 343, in _wrapper
    result = decorated_function(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Adam/spack/lib/spack/spack/directives.py", line 596, in depends_on
    return _language(lang_spec_str=spec, when=when)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Adam/spack/lib/spack/spack/directives.py", line 343, in _wrapper
    result = decorated_function(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: _language() got an unexpected keyword argument 'type'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/Adam/spack/lib/spack/spack/main.py", line 1070, in main
    return _main(argv)
           ^^^^^^^^^^^
  File "/Users/Adam/spack/lib/spack/spack/main.py", line 1023, in _main
    return finish_parse_and_run(parser, cmd_name, args, env_format_error)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Adam/spack/lib/spack/spack/main.py", line 1053, in finish_parse_and_run
    return _invoke_command(command, parser, args, unknown)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Adam/spack/lib/spack/spack/main.py", line 650, in _invoke_command
    return_val = command(parser, args)
                 ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Adam/spack/lib/spack/spack/cmd/info.py", line 505, in info
    pkg_cls = spack.repo.PATH.get_pkg_class(spec.name)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Adam/spack/lib/spack/spack/repo.py", line 877, in get_pkg_class
    return self.repo_for_pkg(pkg_name).get_pkg_class(pkg_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Adam/spack/lib/spack/spack/repo.py", line 1266, in get_pkg_class
    raise RepoError(msg) from e
spack.repo.RepoError: cannot load package 'zlib' from the 'builtin' repository: _language() got an unexpected keyword argument 'type'

Information on your system

  • Spack: 0.23.0.dev0 (d63ead2)
  • Python: 3.11.6
  • Platform: darwin-sonoma-m2
  • Concretizer: clingo

Not sure if bug in _language (@alalazo) or default_args (@haampie)

General information

  • I have run spack debug report and reported the version of Spack/Python/Platform
  • I have searched the issues of this repo and believe this is not a duplicate
  • I have run the failing commands in debug mode and reported the output

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions