summaryrefslogtreecommitdiff
path: root/lib/spack/spack/ci_needs_workaround.py
blob: 99597edb2e80f87493b3d5a6924a32a9f2ac7b05 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Copyright 2013-2023 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import collections.abc

get_job_name = lambda needs_entry: (
    needs_entry.get("job")
    if (isinstance(needs_entry, collections.abc.Mapping) and needs_entry.get("artifacts", True))
    else needs_entry
    if isinstance(needs_entry, str)
    else None
)


def convert_job(job_entry):
    if not isinstance(job_entry, collections.abc.Mapping):
        return job_entry

    needs = job_entry.get("needs")
    if needs is None:
        return job_entry

    new_job = {}
    new_job.update(job_entry)
    del new_job["needs"]

    new_job["dependencies"] = list(
        filter((lambda x: x is not None), (get_job_name(needs_entry) for needs_entry in needs))
    )

    return new_job


def needs_to_dependencies(yaml):
    return dict((k, convert_job(v)) for k, v in yaml.items())