Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dvc/dependency/http.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import unicode_literals

from dvc.path.http import HTTPPathInfo
from dvc.utils.compat import urlparse, urljoin
from dvc.output.base import OutputBase
from dvc.remote.http import RemoteHTTP
Expand All @@ -16,5 +17,4 @@ def __init__(self, stage, path, info=None, remote=None):
if path.startswith("remote"):
path = urljoin(self.remote.cache_dir, urlparse(path).path)

self.path_info["scheme"] = urlparse(path).scheme
self.path_info["path"] = path
self.path_info = HTTPPathInfo(url=self.url, path=path)
11 changes: 6 additions & 5 deletions dvc/output/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import schema

from dvc.path import Schemes
from dvc.utils.compat import urlparse, str

from dvc.output.base import OutputBase
Expand All @@ -25,11 +26,11 @@
]

OUTS_MAP = {
"hdfs": OutputHDFS,
"s3": OutputS3,
"gs": OutputGS,
"ssh": OutputSSH,
"local": OutputLOCAL,
Schemes.HDFS: OutputHDFS,
Schemes.S3: OutputS3,
Schemes.GS: OutputGS,
Schemes.SSH: OutputSSH,
Schemes.LOCAL: OutputLOCAL,
}

# NOTE: currently there are only 3 possible checksum names:
Expand Down
10 changes: 5 additions & 5 deletions dvc/output/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import re
import logging
from copy import copy

from schema import Or, Optional

from dvc.exceptions import DvcException
Expand Down Expand Up @@ -84,8 +86,6 @@ def __init__(
)
)

self.path_info = {"scheme": self.scheme, "url": self.url}

