def test_set_mode_file(self): perms = [ stat.S_IWUSR, stat.S_IXUSR, stat.S_IRUSR, stat.S_IXGRP, stat.S_IRGRP, stat.S_IROTH ] set_mode = functools.reduce(op.or_, perms) for tmp_dir, repo, pathfunc in parameterize(): filename = "test.txt" filename = os.path.join(tmp_dir, filename) with io.open(filename, "w", encoding = "utf-8") as fh: fh.write("") if repo is not None: repo.index.add([filename]) fio.set_mode_file(pathfunc(filename), set_mode) file_mode = os.stat(filename).st_mode self.assertEqual(file_mode & set_mode, set_mode) if repo is not None: blob = next(repo.index.iter_blobs(BlobFilter(filename)))[1] self.assertEqual(blob.mode & set_mode, set_mode)
def test_set_mode_file(self): perms = [ stat.S_IWUSR, stat.S_IXUSR, stat.S_IRUSR, stat.S_IXGRP, stat.S_IRGRP, stat.S_IROTH ] set_mode = functools.reduce(op.or_, perms) for tmp_dir, repo, pathfunc in parameterize(): filename = "test.txt" filename = os.path.join(tmp_dir, filename) with io.open(filename, "w", encoding="utf-8") as fh: fh.write("") if repo is not None: repo.index.add([filename]) fio.set_mode_file(pathfunc(filename), set_mode) file_mode = os.stat(filename).st_mode self.assertEqual(file_mode & set_mode, set_mode) if repo is not None: blob = next(repo.index.iter_blobs(BlobFilter(filename)))[1] self.assertEqual(blob.mode & set_mode, set_mode)
def render_run_docker_build(jinja_env, forge_config, forge_dir): meta = forge_config['package'] with fudge_subdir('linux-64', build_config=meta_config(meta)): meta.parse_again() matrix = compute_build_matrix(meta, forge_config.get('matrix')) cases_not_skipped = [] for case in matrix: pkgs, vars = split_case(case) with enable_vars(vars): if not ResolvedDistribution(meta, pkgs).skip(): cases_not_skipped.append(vars + sorted(pkgs)) matrix = sorted(cases_not_skipped, key=sort_without_target_arch) if not matrix: # There are no cases to build (not even a case without any special # dependencies), so remove the run_docker_build.sh if it exists. forge_config["circle"]["enabled"] = False target_fnames = [ os.path.join(forge_dir, 'ci_support', 'run_docker_build.sh'), os.path.join(forge_dir, 'ci_support', 'checkout_merge_commit.sh'), ] for each_target_fname in target_fnames: remove_file(each_target_fname) else: forge_config["circle"]["enabled"] = True matrix = prepare_matrix_for_env_vars(matrix) forge_config = update_matrix(forge_config, matrix) # If there is a "yum_requirements.txt" file in the recipe, we honour it. yum_requirements_fpath = os.path.join(forge_dir, 'recipe', 'yum_requirements.txt') if os.path.exists(yum_requirements_fpath): with open(yum_requirements_fpath) as fh: requirements = [ line.strip() for line in fh if line.strip() and not line.strip().startswith('#') ] if not requirements: raise ValueError( "No yum requirements enabled in the " "yum_requirements.txt, please remove the file " "or add some.") build_setup = textwrap.dedent("""\ # Install the yum requirements defined canonically in the # "recipe/yum_requirements.txt" file. After updating that file, # run "conda smithy rerender" and this line be updated # automatically. yum install -y {} """.format(' '.join(requirements))) forge_config['build_setup'] = build_setup # TODO: Conda has a convenience for accessing nested yaml content. templates = forge_config.get('templates', {}) template_name = templates.get('run_docker_build', 'run_docker_build_matrix.tmpl') template = jinja_env.get_template(template_name) target_fname = os.path.join(forge_dir, 'ci_support', 'run_docker_build.sh') with write_file(target_fname) as fh: fh.write(template.render(**forge_config)) # Fix permissions. target_fnames = [ os.path.join(forge_dir, 'ci_support', 'run_docker_build.sh'), os.path.join(forge_dir, 'ci_support', 'checkout_merge_commit.sh'), ] for each_target_fname in target_fnames: mode = get_mode_file(each_target_fname) set_mode_file(each_target_fname, mode | stat.S_IXOTH | stat.S_IXGRP | stat.S_IXUSR)
def render_run_docker_build(jinja_env, forge_config, forge_dir): meta = forge_config['package'] with fudge_subdir('linux-64', build_config=meta_config(meta)): meta.parse_again() matrix = compute_build_matrix(meta, forge_config.get('matrix')) cases_not_skipped = [] for case in matrix: pkgs, vars = split_case(case) with enable_vars(vars): if not ResolvedDistribution(meta, pkgs).skip(): cases_not_skipped.append(vars + sorted(pkgs)) matrix = sorted(cases_not_skipped, key=sort_without_target_arch) if not matrix: # There are no cases to build (not even a case without any special # dependencies), so remove the run_docker_build.sh if it exists. forge_config["circle"]["enabled"] = False target_fnames = [ os.path.join(forge_dir, 'ci_support', 'run_docker_build.sh'), os.path.join(forge_dir, 'ci_support', 'checkout_merge_commit.sh'), ] for each_target_fname in target_fnames: remove_file(each_target_fname) else: forge_config["circle"]["enabled"] = True matrix = prepare_matrix_for_env_vars(matrix) forge_config = update_matrix(forge_config, matrix) # If there is a "yum_requirements.txt" file in the recipe, we honour it. yum_requirements_fpath = os.path.join(forge_dir, 'recipe', 'yum_requirements.txt') if os.path.exists(yum_requirements_fpath): with open(yum_requirements_fpath) as fh: requirements = [line.strip() for line in fh if line.strip() and not line.strip().startswith('#')] if not requirements: raise ValueError("No yum requirements enabled in the " "yum_requirements.txt, please remove the file " "or add some.") build_setup = textwrap.dedent("""\ # Install the yum requirements defined canonically in the # "recipe/yum_requirements.txt" file. After updating that file, # run "conda smithy rerender" and this line be updated # automatically. yum install -y {} """.format(' '.join(requirements))) forge_config['build_setup'] = build_setup # TODO: Conda has a convenience for accessing nested yaml content. templates = forge_config.get('templates', {}) template_name = templates.get('run_docker_build', 'run_docker_build_matrix.tmpl') template = jinja_env.get_template(template_name) target_fname = os.path.join(forge_dir, 'ci_support', 'run_docker_build.sh') with write_file(target_fname) as fh: fh.write(template.render(**forge_config)) # Fix permissions. target_fnames = [ os.path.join(forge_dir, 'ci_support', 'run_docker_build.sh'), os.path.join(forge_dir, 'ci_support', 'checkout_merge_commit.sh'), ] for each_target_fname in target_fnames: mode = get_mode_file(each_target_fname) set_mode_file( each_target_fname, mode | stat.S_IXOTH | stat.S_IXGRP | stat.S_IXUSR )