spack/lib/spack
Todd Gamblin 425bba2f1a
Allow spec queries by namespace (#45416)
* Allow spec queries by `namespace`

Spack specs have "namespaces" that indicate what package repository they come from, but
there has not been a way to use the spec syntax to match one.

You can say things like this:

```console
spack find builtin.zlib
spack find myrepo.zlib
```

But, because namespaces are written as a dot-separated prefix on the name, you can't say
"find me all specs in namespace myrepo". The syntax doesn't allow it.

This PR allows you to specify anonymous specs with namespaces on the CLI. Specifically
you can do queries like this:

```console
spack find namespace=builtin
spack find namespace=myrepo
```

You can use this anywhere else you use spec syntax, e.g. in a config file to separate
installations based on what repo they came from:

```yaml
spack:
    config:
        install_tree:
            root: $spack/opt/spack
            projections:
                namespace=myrepo: "myrepo_special_path/{name}-{hash}"
                namespace=builtin: "builtin/{name}-{hash}"
```

This PR adds a special `namespace_if_anonymous` attribute to specs, which returns the
`namespace` if the spec has no name, otherwise it returns `None`. This allows us to
print the namespace for anonymous specs but to continue hiding it for most views, as
we've done so far.

This is implemented as a special case, but it's one that already exists, along with
`platform`, `os`, `target`, etc. This also reserves existing special case names for
variants so that users cannot define them in their package files. This change is
potentially breaking, but I do not think it will be common. There are no builtin
packages with a variant called `namespace`, and defining `os`, `target`, or `platform`
as a variant would've likely caused other problems if they were already being used.

Signed-off-by: Todd Gamblin <tgamblin@llnl.gov>
2024-08-02 13:38:14 -05:00
..
docs build(deps): bump pytest from 8.2.2 to 8.3.1 in /lib/spack/docs (#45377) 2024-07-23 11:53:55 -04:00
env ldflags=* are compiler flags, not linker flags (#43820) 2024-04-26 09:19:03 +02:00
external Update vendored archspec to v0.2.4 (#44005) 2024-05-06 10:20:56 +02:00
llnl Fix bug in logfile parsing (#42706) 2024-06-27 07:07:30 -06:00
spack Allow spec queries by namespace (#45416) 2024-08-02 13:38:14 -05:00
spack_installable Update copyright year to 2024 (#41919) 2024-01-02 09:21:30 +01:00