From c84833bab1d81dfdf9d89157b2ce41ae085f3781 Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Mon, 1 Feb 2021 16:56:53 +0300 Subject: [PATCH] params: support unicode characters (#5363) * params: support unicode characters * open remove() calls with utf-8 --- dvc/dvcfile.py | 6 +++--- tests/unit/test_params.py | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/dvc/dvcfile.py b/dvc/dvcfile.py index 5092668ab..459f82510 100644 --- a/dvc/dvcfile.py +++ b/dvc/dvcfile.py @@ -131,7 +131,7 @@ class FileMixin: raise StageFileIsNotDvcFileError(self.path) if self._is_git_ignored(): raise FileIsGitIgnored(self.path) - with self.repo.tree.open(self.path) as fd: + with self.repo.tree.open(self.path, encoding="utf-8") as fd: stage_text = fd.read() d = parse_yaml(stage_text, self.path) return self.validate(d, self.relpath), stage_text @@ -276,7 +276,7 @@ class PipelineFile(FileMixin): if not self.exists(): return - with open(self.path, "r") as f: + with open(self.path, "r", encoding="utf-8") as f: d = parse_yaml_for_update(f.read(), self.path) self.validate(d, self.path) @@ -380,7 +380,7 @@ class Lockfile(FileMixin): if not self.exists(): return - with open(self.path) as f: + with open(self.path, encoding="utf-8") as f: d = parse_yaml_for_update(f.read(), self.path) self.validate(d, self.path) diff --git a/tests/unit/test_params.py b/tests/unit/test_params.py index c7ba4fb59..9b777caf1 100644 --- a/tests/unit/test_params.py +++ b/tests/unit/test_params.py @@ -20,3 +20,15 @@ def test_params_order(tmp_dir, dvc, dummy_stage): # params are sorted during dumping, therefore p1 is first assert list(dvc.params.show()[""]) == ["p1.yaml", p2_path, "params.yaml"] + + +def test_repro_unicode(tmp_dir, dvc, dummy_stage): + tmp_dir.gen({"settings.json": '{"Ω_value": 1}'}) + dummy_stage(params=[{"settings.json": ["Ω_value"]}]) + (stage,) = dvc.reproduce(dry=True) + stage.cmd = "foo" + stage.dvcfile._lockfile.dump(stage) + + dvc.remove(stage.name) + assert not (tmp_dir / "dvc.yaml").exists() + assert not (tmp_dir / "dvc.lock").exists()