예제 #1
0
파일: style.py 프로젝트: cgmb/rocm-spack
def run_black(black_cmd, file_list, args):
    # always run with config from running spack prefix
    black_args = ("--config", os.path.join(spack.paths.prefix,
                                           "pyproject.toml"))
    if not args.fix:
        black_args += ("--check", "--diff")
        if color.get_color_when():  # only show color when spack would
            black_args += ("--color", )

    pat = re.compile("would reformat +(.*)")
    replacement = "would reformat {0}"
    returncode = 0
    output = ""
    # run in chunks of 100 at a time to avoid line length limit
    # filename parameter in config *does not work* for this reliably
    for chunk in grouper(file_list, 100):
        packed_args = black_args + tuple(chunk)
        output = black_cmd(*packed_args,
                           fail_on_error=False,
                           output=str,
                           error=str)
        returncode |= black_cmd.returncode

        rewrite_and_print_output(output, args, pat, replacement)

    print_tool_result("black", returncode)

    return returncode
예제 #2
0
파일: diff.py 프로젝트: schmitts/spack
def compare_specs(a, b, to_string=False, colorful=True):
    """
    Generate a comparison, including diffs (for each side) and an intersection.

    We can either print the result to the console, or parse
    into a json object for the user to save. We return an object that shows
    the differences, intersection, and names for a pair of specs a and b.

    Arguments:
        a (spack.spec.Spec): the first spec to compare
        b (spack.spec.Spec): the second spec to compare
        a_name (str): the name of spec a
        b_name (str): the name of spec b
        to_string (bool): return an object that can be json dumped
        colorful (bool): do not format the names for the console
    """
    # Prepare a solver setup to parse differences
    setup = asp.SpackSolverSetup()

    a_facts = set(t for t in setup.spec_clauses(a, body=True))
    b_facts = set(t for t in setup.spec_clauses(b, body=True))

    # We want to present them to the user as simple key: values
    intersect = sorted(a_facts.intersection(b_facts))
    spec1_not_spec2 = sorted(a_facts.difference(b_facts))
    spec2_not_spec1 = sorted(b_facts.difference(a_facts))

    # Format the spec names to be colored
    fmt = "{name}{@version}{/hash}"
    a_name = a.format(fmt, color=color.get_color_when())
    b_name = b.format(fmt, color=color.get_color_when())

    # We want to show what is the same, and then difference for each
    return {
        "intersect": flatten(intersect) if to_string else intersect,
        "a_not_b": flatten(spec1_not_spec2) if to_string else spec1_not_spec2,
        "b_not_a": flatten(spec2_not_spec1) if to_string else spec2_not_spec1,
        "a_name": a_name if colorful else a.format("{name}{@version}{/hash}"),
        "b_name": b_name if colorful else b.format("{name}{@version}{/hash}")
    }
예제 #3
0
파일: diff.py 프로젝트: wrwilliams/spack
def compare_specs(a, b, to_string=False, color=None):
    """
    Generate a comparison, including diffs (for each side) and an intersection.

    We can either print the result to the console, or parse
    into a json object for the user to save. We return an object that shows
    the differences, intersection, and names for a pair of specs a and b.

    Arguments:
        a (spack.spec.Spec): the first spec to compare
        b (spack.spec.Spec): the second spec to compare
        a_name (str): the name of spec a
        b_name (str): the name of spec b
        to_string (bool): return an object that can be json dumped
        color (bool): whether to format the names for the console
    """
    if color is None:
        color = get_color_when()

    # Prepare a solver setup to parse differences
    setup = asp.SpackSolverSetup()

    # get facts for specs, making sure to include build dependencies of concrete
    # specs and to descend into dependency hashes so we include all facts.
    a_facts = set(t for t in setup.spec_clauses(
        a, body=True, expand_hashes=True, concrete_build_deps=True,
    ))
    b_facts = set(t for t in setup.spec_clauses(
        b, body=True, expand_hashes=True, concrete_build_deps=True,
    ))

    # We want to present them to the user as simple key: values
    intersect = sorted(a_facts.intersection(b_facts))
    spec1_not_spec2 = sorted(a_facts.difference(b_facts))
    spec2_not_spec1 = sorted(b_facts.difference(a_facts))

    # Format the spec names to be colored
    fmt = "{name}{@version}{/hash}"
    a_name = a.format(fmt, color=color)
    b_name = b.format(fmt, color=color)

    # We want to show what is the same, and then difference for each
    return {
        "intersect": flatten(intersect) if to_string else intersect,
        "a_not_b": flatten(spec1_not_spec2) if to_string else spec1_not_spec2,
        "b_not_a": flatten(spec2_not_spec1) if to_string else spec2_not_spec1,
        "a_name": a_name,
        "b_name": b_name,
    }
예제 #4
0
def diff(parser, args):
    env = ev.get_env(args, 'diff')

    if len(args.specs) != 2:
        tty.die("You must provide two specs to diff.")

    specs = [spack.cmd.disambiguate_spec(spec, env, first=args.load_first)
             for spec in spack.cmd.parse_specs(args.specs)]

    # Calculate the comparison (c)
    color = False if args.dump_json else get_color_when()
    c = compare_specs(specs[0], specs[1], to_string=True, color=color)

    # Default to all attributes
    attributes = args.attribute or ["all"]

    if args.dump_json:
        print(sjson.dump(c))
    else:
        tty.warn("This interface is subject to change.\n")
        print_difference(c, attributes)