Example #1
0
 def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict",
             **kwargs: Any) -> "MigrationUidTypedDict":
     # in case the render is old
     os.makedirs(os.path.join(recipe_dir, "../.ci_support"), exist_ok=True)
     with indir(os.path.join(recipe_dir, "../.ci_support")):
         os.makedirs("migrations", exist_ok=True)
         with indir("migrations"):
             with open(f"{self.name}.yaml", "w") as f:
                 f.write(self.yaml_contents)
             eval_xonsh("git add .")
     with indir(recipe_dir):
         self.set_build_number("meta.yaml")
     return super().migrate(recipe_dir, attrs)
Example #2
0
 def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict",
             **kwargs: Any) -> None:
     cb_work_dir = _get_source_code(recipe_dir)
     if cb_work_dir is None:
         return
     with indir(cb_work_dir):
         # look for a license file
         license_files = [
             s for s in os.listdir(".")
             if any(s.lower().startswith(k)
                    for k in ["license", "copying", "copyright"])
         ]
     eval_xonsh(f"rm -r {cb_work_dir}")
     # if there is a license file in tarball update things
     if license_files:
         with indir(recipe_dir):
             """BSD 3-Clause License
               Copyright (c) 2017, Anthony Scopatz
               Copyright (c) 2018, The Regro Developers
               All rights reserved."""
             with open("meta.yaml", "r") as f:
                 raw = f.read()
             lines = raw.splitlines()
             ptn = re.compile(r"(\s*?)" + "license:")
             for i, line in enumerate(lines):
                 m = ptn.match(line)
                 if m is not None:
                     break
             # TODO: Sketchy type assertion
             assert m is not None
             ws = m.group(1)
             if len(license_files) == 1:
                 replace_in_file(
                     line,
                     line + "\n" + ws +
                     f"license_file: {list(license_files)[0]}",
                     "meta.yaml",
                 )
             else:
                 # note that this white space is not perfect but works for
                 # most of the situations
                 replace_in_file(
                     line,
                     line + "\n" + ws + "license_file: \n" +
                     "".join(f"{ws*2}- {z} \n" for z in license_files),
                     "meta.yaml",
                 )
def test_migration_yaml_migration(tmock, in_out_yaml, caplog, tmpdir):
    caplog.set_level(
        logging.DEBUG,
        logger="conda_forge_tick.migrators.migration_yaml",
    )
    tmock.return_value = 12345.2
    pname = "boost"
    pin_ver = "1.99.0"
    curr_pin = "1.70.0"
    pin_spec = "x.x"

    MYM = MigrationYamlCreator(pname, pin_ver, curr_pin, pin_spec, "hi", G, G)

    with indir(tmpdir):
        eval_xonsh("git init .")

    os.makedirs(os.path.join(tmpdir, "migrations"), exist_ok=True)

    run_test_migration(
        m=MYM,
        inp=in_out_yaml[0],
        output=in_out_yaml[1],
        kwargs={},
        prb="This PR has been triggered in an effort to update the pin",
        mr_out={
            "migrator_name": "MigrationYamlCreator",
            "migrator_version": MYM.migrator_version,
            "name": pname,
            "pin_version": "1.99",
        },
        tmpdir=tmpdir,
    )

    boost_file = os.path.join(tmpdir, "migrations", "boost199.yaml")
    assert os.path.exists(boost_file)
    with open(boost_file) as fp:
        bf_out = fp.read()
    assert BOOST_YAML == bf_out
Example #4
0
    def migrate(self, recipe_dir: str, attrs: "AttrsTypedDict",
                **kwargs: Any) -> "MigrationUidTypedDict":
        migration_yaml_dict = {
            "__migrator": {
                "build_number": 1,
                "kind": "version",
                "migration_number": 1
            },
            self.package_name: [self.new_pin_version],
            "migrator_ts": float(time.time()),
        }
        with indir(os.path.join(recipe_dir, "migrations")):
            mig_fname = "%s%s.yaml" % (self.package_name,
                                       self.new_pin_version.replace(".", ""))
            with open(mig_fname, "w") as f:
                yaml.dump(
                    migration_yaml_dict,
                    f,
                    default_flow_style=False,
                )
            eval_xonsh("git add .")

        return super().migrate(recipe_dir, attrs)