Skip to content

Commit

Permalink
Merge pull request #3024 from mroutis/unicode-str
Browse files Browse the repository at this point in the history
py3: remove string compat related code
  • Loading branch information
efiop authored Dec 31, 2019
2 parents dd5e058 + 6d36b85 commit 32ee197
Show file tree
Hide file tree
Showing 32 changed files with 52 additions and 89 deletions.
2 changes: 1 addition & 1 deletion dvc/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from dvc.repo import Repo
from dvc.scm import SCM
from dvc.utils import env2bool, is_binary, makedirs
from dvc.utils.compat import str, FileNotFoundError
from dvc.utils.compat import FileNotFoundError


logger = logging.getLogger(__name__)
Expand Down
4 changes: 1 addition & 3 deletions dvc/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
except ImportError:
from contextlib import GeneratorContextManager as GCM

from dvc.utils.compat import urlparse, builtin_str
from dvc.utils.compat import urlparse

import ruamel.yaml
from voluptuous import Schema, Required, Invalid
Expand Down Expand Up @@ -188,8 +188,6 @@ def _import_string(import_name):
:return: imported object
"""
import_name = builtin_str(import_name)

if "." in import_name:
module, obj = import_name.rsplit(".", 1)
else:
Expand Down
3 changes: 1 addition & 2 deletions dvc/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from funcy import cached_property

from dvc.config import Config
from dvc.utils.compat import builtin_str


class CacheConfig(object):
Expand Down Expand Up @@ -54,7 +53,7 @@ def getter(self):

return Remote(self.repo, name=remote)

getter.__name__ = builtin_str(name)
getter.__name__ = str(name)
return cached_property(getter)


Expand Down
5 changes: 2 additions & 3 deletions dvc/command/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import argparse
import logging
from dvc.utils.compat import str

from dvc.command.base import CmdBase, append_doc_link, fix_subparsers
from dvc.exceptions import DvcException
Expand Down Expand Up @@ -102,7 +101,7 @@ def _show_dependencies_tree(self, target, commands, outs):
tree.show()

def __write_dot(self, target, commands, outs):
from dvc.utils.compat import StringIO
import io
import networkx
from networkx.drawing.nx_pydot import write_dot

Expand All @@ -112,7 +111,7 @@ def __write_dot(self, target, commands, outs):
simple_g = networkx.DiGraph()
simple_g.add_edges_from(edges)

dot_file = StringIO()
dot_file = io.StringIO()
write_dot(simple_g, dot_file)
logger.info(dot_file.getvalue())

Expand Down
1 change: 0 additions & 1 deletion dvc/command/status.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging

from dvc.command.data_sync import CmdDataBase
from dvc.utils.compat import str


logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion dvc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from dvc.exceptions import DvcException
from dvc.exceptions import NotDvcRepoError
from dvc.utils.compat import open, str
from dvc.utils.compat import open

logger = logging.getLogger(__name__)

Expand Down
1 change: 0 additions & 1 deletion dvc/dependency/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from .local import DependencyLOCAL
from dvc.external_repo import external_repo
from dvc.utils.compat import str
from dvc.exceptions import OutputNotFoundError
from dvc.exceptions import PathMissingError
from dvc.utils.fs import fs_copy
Expand Down
10 changes: 4 additions & 6 deletions dvc/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import traceback

from dvc.utils import relpath
from dvc.utils.compat import builtin_str
from dvc.utils.compat import str


class DvcException(Exception):
Expand Down Expand Up @@ -38,7 +36,7 @@ class OutputDuplicationError(DvcException):
"""

