Skip to content

Commit

Permalink
Merge pull request #2786 from Suor/convert-to-unicode
Browse files Browse the repository at this point in the history
perf: a small stage validation optimization
  • Loading branch information
efiop authored Nov 16, 2019
2 parents 6147b93 + 3943b0e commit 276621b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dvc/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def update(self):

@staticmethod
def validate(d, fname=None):
from dvc.utils import convert_to_unicode
from dvc.utils.compat import convert_to_unicode

try:
Schema(Stage.SCHEMA).validate(convert_to_unicode(d))
Expand Down
10 changes: 0 additions & 10 deletions dvc/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,6 @@ def fix_env(env=None):
return env


def convert_to_unicode(data):
if isinstance(data, builtin_str):
return str(data)
if isinstance(data, dict):
return dict(map(convert_to_unicode, data.items()))
if isinstance(data, (list, tuple)):
return type(data)(map(convert_to_unicode, data))
return data


def tmp_fname(fname):
""" Temporary name for a partial download """
return fspath(fname) + "." + str(uuid()) + ".tmp"
Expand Down
12 changes: 12 additions & 0 deletions dvc/utils/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ def __enter__(self):
def __exit__(self, *args):
self.close()

def convert_to_unicode(data):
if isinstance(data, builtin_str):
return str(data)
if isinstance(data, dict):
return dict(map(convert_to_unicode, data.items()))
if isinstance(data, (list, tuple)):
return type(data)(map(convert_to_unicode, data))
return data


elif is_py3:
import pathlib # noqa: F401
Expand Down Expand Up @@ -170,6 +179,9 @@ def __exit__(self, *args):
range = range # noqa: F821
FileNotFoundError = FileNotFoundError

def convert_to_unicode(data):
return data


# Backport os.fspath() from Python 3.6
try:
Expand Down

0 comments on commit 276621b

Please sign in to comment.