Skip to content

Commit

Permalink
Merge pull request iterative#3034 from mroutis/remove-py2-comments
Browse files Browse the repository at this point in the history
py3: remove code related to py2 limitations
  • Loading branch information
efiop authored Jan 8, 2020
2 parents 82cdce0 + 71b15d2 commit 049367e
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 57 deletions.
5 changes: 0 additions & 5 deletions dvc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from dvc.exceptions import NotDvcRepoError
from dvc.external_repo import clean_repos
from dvc.logger import FOOTER
from dvc.remote.pool import close_pools


# Workaround for CPython bug. See [1] and [2] for more info.
Expand Down Expand Up @@ -69,10 +68,6 @@ def main(argv=None):
finally:
logger.setLevel(outerLogLevel)

# Python 2 fails to close these clean occasionally and users see
# weird error messages, so we do it manually
close_pools()

# Remove cached repos in the end of the call, these are anonymous
# so won't be reused by any other subsequent run anyway.
clean_repos()
Expand Down
5 changes: 2 additions & 3 deletions dvc/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from dvc.ignore import CleanTree
from dvc.compat import fspath_py35

from funcy import cached_property
from funcy import cached_property, cat

from dvc.config import Config
from dvc.exceptions import (
Expand Down Expand Up @@ -238,7 +238,6 @@ def used_cache(
A dictionary with Schemes (representing output's location) as keys,
and a list with the outputs' `dumpd` as values.
"""
from funcy.py2 import icat
from dvc.cache import NamedCache

cache = NamedCache()
Expand All @@ -250,7 +249,7 @@ def used_cache(
):
targets = targets or [None]

pairs = icat(
pairs = cat(
self.collect_granular(
target, recursive=recursive, with_deps=with_deps
)
Expand Down
5 changes: 1 addition & 4 deletions dvc/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,7 @@ def is_data_source(self):
@staticmethod
def is_valid_filename(path):
return (
# path.endswith doesn't work for encoded unicode filenames on
# Python 2 and since Stage.STAGE_FILE_SUFFIX is ascii then it is
# not needed to decode the path from py2's str
path[-len(Stage.STAGE_FILE_SUFFIX) :] == Stage.STAGE_FILE_SUFFIX
path.endswith(Stage.STAGE_FILE_SUFFIX)
or os.path.basename(path) == Stage.STAGE_FILE
)

Expand Down
7 changes: 1 addition & 6 deletions tests/func/test_ignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ def test_ignore(tmp_dir, dvc, monkeypatch):


def test_ignore_unicode(tmp_dir, dvc):
tmp_dir.gen({"dir": {"other": "text"}})
# Path() doesn't handle unicode paths in Windows/Python 2
# I don't know to debug it further, waiting till Python 2 EOL
with open("dir/тест", "wb") as fd:
fd.write("проверка".encode("utf-8"))

tmp_dir.gen({"dir": {"other": "text", "тест": "проверка"}})
tmp_dir.gen(DvcIgnore.DVCIGNORE_FILE, "dir/тест")

assert _files_set("dir", dvc.tree) == {"dir/other"}
Expand Down
12 changes: 1 addition & 11 deletions tests/func/test_output.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import os
import sys

import pytest

from dvc.output import _get
Expand All @@ -12,14 +9,7 @@
("s3://bucket/path", "s3"),
("gs://bucket/path", "gs"),
("ssh://example.com:/dir/path", "ssh"),
pytest.param(
"hdfs://example.com/dir/path",
"hdfs",
marks=pytest.mark.skipif(
sys.version_info[0] == 2 and os.name == "nt",
reason="Not supported for python 2 on Windows.",
),
),
("hdfs://example.com/dir/path", "hdfs"),
("path/to/file", "local"),
("path\\to\\file", "local"),
("file", "local"),
Expand Down
19 changes: 9 additions & 10 deletions tests/remotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,9 @@ def get_gcp_url():
return "gs://" + get_gcp_storagepath()


# NOTE: staticmethod is only needed in Python 2
class Local:
should_test = staticmethod(lambda: True)
get_url = staticmethod(get_local_url)
should_test = lambda: True # noqa: E731
get_url = get_local_url


class S3:
Expand All @@ -183,7 +182,7 @@ def get_url():


class S3Mocked(S3):
should_test = staticmethod(lambda: True)
should_test = lambda: True # noqa: E731

@classmethod
@contextmanager
Expand All @@ -203,8 +202,8 @@ def put_objects(remote, objects):


class GCP:
should_test = staticmethod(_should_test_gcp)
get_url = staticmethod(get_gcp_url)
should_test = _should_test_gcp
get_url = get_gcp_url

@classmethod
@contextmanager
Expand Down Expand Up @@ -270,10 +269,10 @@ def get_url():


class SSH:
should_test = staticmethod(_should_test_ssh)
get_url = staticmethod(get_ssh_url)
should_test = _should_test_ssh
get_url = get_ssh_url


class HDFS:
should_test = staticmethod(_should_test_hdfs)
get_url = staticmethod(get_hdfs_url)
should_test = _should_test_hdfs
get_url = get_hdfs_url
9 changes: 0 additions & 9 deletions tests/unit/dependency/test_hdfs.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import os
import sys

import pytest

from dvc.dependency.hdfs import DependencyHDFS
from tests.unit.dependency.test_local import TestDependencyLOCAL


@pytest.mark.skipif(
sys.version_info[0] == 2 and os.name == "nt",
reason="Not supported for python 2 on Windows.",
)
class TestDependencyHDFS(TestDependencyLOCAL):
def _get_cls(self):
return DependencyHDFS
9 changes: 0 additions & 9 deletions tests/unit/output/test_hdfs.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import os
import sys

import pytest

from dvc.output.hdfs import OutputHDFS
from tests.unit.output.test_local import TestOutputLOCAL


@pytest.mark.skipif(
sys.version_info[0] == 2 and os.name == "nt",
reason="Not supported for python 2 on Windows.",
)
class TestOutputHDFS(TestOutputLOCAL):
def _get_cls(self):
return OutputHDFS

0 comments on commit 049367e

Please sign in to comment.