예제 #1
0
def test_save_dependency_spec_jsons_subset(tmpdir, config):
    output_path = str(tmpdir.mkdir('spec_jsons'))

    default = ('build', 'link')

    mock_repo = MockPackageMultiRepo()
    g = mock_repo.add_package('g', [], [])
    f = mock_repo.add_package('f', [], [])
    e = mock_repo.add_package('e', [], [])
    d = mock_repo.add_package('d', [f, g], [default, default])
    c = mock_repo.add_package('c', [], [])
    b = mock_repo.add_package('b', [d, e], [default, default])
    mock_repo.add_package('a', [b, c], [default, default])

    with repo.use_repositories(mock_repo):
        spec_a = Spec('a')
        spec_a.concretize()
        b_spec = spec_a['b']
        c_spec = spec_a['c']
        spec_a_json = spec_a.to_json(hash=ht.build_hash)

        save_dependency_specfiles(spec_a_json, output_path, ['b', 'c'])

        assert check_specs_equal(b_spec, os.path.join(output_path, 'b.json'))
        assert check_specs_equal(c_spec, os.path.join(output_path, 'c.json'))
예제 #2
0
def save_specfile_fn(args):
    """Get full spec for dependencies, relative to root spec, and write them
    to files in the specified output directory.  Uses exit code to signal
    success or failure.  An exit code of zero means the command was likely
    successful.  If any errors or exceptions are encountered, or if expected
    command-line arguments are not provided, then the exit code will be
    non-zero.
    """
    if not args.root_spec and not args.root_specfile:
        tty.msg('No root spec provided, exiting.')
        sys.exit(1)

    if not args.specs:
        tty.msg('No dependent specs provided, exiting.')
        sys.exit(1)

    if not args.specfile_dir:
        tty.msg('No yaml directory provided, exiting.')
        sys.exit(1)

    if args.root_specfile:
        with open(args.root_specfile) as fd:
            root_spec_as_json = fd.read()
        spec_format = 'yaml' if args.root_specfile.endswith('yaml') else 'json'
    else:
        root_spec = Spec(args.root_spec)
        root_spec.concretize()
        root_spec_as_json = root_spec.to_json(hash=ht.dag_hash)
        spec_format = 'json'
    save_dependency_specfiles(root_spec_as_json, args.specfile_dir,
                              args.specs.split(), spec_format)

    sys.exit(0)