def __init__(self, output, stages):
assert isinstance(output, (str, builtin_str))
assert isinstance(output, str)
assert all(hasattr(stage, "relpath") for stage in stages)
msg = (
"file/directory '{}' is specified as an output in more than one "
Expand Down Expand Up @@ -75,7 +73,7 @@ class StagePathAsOutputError(DvcException):
"""

def __init__(self, stage, output):
assert isinstance(output, (str, builtin_str))
assert isinstance(output, str)
super(StagePathAsOutputError, self).__init__(
"'{stage}' is within an output '{output}' of another stage".format(
stage=stage.relpath, output=output
Expand All @@ -92,7 +90,7 @@ class CircularDependencyError(DvcException):
"""

def __init__(self, dependency):
assert isinstance(dependency, (str, builtin_str))
assert isinstance(dependency, str)

msg = (
"file/directory '{}' is specified as an output and as a "
Expand All @@ -110,7 +108,7 @@ class ArgumentDuplicationError(DvcException):
"""

def __init__(self, path):
assert isinstance(path, (str, builtin_str))
assert isinstance(path, str)
msg = "file '{}' is specified more than once."
super(ArgumentDuplicationError, self).__init__(msg.format(path))

Expand Down
5 changes: 2 additions & 3 deletions dvc/logger.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"""Manages logging configuration for dvc repo."""

import io
import logging.config
import logging.handlers

import colorama

from dvc.progress import Tqdm
from dvc.utils.compat import RecursionError
from dvc.utils.compat import str
from dvc.utils.compat import StringIO


FOOTER = (
Expand Down Expand Up @@ -105,7 +104,7 @@ def _description(self, message, exception):
def _walk_exc(self, exc_info):
import traceback

buffer = StringIO()
buffer = io.StringIO()

traceback.print_exception(*exc_info, file=buffer)

Expand Down
1 change: 0 additions & 1 deletion dvc/output/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from dvc.remote.local import RemoteLOCAL
from dvc.remote.s3 import RemoteS3
from dvc.scheme import Schemes
from dvc.utils.compat import str
from dvc.utils.compat import urlparse

OUTS = [
Expand Down
1 change: 0 additions & 1 deletion dvc/output/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from dvc.exceptions import CollectCacheError
from dvc.exceptions import DvcException
from dvc.remote.base import RemoteBASE
from dvc.utils.compat import str
from dvc.utils.compat import urlparse


Expand Down
1 change: 0 additions & 1 deletion dvc/output/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from dvc.remote.local import RemoteLOCAL
from dvc.utils import relpath
from dvc.utils.compat import fspath_py35
from dvc.utils.compat import str
from dvc.utils.compat import urlparse
from dvc.utils.fs import path_isin

Expand Down
19 changes: 8 additions & 11 deletions dvc/path_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
from funcy import cached_property

from dvc.utils import relpath
from dvc.utils.compat import basestring
from dvc.utils.compat import builtin_str
from dvc.utils.compat import pathlib
from dvc.utils.compat import str
from dvc.utils.compat import urlparse


class _BasePath(object):
def overlaps(self, other):
if isinstance(other, basestring):
if isinstance(other, (str, bytes)):
other = self.__class__(other)
elif self.__class__ != other.__class__:
return False
Expand Down Expand Up @@ -54,7 +51,7 @@ def __str__(self):
return relpath(path)

def __repr__(self):
return builtin_str("{}: '{}'").format(type(self).__name__, self)
return str("{}: '{}'").format(type(self).__name__, self)

# This permits passing it to file utils directly in Python 3.6+
# With Python 2.7, Python 3.5+ we are stuck with path_info.fspath for now
Expand All @@ -71,7 +68,7 @@ def relpath(self, other):
return self.__class__(relpath(self, other))

def isin(self, other):
if isinstance(other, basestring):
if isinstance(other, (str, bytes)):
other = self.__class__(other)
elif self.__class__ != other.__class__:
return False
Expand Down Expand Up @@ -135,13 +132,13 @@ def from_parts(

def fill_parts(self, scheme, host, user, port, path):
assert scheme != "remote"
assert isinstance(path, (basestring, _URLPathInfo))
assert isinstance(path, (str, bytes, _URLPathInfo))

self.scheme, self.host, self.user = scheme, host, user
self.port = int(port) if port else self.DEFAULT_PORTS.get(self.scheme)

if isinstance(path, _URLPathInfo):
self._spath = builtin_str(path)
self._spath = str(path)
self._path = path
else:
if path and path[0] != "/":
Expand Down Expand Up @@ -170,7 +167,7 @@ def __repr__(self):
return "{}: '{}'".format(type(self).__name__, self)

def __eq__(self, other):
if isinstance(other, basestring):
if isinstance(other, (str, bytes)):
other = self.__class__(other)
return (
self.__class__ == other.__class__
Expand Down Expand Up @@ -220,7 +217,7 @@ def parents(self):
return _URLPathParents(self)

def relative_to(self, other):
if isinstance(other, basestring):
if isinstance(other, (str, bytes)):
other = self.__class__(other)
if self.__class__ != other.__class__:
msg = "'{}' has incompatible class with '{}'".format(self, other)
Expand All @@ -231,7 +228,7 @@ def relative_to(self, other):
return self._path.relative_to(other._path)

def isin(self, other):
if isinstance(other, basestring):
if isinstance(other, (str, bytes)):
other = self.__class__(other)
elif self.__class__ != other.__class__:
return False
Expand Down
4 changes: 2 additions & 2 deletions dvc/remote/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import errno

from dvc.utils.compat import basestring, FileNotFoundError, str, urlparse
from dvc.utils.compat import FileNotFoundError, urlparse

import itertools
import json
Expand Down Expand Up @@ -153,7 +153,7 @@ def __repr__(self):

@classmethod
def supported(cls, config):
if isinstance(config, basestring):
if isinstance(config, (str, bytes)):
url = config
else:
url = config[Config.SECTION_REMOTE_URL]
Expand Down
3 changes: 1 addition & 2 deletions dvc/remote/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from dvc.utils import walk_files
from dvc.utils.compat import fspath_py35
from dvc.utils.compat import open
from dvc.utils.compat import str
from dvc.utils.fs import move
from dvc.utils.fs import remove

Expand Down Expand Up @@ -411,7 +410,7 @@ def _log_missing_caches(checksum_info_dict):
def _unprotect_file(path):
if System.is_symlink(path) or System.is_hardlink(path):
logger.debug("Unprotecting '{}'".format(path))
tmp = os.path.join(os.path.dirname(path), "." + str(uuid()))
tmp = os.path.join(os.path.dirname(path), "." + uuid())

# The operations order is important here - if some application
# would access the file during the process of copyfile then it
Expand Down
3 changes: 1 addition & 2 deletions dvc/remote/ssh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from dvc.remote.pool import get_connection
from dvc.scheme import Schemes
from dvc.utils import to_chunks
from dvc.utils.compat import StringIO
from dvc.utils.compat import urlparse

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -104,7 +103,7 @@ def _load_user_ssh_config(hostname):
ssh_config = paramiko.SSHConfig()
with open(user_config_file) as f:
# For whatever reason parsing directly from f is unreliable
f_copy = StringIO(f.read())
f_copy = io.StringIO(f.read())
ssh_config.parse(f_copy)
user_ssh_config = ssh_config.lookup(hostname)
return user_ssh_config
Expand Down
13 changes: 6 additions & 7 deletions dvc/repo/metrics/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
import json
import logging
import os
import io

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 builtin_str
from dvc.utils.compat import csv_reader
from dvc.utils.compat import open
from dvc.utils.compat import StringIO

NO_METRICS_FILE_AT_REFERENCE_WARNING = (
"Metrics file '{}' does not exist at the reference '{}'."
Expand Down Expand Up @@ -48,7 +47,7 @@ def _read_metric_hxsv(fd, hxsv_path, delimiter):
row = indices[0]
row = int(row) if row else None
col = indices[1] if len(indices) > 1 and indices[1] else None
reader = list(csv.DictReader(fd, delimiter=builtin_str(delimiter)))
reader = list(csv.DictReader(fd, delimiter=delimiter))
return _do_read_metric_xsv(reader, row, col)


Expand All @@ -57,7 +56,7 @@ def _read_metric_xsv(fd, xsv_path, delimiter):
row = indices[0]
row = int(row) if row else None
col = int(indices[1]) if len(indices) > 1 and indices[1] else None
reader = list(csv.reader(fd, delimiter=builtin_str(delimiter)))
reader = list(csv.reader(fd, delimiter=delimiter))
return _do_read_metric_xsv(reader, row, col)


Expand Down Expand Up @@ -102,7 +101,7 @@ def _format_csv(content, delimiter):
"0.67528 0.289545 testing\n"
"0.671502 0.297848 validation\n"
"""
reader = csv_reader(StringIO(content), delimiter=builtin_str(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)]

Expand All @@ -128,10 +127,10 @@ def _format_output(content, typ):
str: Content in a raw or tabular format.
"""

if "csv" in str(typ):
if "csv" in typ:
return _format_csv(content, delimiter=",")

if "tsv" in str(typ):
if "tsv" in typ:
return _format_csv(content, delimiter="\t")

return content
Expand Down
1 change: 0 additions & 1 deletion dvc/scm/git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from dvc.utils.fs import path_isin
from dvc.utils.compat import cast_bytes_py2
from dvc.utils.compat import open
from dvc.utils.compat import str


logger = logging.getLogger(__name__)
Expand Down
Loading

0 comments on commit 32ee197

Please sign in to comment.