diff --git a/vinca/generate_gha.py b/vinca/generate_gha.py index c82faeb..a7b16ab 100644 --- a/vinca/generate_gha.py +++ b/vinca/generate_gha.py @@ -100,14 +100,14 @@ def add_additional_recipes(args): if not os.path.exists(additional_recipes_path): return [] - with open("vinca.yaml", "r") as vinca_yaml: + with open("vinca.yaml", encoding="utf-8") as vinca_yaml: vinca_conf = yaml.safe_load(vinca_yaml) repodatas = get_skip_existing(vinca_conf, args.platform) additional_recipes = [] for recipe_path in glob.glob(additional_recipes_path + "/**/recipe.yaml"): - with open(recipe_path) as recipe: + with open(recipe_path, encoding="utf-8") as recipe: additional_recipe = yaml.safe_load(recipe) name, version, bnumber = ( @@ -152,7 +152,7 @@ def add_additional_recipes(args): def dump_for_gha(doc, f): s = yaml.dump(doc, sort_keys=False, Dumper=NoAliasDumper) s = s.replace("'on':", "on:") - with open(f, "w") as fo: + with open(f, "w", encoding="utf-8") as fo: fo.write(s) workflow_size = os.path.getsize(f) @@ -352,7 +352,7 @@ def build_win_pipeline( f"{WINDOWS_BUILD_SCRIPT} not found in {os.getcwd()}: the Windows workflow " "runs the repository's build script, run vinca-gha where it exists" ) - with open(WINDOWS_BUILD_SCRIPT, "r") as fi: + with open(WINDOWS_BUILD_SCRIPT, encoding="utf-8") as fi: script = lu(fi.read()) prev_batch_keys = [] @@ -468,7 +468,7 @@ def main(): all_recipes = glob.glob(os.path.join(args.dir, "**", "*.yaml")) for f in all_recipes: - with open(f) as fi: + with open(f, encoding="utf-8") as fi: metas.append(yaml.safe_load(fi.read())) platform = args.platform @@ -546,7 +546,7 @@ def main(): stages = batch_stages(filtered_stages, args.batch_size) print(stages) - with open("buildorder.txt", "w") as fo: + with open("buildorder.txt", "w", encoding="utf-8") as fo: order = [] for stage in filtered_stages: for el in stage: diff --git a/vinca/generate_gitlab.py b/vinca/generate_gitlab.py index b92f0a4..f5ffdf3 100644 --- a/vinca/generate_gitlab.py +++ b/vinca/generate_gitlab.py @@ -40,7 +40,7 @@ def main(): for f in glob.glob(os.path.join(sys.argv[1], "*.yaml")): print(f) - with open(f) as fi: + with open(f, encoding="utf-8") as fi: metas.append(yaml.load(fi.read(), Loader=Loader)) requirements = {} @@ -102,5 +102,5 @@ def main(): gitlab_template["stages"] = stage_names - with open(".gitlab-ci.yml", "w") as fo: + with open(".gitlab-ci.yml", "w", encoding="utf-8") as fo: fo.write(yaml.dump(gitlab_template, Dumper=Dumper)) diff --git a/vinca/main.py b/vinca/main.py index c44be0d..922f913 100644 --- a/vinca/main.py +++ b/vinca/main.py @@ -690,7 +690,7 @@ def main(): for add_rec in glob.glob( os.path.join(base_dir, "additional_recipes", "**", "recipe.yaml") ): - with open(add_rec) as fi: + with open(add_rec, encoding="utf-8") as fi: add_rec_y = yaml.load(fi) if arguments.platform == "emscripten-wasm32": additional_recipe_names.add(add_rec_y["package"]["name"]) diff --git a/vinca/migrate.py b/vinca/migrate.py index 71f5b29..3c2090a 100644 --- a/vinca/migrate.py +++ b/vinca/migrate.py @@ -43,7 +43,7 @@ def create_migration_instructions(arch, packages_to_migrate, trigger_branch): url = "https://conda.anaconda.org/robostack/" yaml = ruamel.yaml.YAML() - with open("vinca.yaml", "r") as fi: + with open("vinca.yaml", encoding="utf-8") as fi: vinca_conf = yaml.load(fi) global distro_version, ros_prefix @@ -128,7 +128,7 @@ def create_migration_instructions(arch, packages_to_migrate, trigger_branch): vinca_conf["is_migration"] = True vinca_conf["skip_existing"] = [] - with open("vinca.yaml", "w") as fo: + with open("vinca.yaml", "w", encoding="utf-8") as fo: yaml.dump(vinca_conf, fo) if os.path.exists("recipes"): @@ -211,7 +211,7 @@ def main(): args = parse_command_line(sys.argv) mfile = os.path.join(args.dir + "/migration.yaml") - with open(mfile, "r") as fi: + with open(mfile, encoding="utf-8") as fi: migration = yaml.safe_load(fi) print(migration) create_migration_instructions( diff --git a/vinca/snapshot.py b/vinca/snapshot.py index c777a12..1e158e3 100644 --- a/vinca/snapshot.py +++ b/vinca/snapshot.py @@ -144,7 +144,7 @@ def main(): if not args.quiet: print("{0:{2}} {1}".format(dep, version, max_len + 2)) - with open(args.output, "w") as f: + with open(args.output, "w", encoding="utf-8") as f: source = f" at rosdistro {args.rosdistro_ref}" if args.rosdistro_ref else "" f.write( f"# Snapshot generated by vinca-snapshot on {utc_time} UTC for distro {args.distro}{source}\n" diff --git a/vinca/template.py b/vinca/template.py index de10d00..6873139 100644 --- a/vinca/template.py +++ b/vinca/template.py @@ -66,7 +66,7 @@ def write_recipe_package(recipe): os.makedirs(recipe["package"]["name"], exist_ok=True) recipe_path = os.path.join(recipe["package"]["name"], "recipe.yaml") - with open(recipe_path, "w") as stream: + with open(recipe_path, "w", encoding="utf-8") as stream: file.dump(recipe, stream) @@ -99,7 +99,7 @@ def write_recipe(source, outputs, vinca_conf, distro, single_file=True): del meta["package"] meta["build"]["number"] = vinca_conf.get("build_number", 0) meta["build"]["post_process"] = post_process_items - with open("recipe.yaml", "w") as stream: + with open("recipe.yaml", "w", encoding="utf-8") as stream: file.dump(meta, stream) else: for o in outputs: @@ -163,12 +163,14 @@ def write_recipe(source, outputs, vinca_conf, distro, single_file=True): shutil.rmtree(dest_dir) shutil.copytree(item, dest_dir) - with open(recipe_dir / "recipe.yaml", "w") as stream: + with open(recipe_dir / "recipe.yaml", "w", encoding="utf-8") as stream: file.dump(meta, stream) if get_variants_mode(vinca_conf) is VariantsMode.LOCAL: variants = get_recipe_variants(meta, package_shortname, vinca_conf) - with open(recipe_dir / "variants.yaml", "w") as stream: + with open( + recipe_dir / "variants.yaml", "w", encoding="utf-8" + ) as stream: file.dump(variants, stream) if meta.get("source") and meta["source"].get("patches"): @@ -236,7 +238,7 @@ def generate_template(template_in, template_out, extra_globals=None): output=template_out, options={em.RAW_OPT: True, em.BUFFERED_OPT: True} ) interpreter.updateGlobals(g) - interpreter.file(open(template_in)) + interpreter.file(open(template_in, encoding="utf-8")) interpreter.shutdown() # It seems that rattler-build requires script to have executable permissions @@ -274,7 +276,7 @@ def generate_build_script_for_recipe( if script_name in script_templates: template_in = resources.files("vinca") / script_templates[script_name] - with open(output_path, "w") as output_file: + with open(output_path, "w", encoding="utf-8") as output_file: extra_globals = {} extra_globals["ros_package_prefix"] = ros_package_prefix if additional_cmake_args: @@ -313,7 +315,7 @@ def generate_activation_scripts_for_recipe(recipe_dir): for script_name, template_path in activation_templates.items(): template_in = resources.files("vinca") / template_path output_path = recipe_dir / script_name - with open(output_path, "w") as output_file: + with open(output_path, "w", encoding="utf-8") as output_file: generate_template( template_in, output_file ) # No extra globals needed for activation scripts diff --git a/vinca/utils.py b/vinca/utils.py index bae6f3d..740b5ac 100644 --- a/vinca/utils.py +++ b/vinca/utils.py @@ -49,7 +49,7 @@ def get_repodata(url_or_path, platform=None): if not os.path.exists(url_or_path): print(f"No repodata found at {url_or_path}, assuming no existing packages") return {"packages": {}, "packages.conda": {}} - with open(url_or_path) as fi: + with open(url_or_path, encoding="utf-8") as fi: return json.load(fi) print("Downloading repodata from ", url_or_path) @@ -63,7 +63,7 @@ def get_repodata(url_or_path, platform=None): max_age = 100_000 # seconds == 27 hours if age < max_age: try: - with open(fn) as fi: + with open(fn, encoding="utf-8") as fi: return json.load(fi) except json.JSONDecodeError: print(f"Ignoring invalid cached repodata at {fn}") @@ -86,7 +86,7 @@ def get_repodata(url_or_path, platform=None): ) return {"packages": {}, "packages.conda": {}} - with open(fn, "w") as fcache: + with open(fn, "w", encoding="utf-8") as fcache: fcache.write(content.decode("utf-8")) return parsed_repodata