mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
Merge pull request #2786 from Suor/convert-to-unicode
perf: a small stage validation optimization
This commit is contained in:
+1
-1
@@ -359,7 +359,7 @@ class Stage(object):
|
||||
|
||||
@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))
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -143,6 +143,15 @@ if is_py2:
|
||||
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
|
||||
@@ -170,6 +179,9 @@ elif is_py3:
|
||||
range = range # noqa: F821
|
||||
FileNotFoundError = FileNotFoundError
|
||||
|
||||
def convert_to_unicode(data):
|
||||
return data
|
||||
|
||||
|
||||
# Backport os.fspath() from Python 3.6
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user