Beispiel #1
0
def write_hashes(m):
    from metapack.exc import MetatabFileNotFound
    pm = last_build_marker_path(m)

    hashes = {}

    if pm.exists():
        hashes['last_package'] = pm.read_text()

        try:
            p = MetapackDoc(hashes['last_package'])
            hashes['last_hashes'] = {}
            for r in p.resources():
                try:
                    hashes['last_hashes'][r.name] = r.raw_row_generator.hash
                except AttributeError as e:
                    warn(
                        f"Failed to generate hash for {r.name}, rrg={type(r)}: {type(e)} {e}"
                    )
                except Exception as e:
                    warn(
                        f"Failed to generate hash for {r.name}, rrg={type(r)}: {type(e)} {e}"
                    )

        except MetatabFileNotFound:
            pass

    tm = trial_build_marker_path(m)

    if tm.exists():
        hashes['trial_package'] = tm.read_text()

        p = MetapackDoc(hashes['trial_package'])

        hashes['trial_hashes'] = {
            r.name: r.raw_row_generator.hash
            for r in p.resources()
        }

    hp = Path(m.package_root.fspath, '.hashes.yaml')

    hp.write_text(yaml.safe_dump(hashes))
Beispiel #2
0
def build(m):

    raise NotImplementedError()

    def mp(*args):
        pass

    name = m.doc.name

    lb_file = m.package_root.fspath.joinpath('.last_build')

    if m.args.result:
        prt = print
    else:
        from metapack.cli.core import prt

    if lb_file.exists():
        # Run a test build
        ft_args = ['build', '-FT']
        if m.args.no_cache:
            ft_args = ['-n'] + ft_args
        mp(ft_args, do_cli_init=False)

        tb_path = m.package_root.fspath.joinpath('.trial_build').read_text()
        lb_path = lb_file.read_text()

        tdoc = MetapackDoc(tb_path)
        ldoc = MetapackDoc(lb_path)

        diff_hashes = 0

        for t_r in tdoc.resources():
            l_r = ldoc.resource(t_r.name)

            h1 = t_r.raw_row_generator.hash
            h2 = l_r.raw_row_generator.hash

            if h1 != h2:
                diff_hashes += 1

        if diff_hashes == 0:
            prt(f'👍 {name}: Hashes Unchanged: will not rebuild')
            return

        prt(f'🛠 {name}: Hashes changed. Marked for rebuilding')
        Path(m.mt_file.fspath).touch()

        if m.args.increment:
            m.doc.update_name(mod_version='+')
            m.doc.write()
    else:
        prt(f'🛠 {name}: No previous build')