mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
dvc: use local scheme as default
There is no way to detect if some path is a valid path in a general case, since every filesystem has its own requirements and limitations. Instead, just default to a local path and let fs handle the rest. Fixes #1433 Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
@@ -5,7 +5,6 @@ try:
|
||||
except ImportError:
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from dvc.exceptions import DvcException
|
||||
from dvc.config import Config
|
||||
|
||||
from dvc.dependency.base import DependencyBase
|
||||
@@ -25,9 +24,9 @@ DEPS = [
|
||||
DependencyGS,
|
||||
DependencyHDFS,
|
||||
DependencyHTTP,
|
||||
DependencyLOCAL,
|
||||
DependencyS3,
|
||||
DependencySSH,
|
||||
# NOTE: DependencyLOCAL is the default choice
|
||||
]
|
||||
|
||||
DEP_MAP = {
|
||||
@@ -60,7 +59,7 @@ def _get(stage, p, info):
|
||||
for d in DEPS:
|
||||
if d.supported(p):
|
||||
return d(stage, p, info)
|
||||
raise DvcException('Dependency \'{}\' is not supported'.format(p))
|
||||
return DependencyLOCAL(stage, p, info)
|
||||
|
||||
|
||||
def loadd_from(stage, d_list):
|
||||
|
||||
@@ -12,7 +12,7 @@ from dvc.remote.local import RemoteLOCAL
|
||||
|
||||
|
||||
class DependencyLOCAL(DependencyBase):
|
||||
REGEX = r'^(?P<path>(/+|.:\\+)?[^:]*)$'
|
||||
REGEX = r'^(?P<path>.*)$'
|
||||
|
||||
DoesNotExistError = DependencyDoesNotExistError
|
||||
IsNotFileOrDirError = DependencyIsNotFileOrDirError
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import schema
|
||||
|
||||
from dvc.exceptions import DvcException
|
||||
from dvc.config import Config
|
||||
|
||||
from dvc.dependency import SCHEMA, urlparse
|
||||
@@ -14,7 +13,13 @@ from dvc.output.ssh import OutputSSH
|
||||
from dvc.remote import Remote
|
||||
|
||||
|
||||
OUTS = [OutputHDFS, OutputS3, OutputGS, OutputSSH, OutputLOCAL]
|
||||
OUTS = [
|
||||
OutputHDFS,
|
||||
OutputS3,
|
||||
OutputGS,
|
||||
OutputSSH,
|
||||
# NOTE: OutputLOCAL is the default choice
|
||||
]
|
||||
|
||||
OUTS_MAP = {'hdfs': OutputHDFS,
|
||||
's3': OutputS3,
|
||||
@@ -42,7 +47,7 @@ def _get(stage, p, info, cache, metric):
|
||||
for o in OUTS:
|
||||
if o.supported(p):
|
||||
return o(stage, p, info, cache=cache, remote=None, metric=metric)
|
||||
raise DvcException('Output \'{}\' is not supported'.format(p))
|
||||
return OutputLOCAL(stage, p, info, cache=cache, remote=None, metric=metric)
|
||||
|
||||
|
||||
def loadd_from(stage, d_list):
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
from dvc.dependency import _get
|
||||
from dvc.exceptions import DvcException
|
||||
from dvc.stage import Stage
|
||||
from dvc.dependency import _get, DEP_MAP
|
||||
|
||||
from tests.basic_env import TestDvc
|
||||
from tests.test_output import TestOutScheme
|
||||
|
||||
|
||||
class TestUnsupported(TestDvc):
|
||||
def test(self):
|
||||
with self.assertRaises(DvcException):
|
||||
_get(None, 'unsupported://a/b', None)
|
||||
class TestDepScheme(TestOutScheme):
|
||||
MAP = DEP_MAP
|
||||
|
||||
TESTS = TestOutScheme.TESTS.copy()
|
||||
TESTS['http://example.com/path/to/file'] = 'http'
|
||||
TESTS['https://example.com/path/to/file'] = 'https'
|
||||
|
||||
def _get(self, path):
|
||||
return _get(Stage(self.dvc), path, None)
|
||||
|
||||
+25
-5
@@ -1,10 +1,30 @@
|
||||
from dvc.output import _get
|
||||
from dvc.exceptions import DvcException
|
||||
from dvc.stage import Stage
|
||||
from dvc.output import _get, OUTS_MAP
|
||||
|
||||
from tests.basic_env import TestDvc
|
||||
|
||||
|
||||
class TestUnsupported(TestDvc):
|
||||
class TestOutScheme(TestDvc):
|
||||
MAP = OUTS_MAP
|
||||
|
||||
TESTS = {
|
||||
's3://bucket/path': 's3',
|
||||
'gs://bucket/path': 'gs',
|
||||
'ssh://example.com:/dir/path': 'ssh',
|
||||
'hdfs://example.com/dir/path': 'hdfs',
|
||||
'path/to/file': '',
|
||||
'path\\to\\file': '',
|
||||
'file': '',
|
||||
'./file': '',
|
||||
'.\\file': '',
|
||||
'../file': '',
|
||||
'..\\file': '',
|
||||
'unknown://path': '',
|
||||
}
|
||||
|
||||
def _get(self, path):
|
||||
return _get(Stage(self.dvc), path, None, None, None)
|
||||
|
||||
def test(self):
|
||||
with self.assertRaises(DvcException):
|
||||
_get(None, 'unsupported://a/b', None, None, None)
|
||||
for path, cls in self.TESTS.items():
|
||||
self.assertIsInstance(self._get(path), self.MAP[cls])
|
||||
|
||||
Reference in New Issue
Block a user