py3: remove compat csv_reader

This commit is contained in:
Mr. Outis
2019-12-31 22:17:02 -06:00
parent 1ef466b849
commit 999130b029
2 changed files with 1 additions and 33 deletions
+1 -2
View File
@@ -10,7 +10,6 @@ from jsonpath_ng.ext import parse
from dvc.exceptions import NoMetricsError
from dvc.exceptions import OutputNotFoundError
from dvc.repo import locked
from dvc.utils.compat import csv_reader
from dvc.utils.compat import open
NO_METRICS_FILE_AT_REFERENCE_WARNING = (
@@ -101,7 +100,7 @@ def _format_csv(content, delimiter):
"0.67528 0.289545 testing\n"
"0.671502 0.297848 validation\n"
"""
reader = csv_reader(io.StringIO(content), delimiter=delimiter)
reader = csv.reader(io.StringIO(content), delimiter=delimiter)
rows = [row for row in reader]
max_widths = [max(map(len, column)) for column in zip(*rows)]
-31
View File
@@ -15,37 +15,6 @@ is_py2 = _ver[0] == 2
is_py3 = _ver[0] == 3
def csv_reader(unicode_csv_data, dialect=None, **kwargs):
"""csv.reader doesn't support Unicode input, so need to use some tricks
to work around this.
Source: https://docs.python.org/2/library/csv.html#csv-examples
"""
import csv
dialect = dialect or csv.excel
if is_py3:
# Python3 supports encoding by default, so just return the object
for row in csv.reader(unicode_csv_data, dialect=dialect, **kwargs):
yield [cell for cell in row]
else:
# csv.py doesn't do Unicode; encode temporarily as UTF-8:
reader = csv.reader(
utf_8_encoder(unicode_csv_data), dialect=dialect, **kwargs
)
for row in reader:
# decode UTF-8 back to Unicode, cell by cell:
yield [unicode(cell, "utf-8") for cell in row] # noqa: F821
def utf_8_encoder(unicode_csv_data):
"""Source: https://docs.python.org/2/library/csv.html#csv-examples"""
for line in unicode_csv_data:
yield line.encode("utf-8")
def _makedirs(name, mode=0o777, exist_ok=False):
"""Source: https://github.com/python/cpython/blob/
3ce3dea60646d8a5a1c952469a2eb65f937875b3/Lib/os.py#L196-L226