def __repr__(self):
return "{class_name}: '{url}'".format(
class_name=type(self).__name__, url=(self.url or "No url")
Expand Down Expand Up @@ -131,7 +131,7 @@ def scheme(self):

@property
def path(self):
return self.path_info["path"]
return self.path_info.path

@property
def cache_path(self):
Expand Down Expand Up @@ -241,7 +241,7 @@ def commit(self):
self.cache.save(self.path_info, self.info)

def dumpd(self):
ret = self.info.copy()
ret = copy(self.info)
ret[self.PARAM_PATH] = self.url

if self.IS_DEPENDENCY:
Expand Down Expand Up @@ -302,7 +302,7 @@ def move(self, out):

self.remote.move(self.path_info, out.path_info)
self.url = out.url
self.path_info = out.path_info.copy()
self.path_info = copy(out.path_info)
self.save()
self.commit()

Expand Down
4 changes: 2 additions & 2 deletions dvc/output/hdfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import posixpath

from dvc.path.hdfs import HDFSPathInfo
from dvc.utils.compat import urlparse
from dvc.output.base import OutputBase
from dvc.remote.hdfs import RemoteHDFS
Expand Down Expand Up @@ -34,5 +35,4 @@ def __init__(
if remote:
path = posixpath.join(remote.url, urlparse(path).path.lstrip("/"))
user = remote.user if remote else self.group("user")
self.path_info["user"] = user
self.path_info["path"] = path
self.path_info = HDFSPathInfo(user=user, url=self.url, path=path)
5 changes: 3 additions & 2 deletions dvc/output/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import logging

from dvc.path.local import LocalPathInfo
from dvc.utils.compat import urlparse
from dvc.istextfile import istextfile
from dvc.exceptions import DvcException
Expand Down Expand Up @@ -49,7 +50,7 @@ def __init__(
p = os.path.join(stage.wdir, p)
p = os.path.abspath(os.path.normpath(p))

self.path_info["path"] = p
self.path_info = LocalPathInfo(url=self.url, path=p)

def __str__(self):
return self.rel_path
Expand All @@ -64,7 +65,7 @@ def assign_to_stage_file(self, stage):
from dvc.repo import Repo

fullpath = os.path.abspath(stage.wdir)
self.path_info["path"] = os.path.join(fullpath, self.stage_path)
self.path_info.path = os.path.join(fullpath, self.stage_path)

self.repo = Repo(self.path)

Expand Down
6 changes: 4 additions & 2 deletions dvc/output/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import posixpath

from dvc.path.utils import PathInfo
from dvc.remote.s3 import RemoteS3
from dvc.utils.compat import urlparse
from dvc.output.base import OutputBase
Expand Down Expand Up @@ -36,5 +37,6 @@ def __init__(
if remote:
path = posixpath.join(remote.prefix, path)

self.path_info["bucket"] = bucket
self.path_info["path"] = path
self.path_info = PathInfo(
self.scheme, bucket=bucket, path=path, url=self.url
)
8 changes: 4 additions & 4 deletions dvc/output/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import getpass
import posixpath

from dvc.path.ssh import SSHPathInfo
from dvc.utils.compat import urlparse
from dvc.output.base import OutputBase
from dvc.remote.ssh import RemoteSSH
Expand Down Expand Up @@ -48,7 +49,6 @@ def __init__(
else:
path = parsed.path

self.path_info["host"] = host
self.path_info["port"] = port
self.path_info["user"] = user
self.path_info["path"] = path
self.path_info = SSHPathInfo(
host=host, user=user, port=port, url=self.url, path=path
)
34 changes: 34 additions & 0 deletions dvc/path/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from dvc.utils.compat import urlunsplit


class Schemes:
SSH = "ssh"
HDFS = "hdfs"
S3 = "s3"
AZURE = "azure"
HTTP = "http"
GS = "gs"
LOCAL = "local"
OSS = "oss"


class BasePathInfo(object):
scheme = None

def __init__(self, url=None, path=None):
self.url = url
self.path = path

def __str__(self):
return self.url


class DefaultCloudPathInfo(BasePathInfo):
def __init__(self, bucket, url=None, path=None):
super(DefaultCloudPathInfo, self).__init__(url, path)
self.bucket = bucket

def __str__(self):
if not self.url:
return urlunsplit((self.scheme, self.bucket, self.path, "", ""))
return self.url
5 changes: 5 additions & 0 deletions dvc/path/azure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from dvc.path import Schemes, DefaultCloudPathInfo


class AzurePathInfo(DefaultCloudPathInfo):
scheme = Schemes.AZURE
5 changes: 5 additions & 0 deletions dvc/path/gs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from dvc.path import Schemes, DefaultCloudPathInfo


class GSPathInfo(DefaultCloudPathInfo):
scheme = Schemes.GS
15 changes: 15 additions & 0 deletions dvc/path/hdfs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from dvc.utils.compat import urlunsplit
from dvc.path import BasePathInfo, Schemes


class HDFSPathInfo(BasePathInfo):
scheme = Schemes.HDFS

def __init__(self, user, url=None, path=None):
super(HDFSPathInfo, self).__init__(url, path)
self.user = user

def __str__(self):
if not self.url:
return urlunsplit((self.scheme, self.user, self.path, "", ""))
return self.url
16 changes: 16 additions & 0 deletions dvc/path/http.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from dvc.path import BasePathInfo, Schemes
from dvc.utils.compat import urlparse, urlunsplit


class HTTPPathInfo(BasePathInfo):
@property
def scheme(self):
if self.path:
return urlparse(self.path).scheme
else:
return Schemes.HTTP

def __str__(self):
if not self.url:
return urlunsplit((self.scheme, self.path, "", "", ""))
return self.url
10 changes: 10 additions & 0 deletions dvc/path/local.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os

from dvc.path import BasePathInfo, Schemes


class LocalPathInfo(BasePathInfo):
scheme = Schemes.LOCAL

def __str__(self):
return os.path.relpath(self.path)
5 changes: 5 additions & 0 deletions dvc/path/oss.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from dvc.path import Schemes, DefaultCloudPathInfo


class OSSPathInfo(DefaultCloudPathInfo):
scheme = Schemes.OSS
5 changes: 5 additions & 0 deletions dvc/path/s3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from dvc.path import Schemes, DefaultCloudPathInfo


class S3PathInfo(DefaultCloudPathInfo):
scheme = Schemes.S3
25 changes: 25 additions & 0 deletions dvc/path/ssh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from dvc.utils.compat import urlunsplit
from dvc.path import BasePathInfo, Schemes


class SSHPathInfo(BasePathInfo):
scheme = Schemes.SSH

def __init__(self, host, user, port, url=None, path=None):
super(SSHPathInfo, self).__init__(url, path)
self.host = host
self.user = user
self.port = port

def __str__(self):
if not self.url:
return urlunsplit(
(
self.scheme,
"{}@{}:{}".format(self.user, self.host, self.port),
self.path,
"",
"",
)
)
return self.url
25 changes: 25 additions & 0 deletions dvc/path/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from dvc.path import Schemes
from dvc.path.azure import AzurePathInfo
from dvc.path.gs import GSPathInfo
from dvc.path.hdfs import HDFSPathInfo
from dvc.path.http import HTTPPathInfo
from dvc.path.local import LocalPathInfo
from dvc.path.oss import OSSPathInfo
from dvc.path.s3 import S3PathInfo
from dvc.path.ssh import SSHPathInfo

PATH_MAP = {
Schemes.SSH: SSHPathInfo,
Schemes.HDFS: HDFSPathInfo,
Schemes.S3: S3PathInfo,
Schemes.AZURE: AzurePathInfo,
Schemes.HTTP: HTTPPathInfo,
Schemes.GS: GSPathInfo,
Schemes.LOCAL: LocalPathInfo,
Schemes.OSS: OSSPathInfo,
}


def PathInfo(scheme, *args, **kwargs):
cls = PATH_MAP[scheme]
return cls(*args, **kwargs)
Loading