Skip to content

Commit

Permalink
params: support unicode characters (#5363)
Browse files Browse the repository at this point in the history
* params: support unicode characters

* open remove() calls with utf-8
  • Loading branch information
isidentical authored Feb 1, 2021
1 parent 13db267 commit c84833b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions dvc/dvcfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def _load(self):
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
Expand Down Expand Up @@ -276,7 +276,7 @@ def remove_stage(self, stage):
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)
Expand Down Expand Up @@ -380,7 +380,7 @@ def remove_stage(self, stage):
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)

Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit c84833b

Please sign in to comment.