Skip to content

Commit

Permalink
Drop Python 3.5 support (#3792)
Browse files Browse the repository at this point in the history
* drop python 3.5 support

* dvc: remove fspath() use inside os.path calls

* dvc: replace dvc.compat.fspath with os.fspath

* tests: replace dvc.compat.fspath with os.fspath

* utils: relpath() should use fspath/str

* utils: os.readlink doesn't support path-like obj on Windows until 3.8
  • Loading branch information
pmrowla authored May 13, 2020
1 parent 3916d4f commit 833e82a
Show file tree
Hide file tree
Showing 45 changed files with 268 additions and 358 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ jobs:
env:
- PYTHON_VERSION=3.8.0
- PATH=/c/Python38:/c/Python38/Scripts:$PATH
- name: "3.5 on Linux"
language: python
python: 3.5
- name: "3.6 on Linux"
language: python
python: 3.6
Expand Down
42 changes: 0 additions & 42 deletions dvc/compat.py

This file was deleted.

3 changes: 1 addition & 2 deletions dvc/dependency/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import yaml
from voluptuous import Any

from dvc.compat import fspath_py35
from dvc.dependency.local import LocalDependency
from dvc.exceptions import DvcException

Expand Down Expand Up @@ -87,7 +86,7 @@ def read_params(self):
if not self.exists:
return {}

with self.repo.tree.open(fspath_py35(self.path_info), "r") as fobj:
with self.repo.tree.open(self.path_info, "r") as fobj:
try:
config = yaml.safe_load(fobj)
except yaml.YAMLError as exc:
Expand Down
7 changes: 3 additions & 4 deletions dvc/external_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from funcy import cached_property, retry, suppress, wrap_with

from dvc.compat import fspath
from dvc.config import NoRemoteError, NotDvcRepoError
from dvc.exceptions import (
CheckoutError,
Expand Down Expand Up @@ -84,7 +83,7 @@ def pull_to(self, path, to_info):
path_info = PathInfo(self.root_dir) / path

with suppress(OutputNotFoundError):
(out,) = self.find_outs_by_path(fspath(path_info), strict=False)
(out,) = self.find_outs_by_path(path_info, strict=False)

try:
if out and out.use_cache:
Expand All @@ -95,7 +94,7 @@ def pull_to(self, path, to_info):
if os.path.isabs(path):
raise FileNotFoundError

fs_copy(fspath(path_info), fspath(to_info))
fs_copy(path_info, to_info)
except FileNotFoundError:
raise PathMissingError(path, self.url)

Expand Down Expand Up @@ -188,7 +187,7 @@ def pull_to(self, path, to_info):
if os.path.isabs(path):
raise FileNotFoundError

fs_copy(os.path.join(self.root_dir, path), fspath(to_info))
fs_copy(os.path.join(self.root_dir, path), to_info)
except FileNotFoundError:
raise PathMissingError(path, self.url)

Expand Down
5 changes: 2 additions & 3 deletions dvc/output/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
from urllib.parse import urlparse

from dvc.compat import fspath_py35
from dvc.exceptions import DvcException
from dvc.istextfile import istextfile
from dvc.output.base import BaseOutput
Expand Down Expand Up @@ -38,7 +37,7 @@ def _parse_path(self, remote, path):
if not p.is_absolute():
p = self.stage.wdir / p

abs_p = os.path.abspath(os.path.normpath(fspath_py35(p)))
abs_p = os.path.abspath(os.path.normpath(p))
return self.REMOTE.path_cls(abs_p)

def __str__(self):
Expand Down Expand Up @@ -75,7 +74,7 @@ def verify_metric(self):
if not self.metric:
return

path = fspath_py35(self.path_info)
path = os.fspath(self.path_info)
if not os.path.exists(path):
return

Expand Down
1 change: 0 additions & 1 deletion dvc/path_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def __repr__(self):
return "{}: '{}'".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
def __fspath__(self):
return pathlib.PurePath.__str__(self)

Expand Down
25 changes: 12 additions & 13 deletions dvc/remote/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from funcy import cached_property, concat
from shortuuid import uuid

from dvc.compat import fspath_py35
from dvc.exceptions import DownloadError, DvcException, UploadError
from dvc.path_info import PathInfo
from dvc.progress import Tqdm
Expand Down Expand Up @@ -95,7 +94,7 @@ def get(self, md5):
def exists(self, path_info):
assert is_working_tree(self.repo.tree)
assert isinstance(path_info, str) or path_info.scheme == "local"
return self.repo.tree.exists(fspath_py35(path_info))
return self.repo.tree.exists(path_info)

def makedirs(self, path_info):
makedirs(path_info, exist_ok=True, mode=self._dir_mode)
Expand Down Expand Up @@ -129,11 +128,11 @@ def is_empty(self, path_info):

@staticmethod
def isfile(path_info):
return os.path.isfile(fspath_py35(path_info))
return os.path.isfile(path_info)

@staticmethod
def isdir(path_info):
return os.path.isdir(fspath_py35(path_info))
return os.path.isdir(path_info)

def iscopy(self, path_info):
return not (
Expand All @@ -142,7 +141,7 @@ def iscopy(self, path_info):

@staticmethod
def getsize(path_info):
return os.path.getsize(fspath_py35(path_info))
return os.path.getsize(path_info)

def walk_files(self, path_info):
assert is_working_tree(self.repo.tree)
Expand Down Expand Up @@ -182,8 +181,8 @@ def copy(self, from_info, to_info):
tmp_info = to_info.parent / tmp_fname(to_info.name)
try:
System.copy(from_info, tmp_info)
os.chmod(fspath_py35(tmp_info), self._file_mode)
os.rename(fspath_py35(tmp_info), fspath_py35(to_info))
os.chmod(tmp_info, self._file_mode)
os.rename(tmp_info, to_info)
except Exception:
self.remove(tmp_info)
raise
Expand Down Expand Up @@ -231,8 +230,8 @@ def reflink(self, from_info, to_info):
System.reflink(from_info, tmp_info)
# NOTE: reflink has its own separate inode, so you can set permissions
# that are different from the source.
os.chmod(fspath_py35(tmp_info), self._file_mode)
os.rename(fspath_py35(tmp_info), fspath_py35(to_info))
os.chmod(tmp_info, self._file_mode)
os.rename(tmp_info, to_info)

def cache_exists(self, checksums, jobs=None, name=None):
return [
Expand All @@ -255,7 +254,7 @@ def _upload(
copyfile(
from_file, tmp_file, name=name, no_progress_bar=no_progress_bar
)
os.rename(tmp_file, fspath_py35(to_info))
os.rename(tmp_file, to_info)

def _download(
self, from_info, to_file, name=None, no_progress_bar=False, **_kwargs
Expand All @@ -266,7 +265,7 @@ def _download(

@staticmethod
def open(path_info, mode="r", encoding=None):
return open(fspath_py35(path_info), mode=mode, encoding=encoding)
return open(path_info, mode=mode, encoding=encoding)

@index_locked
def status(
Expand Down Expand Up @@ -635,7 +634,7 @@ def unprotect(self, path_info):
self._unprotect_file(path)

def protect(self, path_info):
path = fspath_py35(path_info)
path = os.fspath(path_info)
mode = self.CACHE_MODE

try:
Expand Down Expand Up @@ -718,6 +717,6 @@ def is_protected(self, path_info):
if not self.exists(path_info):
return False

mode = os.stat(fspath_py35(path_info)).st_mode
mode = os.stat(path_info).st_mode

return stat.S_IMODE(mode) == self.CACHE_MODE
2 changes: 0 additions & 2 deletions dvc/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from funcy import cached_property, cat, first

from dvc.compat import fspath_py35
from dvc.config import Config
from dvc.exceptions import (
FileMissingError,
Expand Down Expand Up @@ -515,7 +514,6 @@ def _open_cached(self, out, remote=None, mode="r", encoding=None):
raise IsADirectoryError("Can't open a dir")

cache_file = self.cache.local.checksum_to_path_info(out.checksum)
cache_file = fspath_py35(cache_file)

if os.path.exists(cache_file):
return open(cache_file, mode=mode, encoding=encoding)
Expand Down
3 changes: 1 addition & 2 deletions dvc/repo/checkout.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import os

from dvc.compat import fspath
from dvc.exceptions import CheckoutError, CheckoutErrorSuggestGit
from dvc.progress import Tqdm
from dvc.utils import relpath
Expand All @@ -23,7 +22,7 @@ def _fspath_dir(path, root):
if not os.path.exists(str(path)):
return str(path)

path = relpath(fspath(path), root)
path = relpath(path, root)
return os.path.join(path, "") if os.path.isdir(path) else path


Expand Down
5 changes: 2 additions & 3 deletions dvc/repo/metrics/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import yaml

from dvc.compat import fspath_py35
from dvc.exceptions import NoMetricsError
from dvc.path_info import PathInfo
from dvc.repo import locked
Expand Down Expand Up @@ -58,10 +57,10 @@ def _read_metrics(repo, metrics, rev):

res = {}
for metric in metrics:
if not tree.exists(fspath_py35(metric)):
if not tree.exists(metric):
continue

with tree.open(fspath_py35(metric), "r") as fobj:
with tree.open(metric, "r") as fobj:
try:
# NOTE this also supports JSON
val = yaml.safe_load(fobj)
Expand Down
5 changes: 2 additions & 3 deletions dvc/repo/params/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import yaml

from dvc.compat import fspath_py35
from dvc.dependency.param import ParamsDependency
from dvc.exceptions import DvcException
from dvc.path_info import PathInfo
Expand Down Expand Up @@ -30,10 +29,10 @@ def _collect_configs(repo):
def _read_params(repo, configs, rev):
res = {}
for config in configs:
if not repo.tree.exists(fspath_py35(config)):
if not repo.tree.exists(config):
continue

with repo.tree.open(fspath_py35(config), "r") as fobj:
with repo.tree.open(config, "r") as fobj:
try:
res[str(config)] = yaml.safe_load(fobj)
except yaml.YAMLError:
Expand Down
4 changes: 0 additions & 4 deletions dvc/scm/tree.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import os
import stat

from dvc.compat import fspath


class BaseTree(object):
"""Abstract class to represent access to files"""
Expand Down Expand Up @@ -66,8 +64,6 @@ def walk(self, top, topdown=True):
- it could raise exceptions, there is no onerror argument
"""

top = fspath(top)

def onerror(e):
raise e

Expand Down
7 changes: 3 additions & 4 deletions dvc/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import sqlite3
from urllib.parse import urlencode, urlunparse

from dvc.compat import fspath_py35
from dvc.exceptions import DvcException
from dvc.utils import current_timestamp, relpath, to_chunks
from dvc.utils.fs import get_inode, get_mtime_and_size, remove
Expand Down Expand Up @@ -363,7 +362,7 @@ def save(self, path_info, checksum):
"""
assert isinstance(path_info, str) or path_info.scheme == "local"
assert checksum is not None
assert os.path.exists(fspath_py35(path_info))
assert os.path.exists(path_info)

actual_mtime, actual_size = get_mtime_and_size(
path_info, self.repo.tree
Expand Down Expand Up @@ -393,7 +392,7 @@ def get(self, path_info):
doesn't exist in the state database.
"""
assert isinstance(path_info, str) or path_info.scheme == "local"
path = fspath_py35(path_info)
path = os.fspath(path_info)

if not os.path.exists(path):
return None
Expand Down Expand Up @@ -421,7 +420,7 @@ def save_link(self, path_info):
"""
assert isinstance(path_info, str) or path_info.scheme == "local"

if not os.path.exists(fspath_py35(path_info)):
if not os.path.exists(path_info):
return

mtime, _ = get_mtime_and_size(path_info, self.repo.tree)
Expand Down
Loading

0 comments on commit 833e82a

Please sign in to comment.