mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-28 15:28:27 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c6351d039 | ||
|
|
613ca0bdb5 | ||
|
|
0fb9870de6 | ||
|
|
73e60a8c13 | ||
|
|
9d1dde4051 | ||
|
|
38dc0f85d4 | ||
|
|
d2dbe9649c | ||
|
|
ece6f2d3ee | ||
|
|
b672622324 | ||
|
|
c9391df313 | ||
|
|
a0c229cf9b | ||
|
|
a59f90fac9 | ||
|
|
bba502314d | ||
|
|
bc4bf66d17 | ||
|
|
f7348af1e0 | ||
|
|
4d140a9944 | ||
|
|
2ba73daedc | ||
|
|
7a31a35cbf | ||
|
|
24a14563cc | ||
|
|
a1d3440f85 | ||
|
|
45dcb7c27d | ||
|
|
9ff6fef53a | ||
|
|
9e7dc2640e | ||
|
|
584c97a58d | ||
|
|
b94a18cfb9 | ||
|
|
9ead641c95 | ||
|
|
652f5ab439 | ||
|
|
28a123e727 | ||
|
|
566472f088 | ||
|
|
2e12a31c5a | ||
|
|
d7788887f0 | ||
|
|
87276faef2 | ||
|
|
4042d5232d | ||
|
|
fda14c82d3 | ||
|
|
64be262d18 | ||
|
|
1d6c80001d | ||
|
|
91a7194e4f | ||
|
|
afe539aaba | ||
|
|
f259bc52cd | ||
|
|
db69def834 | ||
|
|
5efc3bbee2 | ||
|
|
7230d87137 | ||
|
|
56833387ce | ||
|
|
593e67318b | ||
|
|
afc183f4e7 | ||
|
|
d201fad1e3 | ||
|
|
5be12b5aac | ||
|
|
c1e5b10cbd | ||
|
|
b47b2c5673 | ||
|
|
939f78948a | ||
|
|
215ea4944c | ||
|
|
4e12e76e19 | ||
|
|
33092e8614 | ||
|
|
ae7b604531 | ||
|
|
b7c174641e | ||
|
|
cb43f9cdda | ||
|
|
791ce22759 | ||
|
|
c70adebc75 | ||
|
|
2c9cb87679 | ||
|
|
b57077af11 | ||
|
|
803bb3eb61 | ||
|
|
99b58d3d05 | ||
|
|
5bbaa28cae | ||
|
|
74bd8137ba | ||
|
|
72a576cefe | ||
|
|
036ce9398e | ||
|
|
13012f9c0c | ||
|
|
a65c7989c8 | ||
|
|
3590fe8414 | ||
|
|
05100122e1 | ||
|
|
9a55b909f8 | ||
|
|
ff54ac1bfb | ||
|
|
57e920aa39 | ||
|
|
ac4f351daf | ||
|
|
2c0116ccf9 | ||
|
|
c03ce4aa0f | ||
|
|
72dcbc0a9e | ||
|
|
fd65f44b7f | ||
|
|
7504b68c12 | ||
|
|
86f3457dec | ||
|
|
219662597b | ||
|
|
536966f9d1 | ||
|
|
076eadceba | ||
|
|
d1e08b6157 | ||
|
|
edfa1741db | ||
|
|
9ee62ef8f0 | ||
|
|
0bb49d2549 | ||
|
|
516d82e411 | ||
|
|
ec312d8601 | ||
|
|
f504245f35 | ||
|
|
bb50fb8664 | ||
|
|
777a9f80ae | ||
|
|
02a52d038a | ||
|
|
7d0a06248d | ||
|
|
2d8c6043ca | ||
|
|
3f996048e8 | ||
|
|
8d9435e8ee | ||
|
|
889a17e2fc | ||
|
|
63972c3d12 | ||
|
|
7027c631c5 | ||
|
|
e8f6cd7f5b | ||
|
|
10f2bb93fa | ||
|
|
2fecc66cb9 | ||
|
|
b47998463f | ||
|
|
d53b740f35 | ||
|
|
9198fa7459 | ||
|
|
6954efc6e6 | ||
|
|
d77af8196e | ||
|
|
c5920b00ab | ||
|
|
ce8036e535 | ||
|
|
b7ad2dc841 | ||
|
|
5ab948f8b6 | ||
|
|
f9fbe97509 | ||
|
|
2fba2e030a | ||
|
|
3e951162b8 | ||
|
|
d74358eecd | ||
|
|
58c9ff0de2 | ||
|
|
f0e991790e | ||
|
|
b7cd785eba | ||
|
|
21a3efe2c7 | ||
|
|
865d355554 | ||
|
|
84712c4acc | ||
|
|
0f16e15453 | ||
|
|
61f30ed5ba | ||
|
|
cde15e3d3e | ||
|
|
7672e324d2 | ||
|
|
130b76c7a5 | ||
|
|
040458a726 | ||
|
|
75e795c491 | ||
|
|
4dac2092c9 | ||
|
|
19eaced304 | ||
|
|
184028f176 | ||
|
|
5f63d538d2 | ||
|
|
324ff4be59 | ||
|
|
3f846a1794 | ||
|
|
b52c925d5f | ||
|
|
4a4f07968c | ||
|
|
09136f2378 | ||
|
|
aaca1401ea | ||
|
|
2aaf065ea3 | ||
|
|
d4ec871a76 | ||
|
|
f44ddcf64e | ||
|
|
b88b3b81c6 | ||
|
|
81d04f887a | ||
|
|
afbb3a0add | ||
|
|
b8aa8ad951 | ||
|
|
9897f7c470 | ||
|
|
cf7f125c14 | ||
|
|
cec4b4e003 | ||
|
|
ff4fcc937b | ||
|
|
1676a7a1cd | ||
|
|
974cf097dd | ||
|
|
597ab98d0e | ||
|
|
833e82a7ea | ||
|
|
3916d4fa07 | ||
|
|
d81b56978f | ||
|
|
1e7efffe42 | ||
|
|
cc16b28a26 | ||
|
|
451c7aac04 | ||
|
|
7b4466c982 | ||
|
|
7ca3a1119c | ||
|
|
2c026066db | ||
|
|
7f17c6aa03 | ||
|
|
9f015fac1d | ||
|
|
666e203bbb | ||
|
|
ce946d1160 | ||
|
|
76b31ac282 | ||
|
|
6093a1fe97 | ||
|
|
d62a54c7b0 | ||
|
|
c922da4f3f | ||
|
|
2a16b021ad | ||
|
|
fc42ca721c | ||
|
|
785dcfeef0 | ||
|
|
9714b14456 | ||
|
|
6a406abde8 | ||
|
|
7ca055e868 | ||
|
|
6a64f86178 | ||
|
|
227dbf44d9 | ||
|
|
2bb7257a06 | ||
|
|
e3831066de | ||
|
|
aa99cc9934 | ||
|
|
26e203242f | ||
|
|
d00bd4dfe5 | ||
|
|
795f001929 | ||
|
|
93d7b9173b | ||
|
|
bc7f177c7a | ||
|
|
6f73a67c60 | ||
|
|
68a0c39ad1 | ||
|
|
c186a8ea8f | ||
|
|
af8ac006ad | ||
|
|
b2ea279c9e | ||
|
|
2dda540db6 | ||
|
|
76e6ba24f7 | ||
|
|
505b88afae | ||
|
|
415a85c6be | ||
|
|
4e9b38970a | ||
|
|
3e1eb6d1e7 | ||
|
|
c873787d73 | ||
|
|
e553511085 | ||
|
|
827c994e74 | ||
|
|
22c60dd608 | ||
|
|
f9088e1c67 | ||
|
|
71d156ac49 | ||
|
|
d998c0a536 | ||
|
|
af12f0d06c | ||
|
|
18e8f07572 |
@@ -1,7 +0,0 @@
|
|||||||
[flake8]
|
|
||||||
ignore =
|
|
||||||
E203, # Whitespace before ':'
|
|
||||||
E266, # Too many leading '#' for block comment
|
|
||||||
W503, # Line break occurred before a binary operator
|
|
||||||
max-line-length = 79
|
|
||||||
select = B,C,E,F,W,T4,B9
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
patreon: DVCorg
|
||||||
@@ -1,10 +1,18 @@
|
|||||||
---
|
---
|
||||||
name: Bug report
|
name: "\U0001F41B Bug Report"
|
||||||
about: Create a report to help us improve
|
about: Create a bug report to help us improve DVC
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Bug Report
|
||||||
|
|
||||||
**Please provide information about your setup**
|
### Please provide information about your setup
|
||||||
DVC version(i.e. `dvc --version`), Platform and method of installation (pip, homebrew, pkg Mac, exe (Windows), DEB(Linux), RPM(Linux))
|
|
||||||
|
|
||||||
|
**Output of `dvc version`:**
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ dvc version
|
||||||
|
```
|
||||||
|
|
||||||
|
**Additional Information (if any):**
|
||||||
|
|
||||||
|
If applicable, please also provide a `--verbose` output of the command, eg: `dvc add --verbose`.
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
blank_issues_enabled: false
|
||||||
|
contact_links:
|
||||||
|
- name: "🤗 Need help?"
|
||||||
|
url: https://dvc.org/chat
|
||||||
|
about: If you have a question, ask us on Discord. Please join with this invite 👉
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
---
|
---
|
||||||
name: Feature request
|
name: "\U0001F680 Feature Request"
|
||||||
about: Suggest an idea for this project
|
about: Suggest an idea for this project
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
+35
-7
@@ -4,6 +4,15 @@ repos:
|
|||||||
language_version: python3
|
language_version: python3
|
||||||
repo: https://github.com/ambv/black
|
repo: https://github.com/ambv/black
|
||||||
rev: 19.10b0
|
rev: 19.10b0
|
||||||
|
- repo: https://github.com/asottile/seed-isort-config
|
||||||
|
rev: v2.1.1
|
||||||
|
hooks:
|
||||||
|
- id: seed-isort-config
|
||||||
|
- hooks:
|
||||||
|
- id: isort
|
||||||
|
language_version: python3
|
||||||
|
repo: https://github.com/timothycrosley/isort
|
||||||
|
rev: 4.3.21
|
||||||
- hooks:
|
- hooks:
|
||||||
- id: flake8
|
- id: flake8
|
||||||
language_version: python3
|
language_version: python3
|
||||||
@@ -18,18 +27,37 @@ repos:
|
|||||||
repo: https://github.com/lovesegfault/beautysh
|
repo: https://github.com/lovesegfault/beautysh
|
||||||
rev: master
|
rev: master
|
||||||
- hooks:
|
- hooks:
|
||||||
- id: dvc-pre-commit
|
- args:
|
||||||
language_version: python3
|
- git-hook
|
||||||
|
- pre-commit
|
||||||
|
entry: dvc
|
||||||
|
id: dvc-pre-commit
|
||||||
|
language: system
|
||||||
|
name: DVC pre-commit
|
||||||
stages:
|
stages:
|
||||||
- commit
|
- commit
|
||||||
- id: dvc-pre-push
|
verbose: true
|
||||||
language_version: python3
|
require_serial: true
|
||||||
|
- args:
|
||||||
|
- git-hook
|
||||||
|
- pre-push
|
||||||
|
entry: dvc
|
||||||
|
id: dvc-pre-push
|
||||||
|
language: system
|
||||||
|
name: DVC pre-push
|
||||||
stages:
|
stages:
|
||||||
- push
|
- push
|
||||||
|
require_serial: true
|
||||||
- always_run: true
|
- always_run: true
|
||||||
|
args:
|
||||||
|
- git-hook
|
||||||
|
- post-checkout
|
||||||
|
entry: dvc
|
||||||
id: dvc-post-checkout
|
id: dvc-post-checkout
|
||||||
language_version: python3
|
language: system
|
||||||
|
minimum_pre_commit_version: 2.2.0
|
||||||
|
name: DVC post-checkout
|
||||||
stages:
|
stages:
|
||||||
- post-checkout
|
- post-checkout
|
||||||
repo: https://github.com/iterative/dvc
|
require_serial: true
|
||||||
rev: master
|
repo: local
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
language: python
|
language: python
|
||||||
language_version: python3
|
language_version: python3
|
||||||
name: DVC pre-commit
|
name: DVC pre-commit
|
||||||
|
require_serial: true
|
||||||
stages:
|
stages:
|
||||||
- commit
|
- commit
|
||||||
verbose: true
|
verbose: true
|
||||||
@@ -17,6 +18,7 @@
|
|||||||
language: python
|
language: python
|
||||||
language_version: python3
|
language_version: python3
|
||||||
name: DVC pre-push
|
name: DVC pre-push
|
||||||
|
require_serial: true
|
||||||
stages:
|
stages:
|
||||||
- push
|
- push
|
||||||
- always_run: true
|
- always_run: true
|
||||||
@@ -29,5 +31,6 @@
|
|||||||
language_version: python3
|
language_version: python3
|
||||||
minimum_pre_commit_version: 2.2.0
|
minimum_pre_commit_version: 2.2.0
|
||||||
name: DVC post-checkout
|
name: DVC post-checkout
|
||||||
|
require_serial: true
|
||||||
stages:
|
stages:
|
||||||
- post-checkout
|
- post-checkout
|
||||||
|
|||||||
@@ -9,3 +9,12 @@ restylers:
|
|||||||
- "**/*.py"
|
- "**/*.py"
|
||||||
interpreters:
|
interpreters:
|
||||||
- python
|
- python
|
||||||
|
- name: isort
|
||||||
|
image: restyled/restyler-isort:v4.3.21
|
||||||
|
command:
|
||||||
|
- isort
|
||||||
|
arguments: []
|
||||||
|
include:
|
||||||
|
- "**/*.py"
|
||||||
|
interpreters:
|
||||||
|
- python
|
||||||
|
|||||||
+14
-5
@@ -46,9 +46,6 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
- PYTHON_VERSION=3.8.0
|
- PYTHON_VERSION=3.8.0
|
||||||
- PATH=/c/Python38:/c/Python38/Scripts:$PATH
|
- PATH=/c/Python38:/c/Python38/Scripts:$PATH
|
||||||
- name: "3.5 on Linux"
|
|
||||||
language: python
|
|
||||||
python: 3.5
|
|
||||||
- name: "3.6 on Linux"
|
- name: "3.6 on Linux"
|
||||||
language: python
|
language: python
|
||||||
python: 3.6
|
python: 3.6
|
||||||
@@ -101,8 +98,12 @@ jobs:
|
|||||||
- name: lxd
|
- name: lxd
|
||||||
channel: stable
|
channel: stable
|
||||||
env:
|
env:
|
||||||
- SNAPCRAFT_IMAGE_INFO: '{"build_url": "$TRAVIS_BUILD_URL"}'
|
- SNAPCRAFT_IMAGE_INFO: |
|
||||||
|
'{"build_url": "$TRAVIS_JOB_WEB_URL"}'
|
||||||
|
- SNAPCRAFT_BUILD_ENVIRONMENT: lxd
|
||||||
|
- SNAPCRAFT_BUILD_INFO: 1 # https://snapcraft.io/blog/introducing-developer-notifications-for-snap-security-updates
|
||||||
install:
|
install:
|
||||||
|
- sudo usermod --append --groups lxd $USER
|
||||||
- sudo /snap/bin/lxd.migrate -yes
|
- sudo /snap/bin/lxd.migrate -yes
|
||||||
- sudo /snap/bin/lxd waitready
|
- sudo /snap/bin/lxd waitready
|
||||||
- sudo /snap/bin/lxd init --auto
|
- sudo /snap/bin/lxd init --auto
|
||||||
@@ -156,6 +157,14 @@ deploy:
|
|||||||
script: "(echo $SNAP_TOKEN | snapcraft login --with -) && timeout 600 snapcraft push dvc_*.snap --release $SNAP_CHANNEL || echo timed out"
|
script: "(echo $SNAP_TOKEN | snapcraft login --with -) && timeout 600 snapcraft push dvc_*.snap --release $SNAP_CHANNEL || echo timed out"
|
||||||
on:
|
on:
|
||||||
all_branches: true
|
all_branches: true
|
||||||
condition: "$(./scripts/ci/deploy_condition.sh dvc_*.snap) && ($TRAVIS_BRANCH = master || -n $TRAVIS_TAG)"
|
condition: "$(./scripts/ci/deploy_condition.sh dvc_*.snap) && ($TRAVIS_BRANCH = master || -n $TRAVIS_TAG) && -n $SNAP_CHANNEL"
|
||||||
|
repo: iterative/dvc
|
||||||
|
stage: build
|
||||||
|
- provider: script
|
||||||
|
skip_cleanup: true
|
||||||
|
script: "(echo $SNAP_TOKEN | snapcraft login --with -) && timeout 600 snapcraft push dvc_*.snap --release $SNAP_CHANNEL_MAJOR || echo timed out"
|
||||||
|
on:
|
||||||
|
all_branches: true
|
||||||
|
condition: "$(./scripts/ci/deploy_condition.sh dvc_*.snap) && ($TRAVIS_BRANCH = master || -n $TRAVIS_TAG) && -n $SNAP_CHANNEL_MAJOR"
|
||||||
repo: iterative/dvc
|
repo: iterative/dvc
|
||||||
stage: build
|
stage: build
|
||||||
|
|||||||
+2
-1
@@ -101,7 +101,8 @@ Snap (Snapcraft/Linux)
|
|||||||
snap install dvc --classic
|
snap install dvc --classic
|
||||||
|
|
||||||
This corresponds to the latest tagged release.
|
This corresponds to the latest tagged release.
|
||||||
Add ``--edge`` for the latest ``master`` version.
|
Add ``--beta`` for the latest tagged release candidate,
|
||||||
|
or ``--edge`` for the latest ``master`` version.
|
||||||
|
|
||||||
Choco (Chocolatey/Windows)
|
Choco (Chocolatey/Windows)
|
||||||
--------------------------
|
--------------------------
|
||||||
|
|||||||
@@ -6,5 +6,4 @@ Make your data science projects reproducible and shareable.
|
|||||||
import dvc.logger
|
import dvc.logger
|
||||||
from dvc.version import __version__ # noqa: F401
|
from dvc.version import __version__ # noqa: F401
|
||||||
|
|
||||||
|
|
||||||
dvc.logger.setup()
|
dvc.logger.setup()
|
||||||
|
|||||||
+4
-7
@@ -2,12 +2,12 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import requests
|
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import distro
|
import distro
|
||||||
|
import requests
|
||||||
|
|
||||||
from dvc import __version__
|
from dvc import __version__
|
||||||
from dvc.config import Config, to_bool
|
from dvc.config import Config, to_bool
|
||||||
@@ -20,7 +20,6 @@ from dvc.scm.base import SCMError
|
|||||||
from dvc.utils import env2bool, is_binary
|
from dvc.utils import env2bool, is_binary
|
||||||
from dvc.utils.fs import makedirs
|
from dvc.utils.fs import makedirs
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -73,7 +72,7 @@ def send(path):
|
|||||||
url = "https://analytics.dvc.org"
|
url = "https://analytics.dvc.org"
|
||||||
headers = {"content-type": "application/json"}
|
headers = {"content-type": "application/json"}
|
||||||
|
|
||||||
with open(path, "r") as fobj:
|
with open(path) as fobj:
|
||||||
report = json.load(fobj)
|
report = json.load(fobj)
|
||||||
|
|
||||||
report.update(_runtime_info())
|
report.update(_runtime_info())
|
||||||
@@ -159,7 +158,7 @@ def _find_or_create_user_id():
|
|||||||
try:
|
try:
|
||||||
with Lock(lockfile):
|
with Lock(lockfile):
|
||||||
try:
|
try:
|
||||||
with open(fname, "r") as fobj:
|
with open(fname) as fobj:
|
||||||
user_id = json.load(fobj)["user_id"]
|
user_id = json.load(fobj)["user_id"]
|
||||||
|
|
||||||
except (FileNotFoundError, ValueError, KeyError):
|
except (FileNotFoundError, ValueError, KeyError):
|
||||||
@@ -171,6 +170,4 @@ def _find_or_create_user_id():
|
|||||||
return user_id
|
return user_id
|
||||||
|
|
||||||
except LockError:
|
except LockError:
|
||||||
logger.debug(
|
logger.debug(f"Failed to acquire '{lockfile}'")
|
||||||
"Failed to acquire '{lockfile}'".format(lockfile=lockfile)
|
|
||||||
)
|
|
||||||
|
|||||||
+5
-4
@@ -1,16 +1,17 @@
|
|||||||
import os
|
import os
|
||||||
from contextlib import contextmanager, _GeneratorContextManager as GCM
|
from contextlib import _GeneratorContextManager as GCM
|
||||||
|
from contextlib import contextmanager
|
||||||
|
|
||||||
from dvc.repo import Repo
|
|
||||||
from dvc.exceptions import DvcException, NotDvcRepoError
|
from dvc.exceptions import DvcException, NotDvcRepoError
|
||||||
from dvc.external_repo import external_repo
|
from dvc.external_repo import external_repo
|
||||||
|
from dvc.repo import Repo
|
||||||
|
|
||||||
|
|
||||||
class UrlNotDvcRepoError(DvcException):
|
class UrlNotDvcRepoError(DvcException):
|
||||||
"""Thrown if the given URL is not a DVC repository."""
|
"""Thrown if the given URL is not a DVC repository."""
|
||||||
|
|
||||||
def __init__(self, url):
|
def __init__(self, url):
|
||||||
super().__init__("'{}' is not a DVC repository.".format(url))
|
super().__init__(f"'{url}' is not a DVC repository.")
|
||||||
|
|
||||||
|
|
||||||
def get_url(path, repo=None, rev=None, remote=None):
|
def get_url(path, repo=None, rev=None, remote=None):
|
||||||
@@ -29,7 +30,7 @@ def get_url(path, repo=None, rev=None, remote=None):
|
|||||||
raise UrlNotDvcRepoError(_repo.url)
|
raise UrlNotDvcRepoError(_repo.url)
|
||||||
out = _repo.find_out_by_relpath(path)
|
out = _repo.find_out_by_relpath(path)
|
||||||
remote_obj = _repo.cloud.get_remote(remote)
|
remote_obj = _repo.cloud.get_remote(remote)
|
||||||
return str(remote_obj.checksum_to_path_info(out.checksum))
|
return str(remote_obj.hash_to_path_info(out.checksum))
|
||||||
|
|
||||||
|
|
||||||
def open(path, repo=None, rev=None, remote=None, mode="r", encoding=None):
|
def open(path, repo=None, rev=None, remote=None, mode="r", encoding=None):
|
||||||
|
|||||||
+10
-6
@@ -28,19 +28,21 @@ def _make_remote_property(name):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def getter(self):
|
def getter(self):
|
||||||
from dvc.remote import Remote
|
from dvc.remote import get_cloud_tree
|
||||||
|
from dvc.remote.base import CloudCache
|
||||||
|
|
||||||
remote = self.config.get(name)
|
remote = self.config.get(name)
|
||||||
if not remote:
|
if not remote:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return Remote(self.repo, name=remote)
|
tree = get_cloud_tree(self.repo, name=remote)
|
||||||
|
return CloudCache(tree)
|
||||||
|
|
||||||
getter.__name__ = name
|
getter.__name__ = name
|
||||||
return cached_property(getter)
|
return cached_property(getter)
|
||||||
|
|
||||||
|
|
||||||
class Cache(object):
|
class Cache:
|
||||||
"""Class that manages cache locations of a DVC repo.
|
"""Class that manages cache locations of a DVC repo.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -50,7 +52,8 @@ class Cache(object):
|
|||||||
CACHE_DIR = "cache"
|
CACHE_DIR = "cache"
|
||||||
|
|
||||||
def __init__(self, repo):
|
def __init__(self, repo):
|
||||||
from dvc.remote import Remote
|
from dvc.remote import get_cloud_tree
|
||||||
|
from dvc.remote.local import LocalCache
|
||||||
|
|
||||||
self.repo = repo
|
self.repo = repo
|
||||||
self.config = config = repo.config["cache"]
|
self.config = config = repo.config["cache"]
|
||||||
@@ -62,7 +65,8 @@ class Cache(object):
|
|||||||
else:
|
else:
|
||||||
settings = {**config, "url": config["dir"]}
|
settings = {**config, "url": config["dir"]}
|
||||||
|
|
||||||
self.local = Remote(repo, **settings)
|
tree = get_cloud_tree(repo, **settings)
|
||||||
|
self.local = LocalCache(tree)
|
||||||
|
|
||||||
s3 = _make_remote_property("s3")
|
s3 = _make_remote_property("s3")
|
||||||
gs = _make_remote_property("gs")
|
gs = _make_remote_property("gs")
|
||||||
@@ -101,7 +105,7 @@ class NamedCacheItem:
|
|||||||
self.children[checksum].update(child_item)
|
self.children[checksum].update(child_item)
|
||||||
|
|
||||||
|
|
||||||
class NamedCache(object):
|
class NamedCache:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._items = defaultdict(lambda: defaultdict(NamedCacheItem))
|
self._items = defaultdict(lambda: defaultdict(NamedCacheItem))
|
||||||
self.external = defaultdict(set)
|
self.external = defaultdict(set)
|
||||||
|
|||||||
+27
-15
@@ -10,22 +10,24 @@ from .command import (
|
|||||||
commit,
|
commit,
|
||||||
config,
|
config,
|
||||||
daemon,
|
daemon,
|
||||||
|
dag,
|
||||||
data_sync,
|
data_sync,
|
||||||
destroy,
|
destroy,
|
||||||
diff,
|
diff,
|
||||||
|
freeze,
|
||||||
gc,
|
gc,
|
||||||
get,
|
get,
|
||||||
get_url,
|
get_url,
|
||||||
|
git_hook,
|
||||||
imp,
|
imp,
|
||||||
imp_url,
|
imp_url,
|
||||||
init,
|
init,
|
||||||
install,
|
install,
|
||||||
ls,
|
ls,
|
||||||
lock,
|
|
||||||
metrics,
|
metrics,
|
||||||
params,
|
|
||||||
move,
|
move,
|
||||||
pipeline,
|
params,
|
||||||
|
plots,
|
||||||
remote,
|
remote,
|
||||||
remove,
|
remove,
|
||||||
repro,
|
repro,
|
||||||
@@ -34,12 +36,10 @@ from .command import (
|
|||||||
unprotect,
|
unprotect,
|
||||||
update,
|
update,
|
||||||
version,
|
version,
|
||||||
git_hook,
|
|
||||||
)
|
)
|
||||||
from .command.base import fix_subparsers
|
from .command.base import fix_subparsers
|
||||||
from .exceptions import DvcParserError
|
from .exceptions import DvcParserError
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
COMMANDS = [
|
COMMANDS = [
|
||||||
@@ -66,32 +66,48 @@ COMMANDS = [
|
|||||||
install,
|
install,
|
||||||
root,
|
root,
|
||||||
ls,
|
ls,
|
||||||
lock,
|
freeze,
|
||||||
pipeline,
|
dag,
|
||||||
daemon,
|
daemon,
|
||||||
commit,
|
commit,
|
||||||
diff,
|
diff,
|
||||||
version,
|
version,
|
||||||
update,
|
update,
|
||||||
git_hook,
|
git_hook,
|
||||||
|
plots,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class DvcParser(argparse.ArgumentParser):
|
class DvcParser(argparse.ArgumentParser):
|
||||||
"""Custom parser class for dvc CLI."""
|
"""Custom parser class for dvc CLI."""
|
||||||
|
|
||||||
def error(self, message):
|
def error(self, message, command=None):
|
||||||
"""Custom error method.
|
"""Custom error method.
|
||||||
Args:
|
Args:
|
||||||
message (str): error message.
|
message (str): error message.
|
||||||
|
command (str): subcommand name for help message
|
||||||
Raises:
|
Raises:
|
||||||
dvc.exceptions.DvcParser: dvc parser exception.
|
dvc.exceptions.DvcParser: dvc parser exception.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
logger.error(message)
|
logger.error(message)
|
||||||
|
if command is not None:
|
||||||
|
for action in self._actions:
|
||||||
|
if action.dest == "cmd" and command in action.choices:
|
||||||
|
subparser = action.choices[command]
|
||||||
|
subparser.print_help()
|
||||||
|
raise DvcParserError()
|
||||||
self.print_help()
|
self.print_help()
|
||||||
raise DvcParserError()
|
raise DvcParserError()
|
||||||
|
|
||||||
|
# override this to send subcommand name to error method
|
||||||
|
def parse_args(self, args=None, namespace=None):
|
||||||
|
args, argv = self.parse_known_args(args, namespace)
|
||||||
|
if argv:
|
||||||
|
msg = "unrecognized arguments: %s"
|
||||||
|
self.error(msg % " ".join(argv), args.cmd)
|
||||||
|
return args
|
||||||
|
|
||||||
|
|
||||||
class VersionAction(argparse.Action): # pragma: no cover
|
class VersionAction(argparse.Action): # pragma: no cover
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
@@ -115,14 +131,10 @@ def get_parent_parser():
|
|||||||
|
|
||||||
log_level_group = parent_parser.add_mutually_exclusive_group()
|
log_level_group = parent_parser.add_mutually_exclusive_group()
|
||||||
log_level_group.add_argument(
|
log_level_group.add_argument(
|
||||||
"-q", "--quiet", action="store_true", default=False, help="Be quiet."
|
"-q", "--quiet", action="count", default=0, help="Be quiet."
|
||||||
)
|
)
|
||||||
log_level_group.add_argument(
|
log_level_group.add_argument(
|
||||||
"-v",
|
"-v", "--verbose", action="count", default=0, help="Be verbose."
|
||||||
"--verbose",
|
|
||||||
action="store_true",
|
|
||||||
default=False,
|
|
||||||
help="Be verbose.",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return parent_parser
|
return parent_parser
|
||||||
|
|||||||
+8
-2
@@ -1,7 +1,7 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dvc.command.base import append_doc_link, CmdBase
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
from dvc.exceptions import DvcException, RecursiveAddingWhileUsingFilename
|
from dvc.exceptions import DvcException, RecursiveAddingWhileUsingFilename
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -18,6 +18,7 @@ class CmdAdd(CmdBase):
|
|||||||
recursive=self.args.recursive,
|
recursive=self.args.recursive,
|
||||||
no_commit=self.args.no_commit,
|
no_commit=self.args.no_commit,
|
||||||
fname=self.args.file,
|
fname=self.args.file,
|
||||||
|
external=self.args.external,
|
||||||
)
|
)
|
||||||
|
|
||||||
except DvcException:
|
except DvcException:
|
||||||
@@ -50,7 +51,12 @@ def add_parser(subparsers, parent_parser):
|
|||||||
help="Don't put files/directories into cache.",
|
help="Don't put files/directories into cache.",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-f",
|
"--external",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Allow targets that are outside of the DVC repository.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
"--file",
|
"--file",
|
||||||
help="Specify name of the DVC-file this command will generate.",
|
help="Specify name of the DVC-file this command will generate.",
|
||||||
metavar="<filename>",
|
metavar="<filename>",
|
||||||
|
|||||||
+6
-8
@@ -1,6 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -27,7 +26,7 @@ def append_doc_link(help_message, path):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class CmdBase(object):
|
class CmdBase:
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
from dvc.repo import Repo
|
from dvc.repo import Repo
|
||||||
from dvc.updater import Updater
|
from dvc.updater import Updater
|
||||||
@@ -36,17 +35,16 @@ class CmdBase(object):
|
|||||||
self.config = self.repo.config
|
self.config = self.repo.config
|
||||||
self.args = args
|
self.args = args
|
||||||
hardlink_lock = self.config["core"].get("hardlink_lock", False)
|
hardlink_lock = self.config["core"].get("hardlink_lock", False)
|
||||||
updater = Updater(self.repo.dvc_dir, hardlink_lock=hardlink_lock)
|
updater = Updater(self.repo.tmp_dir, hardlink_lock=hardlink_lock)
|
||||||
updater.check()
|
updater.check()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def default_targets(self):
|
def default_targets(self):
|
||||||
"""Default targets for `dvc repro` and `dvc pipeline`."""
|
"""Default targets for `dvc repro`."""
|
||||||
from dvc.dvcfile import DVC_FILE
|
from dvc.dvcfile import PIPELINE_FILE
|
||||||
|
|
||||||
msg = "assuming default target '{}'.".format(DVC_FILE)
|
logger.debug(f"assuming default target '{PIPELINE_FILE}'.")
|
||||||
logger.warning(msg)
|
return [PIPELINE_FILE]
|
||||||
return [DVC_FILE]
|
|
||||||
|
|
||||||
# Abstract methods that have to be implemented by any inheritance class
|
# Abstract methods that have to be implemented by any inheritance class
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|||||||
+8
-27
@@ -1,39 +1,16 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
import operator
|
||||||
|
|
||||||
import colorama
|
import colorama
|
||||||
|
|
||||||
from dvc.command.base import append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
from dvc.command.base import CmdBase
|
|
||||||
from dvc.exceptions import CheckoutError
|
from dvc.exceptions import CheckoutError
|
||||||
|
from dvc.utils.humanize import get_summary
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _human_join(words):
|
|
||||||
words = list(words)
|
|
||||||
if not words:
|
|
||||||
return ""
|
|
||||||
|
|
||||||
return (
|
|
||||||
"{before} and {after}".format(
|
|
||||||
before=", ".join(words[:-1]), after=words[-1],
|
|
||||||
)
|
|
||||||
if len(words) > 1
|
|
||||||
else words[0]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def log_summary(stats):
|
|
||||||
states = ("added", "deleted", "modified")
|
|
||||||
summary = (
|
|
||||||
"{} {}".format(len(stats[state]), state)
|
|
||||||
for state in states
|
|
||||||
if stats.get(state)
|
|
||||||
)
|
|
||||||
logger.info(_human_join(summary) or "No changes.")
|
|
||||||
|
|
||||||
|
|
||||||
def log_changes(stats):
|
def log_changes(stats):
|
||||||
colors = [
|
colors = [
|
||||||
("modified", colorama.Fore.YELLOW,),
|
("modified", colorama.Fore.YELLOW,),
|
||||||
@@ -75,7 +52,11 @@ class CmdCheckout(CmdBase):
|
|||||||
stats = exc.stats
|
stats = exc.stats
|
||||||
|
|
||||||
if self.args.summary:
|
if self.args.summary:
|
||||||
log_summary(stats)
|
default_message = "No changes."
|
||||||
|
msg = get_summary(
|
||||||
|
sorted(stats.items(), key=operator.itemgetter(0))
|
||||||
|
)
|
||||||
|
logger.info(msg or default_message)
|
||||||
else:
|
else:
|
||||||
log_changes(stats)
|
log_changes(stats)
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dvc.command.base import append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
from dvc.command.base import CmdBase
|
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dvc.command.base import append_doc_link, CmdBaseNoRepo
|
from dvc.command.base import CmdBaseNoRepo, append_doc_link
|
||||||
from dvc.config import Config, ConfigError
|
from dvc.config import Config, ConfigError
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -50,21 +50,22 @@ class CmdConfig(CmdBaseNoRepo):
|
|||||||
|
|
||||||
|
|
||||||
parent_config_parser = argparse.ArgumentParser(add_help=False)
|
parent_config_parser = argparse.ArgumentParser(add_help=False)
|
||||||
parent_config_parser.add_argument(
|
level_group = parent_config_parser.add_mutually_exclusive_group()
|
||||||
|
level_group.add_argument(
|
||||||
"--global",
|
"--global",
|
||||||
dest="level",
|
dest="level",
|
||||||
action="store_const",
|
action="store_const",
|
||||||
const="global",
|
const="global",
|
||||||
help="Use global config.",
|
help="Use global config.",
|
||||||
)
|
)
|
||||||
parent_config_parser.add_argument(
|
level_group.add_argument(
|
||||||
"--system",
|
"--system",
|
||||||
dest="level",
|
dest="level",
|
||||||
action="store_const",
|
action="store_const",
|
||||||
const="system",
|
const="system",
|
||||||
help="Use system config.",
|
help="Use system config.",
|
||||||
)
|
)
|
||||||
parent_config_parser.add_argument(
|
level_group.add_argument(
|
||||||
"--local",
|
"--local",
|
||||||
dest="level",
|
dest="level",
|
||||||
action="store_const",
|
action="store_const",
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from dvc.command.base import CmdBaseNoRepo
|
from dvc.command.base import CmdBaseNoRepo, fix_subparsers
|
||||||
from dvc.command.base import fix_subparsers
|
|
||||||
|
|
||||||
|
|
||||||
class CmdDaemonBase(CmdBaseNoRepo):
|
class CmdDaemonBase(CmdBaseNoRepo):
|
||||||
@@ -15,9 +14,10 @@ class CmdDaemonUpdater(CmdDaemonBase):
|
|||||||
|
|
||||||
root_dir = Repo.find_root()
|
root_dir = Repo.find_root()
|
||||||
dvc_dir = os.path.join(root_dir, Repo.DVC_DIR)
|
dvc_dir = os.path.join(root_dir, Repo.DVC_DIR)
|
||||||
|
tmp_dir = os.path.join(dvc_dir, "tmp")
|
||||||
config = Config(dvc_dir, validate=False)
|
config = Config(dvc_dir, validate=False)
|
||||||
hardlink_lock = config.get("core", {}).get("hardlink_lock", False)
|
hardlink_lock = config.get("core", {}).get("hardlink_lock", False)
|
||||||
updater = Updater(dvc_dir, hardlink_lock=hardlink_lock)
|
updater = Updater(tmp_dir, hardlink_lock=hardlink_lock)
|
||||||
updater.fetch(detach=False)
|
updater.fetch(detach=False)
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@@ -0,0 +1,115 @@
|
|||||||
|
import argparse
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def _show_ascii(G):
|
||||||
|
from dvc.repo.graph import get_pipelines
|
||||||
|
from dvc.dagascii import draw
|
||||||
|
|
||||||
|
pipelines = get_pipelines(G)
|
||||||
|
|
||||||
|
ret = []
|
||||||
|
for pipeline in pipelines:
|
||||||
|
ret.append(draw(pipeline.nodes, pipeline.edges))
|
||||||
|
|
||||||
|
return "\n".join(ret)
|
||||||
|
|
||||||
|
|
||||||
|
def _show_dot(G):
|
||||||
|
import io
|
||||||
|
from networkx.drawing.nx_pydot import write_dot
|
||||||
|
|
||||||
|
dot_file = io.StringIO()
|
||||||
|
write_dot(G, dot_file)
|
||||||
|
return dot_file.getvalue()
|
||||||
|
|
||||||
|
|
||||||
|
def _build(G, target=None, full=False):
|
||||||
|
import networkx as nx
|
||||||
|
from dvc.repo.graph import get_pipeline, get_pipelines
|
||||||
|
|
||||||
|
if target:
|
||||||
|
H = get_pipeline(get_pipelines(G), target)
|
||||||
|
if not full:
|
||||||
|
descendants = nx.descendants(G, target)
|
||||||
|
descendants.add(target)
|
||||||
|
H.remove_nodes_from(set(G.nodes()) - descendants)
|
||||||
|
else:
|
||||||
|
H = G
|
||||||
|
|
||||||
|
def _relabel(stage):
|
||||||
|
return stage.addressing
|
||||||
|
|
||||||
|
return nx.relabel_nodes(H, _relabel, copy=False)
|
||||||
|
|
||||||
|
|
||||||
|
class CmdDAG(CmdBase):
|
||||||
|
def run(self):
|
||||||
|
try:
|
||||||
|
target = None
|
||||||
|
if self.args.target:
|
||||||
|
stages = self.repo.collect(self.args.target)
|
||||||
|
if len(stages) > 1:
|
||||||
|
logger.error(
|
||||||
|
f"'{self.args.target}' contains more than one stage "
|
||||||
|
"{stages}, please specify one stage"
|
||||||
|
)
|
||||||
|
return 1
|
||||||
|
target = stages[0]
|
||||||
|
|
||||||
|
G = _build(self.repo.graph, target=target, full=self.args.full,)
|
||||||
|
|
||||||
|
if self.args.dot:
|
||||||
|
logger.info(_show_dot(G))
|
||||||
|
else:
|
||||||
|
from dvc.utils.pager import pager
|
||||||
|
|
||||||
|
pager(_show_ascii(G))
|
||||||
|
|
||||||
|
return 0
|
||||||
|
except DvcException:
|
||||||
|
msg = "failed to show "
|
||||||
|
if self.args.target:
|
||||||
|
msg += f"a pipeline for '{target}'"
|
||||||
|
else:
|
||||||
|
msg += "pipelines"
|
||||||
|
logger.exception(msg)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
def add_parser(subparsers, parent_parser):
|
||||||
|
DAG_HELP = "Visualize DVC project DAG."
|
||||||
|
dag_parser = subparsers.add_parser(
|
||||||
|
"dag",
|
||||||
|
parents=[parent_parser],
|
||||||
|
description=append_doc_link(DAG_HELP, "dag"),
|
||||||
|
help=DAG_HELP,
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
)
|
||||||
|
dag_parser.add_argument(
|
||||||
|
"--dot",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Print DAG with .dot format.",
|
||||||
|
)
|
||||||
|
dag_parser.add_argument(
|
||||||
|
"--full",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help=(
|
||||||
|
"Show full DAG that the target belongs too, instead of "
|
||||||
|
"showing DAG consisting only of ancestors."
|
||||||
|
),
|
||||||
|
)
|
||||||
|
dag_parser.add_argument(
|
||||||
|
"target",
|
||||||
|
nargs="?",
|
||||||
|
help="Stage or output to show pipeline for (optional). "
|
||||||
|
"Finds all stages in the workspace by default.",
|
||||||
|
)
|
||||||
|
dag_parser.set_defaults(func=CmdDAG)
|
||||||
+54
-18
@@ -1,23 +1,25 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dvc.command.base import append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
from dvc.command.base import CmdBase
|
from dvc.command.checkout import log_changes
|
||||||
from dvc.command.checkout import log_summary
|
from dvc.exceptions import CheckoutError, DvcException
|
||||||
from dvc.exceptions import DvcException, CheckoutError
|
from dvc.utils.humanize import get_summary
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CmdDataBase(CmdBase):
|
class CmdDataBase(CmdBase):
|
||||||
@classmethod
|
def log_summary(self, stats):
|
||||||
def check_up_to_date(cls, processed_files_count):
|
default_msg = "Everything is up to date."
|
||||||
if processed_files_count == 0:
|
logger.info(get_summary(stats.items()) or default_msg)
|
||||||
logger.info("Everything is up to date.")
|
|
||||||
|
|
||||||
|
|
||||||
class CmdDataPull(CmdDataBase):
|
class CmdDataPull(CmdDataBase):
|
||||||
|
def log_summary(self, stats):
|
||||||
|
log_changes(stats)
|
||||||
|
super().log_summary(stats)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
stats = self.repo.pull(
|
stats = self.repo.pull(
|
||||||
@@ -30,14 +32,14 @@ class CmdDataPull(CmdDataBase):
|
|||||||
with_deps=self.args.with_deps,
|
with_deps=self.args.with_deps,
|
||||||
force=self.args.force,
|
force=self.args.force,
|
||||||
recursive=self.args.recursive,
|
recursive=self.args.recursive,
|
||||||
|
run_cache=self.args.run_cache,
|
||||||
)
|
)
|
||||||
log_summary(stats)
|
self.log_summary(stats)
|
||||||
except (CheckoutError, DvcException) as exc:
|
except (CheckoutError, DvcException) as exc:
|
||||||
log_summary(getattr(exc, "stats", {}))
|
self.log_summary(getattr(exc, "stats", {}))
|
||||||
logger.exception("failed to pull data from the cloud")
|
logger.exception("failed to pull data from the cloud")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
self.check_up_to_date(stats["downloaded"])
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
@@ -53,11 +55,12 @@ class CmdDataPush(CmdDataBase):
|
|||||||
all_commits=self.args.all_commits,
|
all_commits=self.args.all_commits,
|
||||||
with_deps=self.args.with_deps,
|
with_deps=self.args.with_deps,
|
||||||
recursive=self.args.recursive,
|
recursive=self.args.recursive,
|
||||||
|
run_cache=self.args.run_cache,
|
||||||
)
|
)
|
||||||
|
self.log_summary({"pushed": processed_files_count})
|
||||||
except DvcException:
|
except DvcException:
|
||||||
logger.exception("failed to push data to the cloud")
|
logger.exception("failed to push data to the cloud")
|
||||||
return 1
|
return 1
|
||||||
self.check_up_to_date(processed_files_count)
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
@@ -73,11 +76,12 @@ class CmdDataFetch(CmdDataBase):
|
|||||||
all_commits=self.args.all_commits,
|
all_commits=self.args.all_commits,
|
||||||
with_deps=self.args.with_deps,
|
with_deps=self.args.with_deps,
|
||||||
recursive=self.args.recursive,
|
recursive=self.args.recursive,
|
||||||
|
run_cache=self.args.run_cache,
|
||||||
)
|
)
|
||||||
|
self.log_summary({"fetched": processed_files_count})
|
||||||
except DvcException:
|
except DvcException:
|
||||||
logger.exception("failed to fetch data from the cloud")
|
logger.exception("failed to fetch data from the cloud")
|
||||||
return 1
|
return 1
|
||||||
self.check_up_to_date(processed_files_count)
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
@@ -85,24 +89,24 @@ def shared_parent_parser():
|
|||||||
from dvc.cli import get_parent_parser
|
from dvc.cli import get_parent_parser
|
||||||
|
|
||||||
# Parent parser used in pull/push/status
|
# Parent parser used in pull/push/status
|
||||||
shared_parent_parser = argparse.ArgumentParser(
|
parent_parser = argparse.ArgumentParser(
|
||||||
add_help=False, parents=[get_parent_parser()]
|
add_help=False, parents=[get_parent_parser()]
|
||||||
)
|
)
|
||||||
shared_parent_parser.add_argument(
|
parent_parser.add_argument(
|
||||||
"-j",
|
"-j",
|
||||||
"--jobs",
|
"--jobs",
|
||||||
type=int,
|
type=int,
|
||||||
help="Number of jobs to run simultaneously.",
|
help="Number of jobs to run simultaneously.",
|
||||||
metavar="<number>",
|
metavar="<number>",
|
||||||
)
|
)
|
||||||
shared_parent_parser.add_argument(
|
parent_parser.add_argument(
|
||||||
"targets",
|
"targets",
|
||||||
nargs="*",
|
nargs="*",
|
||||||
help="Limit command scope to these DVC-files. "
|
help="Limit command scope to these DVC-files. "
|
||||||
"Using -R, directories to search DVC-files in can also be given.",
|
"Using -R, directories to search DVC-files in can also be given.",
|
||||||
)
|
)
|
||||||
|
|
||||||
return shared_parent_parser
|
return parent_parser
|
||||||
|
|
||||||
|
|
||||||
def add_parser(subparsers, _parent_parser):
|
def add_parser(subparsers, _parent_parser):
|
||||||
@@ -162,6 +166,12 @@ def add_parser(subparsers, _parent_parser):
|
|||||||
default=False,
|
default=False,
|
||||||
help="Pull cache for subdirectories of the specified directory.",
|
help="Pull cache for subdirectories of the specified directory.",
|
||||||
)
|
)
|
||||||
|
pull_parser.add_argument(
|
||||||
|
"--run-cache",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help=argparse.SUPPRESS,
|
||||||
|
)
|
||||||
pull_parser.set_defaults(func=CmdDataPull)
|
pull_parser.set_defaults(func=CmdDataPull)
|
||||||
|
|
||||||
# Push
|
# Push
|
||||||
@@ -211,6 +221,12 @@ def add_parser(subparsers, _parent_parser):
|
|||||||
default=False,
|
default=False,
|
||||||
help="Push cache for subdirectories of specified directory.",
|
help="Push cache for subdirectories of specified directory.",
|
||||||
)
|
)
|
||||||
|
push_parser.add_argument(
|
||||||
|
"--run-cache",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help=argparse.SUPPRESS,
|
||||||
|
)
|
||||||
push_parser.set_defaults(func=CmdDataPush)
|
push_parser.set_defaults(func=CmdDataPush)
|
||||||
|
|
||||||
# Fetch
|
# Fetch
|
||||||
@@ -266,6 +282,12 @@ def add_parser(subparsers, _parent_parser):
|
|||||||
default=False,
|
default=False,
|
||||||
help="Fetch cache for subdirectories of specified directory.",
|
help="Fetch cache for subdirectories of specified directory.",
|
||||||
)
|
)
|
||||||
|
fetch_parser.add_argument(
|
||||||
|
"--run-cache",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help=argparse.SUPPRESS,
|
||||||
|
)
|
||||||
fetch_parser.set_defaults(func=CmdDataFetch)
|
fetch_parser.set_defaults(func=CmdDataFetch)
|
||||||
|
|
||||||
# Status
|
# Status
|
||||||
@@ -334,4 +356,18 @@ def add_parser(subparsers, _parent_parser):
|
|||||||
default=False,
|
default=False,
|
||||||
help="Show status for all dependencies of the specified target.",
|
help="Show status for all dependencies of the specified target.",
|
||||||
)
|
)
|
||||||
|
status_parser.add_argument(
|
||||||
|
"-R",
|
||||||
|
"--recursive",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Show status of all stages in the specified directory.",
|
||||||
|
)
|
||||||
|
status_parser.add_argument(
|
||||||
|
"--show-json",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Show status in JSON format.",
|
||||||
|
)
|
||||||
|
|
||||||
status_parser.set_defaults(func=CmdDataStatus)
|
status_parser.set_defaults(func=CmdDataStatus)
|
||||||
|
|||||||
@@ -2,11 +2,9 @@ import argparse
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import dvc.prompt as prompt
|
import dvc.prompt as prompt
|
||||||
from dvc.command.base import append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
from dvc.command.base import CmdBase
|
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+26
-9
@@ -8,10 +8,24 @@ import colorama
|
|||||||
from dvc.command.base import CmdBase, append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def _show_md(diff):
|
||||||
|
from dvc.utils.diff import table
|
||||||
|
|
||||||
|
rows = []
|
||||||
|
for status in ["added", "deleted", "modified"]:
|
||||||
|
entries = diff.get(status, [])
|
||||||
|
if not entries:
|
||||||
|
continue
|
||||||
|
paths = sorted([entry["path"] for entry in entries])
|
||||||
|
for path in paths:
|
||||||
|
rows.append([status, path])
|
||||||
|
|
||||||
|
return table(["Status", "Path"], rows, True)
|
||||||
|
|
||||||
|
|
||||||
class CmdDiff(CmdBase):
|
class CmdDiff(CmdBase):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _format(diff):
|
def _format(diff):
|
||||||
@@ -97,20 +111,17 @@ class CmdDiff(CmdBase):
|
|||||||
try:
|
try:
|
||||||
diff = self.repo.diff(self.args.a_rev, self.args.b_rev)
|
diff = self.repo.diff(self.args.a_rev, self.args.b_rev)
|
||||||
|
|
||||||
if not any(diff.values()):
|
|
||||||
return 0
|
|
||||||
|
|
||||||
if not self.args.show_hash:
|
if not self.args.show_hash:
|
||||||
for _, entries in diff.items():
|
for _, entries in diff.items():
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
del entry["hash"]
|
del entry["hash"]
|
||||||
|
|
||||||
if self.args.show_json:
|
if self.args.show_json:
|
||||||
res = json.dumps(diff)
|
logger.info(json.dumps(diff))
|
||||||
else:
|
elif self.args.show_md:
|
||||||
res = self._format(diff)
|
logger.info(_show_md(diff))
|
||||||
|
elif diff:
|
||||||
logger.info(res)
|
logger.info(self._format(diff))
|
||||||
|
|
||||||
except DvcException:
|
except DvcException:
|
||||||
logger.exception("failed to get diff")
|
logger.exception("failed to get diff")
|
||||||
@@ -153,4 +164,10 @@ def add_parser(subparsers, parent_parser):
|
|||||||
action="store_true",
|
action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
)
|
)
|
||||||
|
diff_parser.add_argument(
|
||||||
|
"--show-md",
|
||||||
|
help="Show tabulated output in the Markdown format (GFM).",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
)
|
||||||
diff_parser.set_defaults(func=CmdDiff)
|
diff_parser.set_defaults(func=CmdDiff)
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import argparse
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class CmdFreezeBase(CmdBase):
|
||||||
|
def _run(self, func, name):
|
||||||
|
ret = 0
|
||||||
|
for target in self.args.targets:
|
||||||
|
try:
|
||||||
|
func(target)
|
||||||
|
except DvcException:
|
||||||
|
logger.exception(f"failed to {name} '{target}'")
|
||||||
|
ret = 1
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
class CmdFreeze(CmdFreezeBase):
|
||||||
|
def run(self):
|
||||||
|
return self._run(self.repo.freeze, "freeze")
|
||||||
|
|
||||||
|
|
||||||
|
class CmdUnfreeze(CmdFreezeBase):
|
||||||
|
def run(self):
|
||||||
|
return self._run(self.repo.unfreeze, "unfreeze")
|
||||||
|
|
||||||
|
|
||||||
|
def add_parser(subparsers, parent_parser):
|
||||||
|
FREEZE_HELP = "Freeze DVC-files."
|
||||||
|
freeze_parser = subparsers.add_parser(
|
||||||
|
"freeze",
|
||||||
|
parents=[parent_parser],
|
||||||
|
description=append_doc_link(FREEZE_HELP, "freeze"),
|
||||||
|
help=FREEZE_HELP,
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
)
|
||||||
|
freeze_parser.add_argument(
|
||||||
|
"targets", nargs="+", help="DVC-files to freeze."
|
||||||
|
)
|
||||||
|
freeze_parser.set_defaults(func=CmdFreeze)
|
||||||
|
|
||||||
|
UNFREEZE_HELP = "Unfreeze DVC-files."
|
||||||
|
unfreeze_parser = subparsers.add_parser(
|
||||||
|
"unfreeze",
|
||||||
|
parents=[parent_parser],
|
||||||
|
description=append_doc_link(UNFREEZE_HELP, "unfreeze"),
|
||||||
|
help=UNFREEZE_HELP,
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
)
|
||||||
|
unfreeze_parser.add_argument(
|
||||||
|
"targets", nargs="+", help="DVC-files to unfreeze."
|
||||||
|
)
|
||||||
|
unfreeze_parser.set_defaults(func=CmdUnfreeze)
|
||||||
+3
-5
@@ -3,9 +3,7 @@ import logging
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import dvc.prompt as prompt
|
import dvc.prompt as prompt
|
||||||
from dvc.command.base import append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
from dvc.command.base import CmdBase
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -23,7 +21,7 @@ class CmdGC(CmdBase):
|
|||||||
|
|
||||||
msg = "This will remove all cache except items used in "
|
msg = "This will remove all cache except items used in "
|
||||||
|
|
||||||
msg += "the working tree"
|
msg += "the workspace"
|
||||||
if self.args.all_commits:
|
if self.args.all_commits:
|
||||||
msg += " and all git commits"
|
msg += " and all git commits"
|
||||||
elif self.args.all_branches and self.args.all_tags:
|
elif self.args.all_branches and self.args.all_tags:
|
||||||
@@ -79,7 +77,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"--workspace",
|
"--workspace",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
help="Keep data files used in the current workspace (working tree).",
|
help="Keep data files used in the current workspace.",
|
||||||
)
|
)
|
||||||
gc_parser.add_argument(
|
gc_parser.add_argument(
|
||||||
"-a",
|
"-a",
|
||||||
|
|||||||
+1
-2
@@ -1,10 +1,9 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from .base import append_doc_link
|
|
||||||
from .base import CmdBaseNoRepo
|
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
|
from .base import CmdBaseNoRepo, append_doc_link
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from .base import append_doc_link
|
|
||||||
from .base import CmdBaseNoRepo
|
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
|
from .base import CmdBaseNoRepo, append_doc_link
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -17,7 +16,7 @@ class CmdGetUrl(CmdBaseNoRepo):
|
|||||||
Repo.get_url(self.args.url, out=self.args.out)
|
Repo.get_url(self.args.url, out=self.args.out)
|
||||||
return 0
|
return 0
|
||||||
except DvcException:
|
except DvcException:
|
||||||
logger.exception("failed to get '{}'".format(self.args.url))
|
logger.exception(f"failed to get '{self.args.url}'")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -1,11 +1,9 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dvc.command.base import append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
from dvc.command.base import CmdBase
|
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dvc.command.base import append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
from dvc.command.base import CmdBase
|
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -59,7 +57,6 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"out", nargs="?", help="Destination path to put files to."
|
"out", nargs="?", help="Destination path to put files to."
|
||||||
)
|
)
|
||||||
import_parser.add_argument(
|
import_parser.add_argument(
|
||||||
"-f",
|
|
||||||
"--file",
|
"--file",
|
||||||
help="Specify name of the DVC-file this command will generate.",
|
help="Specify name of the DVC-file this command will generate.",
|
||||||
metavar="<filename>",
|
metavar="<filename>",
|
||||||
|
|||||||
+1
-3
@@ -1,9 +1,7 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dvc.command.base import append_doc_link
|
from dvc.command.base import CmdBaseNoRepo, append_doc_link
|
||||||
from dvc.command.base import CmdBaseNoRepo
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dvc.command.base import append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
from dvc.command.base import CmdBase
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
import argparse
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from dvc.command.base import append_doc_link
|
|
||||||
from dvc.command.base import CmdBase
|
|
||||||
from dvc.exceptions import DvcException
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class CmdLockBase(CmdBase):
|
|
||||||
def _run(self, unlock):
|
|
||||||
for target in self.args.targets:
|
|
||||||
try:
|
|
||||||
self.repo.lock_stage(target, unlock=unlock)
|
|
||||||
except DvcException:
|
|
||||||
logger.exception(
|
|
||||||
"failed to {}lock '{}'".format(
|
|
||||||
"un" if unlock else "", target
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
return 1
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
class CmdLock(CmdLockBase):
|
|
||||||
def run(self):
|
|
||||||
return self._run(False)
|
|
||||||
|
|
||||||
|
|
||||||
class CmdUnlock(CmdLockBase):
|
|
||||||
def run(self):
|
|
||||||
return self._run(True)
|
|
||||||
|
|
||||||
|
|
||||||
def add_parser(subparsers, parent_parser):
|
|
||||||
LOCK_HELP = "Lock DVC-files."
|
|
||||||
lock_parser = subparsers.add_parser(
|
|
||||||
"lock",
|
|
||||||
parents=[parent_parser],
|
|
||||||
description=append_doc_link(LOCK_HELP, "lock"),
|
|
||||||
help=LOCK_HELP,
|
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
||||||
)
|
|
||||||
lock_parser.add_argument("targets", nargs="+", help="DVC-files to lock.")
|
|
||||||
lock_parser.set_defaults(func=CmdLock)
|
|
||||||
|
|
||||||
UNLOCK_HELP = "Unlock DVC-files."
|
|
||||||
unlock_parser = subparsers.add_parser(
|
|
||||||
"unlock",
|
|
||||||
parents=[parent_parser],
|
|
||||||
description=append_doc_link(UNLOCK_HELP, "unlock"),
|
|
||||||
help=UNLOCK_HELP,
|
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
||||||
)
|
|
||||||
unlock_parser.add_argument(
|
|
||||||
"targets", nargs="+", help="DVC-files to unlock."
|
|
||||||
)
|
|
||||||
unlock_parser.set_defaults(func=CmdUnlock)
|
|
||||||
@@ -2,12 +2,10 @@ import argparse
|
|||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from dvc.command.base import append_doc_link
|
from dvc.command.base import CmdBaseNoRepo, append_doc_link
|
||||||
from dvc.command.base import CmdBaseNoRepo
|
|
||||||
from dvc.command.ls.ls_colors import LsColors
|
from dvc.command.ls.ls_colors import LsColors
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -33,14 +31,14 @@ class CmdList(CmdBaseNoRepo):
|
|||||||
self.args.path,
|
self.args.path,
|
||||||
rev=self.args.rev,
|
rev=self.args.rev,
|
||||||
recursive=self.args.recursive,
|
recursive=self.args.recursive,
|
||||||
outs_only=self.args.outs_only,
|
dvc_only=self.args.dvc_only,
|
||||||
)
|
)
|
||||||
if entries:
|
if entries:
|
||||||
entries = _prettify(entries, sys.stdout.isatty())
|
entries = _prettify(entries, sys.stdout.isatty())
|
||||||
logger.info("\n".join(entries))
|
logger.info("\n".join(entries))
|
||||||
return 0
|
return 0
|
||||||
except DvcException:
|
except DvcException:
|
||||||
logger.exception("failed to list '{}'".format(self.args.url))
|
logger.exception(f"failed to list '{self.args.url}'")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
@@ -64,7 +62,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
help="Recursively list files.",
|
help="Recursively list files.",
|
||||||
)
|
)
|
||||||
list_parser.add_argument(
|
list_parser.add_argument(
|
||||||
"--outs-only", action="store_true", help="Show only DVC outputs."
|
"--dvc-only", action="store_true", help="Show only DVC outputs."
|
||||||
)
|
)
|
||||||
list_parser.add_argument(
|
list_parser.add_argument(
|
||||||
"--rev",
|
"--rev",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
class LsColors(object):
|
class LsColors:
|
||||||
default = "rs=0:di=01;34:ex=01;32"
|
default = "rs=0:di=01;34:ex=01;32"
|
||||||
|
|
||||||
def __init__(self, lscolors=None):
|
def __init__(self, lscolors=None):
|
||||||
@@ -45,4 +45,4 @@ class LsColors(object):
|
|||||||
if not val:
|
if not val:
|
||||||
return text
|
return text
|
||||||
rs = self._codes.get("rs", 0)
|
rs = self._codes.get("rs", 0)
|
||||||
return "\033[{}m{}\033[{}m".format(val, text, rs)
|
return f"\033[{val}m{text}\033[{rs}m"
|
||||||
|
|||||||
+86
-79
@@ -1,16 +1,15 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dvc.command.base import append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link, fix_subparsers
|
||||||
from dvc.command.base import CmdBase
|
from dvc.exceptions import BadMetricError, DvcException
|
||||||
from dvc.command.base import fix_subparsers
|
|
||||||
from dvc.exceptions import BadMetricError
|
|
||||||
from dvc.exceptions import DvcException
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_PRECISION = 5
|
||||||
|
|
||||||
|
|
||||||
def show_metrics(
|
def show_metrics(
|
||||||
metrics, all_branches=False, all_tags=False, all_commits=False
|
metrics, all_branches=False, all_tags=False, all_commits=False
|
||||||
):
|
):
|
||||||
@@ -23,16 +22,16 @@ def show_metrics(
|
|||||||
|
|
||||||
for branch, val in metrics.items():
|
for branch, val in metrics.items():
|
||||||
if all_branches or all_tags or all_commits:
|
if all_branches or all_tags or all_commits:
|
||||||
logger.info("{branch}:".format(branch=branch))
|
logger.info(f"{branch}:")
|
||||||
|
|
||||||
for fname, metric in val.items():
|
for fname, metric in val.items():
|
||||||
if not isinstance(metric, dict):
|
if not isinstance(metric, dict):
|
||||||
logger.info("\t{}: {}".format(fname, str(metric)))
|
logger.info("\t{}: {}".format(fname, str(metric)))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
logger.info("\t{}:".format(fname))
|
logger.info(f"\t{fname}:")
|
||||||
for key, value in flatten(format_dict(metric), ".").items():
|
for key, value in flatten(format_dict(metric), ".").items():
|
||||||
logger.info("\t\t{}: {}".format(key, value))
|
logger.info(f"\t\t{key}: {value}")
|
||||||
|
|
||||||
if missing:
|
if missing:
|
||||||
raise BadMetricError(missing)
|
raise BadMetricError(missing)
|
||||||
@@ -67,49 +66,41 @@ class CmdMetricsShow(CmdBase):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
class CmdMetricsAdd(CmdBase):
|
def _show_diff(diff, markdown=False, no_path=False, old=False, precision=None):
|
||||||
def run(self):
|
|
||||||
try:
|
|
||||||
self.repo.metrics.add(self.args.path)
|
|
||||||
except DvcException:
|
|
||||||
msg = "failed to add metric file '{}'".format(self.args.path)
|
|
||||||
logger.exception(msg)
|
|
||||||
return 1
|
|
||||||
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
class CmdMetricsRemove(CmdBase):
|
|
||||||
def run(self):
|
|
||||||
try:
|
|
||||||
self.repo.metrics.remove(self.args.path)
|
|
||||||
except DvcException:
|
|
||||||
msg = "failed to remove metric file '{}'".format(self.args.path)
|
|
||||||
logger.exception(msg)
|
|
||||||
return 1
|
|
||||||
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
def _show_diff(diff):
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
from dvc.utils.diff import table
|
from dvc.utils.diff import table
|
||||||
|
|
||||||
|
if precision is None:
|
||||||
|
precision = DEFAULT_PRECISION
|
||||||
|
|
||||||
|
def _round(val):
|
||||||
|
if isinstance(val, float):
|
||||||
|
return round(val, precision)
|
||||||
|
|
||||||
|
return val
|
||||||
|
|
||||||
rows = []
|
rows = []
|
||||||
for fname, mdiff in diff.items():
|
for fname, mdiff in diff.items():
|
||||||
sorted_mdiff = OrderedDict(sorted(mdiff.items()))
|
sorted_mdiff = OrderedDict(sorted(mdiff.items()))
|
||||||
for metric, change in sorted_mdiff.items():
|
for metric, change in sorted_mdiff.items():
|
||||||
rows.append(
|
row = [] if no_path else [fname]
|
||||||
[
|
row.append(metric)
|
||||||
fname,
|
if old:
|
||||||
metric,
|
row.append(_round(change.get("old")))
|
||||||
change["new"],
|
row.append(_round(change["new"]))
|
||||||
change.get("diff", "diff not supported"),
|
row.append(_round(change.get("diff", "diff not supported")))
|
||||||
]
|
rows.append(row)
|
||||||
)
|
|
||||||
|
|
||||||
return table(["Path", "Metric", "Value", "Change"], rows)
|
header = [] if no_path else ["Path"]
|
||||||
|
header.append("Metric")
|
||||||
|
if old:
|
||||||
|
header.extend(["Old", "New"])
|
||||||
|
else:
|
||||||
|
header.append("Value")
|
||||||
|
header.append("Change")
|
||||||
|
|
||||||
|
return table(header, rows, markdown)
|
||||||
|
|
||||||
|
|
||||||
class CmdMetricsDiff(CmdBase):
|
class CmdMetricsDiff(CmdBase):
|
||||||
@@ -128,7 +119,13 @@ class CmdMetricsDiff(CmdBase):
|
|||||||
|
|
||||||
logger.info(json.dumps(diff))
|
logger.info(json.dumps(diff))
|
||||||
else:
|
else:
|
||||||
table = _show_diff(diff)
|
table = _show_diff(
|
||||||
|
diff,
|
||||||
|
self.args.show_md,
|
||||||
|
self.args.no_path,
|
||||||
|
self.args.old,
|
||||||
|
precision=self.args.precision,
|
||||||
|
)
|
||||||
if table:
|
if table:
|
||||||
logger.info(table)
|
logger.info(table)
|
||||||
|
|
||||||
@@ -140,7 +137,7 @@ class CmdMetricsDiff(CmdBase):
|
|||||||
|
|
||||||
|
|
||||||
def add_parser(subparsers, parent_parser):
|
def add_parser(subparsers, parent_parser):
|
||||||
METRICS_HELP = "Commands to add, manage, collect, and display metrics."
|
METRICS_HELP = "Commands to display and compare metrics."
|
||||||
|
|
||||||
metrics_parser = subparsers.add_parser(
|
metrics_parser = subparsers.add_parser(
|
||||||
"metrics",
|
"metrics",
|
||||||
@@ -157,17 +154,6 @@ def add_parser(subparsers, parent_parser):
|
|||||||
|
|
||||||
fix_subparsers(metrics_subparsers)
|
fix_subparsers(metrics_subparsers)
|
||||||
|
|
||||||
METRICS_ADD_HELP = "Mark a DVC-tracked file as a metric."
|
|
||||||
metrics_add_parser = metrics_subparsers.add_parser(
|
|
||||||
"add",
|
|
||||||
parents=[parent_parser],
|
|
||||||
description=append_doc_link(METRICS_ADD_HELP, "metrics/add"),
|
|
||||||
help=METRICS_ADD_HELP,
|
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
||||||
)
|
|
||||||
metrics_add_parser.add_argument("path", help="Path to a metric file.")
|
|
||||||
metrics_add_parser.set_defaults(func=CmdMetricsAdd)
|
|
||||||
|
|
||||||
METRICS_SHOW_HELP = "Print metrics, with optional formatting."
|
METRICS_SHOW_HELP = "Print metrics, with optional formatting."
|
||||||
metrics_show_parser = metrics_subparsers.add_parser(
|
metrics_show_parser = metrics_subparsers.add_parser(
|
||||||
"show",
|
"show",
|
||||||
@@ -179,7 +165,10 @@ def add_parser(subparsers, parent_parser):
|
|||||||
metrics_show_parser.add_argument(
|
metrics_show_parser.add_argument(
|
||||||
"targets",
|
"targets",
|
||||||
nargs="*",
|
nargs="*",
|
||||||
help="Metric files or directories (see -R) to show",
|
help=(
|
||||||
|
"Limit command scope to these metric files. Using -R, "
|
||||||
|
"directories to search metric files in can also be given."
|
||||||
|
),
|
||||||
)
|
)
|
||||||
metrics_show_parser.add_argument(
|
metrics_show_parser.add_argument(
|
||||||
"-a",
|
"-a",
|
||||||
@@ -201,6 +190,12 @@ def add_parser(subparsers, parent_parser):
|
|||||||
default=False,
|
default=False,
|
||||||
help="Show metrics for all commits.",
|
help="Show metrics for all commits.",
|
||||||
)
|
)
|
||||||
|
metrics_show_parser.add_argument(
|
||||||
|
"--show-json",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Show output in JSON format.",
|
||||||
|
)
|
||||||
metrics_show_parser.add_argument(
|
metrics_show_parser.add_argument(
|
||||||
"-R",
|
"-R",
|
||||||
"--recursive",
|
"--recursive",
|
||||||
@@ -211,16 +206,12 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"metric files."
|
"metric files."
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
metrics_show_parser.add_argument(
|
|
||||||
"--show-json",
|
|
||||||
action="store_true",
|
|
||||||
default=False,
|
|
||||||
help="Show output in JSON format.",
|
|
||||||
)
|
|
||||||
metrics_show_parser.set_defaults(func=CmdMetricsShow)
|
metrics_show_parser.set_defaults(func=CmdMetricsShow)
|
||||||
|
|
||||||
METRICS_DIFF_HELP = "Show changes in metrics between commits"
|
METRICS_DIFF_HELP = (
|
||||||
" in the DVC repository, or between a commit and the workspace."
|
"Show changes in metrics between commits in the DVC repository, or "
|
||||||
|
"between a commit and the workspace."
|
||||||
|
)
|
||||||
metrics_diff_parser = metrics_subparsers.add_parser(
|
metrics_diff_parser = metrics_subparsers.add_parser(
|
||||||
"diff",
|
"diff",
|
||||||
parents=[parent_parser],
|
parents=[parent_parser],
|
||||||
@@ -234,14 +225,14 @@ def add_parser(subparsers, parent_parser):
|
|||||||
metrics_diff_parser.add_argument(
|
metrics_diff_parser.add_argument(
|
||||||
"b_rev",
|
"b_rev",
|
||||||
nargs="?",
|
nargs="?",
|
||||||
help=("New Git commit to compare (defaults to the current workspace)"),
|
help="New Git commit to compare (defaults to the current workspace)",
|
||||||
)
|
)
|
||||||
metrics_diff_parser.add_argument(
|
metrics_diff_parser.add_argument(
|
||||||
"--targets",
|
"--targets",
|
||||||
nargs="*",
|
nargs="*",
|
||||||
help=(
|
help=(
|
||||||
"Metric files or directories (see -R) to show diff for. "
|
"Limit command scope to these metric files. Using -R, "
|
||||||
"Shows diff for all metric files by default."
|
"directories to search metric files in can also be given."
|
||||||
),
|
),
|
||||||
metavar="<paths>",
|
metavar="<paths>",
|
||||||
)
|
)
|
||||||
@@ -267,15 +258,31 @@ def add_parser(subparsers, parent_parser):
|
|||||||
default=False,
|
default=False,
|
||||||
help="Show output in JSON format.",
|
help="Show output in JSON format.",
|
||||||
)
|
)
|
||||||
metrics_diff_parser.set_defaults(func=CmdMetricsDiff)
|
metrics_diff_parser.add_argument(
|
||||||
|
"--show-md",
|
||||||
METRICS_REMOVE_HELP = "Remove metric mark on a DVC-tracked file."
|
action="store_true",
|
||||||
metrics_remove_parser = metrics_subparsers.add_parser(
|
default=False,
|
||||||
"remove",
|
help="Show tabulated output in the Markdown format (GFM).",
|
||||||
parents=[parent_parser],
|
|
||||||
description=append_doc_link(METRICS_REMOVE_HELP, "metrics/remove"),
|
|
||||||
help=METRICS_REMOVE_HELP,
|
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
||||||
)
|
)
|
||||||
metrics_remove_parser.add_argument("path", help="Path to a metric file.")
|
metrics_diff_parser.add_argument(
|
||||||
metrics_remove_parser.set_defaults(func=CmdMetricsRemove)
|
"--old",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Show old metric value.",
|
||||||
|
)
|
||||||
|
metrics_diff_parser.add_argument(
|
||||||
|
"--no-path",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Don't show metric path.",
|
||||||
|
)
|
||||||
|
metrics_diff_parser.add_argument(
|
||||||
|
"--precision",
|
||||||
|
type=int,
|
||||||
|
help=(
|
||||||
|
"Round metrics to `n` digits precision after the decimal point. "
|
||||||
|
f"Rounds to {DEFAULT_PRECISION} digits by default."
|
||||||
|
),
|
||||||
|
metavar="<n>",
|
||||||
|
)
|
||||||
|
metrics_diff_parser.set_defaults(func=CmdMetricsDiff)
|
||||||
|
|||||||
+1
-3
@@ -1,11 +1,9 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dvc.command.base import append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
from dvc.command.base import CmdBase
|
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+26
-9
@@ -1,27 +1,32 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
from dvc.command.base import append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link, fix_subparsers
|
||||||
from dvc.command.base import CmdBase
|
|
||||||
from dvc.command.base import fix_subparsers
|
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _show_diff(diff):
|
def _show_diff(diff, markdown=False, no_path=False):
|
||||||
from dvc.utils.diff import table
|
from dvc.utils.diff import table
|
||||||
|
|
||||||
rows = []
|
rows = []
|
||||||
for fname, pdiff in diff.items():
|
for fname, pdiff in diff.items():
|
||||||
sorted_pdiff = OrderedDict(sorted(pdiff.items()))
|
sorted_pdiff = OrderedDict(sorted(pdiff.items()))
|
||||||
for param, change in sorted_pdiff.items():
|
for param, change in sorted_pdiff.items():
|
||||||
rows.append([fname, param, change["old"], change["new"]])
|
row = [] if no_path else [fname]
|
||||||
|
row.append(param)
|
||||||
|
row.append(change["old"])
|
||||||
|
row.append(change["new"])
|
||||||
|
rows.append(row)
|
||||||
|
|
||||||
return table(["Path", "Param", "Old", "New"], rows)
|
header = [] if no_path else ["Path"]
|
||||||
|
header.append("Param")
|
||||||
|
header.append("Old")
|
||||||
|
header.append("New")
|
||||||
|
|
||||||
|
return table(header, rows, markdown)
|
||||||
|
|
||||||
|
|
||||||
class CmdParamsDiff(CmdBase):
|
class CmdParamsDiff(CmdBase):
|
||||||
@@ -38,7 +43,7 @@ class CmdParamsDiff(CmdBase):
|
|||||||
|
|
||||||
logger.info(json.dumps(diff))
|
logger.info(json.dumps(diff))
|
||||||
else:
|
else:
|
||||||
table = _show_diff(diff)
|
table = _show_diff(diff, self.args.show_md, self.args.no_path)
|
||||||
if table:
|
if table:
|
||||||
logger.info(table)
|
logger.info(table)
|
||||||
|
|
||||||
@@ -98,4 +103,16 @@ def add_parser(subparsers, parent_parser):
|
|||||||
default=False,
|
default=False,
|
||||||
help="Show output in JSON format.",
|
help="Show output in JSON format.",
|
||||||
)
|
)
|
||||||
|
params_diff_parser.add_argument(
|
||||||
|
"--show-md",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Show tabulated output in the Markdown format (GFM).",
|
||||||
|
)
|
||||||
|
params_diff_parser.add_argument(
|
||||||
|
"--no-path",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Don't show params path.",
|
||||||
|
)
|
||||||
params_diff_parser.set_defaults(func=CmdParamsDiff)
|
params_diff_parser.set_defaults(func=CmdParamsDiff)
|
||||||
|
|||||||
@@ -1,245 +0,0 @@
|
|||||||
import argparse
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from dvc.command.base import CmdBase, append_doc_link, fix_subparsers
|
|
||||||
from dvc.exceptions import DvcException
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class CmdPipelineShow(CmdBase):
|
|
||||||
def _show(self, target, commands, outs, locked):
|
|
||||||
import networkx
|
|
||||||
from dvc import dvcfile
|
|
||||||
from dvc.utils import parse_target
|
|
||||||
|
|
||||||
path, name = parse_target(target)
|
|
||||||
stage = dvcfile.Dvcfile(self.repo, path).stages[name]
|
|
||||||
G = self.repo.graph
|
|
||||||
stages = networkx.dfs_postorder_nodes(G, stage)
|
|
||||||
if locked:
|
|
||||||
stages = [s for s in stages if s.locked]
|
|
||||||
|
|
||||||
for stage in stages:
|
|
||||||
if commands:
|
|
||||||
if stage.cmd is None:
|
|
||||||
continue
|
|
||||||
logger.info(stage.cmd)
|
|
||||||
elif outs:
|
|
||||||
for out in stage.outs:
|
|
||||||
logger.info(str(out))
|
|
||||||
else:
|
|
||||||
logger.info(stage.addressing)
|
|
||||||
|
|
||||||
def _build_graph(self, target, commands=False, outs=False):
|
|
||||||
import networkx
|
|
||||||
from dvc import dvcfile
|
|
||||||
from dvc.repo.graph import get_pipeline
|
|
||||||
from dvc.utils import parse_target
|
|
||||||
|
|
||||||
path, name = parse_target(target)
|
|
||||||
target_stage = dvcfile.Dvcfile(self.repo, path).stages[name]
|
|
||||||
G = get_pipeline(self.repo.pipelines, target_stage)
|
|
||||||
|
|
||||||
nodes = set()
|
|
||||||
for stage in networkx.dfs_preorder_nodes(G, target_stage):
|
|
||||||
if commands:
|
|
||||||
if stage.cmd is None:
|
|
||||||
continue
|
|
||||||
nodes.add(stage.cmd)
|
|
||||||
elif outs:
|
|
||||||
for out in stage.outs:
|
|
||||||
nodes.add(str(out))
|
|
||||||
else:
|
|
||||||
nodes.add(stage.addressing)
|
|
||||||
|
|
||||||
edges = []
|
|
||||||
for from_stage, to_stage in networkx.edge_dfs(G, target_stage):
|
|
||||||
if commands:
|
|
||||||
if to_stage.cmd is None:
|
|
||||||
continue
|
|
||||||
edges.append((from_stage.cmd, to_stage.cmd))
|
|
||||||
elif outs:
|
|
||||||
for from_out in from_stage.outs:
|
|
||||||
for to_out in to_stage.outs:
|
|
||||||
edges.append((str(from_out), str(to_out)))
|
|
||||||
else:
|
|
||||||
edges.append((from_stage.addressing, to_stage.addressing))
|
|
||||||
|
|
||||||
return list(nodes), edges, networkx.is_tree(G)
|
|
||||||
|
|
||||||
def _show_ascii(self, target, commands, outs):
|
|
||||||
from dvc.dagascii import draw
|
|
||||||
|
|
||||||
nodes, edges, _ = self._build_graph(target, commands, outs)
|
|
||||||
|
|
||||||
if not nodes:
|
|
||||||
return
|
|
||||||
|
|
||||||
draw(nodes, edges)
|
|
||||||
|
|
||||||
def _show_dependencies_tree(self, target, commands, outs):
|
|
||||||
from treelib import Tree
|
|
||||||
|
|
||||||
nodes, edges, is_tree = self._build_graph(target, commands, outs)
|
|
||||||
if not nodes:
|
|
||||||
return
|
|
||||||
if not is_tree:
|
|
||||||
raise DvcException(
|
|
||||||
"DAG is not a tree, can not print it in tree-structure way, "
|
|
||||||
"please use --ascii instead"
|
|
||||||
)
|
|
||||||
|
|
||||||
tree = Tree()
|
|
||||||
tree.create_node(target, target) # Root node
|
|
||||||
observe_list = [target]
|
|
||||||
while len(observe_list) > 0:
|
|
||||||
current_root = observe_list[0]
|
|
||||||
for edge in edges:
|
|
||||||
if edge[0] == current_root:
|
|
||||||
tree.create_node(edge[1], edge[1], parent=current_root)
|
|
||||||
observe_list.append(edge[1])
|
|
||||||
observe_list.pop(0)
|
|
||||||
tree.show()
|
|
||||||
|
|
||||||
def _write_dot(self, target, commands, outs):
|
|
||||||
import io
|
|
||||||
import networkx
|
|
||||||
from networkx.drawing.nx_pydot import write_dot
|
|
||||||
|
|
||||||
_, edges, _ = self._build_graph(target, commands, outs)
|
|
||||||
edges = [edge[::-1] for edge in edges]
|
|
||||||
|
|
||||||
simple_g = networkx.DiGraph()
|
|
||||||
simple_g.add_edges_from(edges)
|
|
||||||
|
|
||||||
dot_file = io.StringIO()
|
|
||||||
write_dot(simple_g, dot_file)
|
|
||||||
logger.info(dot_file.getvalue())
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
if not self.args.targets:
|
|
||||||
self.args.targets = self.default_targets
|
|
||||||
|
|
||||||
for target in self.args.targets:
|
|
||||||
try:
|
|
||||||
if self.args.ascii:
|
|
||||||
self._show_ascii(
|
|
||||||
target, self.args.commands, self.args.outs
|
|
||||||
)
|
|
||||||
elif self.args.dot:
|
|
||||||
self._write_dot(target, self.args.commands, self.args.outs)
|
|
||||||
elif self.args.tree:
|
|
||||||
self._show_dependencies_tree(
|
|
||||||
target, self.args.commands, self.args.outs
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
self._show(
|
|
||||||
target,
|
|
||||||
self.args.commands,
|
|
||||||
self.args.outs,
|
|
||||||
self.args.locked,
|
|
||||||
)
|
|
||||||
except DvcException:
|
|
||||||
msg = "failed to show pipeline for '{}'".format(target)
|
|
||||||
logger.exception(msg)
|
|
||||||
return 1
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
class CmdPipelineList(CmdBase):
|
|
||||||
def run(self):
|
|
||||||
pipelines = self.repo.pipelines
|
|
||||||
for pipeline in pipelines:
|
|
||||||
for stage in pipeline:
|
|
||||||
logger.info(stage.addressing)
|
|
||||||
if len(pipeline) != 0:
|
|
||||||
logger.info("=" * 80)
|
|
||||||
logger.info("{} pipelines total".format(len(pipelines)))
|
|
||||||
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
def add_parser(subparsers, parent_parser):
|
|
||||||
PIPELINE_HELP = "Manage pipelines."
|
|
||||||
pipeline_parser = subparsers.add_parser(
|
|
||||||
"pipeline",
|
|
||||||
parents=[parent_parser],
|
|
||||||
description=append_doc_link(PIPELINE_HELP, "pipeline"),
|
|
||||||
help=PIPELINE_HELP,
|
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
||||||
)
|
|
||||||
|
|
||||||
pipeline_subparsers = pipeline_parser.add_subparsers(
|
|
||||||
dest="cmd",
|
|
||||||
help="Use `dvc pipeline CMD --help` for command-specific help.",
|
|
||||||
)
|
|
||||||
|
|
||||||
fix_subparsers(pipeline_subparsers)
|
|
||||||
|
|
||||||
PIPELINE_LIST_HELP = "List connected groups of stages (pipelines)."
|
|
||||||
pipeline_list_parser = pipeline_subparsers.add_parser(
|
|
||||||
"list",
|
|
||||||
parents=[parent_parser],
|
|
||||||
description=append_doc_link(PIPELINE_LIST_HELP, "pipeline/list"),
|
|
||||||
help=PIPELINE_LIST_HELP,
|
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
||||||
)
|
|
||||||
pipeline_list_parser.set_defaults(func=CmdPipelineList)
|
|
||||||
|
|
||||||
PIPELINE_SHOW_HELP = "Show stages in a pipeline."
|
|
||||||
pipeline_show_parser = pipeline_subparsers.add_parser(
|
|
||||||
"show",
|
|
||||||
parents=[parent_parser],
|
|
||||||
description=append_doc_link(PIPELINE_SHOW_HELP, "pipeline/show"),
|
|
||||||
help=PIPELINE_SHOW_HELP,
|
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
||||||
)
|
|
||||||
pipeline_show_group = pipeline_show_parser.add_mutually_exclusive_group()
|
|
||||||
pipeline_show_group.add_argument(
|
|
||||||
"-c",
|
|
||||||
"--commands",
|
|
||||||
action="store_true",
|
|
||||||
default=False,
|
|
||||||
help="Print commands instead of paths to DVC-files.",
|
|
||||||
)
|
|
||||||
pipeline_show_group.add_argument(
|
|
||||||
"-o",
|
|
||||||
"--outs",
|
|
||||||
action="store_true",
|
|
||||||
default=False,
|
|
||||||
help="Print output files instead of paths to DVC-files.",
|
|
||||||
)
|
|
||||||
pipeline_show_parser.add_argument(
|
|
||||||
"-l",
|
|
||||||
"--locked",
|
|
||||||
action="store_true",
|
|
||||||
default=False,
|
|
||||||
help="Print locked DVC stages",
|
|
||||||
)
|
|
||||||
pipeline_show_parser.add_argument(
|
|
||||||
"--ascii",
|
|
||||||
action="store_true",
|
|
||||||
default=False,
|
|
||||||
help="Output DAG as ASCII.",
|
|
||||||
)
|
|
||||||
pipeline_show_parser.add_argument(
|
|
||||||
"--dot",
|
|
||||||
action="store_true",
|
|
||||||
default=False,
|
|
||||||
help="Print DAG with .dot format.",
|
|
||||||
)
|
|
||||||
pipeline_show_parser.add_argument(
|
|
||||||
"--tree",
|
|
||||||
action="store_true",
|
|
||||||
default=False,
|
|
||||||
help="Output DAG as Dependencies Tree.",
|
|
||||||
)
|
|
||||||
pipeline_show_parser.add_argument(
|
|
||||||
"targets",
|
|
||||||
nargs="*",
|
|
||||||
help="DVC-files to show pipeline for. Optional. "
|
|
||||||
"(Finds all DVC-files in the workspace by default.)",
|
|
||||||
)
|
|
||||||
pipeline_show_parser.set_defaults(func=CmdPipelineShow)
|
|
||||||
@@ -0,0 +1,232 @@
|
|||||||
|
import argparse
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
from dvc.command.base import CmdBase, append_doc_link, fix_subparsers
|
||||||
|
from dvc.exceptions import DvcException
|
||||||
|
from dvc.schema import PLOT_PROPS
|
||||||
|
from dvc.utils import format_link
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
PAGE_HTML = """<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>DVC Plot</title>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{divs}
|
||||||
|
</body>
|
||||||
|
</html>"""
|
||||||
|
|
||||||
|
DIV_HTML = """<div id = "{id}"></div>
|
||||||
|
<script type = "text/javascript">
|
||||||
|
var spec = {vega_json};
|
||||||
|
vegaEmbed('#{id}', spec);
|
||||||
|
</script>"""
|
||||||
|
|
||||||
|
|
||||||
|
class CmdPlots(CmdBase):
|
||||||
|
def _func(self, *args, **kwargs):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def _props(self):
|
||||||
|
# Pass only props specified by user, to not shadow ones from plot def
|
||||||
|
props = {p: getattr(self.args, p) for p in PLOT_PROPS}
|
||||||
|
return {k: v for k, v in props.items() if v is not None}
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
if self.args.show_vega:
|
||||||
|
if not self.args.targets:
|
||||||
|
logger.error("please specify a target for `--show-vega`")
|
||||||
|
return 1
|
||||||
|
if len(self.args.targets) > 1:
|
||||||
|
logger.error(
|
||||||
|
"you can only specify one target for `--show-vega`"
|
||||||
|
)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
try:
|
||||||
|
plots = self._func(targets=self.args.targets, props=self._props())
|
||||||
|
|
||||||
|
if self.args.show_vega:
|
||||||
|
target = self.args.targets[0]
|
||||||
|
logger.info(plots[target])
|
||||||
|
return 0
|
||||||
|
|
||||||
|
divs = [
|
||||||
|
DIV_HTML.format(id=f"plot{i}", vega_json=plot)
|
||||||
|
for i, plot in enumerate(plots.values())
|
||||||
|
]
|
||||||
|
html = PAGE_HTML.format(divs="\n".join(divs))
|
||||||
|
path = self.args.out or "plots.html"
|
||||||
|
|
||||||
|
with open(path, "w") as fobj:
|
||||||
|
fobj.write(html)
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
"file://{}".format(os.path.join(self.repo.root_dir, path))
|
||||||
|
)
|
||||||
|
|
||||||
|
except DvcException:
|
||||||
|
logger.exception("")
|
||||||
|
return 1
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
class CmdPlotsShow(CmdPlots):
|
||||||
|
def _func(self, *args, **kwargs):
|
||||||
|
return self.repo.plots.show(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class CmdPlotsDiff(CmdPlots):
|
||||||
|
def _func(self, *args, **kwargs):
|
||||||
|
return self.repo.plots.diff(*args, revs=self.args.revisions, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class CmdPlotsModify(CmdPlots):
|
||||||
|
def run(self):
|
||||||
|
self.repo.plots.modify(
|
||||||
|
self.args.target, props=self._props(), unset=self.args.unset,
|
||||||
|
)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def add_parser(subparsers, parent_parser):
|
||||||
|
PLOTS_HELP = (
|
||||||
|
"Commands to visualize and compare plot metrics in structured files "
|
||||||
|
"(JSON, YAML, CSV, TSV)"
|
||||||
|
)
|
||||||
|
|
||||||
|
plots_parser = subparsers.add_parser(
|
||||||
|
"plots",
|
||||||
|
parents=[parent_parser],
|
||||||
|
description=append_doc_link(PLOTS_HELP, "plots"),
|
||||||
|
help=PLOTS_HELP,
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
)
|
||||||
|
plots_subparsers = plots_parser.add_subparsers(
|
||||||
|
dest="cmd",
|
||||||
|
help="Use `dvc plots CMD --help` to display command-specific help.",
|
||||||
|
)
|
||||||
|
|
||||||
|
fix_subparsers(plots_subparsers)
|
||||||
|
|
||||||
|
SHOW_HELP = "Generate plots from metric files."
|
||||||
|
plots_show_parser = plots_subparsers.add_parser(
|
||||||
|
"show",
|
||||||
|
parents=[parent_parser],
|
||||||
|
description=append_doc_link(SHOW_HELP, "plots/show"),
|
||||||
|
help=SHOW_HELP,
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
)
|
||||||
|
plots_show_parser.add_argument(
|
||||||
|
"targets",
|
||||||
|
nargs="*",
|
||||||
|
help="Plots files to visualize. Shows all plots by default.",
|
||||||
|
)
|
||||||
|
_add_props_arguments(plots_show_parser)
|
||||||
|
_add_output_arguments(plots_show_parser)
|
||||||
|
plots_show_parser.set_defaults(func=CmdPlotsShow)
|
||||||
|
|
||||||
|
PLOTS_DIFF_HELP = (
|
||||||
|
"Show multiple versions of plot metrics "
|
||||||
|
"by plotting them in a single image."
|
||||||
|
)
|
||||||
|
plots_diff_parser = plots_subparsers.add_parser(
|
||||||
|
"diff",
|
||||||
|
parents=[parent_parser],
|
||||||
|
description=append_doc_link(PLOTS_DIFF_HELP, "plots/diff"),
|
||||||
|
help=PLOTS_DIFF_HELP,
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
)
|
||||||
|
plots_diff_parser.add_argument(
|
||||||
|
"--targets",
|
||||||
|
nargs="*",
|
||||||
|
help="Plots file to visualize. Shows all plots by default.",
|
||||||
|
metavar="<path>",
|
||||||
|
)
|
||||||
|
plots_diff_parser.add_argument(
|
||||||
|
"revisions", nargs="*", default=None, help="Git commits to plot from",
|
||||||
|
)
|
||||||
|
_add_props_arguments(plots_diff_parser)
|
||||||
|
_add_output_arguments(plots_diff_parser)
|
||||||
|
plots_diff_parser.set_defaults(func=CmdPlotsDiff)
|
||||||
|
|
||||||
|
PLOTS_MODIFY_HELP = "Modify display properties of plot metric files."
|
||||||
|
plots_modify_parser = plots_subparsers.add_parser(
|
||||||
|
"modify",
|
||||||
|
parents=[parent_parser],
|
||||||
|
description=append_doc_link(PLOTS_MODIFY_HELP, "plots/modify"),
|
||||||
|
help=PLOTS_MODIFY_HELP,
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
)
|
||||||
|
plots_modify_parser.add_argument(
|
||||||
|
"target", help="Metric file to set properties to",
|
||||||
|
)
|
||||||
|
_add_props_arguments(plots_modify_parser)
|
||||||
|
plots_modify_parser.add_argument(
|
||||||
|
"--unset",
|
||||||
|
nargs="*",
|
||||||
|
metavar="<property>",
|
||||||
|
help="Unset one or more display properties.",
|
||||||
|
)
|
||||||
|
plots_modify_parser.set_defaults(func=CmdPlotsModify)
|
||||||
|
|
||||||
|
|
||||||
|
def _add_props_arguments(parser):
|
||||||
|
parser.add_argument(
|
||||||
|
"-t",
|
||||||
|
"--template",
|
||||||
|
nargs="?",
|
||||||
|
default=None,
|
||||||
|
help=(
|
||||||
|
"Special JSON or HTML schema file to inject with the data. "
|
||||||
|
"See {}".format(
|
||||||
|
format_link("https://man.dvc.org/plots#plot-templates")
|
||||||
|
)
|
||||||
|
),
|
||||||
|
metavar="<path>",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-x", default=None, help="Field name for X axis.", metavar="<field>"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-y", default=None, help="Field name for Y axis.", metavar="<field>"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--no-header",
|
||||||
|
action="store_false",
|
||||||
|
dest="header",
|
||||||
|
default=None, # Use default None to distinguish when it's not used
|
||||||
|
help="Provided CSV or TSV datafile does not have a header.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--title", default=None, metavar="<text>", help="Plot title."
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--x-label", default=None, help="X axis label", metavar="<text>"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--y-label", default=None, help="Y axis label", metavar="<text>"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _add_output_arguments(parser):
|
||||||
|
parser.add_argument(
|
||||||
|
"-o",
|
||||||
|
"--out",
|
||||||
|
default=None,
|
||||||
|
help="Destination path to save plots to",
|
||||||
|
metavar="<path>",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--show-vega",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Show output in Vega format.",
|
||||||
|
)
|
||||||
+60
-9
@@ -1,9 +1,9 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dvc.config import ConfigError
|
|
||||||
from dvc.command.base import append_doc_link, fix_subparsers
|
from dvc.command.base import append_doc_link, fix_subparsers
|
||||||
from dvc.command.config import CmdConfig
|
from dvc.command.config import CmdConfig
|
||||||
|
from dvc.config import ConfigError
|
||||||
from dvc.utils import format_link
|
from dvc.utils import format_link
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -18,17 +18,13 @@ class CmdRemote(CmdConfig):
|
|||||||
|
|
||||||
def _check_exists(self, conf):
|
def _check_exists(self, conf):
|
||||||
if self.args.name not in conf["remote"]:
|
if self.args.name not in conf["remote"]:
|
||||||
raise ConfigError(
|
raise ConfigError(f"remote '{self.args.name}' doesn't exists.")
|
||||||
"remote '{}' doesn't exists.".format(self.args.name)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class CmdRemoteAdd(CmdRemote):
|
class CmdRemoteAdd(CmdRemote):
|
||||||
def run(self):
|
def run(self):
|
||||||
if self.args.default:
|
if self.args.default:
|
||||||
logger.info(
|
logger.info(f"Setting '{self.args.name}' as a default remote.")
|
||||||
"Setting '{}' as a default remote.".format(self.args.name)
|
|
||||||
)
|
|
||||||
|
|
||||||
with self.config.edit(self.args.level) as conf:
|
with self.config.edit(self.args.level) as conf:
|
||||||
if self.args.name in conf["remote"] and not self.args.force:
|
if self.args.name in conf["remote"] and not self.args.force:
|
||||||
@@ -66,7 +62,11 @@ class CmdRemoteModify(CmdRemote):
|
|||||||
def run(self):
|
def run(self):
|
||||||
with self.config.edit(self.args.level) as conf:
|
with self.config.edit(self.args.level) as conf:
|
||||||
self._check_exists(conf)
|
self._check_exists(conf)
|
||||||
conf["remote"][self.args.name][self.args.option] = self.args.value
|
section = conf["remote"][self.args.name]
|
||||||
|
if self.args.unset:
|
||||||
|
section.pop(self.args.option, None)
|
||||||
|
else:
|
||||||
|
section[self.args.option] = self.args.value
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
@@ -85,7 +85,18 @@ class CmdRemoteDefault(CmdRemote):
|
|||||||
if self.args.unset:
|
if self.args.unset:
|
||||||
conf["core"].pop("remote", None)
|
conf["core"].pop("remote", None)
|
||||||
else:
|
else:
|
||||||
conf["core"]["remote"] = self.args.name
|
merged_conf = self.config.load_config_to_level(
|
||||||
|
self.args.level
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
self.args.name in conf["remote"]
|
||||||
|
or self.args.name in merged_conf["remote"]
|
||||||
|
):
|
||||||
|
conf["core"]["remote"] = self.args.name
|
||||||
|
else:
|
||||||
|
raise ConfigError(
|
||||||
|
"default remote must be present in remote list."
|
||||||
|
)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
@@ -97,6 +108,35 @@ class CmdRemoteList(CmdRemote):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
class CmdRemoteRename(CmdRemote):
|
||||||
|
def _rename_default(self, conf):
|
||||||
|
if conf["core"].get("remote") == self.args.name:
|
||||||
|
conf["core"]["remote"] = self.args.new
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
all_config = self.config.load_config_to_level(None)
|
||||||
|
if self.args.new in all_config.get("remote", {}):
|
||||||
|
raise ConfigError(
|
||||||
|
"Rename failed. Remote name '{}' already exists.".format(
|
||||||
|
{self.args.new}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
with self.config.edit(self.args.level) as conf:
|
||||||
|
self._check_exists(conf)
|
||||||
|
conf["remote"][self.args.new] = conf["remote"][self.args.name]
|
||||||
|
del conf["remote"][self.args.name]
|
||||||
|
self._rename_default(conf)
|
||||||
|
|
||||||
|
for level in reversed(self.config.LEVELS):
|
||||||
|
if level == self.args.level:
|
||||||
|
break
|
||||||
|
with self.config.edit(level) as level_conf:
|
||||||
|
self._rename_default(level_conf)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def add_parser(subparsers, parent_parser):
|
def add_parser(subparsers, parent_parser):
|
||||||
from dvc.command.config import parent_config_parser
|
from dvc.command.config import parent_config_parser
|
||||||
|
|
||||||
@@ -213,3 +253,14 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"name", help="Name of the remote to remove."
|
"name", help="Name of the remote to remove."
|
||||||
)
|
)
|
||||||
remote_remove_parser.set_defaults(func=CmdRemoteRemove)
|
remote_remove_parser.set_defaults(func=CmdRemoteRemove)
|
||||||
|
REMOTE_RENAME_HELP = "Rename a DVC remote"
|
||||||
|
remote_rename_parser = remote_subparsers.add_parser(
|
||||||
|
"rename",
|
||||||
|
parents=[parent_config_parser, parent_parser],
|
||||||
|
description=append_doc_link(REMOTE_RENAME_HELP, "remote/rename"),
|
||||||
|
help=REMOTE_RENAME_HELP,
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
)
|
||||||
|
remote_rename_parser.add_argument("name", help="Remote to be renamed")
|
||||||
|
remote_rename_parser.add_argument("new", help="New name of the remote")
|
||||||
|
remote_rename_parser.set_defaults(func=CmdRemoteRename)
|
||||||
|
|||||||
+6
-45
@@ -1,48 +1,25 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import dvc.prompt as prompt
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
from dvc.command.base import append_doc_link
|
|
||||||
from dvc.command.base import CmdBase
|
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CmdRemove(CmdBase):
|
class CmdRemove(CmdBase):
|
||||||
def _is_outs_only(self, target):
|
|
||||||
if not self.args.purge:
|
|
||||||
return True
|
|
||||||
|
|
||||||
if self.args.force:
|
|
||||||
return False
|
|
||||||
|
|
||||||
msg = "Are you sure you want to remove '{}' with its outputs?".format(
|
|
||||||
target
|
|
||||||
)
|
|
||||||
|
|
||||||
if prompt.confirm(msg):
|
|
||||||
return False
|
|
||||||
|
|
||||||
raise DvcException(
|
|
||||||
"Cannot purge without a confirmation from the user."
|
|
||||||
" Use `-f` to force."
|
|
||||||
)
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
for target in self.args.targets:
|
for target in self.args.targets:
|
||||||
try:
|
try:
|
||||||
outs_only = self._is_outs_only(target)
|
self.repo.remove(target, outs=self.args.outs)
|
||||||
self.repo.remove(target, outs_only=outs_only)
|
|
||||||
except DvcException:
|
except DvcException:
|
||||||
logger.exception("failed to remove '{}'".format(target))
|
logger.exception(f"failed to remove '{target}'")
|
||||||
return 1
|
return 1
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def add_parser(subparsers, parent_parser):
|
def add_parser(subparsers, parent_parser):
|
||||||
REMOVE_HELP = "Remove DVC-tracked files or directories."
|
REMOVE_HELP = "Remove stage entry and unprotect outputs"
|
||||||
remove_parser = subparsers.add_parser(
|
remove_parser = subparsers.add_parser(
|
||||||
"remove",
|
"remove",
|
||||||
parents=[parent_parser],
|
parents=[parent_parser],
|
||||||
@@ -50,27 +27,11 @@ def add_parser(subparsers, parent_parser):
|
|||||||
help=REMOVE_HELP,
|
help=REMOVE_HELP,
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
)
|
)
|
||||||
remove_parser_group = remove_parser.add_mutually_exclusive_group()
|
remove_parser.add_argument(
|
||||||
remove_parser_group.add_argument(
|
|
||||||
"-o",
|
|
||||||
"--outs",
|
"--outs",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=True,
|
|
||||||
help="Only remove DVC-file outputs. (Default)",
|
|
||||||
)
|
|
||||||
remove_parser_group.add_argument(
|
|
||||||
"-p",
|
|
||||||
"--purge",
|
|
||||||
action="store_true",
|
|
||||||
default=False,
|
default=False,
|
||||||
help="Remove DVC-file and all its outputs.",
|
help="Remove outputs as well.",
|
||||||
)
|
|
||||||
remove_parser.add_argument(
|
|
||||||
"-f",
|
|
||||||
"--force",
|
|
||||||
action="store_true",
|
|
||||||
default=False,
|
|
||||||
help="Force purge.",
|
|
||||||
)
|
)
|
||||||
remove_parser.add_argument(
|
remove_parser.add_argument(
|
||||||
"targets", nargs="+", help="DVC-files to remove."
|
"targets", nargs="+", help="DVC-files to remove."
|
||||||
|
|||||||
+15
-6
@@ -2,13 +2,12 @@ import argparse
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from dvc.command.base import append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
from dvc.command.base import CmdBase
|
|
||||||
from dvc.command.metrics import show_metrics
|
from dvc.command.metrics import show_metrics
|
||||||
from dvc.command.status import CmdDataStatus
|
from dvc.command.status import CmdDataStatus
|
||||||
|
from dvc.dvcfile import PIPELINE_FILE
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -35,10 +34,11 @@ class CmdRepro(CmdBase):
|
|||||||
interactive=self.args.interactive,
|
interactive=self.args.interactive,
|
||||||
pipeline=self.args.pipeline,
|
pipeline=self.args.pipeline,
|
||||||
all_pipelines=self.args.all_pipelines,
|
all_pipelines=self.args.all_pipelines,
|
||||||
ignore_build_cache=self.args.ignore_build_cache,
|
run_cache=not self.args.no_run_cache,
|
||||||
no_commit=self.args.no_commit,
|
no_commit=self.args.no_commit,
|
||||||
downstream=self.args.downstream,
|
downstream=self.args.downstream,
|
||||||
recursive=self.args.recursive,
|
recursive=self.args.recursive,
|
||||||
|
force_downstream=self.args.force_downstream,
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(stages) == 0:
|
if len(stages) == 0:
|
||||||
@@ -70,7 +70,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
repro_parser.add_argument(
|
repro_parser.add_argument(
|
||||||
"targets",
|
"targets",
|
||||||
nargs="*",
|
nargs="*",
|
||||||
help="DVC-file to reproduce. 'Dvcfile' by default.",
|
help=f"Stages to reproduce. '{PIPELINE_FILE}' by default.",
|
||||||
)
|
)
|
||||||
repro_parser.add_argument(
|
repro_parser.add_argument(
|
||||||
"-f",
|
"-f",
|
||||||
@@ -138,7 +138,16 @@ def add_parser(subparsers, parent_parser):
|
|||||||
help="Reproduce all stages in the specified directory.",
|
help="Reproduce all stages in the specified directory.",
|
||||||
)
|
)
|
||||||
repro_parser.add_argument(
|
repro_parser.add_argument(
|
||||||
"--ignore-build-cache",
|
"--no-run-cache",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help=(
|
||||||
|
"Execute stage commands even if they have already been run with "
|
||||||
|
"the same command/dependencies/outputs/etc before."
|
||||||
|
),
|
||||||
|
)
|
||||||
|
repro_parser.add_argument(
|
||||||
|
"--force-downstream",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
help="Reproduce all descendants of a changed stage even if their "
|
help="Reproduce all descendants of a changed stage even if their "
|
||||||
|
|||||||
+1
-2
@@ -1,8 +1,7 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dvc.command.base import append_doc_link
|
from dvc.command.base import CmdBaseNoRepo, append_doc_link
|
||||||
from dvc.command.base import CmdBaseNoRepo
|
|
||||||
from dvc.utils import relpath
|
from dvc.utils import relpath
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|||||||
+52
-28
@@ -1,18 +1,14 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dvc.command.base import append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
from dvc.command.base import CmdBase
|
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CmdRun(CmdBase):
|
class CmdRun(CmdBase):
|
||||||
def run(self):
|
def run(self):
|
||||||
overwrite = self.args.yes or self.args.overwrite_dvcfile
|
|
||||||
|
|
||||||
if not any(
|
if not any(
|
||||||
[
|
[
|
||||||
self.args.deps,
|
self.args.deps,
|
||||||
@@ -20,6 +16,8 @@ class CmdRun(CmdBase):
|
|||||||
self.args.outs_no_cache,
|
self.args.outs_no_cache,
|
||||||
self.args.metrics,
|
self.args.metrics,
|
||||||
self.args.metrics_no_cache,
|
self.args.metrics_no_cache,
|
||||||
|
self.args.plots,
|
||||||
|
self.args.plots_no_cache,
|
||||||
self.args.outs_persist,
|
self.args.outs_persist,
|
||||||
self.args.outs_persist_no_cache,
|
self.args.outs_persist_no_cache,
|
||||||
self.args.params,
|
self.args.params,
|
||||||
@@ -28,8 +26,8 @@ class CmdRun(CmdBase):
|
|||||||
): # pragma: no cover
|
): # pragma: no cover
|
||||||
logger.error(
|
logger.error(
|
||||||
"too few arguments. Specify at least one: `-d`, `-o`, `-O`, "
|
"too few arguments. Specify at least one: `-d`, `-o`, `-O`, "
|
||||||
"`-m`, `-M`, `-p`, `--outs-persist`, "
|
"`-m`, `-M`, `-p`, `--plots`, `--plots-no-cache`, "
|
||||||
"`--outs-persist-no-cache`, `command`."
|
"`--outs-persist`, `--outs-persist-no-cache`, `command`."
|
||||||
)
|
)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
@@ -40,21 +38,25 @@ class CmdRun(CmdBase):
|
|||||||
outs_no_cache=self.args.outs_no_cache,
|
outs_no_cache=self.args.outs_no_cache,
|
||||||
metrics=self.args.metrics,
|
metrics=self.args.metrics,
|
||||||
metrics_no_cache=self.args.metrics_no_cache,
|
metrics_no_cache=self.args.metrics_no_cache,
|
||||||
|
plots=self.args.plots,
|
||||||
|
plots_no_cache=self.args.plots_no_cache,
|
||||||
deps=self.args.deps,
|
deps=self.args.deps,
|
||||||
params=self.args.params,
|
params=self.args.params,
|
||||||
fname=self.args.file,
|
fname=self.args.file,
|
||||||
wdir=self.args.wdir,
|
wdir=self.args.wdir,
|
||||||
no_exec=self.args.no_exec,
|
no_exec=self.args.no_exec,
|
||||||
overwrite=overwrite,
|
force=self.args.force,
|
||||||
ignore_build_cache=self.args.ignore_build_cache,
|
run_cache=not self.args.no_run_cache,
|
||||||
no_commit=self.args.no_commit,
|
no_commit=self.args.no_commit,
|
||||||
outs_persist=self.args.outs_persist,
|
outs_persist=self.args.outs_persist,
|
||||||
outs_persist_no_cache=self.args.outs_persist_no_cache,
|
outs_persist_no_cache=self.args.outs_persist_no_cache,
|
||||||
always_changed=self.args.always_changed,
|
always_changed=self.args.always_changed,
|
||||||
name=self.args.name,
|
name=self.args.name,
|
||||||
|
single_stage=self.args.single_stage,
|
||||||
|
external=self.args.external,
|
||||||
)
|
)
|
||||||
except DvcException:
|
except DvcException:
|
||||||
logger.exception("failed to run command")
|
logger.exception("")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@@ -78,7 +80,7 @@ class CmdRun(CmdBase):
|
|||||||
if " " not in argument or '"' in argument:
|
if " " not in argument or '"' in argument:
|
||||||
return argument
|
return argument
|
||||||
|
|
||||||
return '"{}"'.format(argument)
|
return f'"{argument}"'
|
||||||
|
|
||||||
|
|
||||||
def add_parser(subparsers, parent_parser):
|
def add_parser(subparsers, parent_parser):
|
||||||
@@ -98,7 +100,9 @@ def add_parser(subparsers, parent_parser):
|
|||||||
help="Declare dependencies for reproducible cmd.",
|
help="Declare dependencies for reproducible cmd.",
|
||||||
metavar="<path>",
|
metavar="<path>",
|
||||||
)
|
)
|
||||||
run_parser.add_argument("-n", "--name", help=argparse.SUPPRESS)
|
run_parser.add_argument(
|
||||||
|
"-n", "--name", help="Stage name.",
|
||||||
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
"-o",
|
"-o",
|
||||||
"--outs",
|
"--outs",
|
||||||
@@ -129,7 +133,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"--metrics",
|
"--metrics",
|
||||||
action="append",
|
action="append",
|
||||||
default=[],
|
default=[],
|
||||||
help="Declare output metric file or directory.",
|
help="Declare output metric file.",
|
||||||
metavar="<path>",
|
metavar="<path>",
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
@@ -137,12 +141,24 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"--metrics-no-cache",
|
"--metrics-no-cache",
|
||||||
action="append",
|
action="append",
|
||||||
default=[],
|
default=[],
|
||||||
help="Declare output metric file or directory "
|
help="Declare output metric file (do not put into DVC cache).",
|
||||||
"(do not put into DVC cache).",
|
metavar="<path>",
|
||||||
|
)
|
||||||
|
run_parser.add_argument(
|
||||||
|
"--plots",
|
||||||
|
action="append",
|
||||||
|
default=[],
|
||||||
|
help="Declare output plot file.",
|
||||||
|
metavar="<path>",
|
||||||
|
)
|
||||||
|
run_parser.add_argument(
|
||||||
|
"--plots-no-cache",
|
||||||
|
action="append",
|
||||||
|
default=[],
|
||||||
|
help="Declare output plot file (do not put into DVC cache).",
|
||||||
metavar="<path>",
|
metavar="<path>",
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
"-f",
|
|
||||||
"--file",
|
"--file",
|
||||||
help="Specify name of the DVC-file this command will generate.",
|
help="Specify name of the DVC-file this command will generate.",
|
||||||
metavar="<filename>",
|
metavar="<filename>",
|
||||||
@@ -160,24 +176,20 @@ def add_parser(subparsers, parent_parser):
|
|||||||
help="Only create stage file without actually running it.",
|
help="Only create stage file without actually running it.",
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
"-y",
|
"-f",
|
||||||
"--yes",
|
"--force",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
help="Deprecated, use --overwrite-dvcfile instead",
|
help="Overwrite existing stage",
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
"--overwrite-dvcfile",
|
"--no-run-cache",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
help="Overwrite existing DVC-file without asking for confirmation.",
|
help=(
|
||||||
)
|
"Execute the command even if this stage has already been run "
|
||||||
run_parser.add_argument(
|
"with the same command/dependencies/outputs/etc before."
|
||||||
"--ignore-build-cache",
|
),
|
||||||
action="store_true",
|
|
||||||
default=False,
|
|
||||||
help="Run this stage even if it has been already ran with the same "
|
|
||||||
"command/dependencies/outputs/etc before.",
|
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
"--no-commit",
|
"--no-commit",
|
||||||
@@ -207,6 +219,18 @@ def add_parser(subparsers, parent_parser):
|
|||||||
default=False,
|
default=False,
|
||||||
help="Always consider this DVC-file as changed.",
|
help="Always consider this DVC-file as changed.",
|
||||||
)
|
)
|
||||||
|
run_parser.add_argument(
|
||||||
|
"--single-stage",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help=argparse.SUPPRESS,
|
||||||
|
)
|
||||||
|
run_parser.add_argument(
|
||||||
|
"--external",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Allow outputs that are outside of the DVC repository.",
|
||||||
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
"command", nargs=argparse.REMAINDER, help="Command to execute."
|
"command", nargs=argparse.REMAINDER, help="Command to execute."
|
||||||
)
|
)
|
||||||
|
|||||||
+13
-8
@@ -2,7 +2,6 @@ import logging
|
|||||||
|
|
||||||
from dvc.command.data_sync import CmdDataBase
|
from dvc.command.data_sync import CmdDataBase
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -20,7 +19,7 @@ class CmdDataStatus(CmdDataBase):
|
|||||||
ind = indent * self.STATUS_INDENT
|
ind = indent * self.STATUS_INDENT
|
||||||
|
|
||||||
if isinstance(status, str):
|
if isinstance(status, str):
|
||||||
logger.info("{}{}".format(ind, status))
|
logger.info(f"{ind}{status}")
|
||||||
return
|
return
|
||||||
|
|
||||||
if isinstance(status, list):
|
if isinstance(status, list):
|
||||||
@@ -34,7 +33,7 @@ class CmdDataStatus(CmdDataBase):
|
|||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
logger.info("{}{}{}".format(ind, self._normalize(value), key))
|
logger.info("{}{}{}".format(ind, self._normalize(value), key))
|
||||||
elif value:
|
elif value:
|
||||||
logger.info("{}{}:".format(ind, key))
|
logger.info(f"{ind}{key}:")
|
||||||
self._show(value, indent + 1)
|
self._show(value, indent + 1)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
@@ -49,12 +48,18 @@ class CmdDataStatus(CmdDataBase):
|
|||||||
all_tags=self.args.all_tags,
|
all_tags=self.args.all_tags,
|
||||||
all_commits=self.args.all_commits,
|
all_commits=self.args.all_commits,
|
||||||
with_deps=self.args.with_deps,
|
with_deps=self.args.with_deps,
|
||||||
|
recursive=self.args.recursive,
|
||||||
)
|
)
|
||||||
if st:
|
|
||||||
if self.args.quiet:
|
if self.args.quiet:
|
||||||
return 1
|
return bool(st)
|
||||||
else:
|
|
||||||
self._show(st, indent)
|
if self.args.show_json:
|
||||||
|
import json
|
||||||
|
|
||||||
|
logger.info(json.dumps(st))
|
||||||
|
elif st:
|
||||||
|
self._show(st, indent)
|
||||||
else:
|
else:
|
||||||
logger.info(self.UP_TO_DATE_MSG)
|
logger.info(self.UP_TO_DATE_MSG)
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dvc.command.base import append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
from dvc.command.base import CmdBase
|
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -15,7 +13,7 @@ class CmdUnprotect(CmdBase):
|
|||||||
try:
|
try:
|
||||||
self.repo.unprotect(target)
|
self.repo.unprotect(target)
|
||||||
except DvcException:
|
except DvcException:
|
||||||
msg = "failed to unprotect '{}'".format(target)
|
msg = f"failed to unprotect '{target}'"
|
||||||
logger.exception(msg)
|
logger.exception(msg)
|
||||||
return 1
|
return 1
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
+17
-9
@@ -1,23 +1,24 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dvc.command.base import append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
from dvc.command.base import CmdBase
|
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CmdUpdate(CmdBase):
|
class CmdUpdate(CmdBase):
|
||||||
def run(self):
|
def run(self):
|
||||||
ret = 0
|
ret = 0
|
||||||
for target in self.args.targets:
|
try:
|
||||||
try:
|
self.repo.update(
|
||||||
self.repo.update(target, self.args.rev)
|
targets=self.args.targets,
|
||||||
except DvcException:
|
rev=self.args.rev,
|
||||||
logger.exception("failed to update '{}'.".format(target))
|
recursive=self.args.recursive,
|
||||||
ret = 1
|
)
|
||||||
|
except DvcException:
|
||||||
|
logger.exception("failed update data")
|
||||||
|
ret = 1
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
@@ -39,4 +40,11 @@ def add_parser(subparsers, parent_parser):
|
|||||||
help="Git revision (e.g. SHA, branch, tag)",
|
help="Git revision (e.g. SHA, branch, tag)",
|
||||||
metavar="<commit>",
|
metavar="<commit>",
|
||||||
)
|
)
|
||||||
|
update_parser.add_argument(
|
||||||
|
"-R",
|
||||||
|
"--recursive",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Update all stages in the specified directory.",
|
||||||
|
)
|
||||||
update_parser.set_defaults(func=CmdUpdate)
|
update_parser.set_defaults(func=CmdUpdate)
|
||||||
|
|||||||
+22
-21
@@ -2,22 +2,23 @@ import argparse
|
|||||||
import itertools
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import pathlib
|
||||||
import platform
|
import platform
|
||||||
import uuid
|
import uuid
|
||||||
import pathlib
|
|
||||||
|
from dvc.command.base import CmdBaseNoRepo, append_doc_link
|
||||||
|
from dvc.exceptions import DvcException, NotDvcRepoError
|
||||||
|
from dvc.scm.base import SCMError
|
||||||
|
from dvc.system import System
|
||||||
|
from dvc.utils import is_binary, relpath
|
||||||
|
from dvc.utils.pkg import PKG
|
||||||
|
from dvc.version import __version__
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import psutil
|
import psutil
|
||||||
except ImportError:
|
except ImportError:
|
||||||
psutil = None
|
psutil = None
|
||||||
|
|
||||||
from dvc.utils import is_binary, relpath
|
|
||||||
from dvc.command.base import CmdBaseNoRepo, append_doc_link
|
|
||||||
from dvc.version import __version__
|
|
||||||
from dvc.exceptions import DvcException, NotDvcRepoError
|
|
||||||
from dvc.scm.base import SCMError
|
|
||||||
from dvc.system import System
|
|
||||||
from dvc.utils.pkg import PKG
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -27,12 +28,12 @@ class CmdVersion(CmdBaseNoRepo):
|
|||||||
from dvc.repo import Repo
|
from dvc.repo import Repo
|
||||||
|
|
||||||
info = [
|
info = [
|
||||||
"DVC version: {}".format(__version__),
|
f"DVC version: {__version__}",
|
||||||
"Python version: {}".format(platform.python_version()),
|
f"Python version: {platform.python_version()}",
|
||||||
"Platform: {}".format(platform.platform()),
|
f"Platform: {platform.platform()}",
|
||||||
"Binary: {}".format(is_binary()),
|
f"Binary: {is_binary()}",
|
||||||
"Package: {}".format(PKG),
|
f"Package: {PKG}",
|
||||||
"Supported remotes: {}".format(self.get_supported_remotes()),
|
f"Supported remotes: {self.get_supported_remotes()}",
|
||||||
]
|
]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -50,7 +51,7 @@ class CmdVersion(CmdBaseNoRepo):
|
|||||||
if psutil:
|
if psutil:
|
||||||
fs_type = self.get_fs_type(repo.cache.local.cache_dir)
|
fs_type = self.get_fs_type(repo.cache.local.cache_dir)
|
||||||
info.append(
|
info.append(
|
||||||
"Filesystem type (cache directory): {}".format(fs_type)
|
f"Filesystem type (cache directory): {fs_type}"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
@@ -71,7 +72,7 @@ class CmdVersion(CmdBaseNoRepo):
|
|||||||
|
|
||||||
if psutil:
|
if psutil:
|
||||||
fs_root = self.get_fs_type(os.path.abspath(root_directory))
|
fs_root = self.get_fs_type(os.path.abspath(root_directory))
|
||||||
info.append("Filesystem type (workspace): {}".format(fs_root))
|
info.append(f"Filesystem type (workspace): {fs_root}")
|
||||||
|
|
||||||
logger.info("\n".join(info))
|
logger.info("\n".join(info))
|
||||||
return 0
|
return 0
|
||||||
@@ -114,19 +115,19 @@ class CmdVersion(CmdBaseNoRepo):
|
|||||||
os.unlink(dst)
|
os.unlink(dst)
|
||||||
except DvcException:
|
except DvcException:
|
||||||
status = "not supported"
|
status = "not supported"
|
||||||
cache.append("{name} - {status}".format(name=name, status=status))
|
cache.append(f"{name} - {status}")
|
||||||
os.remove(src)
|
os.remove(src)
|
||||||
|
|
||||||
return ", ".join(cache)
|
return ", ".join(cache)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_supported_remotes():
|
def get_supported_remotes():
|
||||||
from dvc.remote import REMOTES
|
from dvc.remote import TREES
|
||||||
|
|
||||||
supported_remotes = []
|
supported_remotes = []
|
||||||
for remote in REMOTES:
|
for tree_cls in TREES:
|
||||||
if not remote.get_missing_deps():
|
if not tree_cls.get_missing_deps():
|
||||||
supported_remotes.append(remote.scheme)
|
supported_remotes.append(tree_cls.scheme)
|
||||||
|
|
||||||
return ", ".join(supported_remotes)
|
return ", ".join(supported_remotes)
|
||||||
|
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
"""Python version compatibility code"""
|
|
||||||
|
|
||||||
# Backport os.fspath() from Python 3.6
|
|
||||||
try:
|
|
||||||
from os import fspath # noqa: F821
|
|
||||||
|
|
||||||
fspath_py35 = lambda s: s # noqa: E731
|
|
||||||
except ImportError:
|
|
||||||
|
|
||||||
def fspath(path):
|
|
||||||
"""Return the path representation of a path-like object.
|
|
||||||
|
|
||||||
If str or bytes is passed in, it is returned unchanged. Otherwise the
|
|
||||||
os.PathLike interface is used to get the path representation. If the
|
|
||||||
path representation is not str or bytes, TypeError is raised. If the
|
|
||||||
provided path is not str, bytes, or os.PathLike, TypeError is raised.
|
|
||||||
"""
|
|
||||||
if isinstance(path, (str, bytes)):
|
|
||||||
return path
|
|
||||||
|
|
||||||
# Work from the object's type to match method resolution of other magic
|
|
||||||
# methods.
|
|
||||||
path_type = type(path)
|
|
||||||
try:
|
|
||||||
path_repr = path_type.__fspath__(path)
|
|
||||||
except AttributeError:
|
|
||||||
if hasattr(path_type, "__fspath__"):
|
|
||||||
raise
|
|
||||||
else:
|
|
||||||
raise TypeError(
|
|
||||||
"expected str, bytes or os.PathLike object, "
|
|
||||||
"not " + path_type.__name__
|
|
||||||
)
|
|
||||||
if isinstance(path_repr, (str, bytes)):
|
|
||||||
return path_repr
|
|
||||||
else:
|
|
||||||
raise TypeError(
|
|
||||||
"expected {}.__fspath__() to return str or bytes, "
|
|
||||||
"not {}".format(path_type.__name__, type(path_repr).__name__)
|
|
||||||
)
|
|
||||||
|
|
||||||
fspath_py35 = fspath
|
|
||||||
+8
-7
@@ -31,7 +31,7 @@ class ConfigError(DvcException):
|
|||||||
"""DVC config exception."""
|
"""DVC config exception."""
|
||||||
|
|
||||||
def __init__(self, msg):
|
def __init__(self, msg):
|
||||||
super().__init__("config file error: {}".format(msg))
|
super().__init__(f"config file error: {msg}")
|
||||||
|
|
||||||
|
|
||||||
class NoRemoteError(ConfigError):
|
class NoRemoteError(ConfigError):
|
||||||
@@ -89,7 +89,7 @@ def ByUrl(mapping):
|
|||||||
if os.name == "nt" and len(parsed.scheme) == 1 and parsed.netloc == "":
|
if os.name == "nt" and len(parsed.scheme) == 1 and parsed.netloc == "":
|
||||||
return schemas[""](data)
|
return schemas[""](data)
|
||||||
if parsed.scheme not in schemas:
|
if parsed.scheme not in schemas:
|
||||||
raise Invalid("Unsupported URL type {}://".format(parsed.scheme))
|
raise Invalid(f"Unsupported URL type {parsed.scheme}://")
|
||||||
|
|
||||||
return schemas[parsed.scheme](data)
|
return schemas[parsed.scheme](data)
|
||||||
|
|
||||||
@@ -151,6 +151,7 @@ SCHEMA = {
|
|||||||
Optional("listobjects", default=False): Bool,
|
Optional("listobjects", default=False): Bool,
|
||||||
Optional("use_ssl", default=True): Bool,
|
Optional("use_ssl", default=True): Bool,
|
||||||
"sse": str,
|
"sse": str,
|
||||||
|
"sse_kms_key_id": str,
|
||||||
"acl": str,
|
"acl": str,
|
||||||
"grant_read": str,
|
"grant_read": str,
|
||||||
"grant_read_acp": str,
|
"grant_read_acp": str,
|
||||||
@@ -289,7 +290,7 @@ class Config(dict):
|
|||||||
Raises:
|
Raises:
|
||||||
ConfigError: thrown if config has an invalid format.
|
ConfigError: thrown if config has an invalid format.
|
||||||
"""
|
"""
|
||||||
conf = self._load_config_to_level()
|
conf = self.load_config_to_level()
|
||||||
|
|
||||||
if validate:
|
if validate:
|
||||||
conf = self.validate(conf)
|
conf = self.validate(conf)
|
||||||
@@ -349,7 +350,7 @@ class Config(dict):
|
|||||||
}
|
}
|
||||||
return Schema(dirs_schema, extra=ALLOW_EXTRA)(conf)
|
return Schema(dirs_schema, extra=ALLOW_EXTRA)(conf)
|
||||||
|
|
||||||
def _load_config_to_level(self, level=None):
|
def load_config_to_level(self, level=None):
|
||||||
merged_conf = {}
|
merged_conf = {}
|
||||||
for merge_level in self.LEVELS:
|
for merge_level in self.LEVELS:
|
||||||
if merge_level == level:
|
if merge_level == level:
|
||||||
@@ -368,7 +369,7 @@ class Config(dict):
|
|||||||
|
|
||||||
conf = self._save_paths(conf, self.files[level])
|
conf = self._save_paths(conf, self.files[level])
|
||||||
|
|
||||||
merged_conf = self._load_config_to_level(level)
|
merged_conf = self.load_config_to_level(level)
|
||||||
_merge(merged_conf, conf)
|
_merge(merged_conf, conf)
|
||||||
self.validate(merged_conf)
|
self.validate(merged_conf)
|
||||||
|
|
||||||
@@ -389,7 +390,7 @@ def _load_config(filename):
|
|||||||
|
|
||||||
|
|
||||||
def _save_config(filename, conf_dict):
|
def _save_config(filename, conf_dict):
|
||||||
logger.debug("Writing '{}'.".format(filename))
|
logger.debug(f"Writing '{filename}'.")
|
||||||
os.makedirs(os.path.dirname(filename), exist_ok=True)
|
os.makedirs(os.path.dirname(filename), exist_ok=True)
|
||||||
|
|
||||||
config = configobj.ConfigObj(_pack_remotes(conf_dict))
|
config = configobj.ConfigObj(_pack_remotes(conf_dict))
|
||||||
@@ -416,7 +417,7 @@ def _pack_remotes(conf):
|
|||||||
|
|
||||||
# Transform remote.name -> 'remote "name"'
|
# Transform remote.name -> 'remote "name"'
|
||||||
for name, val in conf["remote"].items():
|
for name, val in conf["remote"].items():
|
||||||
result['remote "{}"'.format(name)] = val
|
result[f'remote "{name}"'] = val
|
||||||
result.pop("remote", None)
|
result.pop("remote", None)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
+3
-6
@@ -7,9 +7,7 @@ import sys
|
|||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
|
|
||||||
from dvc.env import DVC_DAEMON
|
from dvc.env import DVC_DAEMON
|
||||||
from dvc.utils import fix_env
|
from dvc.utils import fix_env, is_binary
|
||||||
from dvc.utils import is_binary
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -48,7 +46,6 @@ def _spawn_posix(cmd, env):
|
|||||||
os._exit(1) # pylint: disable=protected-access
|
os._exit(1) # pylint: disable=protected-access
|
||||||
|
|
||||||
os.setsid()
|
os.setsid()
|
||||||
os.umask(0)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pid = os.fork()
|
pid = os.fork()
|
||||||
@@ -68,7 +65,7 @@ def _spawn_posix(cmd, env):
|
|||||||
|
|
||||||
|
|
||||||
def _spawn(cmd, env):
|
def _spawn(cmd, env):
|
||||||
logger.debug("Trying to spawn '{}'".format(cmd))
|
logger.debug(f"Trying to spawn '{cmd}'")
|
||||||
|
|
||||||
if os.name == "nt":
|
if os.name == "nt":
|
||||||
_spawn_windows(cmd, env)
|
_spawn_windows(cmd, env)
|
||||||
@@ -77,7 +74,7 @@ def _spawn(cmd, env):
|
|||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
logger.debug("Spawned '{}'".format(cmd))
|
logger.debug(f"Spawned '{cmd}'")
|
||||||
|
|
||||||
|
|
||||||
def daemon(args):
|
def daemon(args):
|
||||||
|
|||||||
+11
-15
@@ -6,12 +6,9 @@ import os
|
|||||||
import pydoc
|
import pydoc
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from grandalf.graphs import Edge
|
from grandalf.graphs import Edge, Graph, Vertex
|
||||||
from grandalf.graphs import Graph
|
|
||||||
from grandalf.graphs import Vertex
|
|
||||||
from grandalf.layouts import SugiyamaLayout
|
from grandalf.layouts import SugiyamaLayout
|
||||||
from grandalf.routing import EdgeViewer
|
from grandalf.routing import EdgeViewer, route_with_lines
|
||||||
from grandalf.routing import route_with_lines
|
|
||||||
|
|
||||||
from dvc.env import DVC_PAGER
|
from dvc.env import DVC_PAGER
|
||||||
from dvc.utils import format_link
|
from dvc.utils import format_link
|
||||||
@@ -40,7 +37,7 @@ def find_pager():
|
|||||||
if env_pager:
|
if env_pager:
|
||||||
return make_pager(env_pager)
|
return make_pager(env_pager)
|
||||||
|
|
||||||
if os.system("({}) 2>{}".format(DEFAULT_PAGER, os.devnull)) == 0:
|
if os.system(f"({DEFAULT_PAGER}) 2>{os.devnull}") == 0:
|
||||||
return make_pager(DEFAULT_PAGER_FORMATTED)
|
return make_pager(DEFAULT_PAGER_FORMATTED)
|
||||||
|
|
||||||
logger.warning(
|
logger.warning(
|
||||||
@@ -52,7 +49,7 @@ def find_pager():
|
|||||||
return pydoc.plainpager
|
return pydoc.plainpager
|
||||||
|
|
||||||
|
|
||||||
class VertexViewer(object):
|
class VertexViewer:
|
||||||
"""Class to define vertex box boundaries that will be accounted for during
|
"""Class to define vertex box boundaries that will be accounted for during
|
||||||
graph building by grandalf.
|
graph building by grandalf.
|
||||||
|
|
||||||
@@ -78,7 +75,7 @@ class VertexViewer(object):
|
|||||||
return self._w
|
return self._w
|
||||||
|
|
||||||
|
|
||||||
class AsciiCanvas(object):
|
class AsciiCanvas:
|
||||||
"""Class for drawing in ASCII.
|
"""Class for drawing in ASCII.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -99,10 +96,9 @@ class AsciiCanvas(object):
|
|||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
"""Draws ASCII canvas on the screen."""
|
"""Draws ASCII canvas on the screen."""
|
||||||
pager = find_pager()
|
|
||||||
lines = map("".join, self.canvas)
|
lines = map("".join, self.canvas)
|
||||||
joined_lines = os.linesep.join(lines)
|
joined_lines = os.linesep.join(lines)
|
||||||
pager(joined_lines)
|
return joined_lines
|
||||||
|
|
||||||
def point(self, x, y, char):
|
def point(self, x, y, char):
|
||||||
"""Create a point on ASCII canvas.
|
"""Create a point on ASCII canvas.
|
||||||
@@ -148,21 +144,21 @@ class AsciiCanvas(object):
|
|||||||
if dx == 0:
|
if dx == 0:
|
||||||
y = y0
|
y = y0
|
||||||
else:
|
else:
|
||||||
y = y0 + int(round((x - x0) * dy / float((dx))))
|
y = y0 + int(round((x - x0) * dy / float(dx)))
|
||||||
self.point(x, y, char)
|
self.point(x, y, char)
|
||||||
elif y0 < y1:
|
elif y0 < y1:
|
||||||
for y in range(y0, y1 + 1):
|
for y in range(y0, y1 + 1):
|
||||||
if dy == 0:
|
if dy == 0:
|
||||||
x = x0
|
x = x0
|
||||||
else:
|
else:
|
||||||
x = x0 + int(round((y - y0) * dx / float((dy))))
|
x = x0 + int(round((y - y0) * dx / float(dy)))
|
||||||
self.point(x, y, char)
|
self.point(x, y, char)
|
||||||
else:
|
else:
|
||||||
for y in range(y1, y0 + 1):
|
for y in range(y1, y0 + 1):
|
||||||
if dy == 0:
|
if dy == 0:
|
||||||
x = x0
|
x = x0
|
||||||
else:
|
else:
|
||||||
x = x1 + int(round((y - y1) * dx / float((dy))))
|
x = x1 + int(round((y - y1) * dx / float(dy)))
|
||||||
self.point(x, y, char)
|
self.point(x, y, char)
|
||||||
|
|
||||||
def text(self, x, y, text):
|
def text(self, x, y, text):
|
||||||
@@ -216,7 +212,7 @@ def _build_sugiyama_layout(vertexes, edges):
|
|||||||
# Y
|
# Y
|
||||||
#
|
#
|
||||||
|
|
||||||
vertexes = {v: Vertex(" {} ".format(v)) for v in vertexes}
|
vertexes = {v: Vertex(f" {v} ") for v in vertexes}
|
||||||
# NOTE: reverting edges to correctly orientate the graph
|
# NOTE: reverting edges to correctly orientate the graph
|
||||||
edges = [Edge(vertexes[e], vertexes[s]) for s, e in edges]
|
edges = [Edge(vertexes[e], vertexes[s]) for s, e in edges]
|
||||||
vertexes = vertexes.values()
|
vertexes = vertexes.values()
|
||||||
@@ -319,4 +315,4 @@ def draw(vertexes, edges):
|
|||||||
int(round(x - minx)) + 1, int(round(y - miny)) + 1, vertex.data
|
int(round(x - minx)) + 1, int(round(y - miny)) + 1, vertex.data
|
||||||
)
|
)
|
||||||
|
|
||||||
canvas.draw()
|
return canvas.draw()
|
||||||
|
|||||||
+16
-13
@@ -3,13 +3,12 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dvc.config import NoRemoteError
|
from dvc.config import NoRemoteError
|
||||||
from dvc.remote import Remote
|
from dvc.remote import get_remote
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class DataCloud(object):
|
class DataCloud:
|
||||||
"""Class that manages dvc remotes.
|
"""Class that manages dvc remotes.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -46,9 +45,11 @@ class DataCloud(object):
|
|||||||
raise NoRemoteError(error_msg)
|
raise NoRemoteError(error_msg)
|
||||||
|
|
||||||
def _init_remote(self, name):
|
def _init_remote(self, name):
|
||||||
return Remote(self.repo, name=name)
|
return get_remote(self.repo, name=name)
|
||||||
|
|
||||||
def push(self, cache, jobs=None, remote=None, show_checksums=False):
|
def push(
|
||||||
|
self, cache, jobs=None, remote=None, show_checksums=False,
|
||||||
|
):
|
||||||
"""Push data items in a cloud-agnostic way.
|
"""Push data items in a cloud-agnostic way.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -59,14 +60,15 @@ class DataCloud(object):
|
|||||||
show_checksums (bool): show checksums instead of file names in
|
show_checksums (bool): show checksums instead of file names in
|
||||||
information messages.
|
information messages.
|
||||||
"""
|
"""
|
||||||
|
remote = self.get_remote(remote, "push")
|
||||||
|
|
||||||
return self.repo.cache.local.push(
|
return self.repo.cache.local.push(
|
||||||
cache,
|
cache, jobs=jobs, remote=remote, show_checksums=show_checksums,
|
||||||
jobs=jobs,
|
|
||||||
remote=self.get_remote(remote, "push"),
|
|
||||||
show_checksums=show_checksums,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def pull(self, cache, jobs=None, remote=None, show_checksums=False):
|
def pull(
|
||||||
|
self, cache, jobs=None, remote=None, show_checksums=False,
|
||||||
|
):
|
||||||
"""Pull data items in a cloud-agnostic way.
|
"""Pull data items in a cloud-agnostic way.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -78,19 +80,20 @@ class DataCloud(object):
|
|||||||
information messages.
|
information messages.
|
||||||
"""
|
"""
|
||||||
remote = self.get_remote(remote, "pull")
|
remote = self.get_remote(remote, "pull")
|
||||||
|
|
||||||
downloaded_items_num = self.repo.cache.local.pull(
|
downloaded_items_num = self.repo.cache.local.pull(
|
||||||
cache, jobs=jobs, remote=remote, show_checksums=show_checksums
|
cache, jobs=jobs, remote=remote, show_checksums=show_checksums
|
||||||
)
|
)
|
||||||
|
|
||||||
if not remote.verify:
|
if not remote.tree.verify:
|
||||||
self._save_pulled_checksums(cache)
|
self._save_pulled_checksums(cache)
|
||||||
|
|
||||||
return downloaded_items_num
|
return downloaded_items_num
|
||||||
|
|
||||||
def _save_pulled_checksums(self, cache):
|
def _save_pulled_checksums(self, cache):
|
||||||
for checksum in cache.scheme_keys("local"):
|
for checksum in cache.scheme_keys("local"):
|
||||||
cache_file = self.repo.cache.local.checksum_to_path_info(checksum)
|
cache_file = self.repo.cache.local.hash_to_path_info(checksum)
|
||||||
if self.repo.cache.local.exists(cache_file):
|
if self.repo.cache.local.tree.exists(cache_file):
|
||||||
# We can safely save here, as existing corrupted files will
|
# We can safely save here, as existing corrupted files will
|
||||||
# be removed upon status, while files corrupted during
|
# be removed upon status, while files corrupted during
|
||||||
# download will not be moved from tmp_file
|
# download will not be moved from tmp_file
|
||||||
|
|||||||
+32
-25
@@ -1,22 +1,24 @@
|
|||||||
from urllib.parse import urlparse
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import dvc.output as output
|
import dvc.output as output
|
||||||
|
from dvc.dependency.azure import AzureDependency
|
||||||
from dvc.dependency.gs import GSDependency
|
from dvc.dependency.gs import GSDependency
|
||||||
from dvc.dependency.hdfs import HDFSDependency
|
from dvc.dependency.hdfs import HDFSDependency
|
||||||
from dvc.dependency.http import HTTPDependency
|
from dvc.dependency.http import HTTPDependency
|
||||||
from dvc.dependency.https import HTTPSDependency
|
from dvc.dependency.https import HTTPSDependency
|
||||||
from dvc.dependency.local import LocalDependency
|
from dvc.dependency.local import LocalDependency
|
||||||
|
from dvc.dependency.param import ParamsDependency
|
||||||
from dvc.dependency.s3 import S3Dependency
|
from dvc.dependency.s3 import S3Dependency
|
||||||
from dvc.dependency.ssh import SSHDependency
|
from dvc.dependency.ssh import SSHDependency
|
||||||
from dvc.dependency.param import ParamsDependency
|
|
||||||
from dvc.output.base import BaseOutput
|
from dvc.output.base import BaseOutput
|
||||||
from dvc.remote import Remote
|
from dvc.remote import get_remote
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
|
|
||||||
from .repo import RepoDependency
|
from .repo import RepoDependency
|
||||||
|
|
||||||
|
|
||||||
DEPS = [
|
DEPS = [
|
||||||
|
AzureDependency,
|
||||||
GSDependency,
|
GSDependency,
|
||||||
HDFSDependency,
|
HDFSDependency,
|
||||||
HTTPDependency,
|
HTTPDependency,
|
||||||
@@ -30,6 +32,7 @@ DEP_MAP = {
|
|||||||
Schemes.LOCAL: LocalDependency,
|
Schemes.LOCAL: LocalDependency,
|
||||||
Schemes.SSH: SSHDependency,
|
Schemes.SSH: SSHDependency,
|
||||||
Schemes.S3: S3Dependency,
|
Schemes.S3: S3Dependency,
|
||||||
|
Schemes.AZURE: AzureDependency,
|
||||||
Schemes.GS: GSDependency,
|
Schemes.GS: GSDependency,
|
||||||
Schemes.HDFS: HDFSDependency,
|
Schemes.HDFS: HDFSDependency,
|
||||||
Schemes.HTTP: HTTPDependency,
|
Schemes.HTTP: HTTPDependency,
|
||||||
@@ -51,7 +54,7 @@ SCHEMA.update(ParamsDependency.PARAM_SCHEMA)
|
|||||||
def _get(stage, p, info):
|
def _get(stage, p, info):
|
||||||
parsed = urlparse(p) if p else None
|
parsed = urlparse(p) if p else None
|
||||||
if parsed and parsed.scheme == "remote":
|
if parsed and parsed.scheme == "remote":
|
||||||
remote = Remote(stage.repo, name=parsed.netloc)
|
remote = get_remote(stage.repo, name=parsed.netloc)
|
||||||
return DEP_MAP[remote.scheme](stage, p, info, remote=remote)
|
return DEP_MAP[remote.scheme](stage, p, info, remote=remote)
|
||||||
|
|
||||||
if info and info.get(RepoDependency.PARAM_REPO):
|
if info and info.get(RepoDependency.PARAM_REPO):
|
||||||
@@ -77,6 +80,7 @@ def loadd_from(stage, d_list):
|
|||||||
|
|
||||||
|
|
||||||
def loads_from(stage, s_list, erepo=None):
|
def loads_from(stage, s_list, erepo=None):
|
||||||
|
assert isinstance(s_list, list)
|
||||||
ret = []
|
ret = []
|
||||||
for s in s_list:
|
for s in s_list:
|
||||||
info = {RepoDependency.PARAM_REPO: erepo} if erepo else {}
|
info = {RepoDependency.PARAM_REPO: erepo} if erepo else {}
|
||||||
@@ -84,26 +88,29 @@ def loads_from(stage, s_list, erepo=None):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def _parse_params(path_params):
|
def _merge_params(s_list):
|
||||||
path, _, params_str = path_params.rpartition(":")
|
d = defaultdict(list)
|
||||||
params = params_str.split(",")
|
default_file = ParamsDependency.DEFAULT_PARAMS_FILE
|
||||||
return path, params
|
for key in s_list:
|
||||||
|
if isinstance(key, str):
|
||||||
|
d[default_file].append(key)
|
||||||
|
continue
|
||||||
|
if not isinstance(key, dict):
|
||||||
|
msg = "Only list of str/dict is supported. Got: "
|
||||||
|
msg += f"'{type(key).__name__}'."
|
||||||
|
raise ValueError(msg)
|
||||||
|
|
||||||
|
for k, params in key.items():
|
||||||
|
if not isinstance(params, list):
|
||||||
|
msg = "Expected list of params for custom params file "
|
||||||
|
msg += f"'{k}', got '{type(params).__name__}'."
|
||||||
|
raise ValueError(msg)
|
||||||
|
d[k].extend(params)
|
||||||
|
return d
|
||||||
|
|
||||||
|
|
||||||
def loads_params(stage, s_list):
|
def loads_params(stage, s_list):
|
||||||
# Creates an object for each unique file that is referenced in the list
|
d = _merge_params(s_list)
|
||||||
params_by_path = defaultdict(list)
|
return [
|
||||||
for s in s_list:
|
ParamsDependency(stage, path, params) for path, params in d.items()
|
||||||
path, params = _parse_params(s)
|
]
|
||||||
params_by_path[path].extend(params)
|
|
||||||
|
|
||||||
d_list = []
|
|
||||||
for path, params in params_by_path.items():
|
|
||||||
d_list.append(
|
|
||||||
{
|
|
||||||
BaseOutput.PARAM_PATH: path,
|
|
||||||
ParamsDependency.PARAM_PARAMS: params,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
return loadd_from(stage, d_list)
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
from dvc.dependency.base import BaseDependency
|
||||||
|
from dvc.output.base import BaseOutput
|
||||||
|
from dvc.remote.azure import AzureRemoteTree
|
||||||
|
|
||||||
|
|
||||||
|
class AzureDependency(BaseDependency, BaseOutput):
|
||||||
|
TREE_CLS = AzureRemoteTree
|
||||||
@@ -3,24 +3,22 @@ from dvc.exceptions import DvcException
|
|||||||
|
|
||||||
class DependencyDoesNotExistError(DvcException):
|
class DependencyDoesNotExistError(DvcException):
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
msg = "dependency '{}' does not exist".format(path)
|
msg = f"dependency '{path}' does not exist"
|
||||||
super().__init__(msg)
|
super().__init__(msg)
|
||||||
|
|
||||||
|
|
||||||
class DependencyIsNotFileOrDirError(DvcException):
|
class DependencyIsNotFileOrDirError(DvcException):
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
msg = "dependency '{}' is not a file or directory".format(path)
|
msg = f"dependency '{path}' is not a file or directory"
|
||||||
super().__init__(msg)
|
super().__init__(msg)
|
||||||
|
|
||||||
|
|
||||||
class DependencyIsStageFileError(DvcException):
|
class DependencyIsStageFileError(DvcException):
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
super().__init__(
|
super().__init__(f"Stage file '{path}' cannot be a dependency.")
|
||||||
"Stage file '{}' cannot be a dependency.".format(path)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class BaseDependency(object):
|
class BaseDependency:
|
||||||
IS_DEPENDENCY = True
|
IS_DEPENDENCY = True
|
||||||
|
|
||||||
DoesNotExistError = DependencyDoesNotExistError
|
DoesNotExistError = DependencyDoesNotExistError
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from dvc.dependency.base import BaseDependency
|
from dvc.dependency.base import BaseDependency
|
||||||
from dvc.output.base import BaseOutput
|
from dvc.output.base import BaseOutput
|
||||||
from dvc.remote.http import HTTPRemote
|
from dvc.remote.http import HTTPRemoteTree
|
||||||
|
|
||||||
|
|
||||||
class HTTPDependency(BaseDependency, BaseOutput):
|
class HTTPDependency(BaseDependency, BaseOutput):
|
||||||
REMOTE = HTTPRemote
|
TREE_CLS = HTTPRemoteTree
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
from dvc.remote.https import HTTPSRemoteTree
|
||||||
|
|
||||||
from .http import HTTPDependency
|
from .http import HTTPDependency
|
||||||
from dvc.remote.https import HTTPSRemote
|
|
||||||
|
|
||||||
|
|
||||||
class HTTPSDependency(HTTPDependency):
|
class HTTPSDependency(HTTPDependency):
|
||||||
REMOTE = HTTPSRemote
|
TREE_CLS = HTTPSRemoteTree
|
||||||
|
|||||||
+12
-4
@@ -1,11 +1,10 @@
|
|||||||
import os
|
import os
|
||||||
import yaml
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
import dpath.util
|
import dpath.util
|
||||||
|
import yaml
|
||||||
from voluptuous import Any
|
from voluptuous import Any
|
||||||
|
|
||||||
from dvc.compat import fspath_py35
|
|
||||||
from dvc.dependency.local import LocalDependency
|
from dvc.dependency.local import LocalDependency
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
@@ -41,6 +40,15 @@ class ParamsDependency(LocalDependency):
|
|||||||
info=info,
|
info=info,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def fill_values(self, values=None):
|
||||||
|
"""Load params values dynamically."""
|
||||||
|
if not values:
|
||||||
|
return
|
||||||
|
for param in self.params:
|
||||||
|
value = values.get(param)
|
||||||
|
if value:
|
||||||
|
self.info[param] = value
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
super().save()
|
super().save()
|
||||||
self.info = self.save_info()
|
self.info = self.save_info()
|
||||||
@@ -78,12 +86,12 @@ class ParamsDependency(LocalDependency):
|
|||||||
if not self.exists:
|
if not self.exists:
|
||||||
return {}
|
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:
|
try:
|
||||||
config = yaml.safe_load(fobj)
|
config = yaml.safe_load(fobj)
|
||||||
except yaml.YAMLError as exc:
|
except yaml.YAMLError as exc:
|
||||||
raise BadParamFileError(
|
raise BadParamFileError(
|
||||||
"Unable to read parameters from '{}'".format(self)
|
f"Unable to read parameters from '{self}'"
|
||||||
) from exc
|
) from exc
|
||||||
|
|
||||||
ret = {}
|
ret = {}
|
||||||
|
|||||||
+18
-8
@@ -2,10 +2,11 @@ import os
|
|||||||
|
|
||||||
from voluptuous import Required
|
from voluptuous import Required
|
||||||
|
|
||||||
from .local import LocalDependency
|
|
||||||
from dvc.exceptions import OutputNotFoundError
|
from dvc.exceptions import OutputNotFoundError
|
||||||
from dvc.path_info import PathInfo
|
from dvc.path_info import PathInfo
|
||||||
|
|
||||||
|
from .local import LocalDependency
|
||||||
|
|
||||||
|
|
||||||
class RepoDependency(LocalDependency):
|
class RepoDependency(LocalDependency):
|
||||||
PARAM_REPO = "repo"
|
PARAM_REPO = "repo"
|
||||||
@@ -49,13 +50,22 @@ class RepoDependency(LocalDependency):
|
|||||||
return external_repo(d["url"], rev=rev)
|
return external_repo(d["url"], rev=rev)
|
||||||
|
|
||||||
def _get_checksum(self, locked=True):
|
def _get_checksum(self, locked=True):
|
||||||
|
from dvc.repo.tree import RepoTree
|
||||||
|
|
||||||
with self._make_repo(locked=locked) as repo:
|
with self._make_repo(locked=locked) as repo:
|
||||||
try:
|
try:
|
||||||
return repo.find_out_by_relpath(self.def_path).info["md5"]
|
return repo.find_out_by_relpath(self.def_path).info["md5"]
|
||||||
except OutputNotFoundError:
|
except OutputNotFoundError:
|
||||||
path = PathInfo(os.path.join(repo.root_dir, self.def_path))
|
path = PathInfo(os.path.join(repo.root_dir, self.def_path))
|
||||||
|
|
||||||
|
# we want stream but not fetch, so DVC out directories are
|
||||||
|
# walked, but dir contents is not fetched
|
||||||
|
tree = RepoTree(repo, stream=True)
|
||||||
|
|
||||||
# We are polluting our repo cache with some dir listing here
|
# We are polluting our repo cache with some dir listing here
|
||||||
return self.repo.cache.local.get_checksum(path)
|
if tree.isdir(path):
|
||||||
|
return self.repo.cache.local.get_hash(path, tree)
|
||||||
|
return tree.get_file_hash(path)
|
||||||
|
|
||||||
def status(self):
|
def status(self):
|
||||||
current_checksum = self._get_checksum(locked=True)
|
current_checksum = self._get_checksum(locked=True)
|
||||||
@@ -75,16 +85,16 @@ class RepoDependency(LocalDependency):
|
|||||||
def download(self, to):
|
def download(self, to):
|
||||||
with self._make_repo() as repo:
|
with self._make_repo() as repo:
|
||||||
if self.def_repo.get(self.PARAM_REV_LOCK) is None:
|
if self.def_repo.get(self.PARAM_REV_LOCK) is None:
|
||||||
self.def_repo[self.PARAM_REV_LOCK] = repo.scm.get_rev()
|
self.def_repo[self.PARAM_REV_LOCK] = repo.get_rev()
|
||||||
|
|
||||||
if hasattr(repo, "cache"):
|
cache = self.repo.cache.local
|
||||||
repo.cache.local.cache_dir = self.repo.cache.local.cache_dir
|
with repo.use_cache(cache):
|
||||||
|
_, _, cache_infos = repo.fetch_external([self.def_path])
|
||||||
repo.pull_to(self.def_path, to.path_info)
|
cache.checkout(to.path_info, cache_infos[0])
|
||||||
|
|
||||||
def update(self, rev=None):
|
def update(self, rev=None):
|
||||||
if rev:
|
if rev:
|
||||||
self.def_repo[self.PARAM_REV] = rev
|
self.def_repo[self.PARAM_REV] = rev
|
||||||
|
|
||||||
with self._make_repo(locked=False) as repo:
|
with self._make_repo(locked=False) as repo:
|
||||||
self.def_repo[self.PARAM_REV_LOCK] = repo.scm.get_rev()
|
self.def_repo[self.PARAM_REV_LOCK] = repo.get_rev()
|
||||||
|
|||||||
+81
-49
@@ -1,39 +1,32 @@
|
|||||||
import contextlib
|
import contextlib
|
||||||
import os
|
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import dvc.prompt as prompt
|
|
||||||
|
|
||||||
from voluptuous import MultipleInvalid
|
from voluptuous import MultipleInvalid
|
||||||
from dvc import serialize
|
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
from dvc.stage.loader import SingleStageLoader, StageLoader
|
from dvc.stage import serialize
|
||||||
from dvc.stage.exceptions import (
|
from dvc.stage.exceptions import (
|
||||||
StageFileBadNameError,
|
StageFileBadNameError,
|
||||||
StageFileDoesNotExistError,
|
StageFileDoesNotExistError,
|
||||||
StageFileIsNotDvcFileError,
|
|
||||||
StageFileFormatError,
|
StageFileFormatError,
|
||||||
StageFileAlreadyExistsError,
|
StageFileIsNotDvcFileError,
|
||||||
)
|
)
|
||||||
|
from dvc.stage.loader import SingleStageLoader, StageLoader
|
||||||
from dvc.utils import relpath
|
from dvc.utils import relpath
|
||||||
from dvc.utils.collections import apply_diff
|
from dvc.utils.collections import apply_diff
|
||||||
from dvc.utils.stage import (
|
from dvc.utils.yaml import dump_yaml, parse_yaml, parse_yaml_for_update
|
||||||
dump_stage_file,
|
|
||||||
parse_stage,
|
|
||||||
parse_stage_for_update,
|
|
||||||
)
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
DVC_FILE = "Dvcfile"
|
DVC_FILE = "Dvcfile"
|
||||||
DVC_FILE_SUFFIX = ".dvc"
|
DVC_FILE_SUFFIX = ".dvc"
|
||||||
PIPELINE_FILE = "pipelines.yaml"
|
PIPELINE_FILE = "dvc.yaml"
|
||||||
PIPELINE_LOCK = "pipelines.lock"
|
PIPELINE_LOCK = "dvc.lock"
|
||||||
|
|
||||||
|
|
||||||
class LockfileCorruptedError(DvcException):
|
class LockfileCorruptedError(DvcException):
|
||||||
def __init__(self, path):
|
pass
|
||||||
super().__init__("Lockfile '{}' is corrupted.".format(path))
|
|
||||||
|
|
||||||
|
|
||||||
def is_valid_filename(path):
|
def is_valid_filename(path):
|
||||||
@@ -80,7 +73,7 @@ class FileMixin:
|
|||||||
) == os.path.abspath(other.path)
|
) == os.path.abspath(other.path)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{}: {}".format(self.__class__.__name__, self.relpath)
|
return f"{self.__class__.__name__}: {self.relpath}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def relpath(self):
|
def relpath(self):
|
||||||
@@ -102,8 +95,8 @@ class FileMixin:
|
|||||||
|
|
||||||
with self.repo.tree.open(self.path) as fd:
|
with self.repo.tree.open(self.path) as fd:
|
||||||
stage_text = fd.read()
|
stage_text = fd.read()
|
||||||
d = parse_stage(stage_text, self.path)
|
d = parse_yaml(stage_text, self.path)
|
||||||
self.validate(d, self.path)
|
self.validate(d, self.relpath)
|
||||||
return d, stage_text
|
return d, stage_text
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -112,10 +105,7 @@ class FileMixin:
|
|||||||
try:
|
try:
|
||||||
cls.SCHEMA(d)
|
cls.SCHEMA(d)
|
||||||
except MultipleInvalid as exc:
|
except MultipleInvalid as exc:
|
||||||
raise StageFileFormatError(fname, exc)
|
raise StageFileFormatError(f"'{fname}' format error: {exc}")
|
||||||
|
|
||||||
def remove_with_prompt(self, force=False):
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def remove(self, force=False):
|
def remove(self, force=False):
|
||||||
with contextlib.suppress(FileNotFoundError):
|
with contextlib.suppress(FileNotFoundError):
|
||||||
@@ -150,20 +140,10 @@ class SingleStageFile(FileMixin):
|
|||||||
logger.debug(
|
logger.debug(
|
||||||
"Saving information to '{file}'.".format(file=relpath(self.path))
|
"Saving information to '{file}'.".format(file=relpath(self.path))
|
||||||
)
|
)
|
||||||
dump_stage_file(self.path, serialize.to_single_stage_file(stage))
|
dump_yaml(self.path, serialize.to_single_stage_file(stage))
|
||||||
self.repo.scm.track_file(relpath(self.path))
|
self.repo.scm.track_file(self.relpath)
|
||||||
|
|
||||||
def remove_with_prompt(self, force=False):
|
|
||||||
if not self.exists():
|
|
||||||
return
|
|
||||||
|
|
||||||
msg = (
|
|
||||||
"'{}' already exists. Do you wish to run the command and "
|
|
||||||
"overwrite it?".format(relpath(self.path))
|
|
||||||
)
|
|
||||||
if not (force or prompt.confirm(msg)):
|
|
||||||
raise StageFileAlreadyExistsError(self.path)
|
|
||||||
|
|
||||||
|
def remove_stage(self, stage):
|
||||||
self.remove()
|
self.remove()
|
||||||
|
|
||||||
|
|
||||||
@@ -176,37 +156,48 @@ class PipelineFile(FileMixin):
|
|||||||
def _lockfile(self):
|
def _lockfile(self):
|
||||||
return Lockfile(self.repo, os.path.splitext(self.path)[0] + ".lock")
|
return Lockfile(self.repo, os.path.splitext(self.path)[0] + ".lock")
|
||||||
|
|
||||||
def dump(self, stage, update_pipeline=False, **kwargs):
|
def dump(self, stage, update_pipeline=False, no_lock=False):
|
||||||
"""Dumps given stage appropriately in the dvcfile."""
|
"""Dumps given stage appropriately in the dvcfile."""
|
||||||
from dvc.stage import PipelineStage
|
from dvc.stage import PipelineStage
|
||||||
|
|
||||||
assert isinstance(stage, PipelineStage)
|
assert isinstance(stage, PipelineStage)
|
||||||
check_dvc_filename(self.path)
|
check_dvc_filename(self.path)
|
||||||
self._dump_lockfile(stage)
|
|
||||||
if update_pipeline and not stage.is_data_source:
|
if update_pipeline and not stage.is_data_source:
|
||||||
self._dump_pipeline_file(stage)
|
self._dump_pipeline_file(stage)
|
||||||
|
|
||||||
|
if not no_lock:
|
||||||
|
self._dump_lockfile(stage)
|
||||||
|
|
||||||
def _dump_lockfile(self, stage):
|
def _dump_lockfile(self, stage):
|
||||||
self._lockfile.dump(stage)
|
self._lockfile.dump(stage)
|
||||||
|
|
||||||
def _dump_pipeline_file(self, stage):
|
def _dump_pipeline_file(self, stage):
|
||||||
data = {}
|
data = {}
|
||||||
if self.exists():
|
if self.exists():
|
||||||
with open(self.path, "r") as fd:
|
with open(self.path) as fd:
|
||||||
data = parse_stage_for_update(fd.read(), self.path)
|
data = parse_yaml_for_update(fd.read(), self.path)
|
||||||
else:
|
else:
|
||||||
|
logger.info("Creating '%s'", self.relpath)
|
||||||
open(self.path, "w+").close()
|
open(self.path, "w+").close()
|
||||||
|
|
||||||
data["stages"] = data.get("stages", {})
|
data["stages"] = data.get("stages", {})
|
||||||
stage_data = serialize.to_pipeline_file(stage)
|
stage_data = serialize.to_pipeline_file(stage)
|
||||||
if data["stages"].get(stage.name):
|
existing_entry = stage.name in data["stages"]
|
||||||
|
|
||||||
|
action = "Modifying" if existing_entry else "Adding"
|
||||||
|
logger.info("%s stage '%s' in '%s'", action, stage.name, self.relpath)
|
||||||
|
|
||||||
|
if existing_entry:
|
||||||
orig_stage_data = data["stages"][stage.name]
|
orig_stage_data = data["stages"][stage.name]
|
||||||
|
if "meta" in orig_stage_data:
|
||||||
|
stage_data[stage.name]["meta"] = orig_stage_data["meta"]
|
||||||
apply_diff(stage_data[stage.name], orig_stage_data)
|
apply_diff(stage_data[stage.name], orig_stage_data)
|
||||||
else:
|
else:
|
||||||
data["stages"].update(stage_data)
|
data["stages"].update(stage_data)
|
||||||
|
|
||||||
dump_stage_file(self.path, data)
|
dump_yaml(self.path, data)
|
||||||
self.repo.scm.track_file(relpath(self.path))
|
self.repo.scm.track_file(self.relpath)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def stage(self):
|
def stage(self):
|
||||||
@@ -228,6 +219,22 @@ class PipelineFile(FileMixin):
|
|||||||
super().remove()
|
super().remove()
|
||||||
self._lockfile.remove()
|
self._lockfile.remove()
|
||||||
|
|
||||||
|
def remove_stage(self, stage):
|
||||||
|
self._lockfile.remove_stage(stage)
|
||||||
|
if not self.exists():
|
||||||
|
return
|
||||||
|
|
||||||
|
with open(self.path, "r") as f:
|
||||||
|
d = parse_yaml_for_update(f.read(), self.path)
|
||||||
|
|
||||||
|
self.validate(d, self.path)
|
||||||
|
if stage.name not in d.get("stages", {}):
|
||||||
|
return
|
||||||
|
|
||||||
|
logger.debug("Removing '%s' from '%s'", stage.name, self.path)
|
||||||
|
del d["stages"][stage.name]
|
||||||
|
dump_yaml(self.path, d)
|
||||||
|
|
||||||
|
|
||||||
class Lockfile(FileMixin):
|
class Lockfile(FileMixin):
|
||||||
from dvc.schema import COMPILED_LOCKFILE_SCHEMA as SCHEMA
|
from dvc.schema import COMPILED_LOCKFILE_SCHEMA as SCHEMA
|
||||||
@@ -236,25 +243,50 @@ class Lockfile(FileMixin):
|
|||||||
if not self.exists():
|
if not self.exists():
|
||||||
return {}
|
return {}
|
||||||
with self.repo.tree.open(self.path) as fd:
|
with self.repo.tree.open(self.path) as fd:
|
||||||
data = parse_stage(fd.read(), self.path)
|
data = parse_yaml(fd.read(), self.path)
|
||||||
try:
|
try:
|
||||||
self.validate(data, fname=self.path)
|
self.validate(data, fname=self.relpath)
|
||||||
except StageFileFormatError:
|
except StageFileFormatError:
|
||||||
raise LockfileCorruptedError(self.path)
|
raise LockfileCorruptedError(
|
||||||
|
f"Lockfile '{self.relpath}' is corrupted."
|
||||||
|
)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def dump(self, stage, **kwargs):
|
def dump(self, stage, **kwargs):
|
||||||
stage_data = serialize.to_lockfile(stage)
|
stage_data = serialize.to_lockfile(stage)
|
||||||
if not self.exists():
|
if not self.exists():
|
||||||
|
modified = True
|
||||||
|
logger.info("Generating lock file '%s'", self.relpath)
|
||||||
data = stage_data
|
data = stage_data
|
||||||
open(self.path, "w+").close()
|
open(self.path, "w+").close()
|
||||||
else:
|
else:
|
||||||
with self.repo.tree.open(self.path, "r") as fd:
|
with self.repo.tree.open(self.path, "r") as fd:
|
||||||
data = parse_stage_for_update(fd.read(), self.path)
|
data = parse_yaml_for_update(fd.read(), self.path)
|
||||||
|
modified = data.get(stage.name, {}) != stage_data.get(
|
||||||
|
stage.name, {}
|
||||||
|
)
|
||||||
|
if modified:
|
||||||
|
logger.info("Updating lock file '%s'", self.relpath)
|
||||||
data.update(stage_data)
|
data.update(stage_data)
|
||||||
|
dump_yaml(self.path, data)
|
||||||
|
if modified:
|
||||||
|
self.repo.scm.track_file(self.relpath)
|
||||||
|
|
||||||
dump_stage_file(self.path, data)
|
def remove_stage(self, stage):
|
||||||
self.repo.scm.track_file(relpath(self.path))
|
if not self.exists():
|
||||||
|
return
|
||||||
|
|
||||||
|
with open(self.path) as f:
|
||||||
|
d = parse_yaml_for_update(f.read(), self.path)
|
||||||
|
self.validate(d, self.path)
|
||||||
|
|
||||||
|
if stage.name not in d:
|
||||||
|
return
|
||||||
|
|
||||||
|
logger.debug("Removing '%s' from '%s'", stage.name, self.path)
|
||||||
|
del d[stage.name]
|
||||||
|
|
||||||
|
dump_yaml(self.path, d)
|
||||||
|
|
||||||
|
|
||||||
class Dvcfile:
|
class Dvcfile:
|
||||||
|
|||||||
+57
-48
@@ -1,11 +1,16 @@
|
|||||||
"""Exceptions raised by the dvc."""
|
"""Exceptions raised by the dvc."""
|
||||||
|
from funcy import first
|
||||||
|
|
||||||
from dvc.utils import relpath, format_link
|
from dvc.utils import format_link, relpath
|
||||||
|
|
||||||
|
|
||||||
class DvcException(Exception):
|
class DvcException(Exception):
|
||||||
"""Base class for all dvc exceptions."""
|
"""Base class for all dvc exceptions."""
|
||||||
|
|
||||||
|
def __init__(self, msg, *args):
|
||||||
|
assert msg
|
||||||
|
super().__init__(msg, *args)
|
||||||
|
|
||||||
|
|
||||||
class InvalidArgumentError(ValueError, DvcException):
|
class InvalidArgumentError(ValueError, DvcException):
|
||||||
"""Thrown if arguments are invalid."""
|
"""Thrown if arguments are invalid."""
|
||||||
@@ -23,13 +28,14 @@ class OutputDuplicationError(DvcException):
|
|||||||
def __init__(self, output, stages):
|
def __init__(self, output, stages):
|
||||||
assert isinstance(output, str)
|
assert isinstance(output, str)
|
||||||
assert all(hasattr(stage, "relpath") for stage in stages)
|
assert all(hasattr(stage, "relpath") for stage in stages)
|
||||||
msg = (
|
if len(stages) == 1:
|
||||||
"file/directory '{}' is specified as an output in more than one "
|
msg = "output '{}' is already specified in {}.".format(
|
||||||
"stage: \n{}\n"
|
output, first(stages)
|
||||||
"This is not allowed. Consider using a different output name."
|
)
|
||||||
).format(
|
else:
|
||||||
output, "\n".join("\t{}".format(s.addressing) for s in stages)
|
msg = "output '{}' is already specified in stages:\n{}".format(
|
||||||
)
|
output, "\n".join(f"\t- {s.addressing}" for s in stages),
|
||||||
|
)
|
||||||
super().__init__(msg)
|
super().__init__(msg)
|
||||||
self.stages = stages
|
self.stages = stages
|
||||||
self.output = output
|
self.output = output
|
||||||
@@ -81,10 +87,7 @@ class CircularDependencyError(DvcException):
|
|||||||
def __init__(self, dependency):
|
def __init__(self, dependency):
|
||||||
assert isinstance(dependency, str)
|
assert isinstance(dependency, str)
|
||||||
|
|
||||||
msg = (
|
msg = "'{}' is specified as an output and as a dependency."
|
||||||
"file/directory '{}' is specified as an output and as a "
|
|
||||||
"dependency."
|
|
||||||
)
|
|
||||||
super().__init__(msg.format(dependency))
|
super().__init__(msg.format(dependency))
|
||||||
|
|
||||||
|
|
||||||
@@ -98,7 +101,7 @@ class ArgumentDuplicationError(DvcException):
|
|||||||
|
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
assert isinstance(path, str)
|
assert isinstance(path, str)
|
||||||
super().__init__("file '{}' is specified more than once.".format(path))
|
super().__init__(f"file '{path}' is specified more than once.")
|
||||||
|
|
||||||
|
|
||||||
class MoveNotDataSourceError(DvcException):
|
class MoveNotDataSourceError(DvcException):
|
||||||
@@ -133,14 +136,8 @@ class DvcParserError(DvcException):
|
|||||||
class CyclicGraphError(DvcException):
|
class CyclicGraphError(DvcException):
|
||||||
def __init__(self, stages):
|
def __init__(self, stages):
|
||||||
assert isinstance(stages, list)
|
assert isinstance(stages, list)
|
||||||
stages = "\n".join(
|
msg = "Pipeline has a cycle involving: {}.".format(
|
||||||
"\t- {}".format(stage.addressing) for stage in stages
|
", ".join(s.addressing for s in stages)
|
||||||
)
|
|
||||||
msg = (
|
|
||||||
"you've introduced a cycle in your pipeline that involves "
|
|
||||||
"the following stages:"
|
|
||||||
"\n"
|
|
||||||
"{stages}".format(stages=stages)
|
|
||||||
)
|
)
|
||||||
super().__init__(msg)
|
super().__init__(msg)
|
||||||
|
|
||||||
@@ -148,7 +145,7 @@ class CyclicGraphError(DvcException):
|
|||||||
class ConfirmRemoveError(DvcException):
|
class ConfirmRemoveError(DvcException):
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
"unable to remove '{}' without a confirmation from the user. Use "
|
"unable to remove '{}' without a confirmation. Use "
|
||||||
"`-f` to force.".format(path)
|
"`-f` to force.".format(path)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -160,7 +157,7 @@ class InitError(DvcException):
|
|||||||
class ReproductionError(DvcException):
|
class ReproductionError(DvcException):
|
||||||
def __init__(self, dvc_file_name):
|
def __init__(self, dvc_file_name):
|
||||||
self.path = dvc_file_name
|
self.path = dvc_file_name
|
||||||
super().__init__("failed to reproduce '{}'".format(dvc_file_name))
|
super().__init__(f"failed to reproduce '{dvc_file_name}'")
|
||||||
|
|
||||||
|
|
||||||
class BadMetricError(DvcException):
|
class BadMetricError(DvcException):
|
||||||
@@ -168,7 +165,7 @@ class BadMetricError(DvcException):
|
|||||||
super().__init__(
|
super().__init__(
|
||||||
"the following metrics do not exist, "
|
"the following metrics do not exist, "
|
||||||
"are not metric files or are malformed: {paths}".format(
|
"are not metric files or are malformed: {paths}".format(
|
||||||
paths=", ".join("'{}'".format(path) for path in paths)
|
paths=", ".join(f"'{path}'" for path in paths)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -176,17 +173,24 @@ class BadMetricError(DvcException):
|
|||||||
class NoMetricsError(DvcException):
|
class NoMetricsError(DvcException):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
"no metric files in this repository. "
|
"no metric files in this repository. Use `-m/-M` options for "
|
||||||
"Use `dvc metrics add` to add a metric file to track."
|
"`dvc run` to mark stage outputs as metrics."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class StageFileCorruptedError(DvcException):
|
class NoPlotsError(DvcException):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(
|
||||||
|
"no plots in this repository. Use `--plots/--plots-no-cache` "
|
||||||
|
"options for `dvc run` to mark stage outputs as plots."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class YAMLFileCorruptedError(DvcException):
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
path = relpath(path)
|
path = relpath(path)
|
||||||
super().__init__(
|
super().__init__(
|
||||||
"unable to read DVC-file: {} "
|
f"unable to read: '{path}', YAML file structure is corrupted"
|
||||||
"YAML file structure is corrupted".format(path)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -206,7 +210,7 @@ class OverlappingOutputPathsError(DvcException):
|
|||||||
|
|
||||||
class CheckoutErrorSuggestGit(DvcException):
|
class CheckoutErrorSuggestGit(DvcException):
|
||||||
def __init__(self, target):
|
def __init__(self, target):
|
||||||
super().__init__("Did you mean `git checkout {}`?".format(target))
|
super().__init__(f"Did you mean `git checkout {target}`?")
|
||||||
|
|
||||||
|
|
||||||
class ETagMismatchError(DvcException):
|
class ETagMismatchError(DvcException):
|
||||||
@@ -218,10 +222,11 @@ class ETagMismatchError(DvcException):
|
|||||||
|
|
||||||
|
|
||||||
class FileMissingError(DvcException):
|
class FileMissingError(DvcException):
|
||||||
def __init__(self, path):
|
def __init__(self, path, hint=None):
|
||||||
self.path = path
|
self.path = path
|
||||||
|
hint = "" if hint is None else f". {hint}"
|
||||||
super().__init__(
|
super().__init__(
|
||||||
"Can't find '{}' neither locally nor on remote".format(path)
|
f"Can't find '{path}' neither locally nor on remote{hint}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -247,18 +252,14 @@ class DownloadError(DvcException):
|
|||||||
def __init__(self, amount):
|
def __init__(self, amount):
|
||||||
self.amount = amount
|
self.amount = amount
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(f"{amount} files failed to download")
|
||||||
"{amount} files failed to download".format(amount=amount)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class UploadError(DvcException):
|
class UploadError(DvcException):
|
||||||
def __init__(self, amount):
|
def __init__(self, amount):
|
||||||
self.amount = amount
|
self.amount = amount
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(f"{amount} files failed to upload")
|
||||||
"{amount} files failed to upload".format(amount=amount)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class CheckoutError(DvcException):
|
class CheckoutError(DvcException):
|
||||||
@@ -280,7 +281,7 @@ class CollectCacheError(DvcException):
|
|||||||
class NoRemoteInExternalRepoError(DvcException):
|
class NoRemoteInExternalRepoError(DvcException):
|
||||||
def __init__(self, url):
|
def __init__(self, url):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
"No DVC remote is specified in target repository '{}'.".format(url)
|
f"No DVC remote is specified in target repository '{url}'."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -295,7 +296,7 @@ class NoOutputInExternalRepoError(DvcException):
|
|||||||
|
|
||||||
class HTTPError(DvcException):
|
class HTTPError(DvcException):
|
||||||
def __init__(self, code, reason):
|
def __init__(self, code, reason):
|
||||||
super().__init__("'{} {}'".format(code, reason))
|
super().__init__(f"'{code} {reason}'")
|
||||||
|
|
||||||
|
|
||||||
class PathMissingError(DvcException):
|
class PathMissingError(DvcException):
|
||||||
@@ -303,19 +304,15 @@ class PathMissingError(DvcException):
|
|||||||
"The path '{}' does not exist in the target repository '{}'"
|
"The path '{}' does not exist in the target repository '{}'"
|
||||||
" neither as a DVC output nor as a Git-tracked file."
|
" neither as a DVC output nor as a Git-tracked file."
|
||||||
)
|
)
|
||||||
default_msg_output_only = (
|
default_msg_dvc_only = (
|
||||||
"The path '{}' does not exist in the target repository '{}'"
|
"The path '{}' does not exist in the target repository '{}'"
|
||||||
" as an DVC output."
|
" as an DVC output."
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, path, repo, output_only=False):
|
def __init__(self, path, repo, dvc_only=False):
|
||||||
msg = (
|
msg = self.default_msg if not dvc_only else self.default_msg_dvc_only
|
||||||
self.default_msg
|
|
||||||
if not output_only
|
|
||||||
else self.default_msg_output_only
|
|
||||||
)
|
|
||||||
super().__init__(msg.format(path, repo))
|
super().__init__(msg.format(path, repo))
|
||||||
self.output_only = output_only
|
self.dvc_only = dvc_only
|
||||||
|
|
||||||
|
|
||||||
class RemoteCacheRequiredError(DvcException):
|
class RemoteCacheRequiredError(DvcException):
|
||||||
@@ -335,3 +332,15 @@ class RemoteCacheRequiredError(DvcException):
|
|||||||
|
|
||||||
class IsADirectoryError(DvcException):
|
class IsADirectoryError(DvcException):
|
||||||
"""Raised when a file operation is requested on a directory."""
|
"""Raised when a file operation is requested on a directory."""
|
||||||
|
|
||||||
|
|
||||||
|
class NoOutputOrStageError(DvcException):
|
||||||
|
"""
|
||||||
|
Raised when the target is neither an output nor a stage name in dvc.yaml
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, target, file):
|
||||||
|
super().__init__(
|
||||||
|
f"'{target}' "
|
||||||
|
f"does not exist as an output or a stage name in '{file}'"
|
||||||
|
)
|
||||||
|
|||||||
+126
-88
@@ -1,23 +1,27 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import threading
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from distutils.dir_util import copy_tree
|
from distutils.dir_util import copy_tree
|
||||||
import threading
|
from typing import Iterable
|
||||||
|
|
||||||
from funcy import retry, suppress, wrap_with, cached_property
|
from funcy import cached_property, retry, wrap_with
|
||||||
|
|
||||||
from dvc.path_info import PathInfo
|
|
||||||
from dvc.compat import fspath
|
|
||||||
from dvc.repo import Repo
|
|
||||||
from dvc.config import NoRemoteError, NotDvcRepoError
|
from dvc.config import NoRemoteError, NotDvcRepoError
|
||||||
from dvc.exceptions import NoRemoteInExternalRepoError, CheckoutError
|
from dvc.exceptions import (
|
||||||
from dvc.exceptions import OutputNotFoundError, NoOutputInExternalRepoError
|
FileMissingError,
|
||||||
from dvc.exceptions import FileMissingError, PathMissingError
|
NoOutputInExternalRepoError,
|
||||||
from dvc.utils.fs import remove, fs_copy, move
|
NoRemoteInExternalRepoError,
|
||||||
from dvc.utils import tmp_fname
|
OutputNotFoundError,
|
||||||
|
PathMissingError,
|
||||||
|
)
|
||||||
|
from dvc.path_info import PathInfo
|
||||||
|
from dvc.repo import Repo
|
||||||
|
from dvc.repo.tree import RepoTree
|
||||||
from dvc.scm.git import Git
|
from dvc.scm.git import Git
|
||||||
|
from dvc.scm.tree import is_working_tree
|
||||||
|
from dvc.utils.fs import remove
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -26,10 +30,12 @@ logger = logging.getLogger(__name__)
|
|||||||
def external_repo(url, rev=None, for_write=False):
|
def external_repo(url, rev=None, for_write=False):
|
||||||
logger.debug("Creating external repo %s@%s", url, rev)
|
logger.debug("Creating external repo %s@%s", url, rev)
|
||||||
path = _cached_clone(url, rev, for_write=for_write)
|
path = _cached_clone(url, rev, for_write=for_write)
|
||||||
|
if not rev:
|
||||||
|
rev = "HEAD"
|
||||||
try:
|
try:
|
||||||
repo = ExternalRepo(path, url)
|
repo = ExternalRepo(path, url, rev, for_write=for_write)
|
||||||
except NotDvcRepoError:
|
except NotDvcRepoError:
|
||||||
repo = ExternalGitRepo(path, url)
|
repo = ExternalGitRepo(path, url, rev)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
yield repo
|
yield repo
|
||||||
@@ -61,59 +67,100 @@ def clean_repos():
|
|||||||
_remove(path)
|
_remove(path)
|
||||||
|
|
||||||
|
|
||||||
class ExternalRepo(Repo):
|
class BaseExternalRepo:
|
||||||
def __init__(self, root_dir, url):
|
|
||||||
super().__init__(root_dir)
|
_local_cache = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def local_cache(self):
|
||||||
|
if hasattr(self, "cache"):
|
||||||
|
return self.cache.local
|
||||||
|
return self._local_cache
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def use_cache(self, cache):
|
||||||
|
"""Use the specified cache in place of default tmpdir cache for
|
||||||
|
download operations.
|
||||||
|
"""
|
||||||
|
if hasattr(self, "cache"):
|
||||||
|
save_cache = self.cache.local
|
||||||
|
self.cache.local = cache
|
||||||
|
self._local_cache = cache
|
||||||
|
|
||||||
|
yield
|
||||||
|
|
||||||
|
if hasattr(self, "cache"):
|
||||||
|
self.cache.local = save_cache
|
||||||
|
self._local_cache = None
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def repo_tree(self):
|
||||||
|
return RepoTree(self, fetch=True)
|
||||||
|
|
||||||
|
def get_rev(self):
|
||||||
|
if is_working_tree(self.tree):
|
||||||
|
return self.scm.get_rev()
|
||||||
|
if hasattr(self.tree, "tree"):
|
||||||
|
return self.tree.tree.rev
|
||||||
|
return self.tree.rev
|
||||||
|
|
||||||
|
def fetch_external(self, paths: Iterable, **kwargs):
|
||||||
|
"""Fetch specified external repo paths into cache.
|
||||||
|
|
||||||
|
Returns 3-tuple in the form
|
||||||
|
(downloaded, failed, list(cache_infos))
|
||||||
|
where cache_infos can be used as checkout targets for the
|
||||||
|
fetched paths.
|
||||||
|
"""
|
||||||
|
download_results = []
|
||||||
|
failed = 0
|
||||||
|
|
||||||
|
paths = [PathInfo(self.root_dir) / path for path in paths]
|
||||||
|
|
||||||
|
def download_update(result):
|
||||||
|
download_results.append(result)
|
||||||
|
|
||||||
|
save_infos = []
|
||||||
|
for path in paths:
|
||||||
|
if not self.repo_tree.exists(path):
|
||||||
|
raise PathMissingError(path, self.url)
|
||||||
|
save_info = self.local_cache.save(
|
||||||
|
path,
|
||||||
|
self.repo_tree,
|
||||||
|
None,
|
||||||
|
save_link=False,
|
||||||
|
download_callback=download_update,
|
||||||
|
)
|
||||||
|
save_infos.append(save_info)
|
||||||
|
|
||||||
|
return sum(download_results), failed, save_infos
|
||||||
|
|
||||||
|
def get_external(self, path, dest):
|
||||||
|
"""Convenience wrapper for fetch_external and checkout."""
|
||||||
|
if self.local_cache:
|
||||||
|
# fetch DVC and git files to tmpdir cache, then checkout
|
||||||
|
_, _, save_infos = self.fetch_external([path])
|
||||||
|
self.local_cache.checkout(PathInfo(dest), save_infos[0])
|
||||||
|
else:
|
||||||
|
# git-only erepo with no cache, just copy files directly
|
||||||
|
# to dest
|
||||||
|
path = PathInfo(self.root_dir) / path
|
||||||
|
if not self.repo_tree.exists(path):
|
||||||
|
raise PathMissingError(path, self.url)
|
||||||
|
self.repo_tree.copytree(path, dest)
|
||||||
|
|
||||||
|
|
||||||
|
class ExternalRepo(Repo, BaseExternalRepo):
|
||||||
|
def __init__(self, root_dir, url, rev, for_write=False):
|
||||||
|
if for_write:
|
||||||
|
super().__init__(root_dir)
|
||||||
|
else:
|
||||||
|
root_dir = os.path.realpath(root_dir)
|
||||||
|
super().__init__(root_dir, scm=Git(root_dir), rev=rev)
|
||||||
self.url = url
|
self.url = url
|
||||||
self._set_cache_dir()
|
self._set_cache_dir()
|
||||||
self._fix_upstream()
|
self._fix_upstream()
|
||||||
|
|
||||||
def pull_to(self, path, to_info):
|
|
||||||
"""
|
|
||||||
Pull the corresponding file or directory specified by `path` and
|
|
||||||
checkout it into `to_info`.
|
|
||||||
|
|
||||||
It works with files tracked by Git and DVC, and also local files
|
|
||||||
outside the repository.
|
|
||||||
"""
|
|
||||||
out = None
|
|
||||||
path_info = PathInfo(self.root_dir) / path
|
|
||||||
|
|
||||||
with suppress(OutputNotFoundError):
|
|
||||||
(out,) = self.find_outs_by_path(fspath(path_info), strict=False)
|
|
||||||
|
|
||||||
try:
|
|
||||||
if out and out.use_cache:
|
|
||||||
self._pull_cached(out, path_info, to_info)
|
|
||||||
return
|
|
||||||
|
|
||||||
# Check if it is handled by Git (it can't have an absolute path)
|
|
||||||
if os.path.isabs(path):
|
|
||||||
raise FileNotFoundError
|
|
||||||
|
|
||||||
fs_copy(fspath(path_info), fspath(to_info))
|
|
||||||
except FileNotFoundError:
|
|
||||||
raise PathMissingError(path, self.url)
|
|
||||||
|
|
||||||
def _pull_cached(self, out, path_info, dest):
|
|
||||||
with self.state:
|
|
||||||
tmp = PathInfo(tmp_fname(dest))
|
|
||||||
src = tmp / path_info.relative_to(out.path_info)
|
|
||||||
|
|
||||||
out.path_info = tmp
|
|
||||||
|
|
||||||
# Only pull unless all needed cache is present
|
|
||||||
if out.changed_cache(filter_info=src):
|
|
||||||
self.cloud.pull(out.get_used_cache(filter_info=src))
|
|
||||||
|
|
||||||
try:
|
|
||||||
out.checkout(filter_info=src)
|
|
||||||
except CheckoutError:
|
|
||||||
raise FileNotFoundError
|
|
||||||
|
|
||||||
move(src, dest)
|
|
||||||
remove(tmp)
|
|
||||||
|
|
||||||
@wrap_with(threading.Lock())
|
@wrap_with(threading.Lock())
|
||||||
def _set_cache_dir(self):
|
def _set_cache_dir(self):
|
||||||
try:
|
try:
|
||||||
@@ -122,6 +169,7 @@ class ExternalRepo(Repo):
|
|||||||
cache_dir = CACHE_DIRS[self.url] = tempfile.mkdtemp("dvc-cache")
|
cache_dir = CACHE_DIRS[self.url] = tempfile.mkdtemp("dvc-cache")
|
||||||
|
|
||||||
self.cache.local.cache_dir = cache_dir
|
self.cache.local.cache_dir = cache_dir
|
||||||
|
self._local_cache = self.cache.local
|
||||||
|
|
||||||
def _fix_upstream(self):
|
def _fix_upstream(self):
|
||||||
if not os.path.isdir(self.url):
|
if not os.path.isdir(self.url):
|
||||||
@@ -162,10 +210,11 @@ class ExternalRepo(Repo):
|
|||||||
self.config["core"]["remote"] = "auto-generated-upstream"
|
self.config["core"]["remote"] = "auto-generated-upstream"
|
||||||
|
|
||||||
|
|
||||||
class ExternalGitRepo:
|
class ExternalGitRepo(BaseExternalRepo):
|
||||||
def __init__(self, root_dir, url):
|
def __init__(self, root_dir, url, rev):
|
||||||
self.root_dir = root_dir
|
self.root_dir = os.path.realpath(root_dir)
|
||||||
self.url = url
|
self.url = url
|
||||||
|
self.tree = self.scm.get_tree(rev)
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def scm(self):
|
def scm(self):
|
||||||
@@ -178,23 +227,15 @@ class ExternalGitRepo:
|
|||||||
def find_out_by_relpath(self, path):
|
def find_out_by_relpath(self, path):
|
||||||
raise OutputNotFoundError(path, self)
|
raise OutputNotFoundError(path, self)
|
||||||
|
|
||||||
def pull_to(self, path, to_info):
|
|
||||||
try:
|
|
||||||
# Git handled files can't have absolute path
|
|
||||||
if os.path.isabs(path):
|
|
||||||
raise FileNotFoundError
|
|
||||||
|
|
||||||
fs_copy(os.path.join(self.root_dir, path), fspath(to_info))
|
|
||||||
except FileNotFoundError:
|
|
||||||
raise PathMissingError(path, self.url)
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def open_by_relpath(self, path, mode="r", encoding=None, **kwargs):
|
def open_by_relpath(self, path, mode="r", encoding=None, **kwargs):
|
||||||
"""Opens a specified resource as a file object."""
|
"""Opens a specified resource as a file object."""
|
||||||
|
tree = RepoTree(self)
|
||||||
try:
|
try:
|
||||||
abs_path = os.path.join(self.root_dir, path)
|
with tree.open(
|
||||||
with open(abs_path, mode, encoding=encoding) as fd:
|
path, mode=mode, encoding=encoding, **kwargs
|
||||||
yield fd
|
) as fobj:
|
||||||
|
yield fobj
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
raise PathMissingError(path, self.url)
|
raise PathMissingError(path, self.url)
|
||||||
|
|
||||||
@@ -206,14 +247,12 @@ def _cached_clone(url, rev, for_write=False):
|
|||||||
revision checked out. If for_write is set prevents reusing this dir via
|
revision checked out. If for_write is set prevents reusing this dir via
|
||||||
cache.
|
cache.
|
||||||
"""
|
"""
|
||||||
if not for_write and Git.is_sha(rev) and (url, rev) in CLONES:
|
# even if we have already cloned this repo, we may need to
|
||||||
return CLONES[url, rev]
|
# fetch/fast-forward to get specified rev
|
||||||
|
|
||||||
clone_path = _clone_default_branch(url, rev)
|
clone_path = _clone_default_branch(url, rev)
|
||||||
rev_sha = Git(clone_path).resolve_rev(rev or "HEAD")
|
|
||||||
|
|
||||||
if not for_write and (url, rev_sha) in CLONES:
|
if not for_write and (url) in CLONES:
|
||||||
return CLONES[url, rev_sha]
|
return CLONES[url]
|
||||||
|
|
||||||
# Copy to a new dir to keep the clone clean
|
# Copy to a new dir to keep the clone clean
|
||||||
repo_path = tempfile.mkdtemp("dvc-erepo")
|
repo_path = tempfile.mkdtemp("dvc-erepo")
|
||||||
@@ -221,11 +260,10 @@ def _cached_clone(url, rev, for_write=False):
|
|||||||
copy_tree(clone_path, repo_path)
|
copy_tree(clone_path, repo_path)
|
||||||
|
|
||||||
# Check out the specified revision
|
# Check out the specified revision
|
||||||
if rev is not None:
|
if for_write:
|
||||||
_git_checkout(repo_path, rev)
|
_git_checkout(repo_path, rev)
|
||||||
|
else:
|
||||||
if not for_write:
|
CLONES[url] = repo_path
|
||||||
CLONES[url, rev_sha] = repo_path
|
|
||||||
return repo_path
|
return repo_path
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+123
-25
@@ -1,17 +1,21 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
from itertools import groupby
|
||||||
|
|
||||||
from funcy import cached_property
|
from funcy import cached_property
|
||||||
from pathspec import PathSpec
|
|
||||||
from pathspec.patterns import GitWildMatchPattern
|
from pathspec.patterns import GitWildMatchPattern
|
||||||
|
from pathspec.util import normalize_file
|
||||||
|
|
||||||
|
from dvc.path_info import PathInfo
|
||||||
from dvc.scm.tree import BaseTree
|
from dvc.scm.tree import BaseTree
|
||||||
|
from dvc.system import System
|
||||||
from dvc.utils import relpath
|
from dvc.utils import relpath
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class DvcIgnore(object):
|
class DvcIgnore:
|
||||||
DVCIGNORE_FILE = ".dvcignore"
|
DVCIGNORE_FILE = ".dvcignore"
|
||||||
|
|
||||||
def __call__(self, root, dirs, files):
|
def __call__(self, root, dirs, files):
|
||||||
@@ -26,7 +30,16 @@ class DvcIgnorePatterns(DvcIgnore):
|
|||||||
self.dirname = os.path.normpath(os.path.dirname(ignore_file_path))
|
self.dirname = os.path.normpath(os.path.dirname(ignore_file_path))
|
||||||
|
|
||||||
with tree.open(ignore_file_path, encoding="utf-8") as fobj:
|
with tree.open(ignore_file_path, encoding="utf-8") as fobj:
|
||||||
self.ignore_spec = PathSpec.from_lines(GitWildMatchPattern, fobj)
|
path_spec_lines = fobj.readlines()
|
||||||
|
regex_pattern_list = map(
|
||||||
|
GitWildMatchPattern.pattern_to_regex, path_spec_lines
|
||||||
|
)
|
||||||
|
self.ignore_spec = [
|
||||||
|
(ignore, re.compile("|".join(item[0] for item in group)))
|
||||||
|
for ignore, group in groupby(
|
||||||
|
regex_pattern_list, lambda x: x[1]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
def __call__(self, root, dirs, files):
|
def __call__(self, root, dirs, files):
|
||||||
files = [f for f in files if not self.matches(root, f)]
|
files = [f for f in files if not self.matches(root, f)]
|
||||||
@@ -35,12 +48,28 @@ class DvcIgnorePatterns(DvcIgnore):
|
|||||||
return dirs, files
|
return dirs, files
|
||||||
|
|
||||||
def matches(self, dirname, basename):
|
def matches(self, dirname, basename):
|
||||||
abs_path = os.path.join(dirname, basename)
|
# NOTE: `relpath` is too slow, so we have to assume that both
|
||||||
rel_path = relpath(abs_path, self.dirname)
|
# `dirname` and `self.dirname` are relative or absolute together.
|
||||||
|
prefix = self.dirname + os.sep
|
||||||
if os.pardir + os.sep in rel_path:
|
if dirname == self.dirname:
|
||||||
|
path = basename
|
||||||
|
elif dirname.startswith(prefix):
|
||||||
|
rel = dirname[len(prefix) :]
|
||||||
|
# NOTE: `os.path.join` is ~x5.5 slower
|
||||||
|
path = f"{rel}{os.sep}{basename}"
|
||||||
|
else:
|
||||||
return False
|
return False
|
||||||
return self.ignore_spec.match_file(rel_path)
|
|
||||||
|
if not System.is_unix():
|
||||||
|
path = normalize_file(path)
|
||||||
|
return self.ignore(path)
|
||||||
|
|
||||||
|
def ignore(self, path):
|
||||||
|
result = False
|
||||||
|
for ignore, pattern in self.ignore_spec:
|
||||||
|
if pattern.match(path):
|
||||||
|
result = ignore
|
||||||
|
return result
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash(self.ignore_file_path)
|
return hash(self.ignore_file_path)
|
||||||
@@ -76,21 +105,22 @@ class DvcIgnoreRepo(DvcIgnore):
|
|||||||
def is_dvc_repo(directory):
|
def is_dvc_repo(directory):
|
||||||
from dvc.repo import Repo
|
from dvc.repo import Repo
|
||||||
|
|
||||||
return os.path.isdir(os.path.join(directory, Repo.DVC_DIR))
|
return os.path.isdir(os.path.join(root, directory, Repo.DVC_DIR))
|
||||||
|
|
||||||
dirs = [d for d in dirs if not is_dvc_repo(d)]
|
dirs = [d for d in dirs if not is_dvc_repo(d)]
|
||||||
|
|
||||||
return dirs, files
|
return dirs, files
|
||||||
|
|
||||||
|
|
||||||
class DvcIgnoreFilter(object):
|
class DvcIgnoreFilter:
|
||||||
def __init__(self, tree):
|
def __init__(self, tree, root_dir):
|
||||||
self.tree = tree
|
self.tree = tree
|
||||||
|
self.root_dir = root_dir
|
||||||
self.ignores = {
|
self.ignores = {
|
||||||
DvcIgnoreDirs([".git", ".hg", ".dvc"]),
|
DvcIgnoreDirs([".git", ".hg", ".dvc"]),
|
||||||
DvcIgnoreRepo(),
|
DvcIgnoreRepo(),
|
||||||
}
|
}
|
||||||
for root, dirs, files in self.tree.walk(self.tree.tree_root):
|
for root, dirs, files in self.tree.walk(self.root_dir):
|
||||||
self._update(root)
|
self._update(root)
|
||||||
dirs[:], files[:] = self(root, dirs, files)
|
dirs[:], files[:] = self(root, dirs, files)
|
||||||
|
|
||||||
@@ -107,39 +137,107 @@ class DvcIgnoreFilter(object):
|
|||||||
|
|
||||||
|
|
||||||
class CleanTree(BaseTree):
|
class CleanTree(BaseTree):
|
||||||
def __init__(self, tree):
|
def __init__(self, tree, tree_root=None):
|
||||||
self.tree = tree
|
self.tree = tree
|
||||||
|
if tree_root:
|
||||||
|
self._tree_root = tree_root
|
||||||
|
else:
|
||||||
|
self._tree_root = self.tree.tree_root
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def dvcignore(self):
|
def dvcignore(self):
|
||||||
return DvcIgnoreFilter(self.tree)
|
return DvcIgnoreFilter(self.tree, self.tree_root)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def tree_root(self):
|
def tree_root(self):
|
||||||
return self.tree.tree_root
|
return self._tree_root
|
||||||
|
|
||||||
def open(self, path, mode="r", encoding="utf-8"):
|
def open(self, path, mode="r", encoding="utf-8"):
|
||||||
return self.tree.open(path, mode, encoding)
|
if self.isfile(path):
|
||||||
|
return self.tree.open(path, mode, encoding)
|
||||||
|
raise FileNotFoundError
|
||||||
|
|
||||||
def exists(self, path):
|
def exists(self, path):
|
||||||
return self.tree.exists(path)
|
if self.tree.exists(path) and self._parents_exist(path):
|
||||||
|
if self.tree.isdir(path):
|
||||||
|
return self._valid_dirname(path)
|
||||||
|
return self._valid_filename(path)
|
||||||
|
return False
|
||||||
|
|
||||||
def isdir(self, path):
|
def isdir(self, path):
|
||||||
return self.tree.isdir(path)
|
return (
|
||||||
|
self.tree.isdir(path)
|
||||||
|
and self._parents_exist(path)
|
||||||
|
and self._valid_dirname(path)
|
||||||
|
)
|
||||||
|
|
||||||
|
def _valid_dirname(self, path):
|
||||||
|
path = os.path.abspath(path)
|
||||||
|
if path == self.tree_root:
|
||||||
|
return True
|
||||||
|
dirname, basename = os.path.split(path)
|
||||||
|
dirs, _ = self.dvcignore(dirname, [basename], [])
|
||||||
|
if dirs:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def isfile(self, path):
|
def isfile(self, path):
|
||||||
return self.tree.isfile(path)
|
return (
|
||||||
|
self.tree.isfile(path)
|
||||||
|
and self._parents_exist(path)
|
||||||
|
and self._valid_filename(path)
|
||||||
|
)
|
||||||
|
|
||||||
|
def _valid_filename(self, path):
|
||||||
|
dirname, basename = os.path.split(os.path.normpath(path))
|
||||||
|
_, files = self.dvcignore(os.path.abspath(dirname), [], [basename])
|
||||||
|
if files:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def isexec(self, path):
|
def isexec(self, path):
|
||||||
return self.tree.isexec(path)
|
return self.exists(path) and self.tree.isexec(path)
|
||||||
|
|
||||||
|
def _parents_exist(self, path):
|
||||||
|
from dvc.repo import Repo
|
||||||
|
|
||||||
|
path = PathInfo(path)
|
||||||
|
|
||||||
|
# if parent is tree_root or inside a .dvc dir we can skip this check
|
||||||
|
if path.parent == self.tree_root or Repo.DVC_DIR in path.parts:
|
||||||
|
return True
|
||||||
|
|
||||||
|
# paths outside of the CleanTree root should be ignored
|
||||||
|
path = relpath(path, self.tree_root)
|
||||||
|
if path.startswith("..") or (
|
||||||
|
os.name == "nt"
|
||||||
|
and not os.path.commonprefix(
|
||||||
|
[os.path.abspath(path), self.tree_root]
|
||||||
|
)
|
||||||
|
):
|
||||||
|
return False
|
||||||
|
|
||||||
|
# check if parent directories are in our ignores, starting from
|
||||||
|
# tree_root
|
||||||
|
for parent_dir in reversed(PathInfo(path).parents):
|
||||||
|
dirname, basename = os.path.split(parent_dir)
|
||||||
|
if basename == ".":
|
||||||
|
# parent_dir == tree_root
|
||||||
|
continue
|
||||||
|
dirs, _ = self.dvcignore(os.path.abspath(dirname), [basename], [])
|
||||||
|
if not dirs:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def walk(self, top, topdown=True):
|
def walk(self, top, topdown=True):
|
||||||
for root, dirs, files in self.tree.walk(top, topdown):
|
for root, dirs, files in self.tree.walk(top, topdown):
|
||||||
dirs[:], files[:] = self.dvcignore(root, dirs, files)
|
dirs[:], files[:] = self.dvcignore(
|
||||||
|
os.path.abspath(root), dirs, files
|
||||||
|
)
|
||||||
|
|
||||||
yield root, dirs, files
|
yield root, dirs, files
|
||||||
|
|
||||||
def walk_files(self, top):
|
def stat(self, path):
|
||||||
for root, _, files in self.walk(top):
|
if self.exists(path):
|
||||||
for file in files:
|
return self.tree.stat(path)
|
||||||
yield os.path.join(root, file)
|
raise FileNotFoundError
|
||||||
|
|||||||
+6
-2
@@ -7,13 +7,17 @@
|
|||||||
TEXT_CHARS = bytes(range(32, 127)) + b"\n\r\t\f\b"
|
TEXT_CHARS = bytes(range(32, 127)) + b"\n\r\t\f\b"
|
||||||
|
|
||||||
|
|
||||||
def istextfile(fname, blocksize=512):
|
def istextfile(fname, blocksize=512, tree=None):
|
||||||
""" Uses heuristics to guess whether the given file is text or binary,
|
""" Uses heuristics to guess whether the given file is text or binary,
|
||||||
by reading a single block of bytes from the file.
|
by reading a single block of bytes from the file.
|
||||||
If more than 30% of the chars in the block are non-text, or there
|
If more than 30% of the chars in the block are non-text, or there
|
||||||
are NUL ('\x00') bytes in the block, assume this is a binary file.
|
are NUL ('\x00') bytes in the block, assume this is a binary file.
|
||||||
"""
|
"""
|
||||||
with open(fname, "rb") as fobj:
|
if tree:
|
||||||
|
open_func = tree.open
|
||||||
|
else:
|
||||||
|
open_func = open
|
||||||
|
with open_func(fname, "rb") as fobj:
|
||||||
block = fobj.read(blocksize)
|
block = fobj.read(blocksize)
|
||||||
|
|
||||||
if not block:
|
if not block:
|
||||||
|
|||||||
+5
-5
@@ -5,19 +5,19 @@ import os
|
|||||||
import time
|
import time
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
import zc.lockfile
|
|
||||||
import flufl.lock
|
import flufl.lock
|
||||||
|
import zc.lockfile
|
||||||
|
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
from dvc.utils import format_link
|
|
||||||
from dvc.progress import Tqdm
|
from dvc.progress import Tqdm
|
||||||
|
from dvc.utils import format_link
|
||||||
|
|
||||||
DEFAULT_TIMEOUT = 5
|
DEFAULT_TIMEOUT = 5
|
||||||
|
|
||||||
FAILED_TO_LOCK_MESSAGE = (
|
FAILED_TO_LOCK_MESSAGE = (
|
||||||
"cannot perform the command because another DVC process seems to be "
|
"cannot perform the command because another DVC process seems to be "
|
||||||
"running on this project. If that is not the case, manually remove "
|
"running on this project. If that is not the case, manually remove "
|
||||||
"`.dvc/lock` and try again."
|
"`.dvc/tmp/lock` and try again."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ class LockError(DvcException):
|
|||||||
"""Thrown when unable to acquire the lock for DVC repo."""
|
"""Thrown when unable to acquire the lock for DVC repo."""
|
||||||
|
|
||||||
|
|
||||||
class Lock(object):
|
class Lock:
|
||||||
"""Class for DVC repo lock.
|
"""Class for DVC repo lock.
|
||||||
|
|
||||||
Uses zc.lockfile as backend.
|
Uses zc.lockfile as backend.
|
||||||
@@ -47,7 +47,7 @@ class Lock(object):
|
|||||||
disable=not self._friendly,
|
disable=not self._friendly,
|
||||||
desc=(
|
desc=(
|
||||||
"If DVC froze, see `hardlink_lock` in {}".format(
|
"If DVC froze, see `hardlink_lock` in {}".format(
|
||||||
format_link("man.dvc.org/config#core")
|
format_link("https://man.dvc.org/config#core")
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
|
|||||||
+50
-11
@@ -7,7 +7,6 @@ import colorama
|
|||||||
|
|
||||||
from dvc.progress import Tqdm
|
from dvc.progress import Tqdm
|
||||||
|
|
||||||
|
|
||||||
FOOTER = (
|
FOOTER = (
|
||||||
"\n{yellow}Having any troubles?{nc}"
|
"\n{yellow}Having any troubles?{nc}"
|
||||||
" Hit us up at {blue}https://dvc.org/support{nc},"
|
" Hit us up at {blue}https://dvc.org/support{nc},"
|
||||||
@@ -19,20 +18,45 @@ FOOTER = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def addLoggingLevel(levelName, levelNum, methodName=None):
|
||||||
|
"""
|
||||||
|
Adds a new logging level to the `logging` module and the
|
||||||
|
currently configured logging class.
|
||||||
|
|
||||||
|
Based on https://stackoverflow.com/questions/2183233
|
||||||
|
"""
|
||||||
|
if methodName is None:
|
||||||
|
methodName = levelName.lower()
|
||||||
|
|
||||||
|
assert not hasattr(logging, levelName)
|
||||||
|
assert not hasattr(logging, methodName)
|
||||||
|
assert not hasattr(logging.getLoggerClass(), methodName)
|
||||||
|
|
||||||
|
def logForLevel(self, message, *args, **kwargs):
|
||||||
|
if self.isEnabledFor(levelNum):
|
||||||
|
self._log(levelNum, message, args, **kwargs)
|
||||||
|
|
||||||
|
def logToRoot(message, *args, **kwargs):
|
||||||
|
logging.log(levelNum, message, *args, **kwargs)
|
||||||
|
|
||||||
|
logging.addLevelName(levelNum, levelName)
|
||||||
|
setattr(logging, levelName, levelNum)
|
||||||
|
setattr(logging.getLoggerClass(), methodName, logForLevel)
|
||||||
|
setattr(logging, methodName, logToRoot)
|
||||||
|
|
||||||
|
|
||||||
class LoggingException(Exception):
|
class LoggingException(Exception):
|
||||||
def __init__(self, record):
|
def __init__(self, record):
|
||||||
msg = "failed to log {}".format(str(record))
|
msg = "failed to log {}".format(str(record))
|
||||||
super().__init__(msg)
|
super().__init__(msg)
|
||||||
|
|
||||||
|
|
||||||
class ExcludeErrorsFilter(logging.Filter):
|
def excludeFilter(level):
|
||||||
def filter(self, record):
|
class ExcludeLevelFilter(logging.Filter):
|
||||||
return record.levelno < logging.WARNING
|
def filter(self, record):
|
||||||
|
return record.levelno < level
|
||||||
|
|
||||||
|
return ExcludeLevelFilter
|
||||||
class ExcludeInfoFilter(logging.Filter):
|
|
||||||
def filter(self, record):
|
|
||||||
return record.levelno < logging.INFO
|
|
||||||
|
|
||||||
|
|
||||||
class ColorFormatter(logging.Formatter):
|
class ColorFormatter(logging.Formatter):
|
||||||
@@ -48,6 +72,7 @@ class ColorFormatter(logging.Formatter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
color_code = {
|
color_code = {
|
||||||
|
"TRACE": colorama.Fore.GREEN,
|
||||||
"DEBUG": colorama.Fore.BLUE,
|
"DEBUG": colorama.Fore.BLUE,
|
||||||
"WARNING": colorama.Fore.YELLOW,
|
"WARNING": colorama.Fore.YELLOW,
|
||||||
"ERROR": colorama.Fore.RED,
|
"ERROR": colorama.Fore.RED,
|
||||||
@@ -117,7 +142,11 @@ class LoggerHandler(logging.StreamHandler):
|
|||||||
|
|
||||||
|
|
||||||
def _is_verbose():
|
def _is_verbose():
|
||||||
return logging.getLogger("dvc").getEffectiveLevel() == logging.DEBUG
|
return (
|
||||||
|
logging.NOTSET
|
||||||
|
< logging.getLogger("dvc").getEffectiveLevel()
|
||||||
|
<= logging.DEBUG
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _iter_causes(exc):
|
def _iter_causes(exc):
|
||||||
@@ -153,12 +182,14 @@ def disable_other_loggers():
|
|||||||
def setup(level=logging.INFO):
|
def setup(level=logging.INFO):
|
||||||
colorama.init()
|
colorama.init()
|
||||||
|
|
||||||
|
addLoggingLevel("TRACE", logging.DEBUG - 5)
|
||||||
logging.config.dictConfig(
|
logging.config.dictConfig(
|
||||||
{
|
{
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"filters": {
|
"filters": {
|
||||||
"exclude_errors": {"()": ExcludeErrorsFilter},
|
"exclude_errors": {"()": excludeFilter(logging.WARNING)},
|
||||||
"exclude_info": {"()": ExcludeInfoFilter},
|
"exclude_info": {"()": excludeFilter(logging.INFO)},
|
||||||
|
"exclude_debug": {"()": excludeFilter(logging.DEBUG)},
|
||||||
},
|
},
|
||||||
"formatters": {"color": {"()": ColorFormatter}},
|
"formatters": {"color": {"()": ColorFormatter}},
|
||||||
"handlers": {
|
"handlers": {
|
||||||
@@ -176,6 +207,13 @@ def setup(level=logging.INFO):
|
|||||||
"stream": "ext://sys.stdout",
|
"stream": "ext://sys.stdout",
|
||||||
"filters": ["exclude_info"],
|
"filters": ["exclude_info"],
|
||||||
},
|
},
|
||||||
|
"console_trace": {
|
||||||
|
"class": "dvc.logger.LoggerHandler",
|
||||||
|
"level": "TRACE",
|
||||||
|
"formatter": "color",
|
||||||
|
"stream": "ext://sys.stdout",
|
||||||
|
"filters": ["exclude_debug"],
|
||||||
|
},
|
||||||
"console_errors": {
|
"console_errors": {
|
||||||
"class": "dvc.logger.LoggerHandler",
|
"class": "dvc.logger.LoggerHandler",
|
||||||
"level": "WARNING",
|
"level": "WARNING",
|
||||||
@@ -189,6 +227,7 @@ def setup(level=logging.INFO):
|
|||||||
"handlers": [
|
"handlers": [
|
||||||
"console_info",
|
"console_info",
|
||||||
"console_debug",
|
"console_debug",
|
||||||
|
"console_trace",
|
||||||
"console_errors",
|
"console_errors",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
+17
-10
@@ -6,12 +6,11 @@ import logging
|
|||||||
from dvc import analytics
|
from dvc import analytics
|
||||||
from dvc.cli import parse_args
|
from dvc.cli import parse_args
|
||||||
from dvc.config import ConfigError
|
from dvc.config import ConfigError
|
||||||
from dvc.exceptions import DvcParserError
|
from dvc.exceptions import DvcException, DvcParserError, NotDvcRepoError
|
||||||
from dvc.exceptions import NotDvcRepoError
|
|
||||||
from dvc.external_repo import clean_repos
|
from dvc.external_repo import clean_repos
|
||||||
from dvc.logger import disable_other_loggers, FOOTER
|
from dvc.logger import FOOTER, disable_other_loggers
|
||||||
from dvc.utils import format_link
|
|
||||||
from dvc.remote.pool import close_pools
|
from dvc.remote.pool import close_pools
|
||||||
|
from dvc.utils import format_link
|
||||||
|
|
||||||
# Workaround for CPython bug. See [1] and [2] for more info.
|
# Workaround for CPython bug. See [1] and [2] for more info.
|
||||||
# [1] https://github.com/aws/aws-cli/blob/1.16.277/awscli/clidriver.py#L55
|
# [1] https://github.com/aws/aws-cli/blob/1.16.277/awscli/clidriver.py#L55
|
||||||
@@ -19,7 +18,6 @@ from dvc.remote.pool import close_pools
|
|||||||
|
|
||||||
"".encode("idna")
|
"".encode("idna")
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger("dvc")
|
logger = logging.getLogger("dvc")
|
||||||
|
|
||||||
|
|
||||||
@@ -39,11 +37,17 @@ def main(argv=None):
|
|||||||
try:
|
try:
|
||||||
args = parse_args(argv)
|
args = parse_args(argv)
|
||||||
|
|
||||||
if args.quiet:
|
verbosity = args.verbose - args.quiet
|
||||||
logger.setLevel(logging.CRITICAL)
|
if verbosity:
|
||||||
|
logger.setLevel(
|
||||||
elif args.verbose:
|
{
|
||||||
logger.setLevel(logging.DEBUG)
|
-2: logging.CRITICAL,
|
||||||
|
-1: logging.ERROR,
|
||||||
|
1: logging.DEBUG,
|
||||||
|
2: logging.TRACE,
|
||||||
|
}[max(-2, min(verbosity, 2))]
|
||||||
|
)
|
||||||
|
logger.trace(args)
|
||||||
|
|
||||||
cmd = args.func(args)
|
cmd = args.func(args)
|
||||||
ret = cmd.run()
|
ret = cmd.run()
|
||||||
@@ -58,6 +62,9 @@ def main(argv=None):
|
|||||||
ret = 253
|
ret = 253
|
||||||
except DvcParserError:
|
except DvcParserError:
|
||||||
ret = 254
|
ret = 254
|
||||||
|
except DvcException:
|
||||||
|
ret = 255
|
||||||
|
logger.exception("")
|
||||||
except Exception as exc: # pylint: disable=broad-except
|
except Exception as exc: # pylint: disable=broad-except
|
||||||
if isinstance(exc, OSError) and exc.errno == errno.EMFILE:
|
if isinstance(exc, OSError) and exc.errno == errno.EMFILE:
|
||||||
logger.exception(
|
logger.exception(
|
||||||
|
|||||||
+83
-24
@@ -1,5 +1,8 @@
|
|||||||
|
from collections import defaultdict
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from voluptuous import Any, Required, Lower, Length, Coerce, And, SetTo
|
|
||||||
|
from funcy import collecting, project
|
||||||
|
from voluptuous import And, Any, Coerce, Length, Lower, Required, SetTo
|
||||||
|
|
||||||
from dvc.output.base import BaseOutput
|
from dvc.output.base import BaseOutput
|
||||||
from dvc.output.gs import GSOutput
|
from dvc.output.gs import GSOutput
|
||||||
@@ -7,10 +10,10 @@ from dvc.output.hdfs import HDFSOutput
|
|||||||
from dvc.output.local import LocalOutput
|
from dvc.output.local import LocalOutput
|
||||||
from dvc.output.s3 import S3Output
|
from dvc.output.s3 import S3Output
|
||||||
from dvc.output.ssh import SSHOutput
|
from dvc.output.ssh import SSHOutput
|
||||||
from dvc.remote import Remote
|
from dvc.remote import get_remote
|
||||||
from dvc.remote.hdfs import HDFSRemote
|
from dvc.remote.hdfs import HDFSRemoteTree
|
||||||
from dvc.remote.local import LocalRemote
|
from dvc.remote.local import LocalRemoteTree
|
||||||
from dvc.remote.s3 import S3Remote
|
from dvc.remote.s3 import S3RemoteTree
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
|
|
||||||
OUTS = [
|
OUTS = [
|
||||||
@@ -44,23 +47,26 @@ CHECKSUM_SCHEMA = Any(
|
|||||||
# so when a few types of outputs share the same name, we only need
|
# so when a few types of outputs share the same name, we only need
|
||||||
# specify it once.
|
# specify it once.
|
||||||
CHECKSUMS_SCHEMA = {
|
CHECKSUMS_SCHEMA = {
|
||||||
LocalRemote.PARAM_CHECKSUM: CHECKSUM_SCHEMA,
|
LocalRemoteTree.PARAM_CHECKSUM: CHECKSUM_SCHEMA,
|
||||||
S3Remote.PARAM_CHECKSUM: CHECKSUM_SCHEMA,
|
S3RemoteTree.PARAM_CHECKSUM: CHECKSUM_SCHEMA,
|
||||||
HDFSRemote.PARAM_CHECKSUM: CHECKSUM_SCHEMA,
|
HDFSRemoteTree.PARAM_CHECKSUM: CHECKSUM_SCHEMA,
|
||||||
}
|
}
|
||||||
|
|
||||||
SCHEMA = CHECKSUMS_SCHEMA.copy()
|
SCHEMA = CHECKSUMS_SCHEMA.copy()
|
||||||
SCHEMA[Required(BaseOutput.PARAM_PATH)] = str
|
SCHEMA[Required(BaseOutput.PARAM_PATH)] = str
|
||||||
SCHEMA[BaseOutput.PARAM_CACHE] = bool
|
SCHEMA[BaseOutput.PARAM_CACHE] = bool
|
||||||
SCHEMA[BaseOutput.PARAM_METRIC] = BaseOutput.METRIC_SCHEMA
|
SCHEMA[BaseOutput.PARAM_METRIC] = BaseOutput.METRIC_SCHEMA
|
||||||
|
SCHEMA[BaseOutput.PARAM_PLOT] = bool
|
||||||
SCHEMA[BaseOutput.PARAM_PERSIST] = bool
|
SCHEMA[BaseOutput.PARAM_PERSIST] = bool
|
||||||
|
|
||||||
|
|
||||||
def _get(stage, p, info, cache, metric, persist=False):
|
def _get(
|
||||||
|
stage, p, info=None, cache=True, metric=False, plot=False, persist=False
|
||||||
|
):
|
||||||
parsed = urlparse(p)
|
parsed = urlparse(p)
|
||||||
|
|
||||||
if parsed.scheme == "remote":
|
if parsed.scheme == "remote":
|
||||||
remote = Remote(stage.repo, name=parsed.netloc)
|
remote = get_remote(stage.repo, name=parsed.netloc)
|
||||||
return OUTS_MAP[remote.scheme](
|
return OUTS_MAP[remote.scheme](
|
||||||
stage,
|
stage,
|
||||||
p,
|
p,
|
||||||
@@ -68,6 +74,7 @@ def _get(stage, p, info, cache, metric, persist=False):
|
|||||||
cache=cache,
|
cache=cache,
|
||||||
remote=remote,
|
remote=remote,
|
||||||
metric=metric,
|
metric=metric,
|
||||||
|
plot=plot,
|
||||||
persist=persist,
|
persist=persist,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -80,6 +87,7 @@ def _get(stage, p, info, cache, metric, persist=False):
|
|||||||
cache=cache,
|
cache=cache,
|
||||||
remote=None,
|
remote=None,
|
||||||
metric=metric,
|
metric=metric,
|
||||||
|
plot=plot,
|
||||||
persist=persist,
|
persist=persist,
|
||||||
)
|
)
|
||||||
return LocalOutput(
|
return LocalOutput(
|
||||||
@@ -89,6 +97,7 @@ def _get(stage, p, info, cache, metric, persist=False):
|
|||||||
cache=cache,
|
cache=cache,
|
||||||
remote=None,
|
remote=None,
|
||||||
metric=metric,
|
metric=metric,
|
||||||
|
plot=plot,
|
||||||
persist=persist,
|
persist=persist,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -99,26 +108,76 @@ def loadd_from(stage, d_list):
|
|||||||
p = d.pop(BaseOutput.PARAM_PATH)
|
p = d.pop(BaseOutput.PARAM_PATH)
|
||||||
cache = d.pop(BaseOutput.PARAM_CACHE, True)
|
cache = d.pop(BaseOutput.PARAM_CACHE, True)
|
||||||
metric = d.pop(BaseOutput.PARAM_METRIC, False)
|
metric = d.pop(BaseOutput.PARAM_METRIC, False)
|
||||||
|
plot = d.pop(BaseOutput.PARAM_PLOT, False)
|
||||||
persist = d.pop(BaseOutput.PARAM_PERSIST, False)
|
persist = d.pop(BaseOutput.PARAM_PERSIST, False)
|
||||||
ret.append(
|
|
||||||
_get(
|
|
||||||
stage, p, info=d, cache=cache, metric=metric, persist=persist,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return ret
|
|
||||||
|
|
||||||
|
|
||||||
def loads_from(stage, s_list, use_cache=True, metric=False, persist=False):
|
|
||||||
ret = []
|
|
||||||
for s in s_list:
|
|
||||||
ret.append(
|
ret.append(
|
||||||
_get(
|
_get(
|
||||||
stage,
|
stage,
|
||||||
s,
|
p,
|
||||||
info={},
|
info=d,
|
||||||
cache=use_cache,
|
cache=cache,
|
||||||
metric=metric,
|
metric=metric,
|
||||||
|
plot=plot,
|
||||||
persist=persist,
|
persist=persist,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
def loads_from(
|
||||||
|
stage, s_list, use_cache=True, metric=False, plot=False, persist=False
|
||||||
|
):
|
||||||
|
return [
|
||||||
|
_get(
|
||||||
|
stage,
|
||||||
|
s,
|
||||||
|
info={},
|
||||||
|
cache=use_cache,
|
||||||
|
metric=metric,
|
||||||
|
plot=plot,
|
||||||
|
persist=persist,
|
||||||
|
)
|
||||||
|
for s in s_list
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def _split_dict(d, keys):
|
||||||
|
return project(d, keys), project(d, d.keys() - keys)
|
||||||
|
|
||||||
|
|
||||||
|
def _merge_data(s_list):
|
||||||
|
d = defaultdict(dict)
|
||||||
|
for key in s_list:
|
||||||
|
if isinstance(key, str):
|
||||||
|
d[key].update({})
|
||||||
|
continue
|
||||||
|
if not isinstance(key, dict):
|
||||||
|
raise ValueError(f"'{type(key).__name__}' not supported.")
|
||||||
|
|
||||||
|
for k, flags in key.items():
|
||||||
|
if not isinstance(flags, dict):
|
||||||
|
raise ValueError(
|
||||||
|
f"Expected dict for '{k}', got: '{type(flags).__name__}'"
|
||||||
|
)
|
||||||
|
d[k].update(flags)
|
||||||
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
@collecting
|
||||||
|
def load_from_pipeline(stage, s_list, typ="outs"):
|
||||||
|
if typ not in (stage.PARAM_OUTS, stage.PARAM_METRICS, stage.PARAM_PLOTS):
|
||||||
|
raise ValueError(f"'{typ}' key is not allowed for pipeline files.")
|
||||||
|
|
||||||
|
metric = typ == stage.PARAM_METRICS
|
||||||
|
plot = typ == stage.PARAM_PLOTS
|
||||||
|
|
||||||
|
d = _merge_data(s_list)
|
||||||
|
|
||||||
|
for path, flags in d.items():
|
||||||
|
plt_d = {}
|
||||||
|
if plot:
|
||||||
|
from dvc.schema import PLOT_PROPS
|
||||||
|
|
||||||
|
plt_d, flags = _split_dict(flags, keys=PLOT_PROPS.keys())
|
||||||
|
extra = project(flags, ["cache", "persist"])
|
||||||
|
yield _get(stage, path, {}, plot=plt_d or plot, metric=metric, **extra)
|
||||||
|
|||||||
+97
-64
@@ -1,53 +1,68 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from urllib.parse import urlparse
|
|
||||||
from copy import copy
|
from copy import copy
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from voluptuous import Any
|
from voluptuous import Any
|
||||||
|
|
||||||
import dvc.prompt as prompt
|
import dvc.prompt as prompt
|
||||||
from dvc.cache import NamedCache
|
from dvc.cache import NamedCache
|
||||||
from dvc.exceptions import CollectCacheError, RemoteCacheRequiredError
|
from dvc.exceptions import (
|
||||||
from dvc.exceptions import DvcException
|
CollectCacheError,
|
||||||
from dvc.remote.base import BaseRemote
|
DvcException,
|
||||||
|
RemoteCacheRequiredError,
|
||||||
|
)
|
||||||
|
from dvc.remote.base import BaseRemoteTree, Remote
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class OutputDoesNotExistError(DvcException):
|
class OutputDoesNotExistError(DvcException):
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
msg = "output '{}' does not exist".format(path)
|
msg = f"output '{path}' does not exist"
|
||||||
super().__init__(msg)
|
super().__init__(msg)
|
||||||
|
|
||||||
|
|
||||||
class OutputIsNotFileOrDirError(DvcException):
|
class OutputIsNotFileOrDirError(DvcException):
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
msg = "output '{}' is not a file or directory".format(path)
|
msg = f"output '{path}' is not a file or directory"
|
||||||
super().__init__(msg)
|
super().__init__(msg)
|
||||||
|
|
||||||
|
|
||||||
class OutputAlreadyTrackedError(DvcException):
|
class OutputAlreadyTrackedError(DvcException):
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
msg = "output '{}' is already tracked by SCM (e.g. Git)".format(path)
|
msg = f""" output '{path}' is already tracked by SCM (e.g. Git).
|
||||||
|
You can remove it from Git, then add to DVC.
|
||||||
|
To stop tracking from Git:
|
||||||
|
git rm -r --cached '{path}'
|
||||||
|
git commit -m "stop tracking {path}" """
|
||||||
super().__init__(msg)
|
super().__init__(msg)
|
||||||
|
|
||||||
|
|
||||||
class OutputIsStageFileError(DvcException):
|
class OutputIsStageFileError(DvcException):
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
super().__init__("Stage file '{}' cannot be an output.".format(path))
|
super().__init__(f"Stage file '{path}' cannot be an output.")
|
||||||
|
|
||||||
|
|
||||||
class BaseOutput(object):
|
class BaseOutput:
|
||||||
IS_DEPENDENCY = False
|
IS_DEPENDENCY = False
|
||||||
|
|
||||||
REMOTE = BaseRemote
|
REMOTE_CLS = Remote
|
||||||
|
TREE_CLS = BaseRemoteTree
|
||||||
|
|
||||||
PARAM_PATH = "path"
|
PARAM_PATH = "path"
|
||||||
PARAM_CACHE = "cache"
|
PARAM_CACHE = "cache"
|
||||||
PARAM_METRIC = "metric"
|
PARAM_METRIC = "metric"
|
||||||
PARAM_METRIC_TYPE = "type"
|
PARAM_METRIC_TYPE = "type"
|
||||||
PARAM_METRIC_XPATH = "xpath"
|
PARAM_METRIC_XPATH = "xpath"
|
||||||
|
PARAM_PLOT = "plot"
|
||||||
|
PARAM_PLOT_TEMPLATE = "template"
|
||||||
|
PARAM_PLOT_X = "x"
|
||||||
|
PARAM_PLOT_Y = "y"
|
||||||
|
PARAM_PLOT_X_LABEL = "x_label"
|
||||||
|
PARAM_PLOT_Y_LABEL = "y_label"
|
||||||
|
PARAM_PLOT_TITLE = "title"
|
||||||
|
PARAM_PLOT_HEADER = "header"
|
||||||
PARAM_PERSIST = "persist"
|
PARAM_PERSIST = "persist"
|
||||||
|
|
||||||
METRIC_SCHEMA = Any(
|
METRIC_SCHEMA = Any(
|
||||||
@@ -73,6 +88,7 @@ class BaseOutput(object):
|
|||||||
remote=None,
|
remote=None,
|
||||||
cache=True,
|
cache=True,
|
||||||
metric=False,
|
metric=False,
|
||||||
|
plot=False,
|
||||||
persist=False,
|
persist=False,
|
||||||
):
|
):
|
||||||
self._validate_output_path(path)
|
self._validate_output_path(path)
|
||||||
@@ -90,9 +106,14 @@ class BaseOutput(object):
|
|||||||
self.repo = stage.repo if stage else None
|
self.repo = stage.repo if stage else None
|
||||||
self.def_path = path
|
self.def_path = path
|
||||||
self.info = info
|
self.info = info
|
||||||
self.remote = remote or self.REMOTE(self.repo, {})
|
if remote:
|
||||||
|
self.remote = remote
|
||||||
|
else:
|
||||||
|
tree = self.TREE_CLS(self.repo, {})
|
||||||
|
self.remote = self.REMOTE_CLS(tree)
|
||||||
self.use_cache = False if self.IS_DEPENDENCY else cache
|
self.use_cache = False if self.IS_DEPENDENCY else cache
|
||||||
self.metric = False if self.IS_DEPENDENCY else metric
|
self.metric = False if self.IS_DEPENDENCY else metric
|
||||||
|
self.plot = False if self.IS_DEPENDENCY else plot
|
||||||
self.persist = persist
|
self.persist = persist
|
||||||
|
|
||||||
self.path_info = self._parse_path(remote, path)
|
self.path_info = self._parse_path(remote, path)
|
||||||
@@ -103,7 +124,7 @@ class BaseOutput(object):
|
|||||||
if remote:
|
if remote:
|
||||||
parsed = urlparse(path)
|
parsed = urlparse(path)
|
||||||
return remote.path_info / parsed.path.lstrip("/")
|
return remote.path_info / parsed.path.lstrip("/")
|
||||||
return self.REMOTE.path_cls(path)
|
return self.TREE_CLS.PATH_CLS(path)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "{class_name}: '{def_path}'".format(
|
return "{class_name}: '{def_path}'".format(
|
||||||
@@ -115,7 +136,7 @@ class BaseOutput(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def scheme(self):
|
def scheme(self):
|
||||||
return self.REMOTE.scheme
|
return self.TREE_CLS.scheme
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_in_repo(self):
|
def is_in_repo(self):
|
||||||
@@ -138,34 +159,34 @@ class BaseOutput(object):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def supported(cls, url):
|
def supported(cls, url):
|
||||||
return cls.REMOTE.supported(url)
|
return cls.TREE_CLS.supported(url)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def cache_path(self):
|
def cache_path(self):
|
||||||
return self.cache.checksum_to_path_info(self.checksum).url
|
return self.cache.hash_to_path_info(self.checksum).url
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def checksum_type(self):
|
def checksum_type(self):
|
||||||
return self.remote.PARAM_CHECKSUM
|
return self.remote.tree.PARAM_CHECKSUM
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def checksum(self):
|
def checksum(self):
|
||||||
return self.info.get(self.remote.PARAM_CHECKSUM)
|
return self.info.get(self.remote.tree.PARAM_CHECKSUM)
|
||||||
|
|
||||||
@checksum.setter
|
@checksum.setter
|
||||||
def checksum(self, checksum):
|
def checksum(self, checksum):
|
||||||
self.info[self.remote.PARAM_CHECKSUM] = checksum
|
self.info[self.remote.tree.PARAM_CHECKSUM] = checksum
|
||||||
|
|
||||||
def get_checksum(self):
|
def get_checksum(self):
|
||||||
return self.remote.get_checksum(self.path_info)
|
return self.remote.get_hash(self.path_info)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_dir_checksum(self):
|
def is_dir_checksum(self):
|
||||||
return self.remote.is_dir_checksum(self.checksum)
|
return self.remote.is_dir_hash(self.checksum)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def exists(self):
|
def exists(self):
|
||||||
return self.remote.exists(self.path_info)
|
return self.remote.tree.exists(self.path_info)
|
||||||
|
|
||||||
def save_info(self):
|
def save_info(self):
|
||||||
return self.remote.save_info(self.path_info)
|
return self.remote.save_info(self.path_info)
|
||||||
@@ -201,13 +222,22 @@ class BaseOutput(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def is_empty(self):
|
def is_empty(self):
|
||||||
return self.remote.is_empty(self.path_info)
|
return self.remote.tree.is_empty(self.path_info)
|
||||||
|
|
||||||
def isdir(self):
|
def isdir(self):
|
||||||
return self.remote.isdir(self.path_info)
|
return self.remote.tree.isdir(self.path_info)
|
||||||
|
|
||||||
def isfile(self):
|
def isfile(self):
|
||||||
return self.remote.isfile(self.path_info)
|
return self.remote.tree.isfile(self.path_info)
|
||||||
|
|
||||||
|
def ignore(self):
|
||||||
|
if not self.use_scm_ignore:
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.repo.scm.is_tracked(self.fspath):
|
||||||
|
raise OutputAlreadyTrackedError(self)
|
||||||
|
|
||||||
|
self.repo.scm.ignore(self.fspath)
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
if not self.exists:
|
if not self.exists:
|
||||||
@@ -217,39 +247,32 @@ class BaseOutput(object):
|
|||||||
raise self.IsNotFileOrDirError(self)
|
raise self.IsNotFileOrDirError(self)
|
||||||
|
|
||||||
if self.is_empty:
|
if self.is_empty:
|
||||||
logger.warning("'{}' is empty.".format(self))
|
logger.warning(f"'{self}' is empty.")
|
||||||
|
|
||||||
if self.use_scm_ignore:
|
self.ignore()
|
||||||
if self.repo.scm.is_tracked(self.fspath):
|
|
||||||
raise OutputAlreadyTrackedError(self)
|
|
||||||
|
|
||||||
self.repo.scm.ignore(self.fspath)
|
if self.metric or self.plot:
|
||||||
|
self.verify_metric()
|
||||||
|
|
||||||
if not self.use_cache:
|
if not self.use_cache:
|
||||||
self.info = self.save_info()
|
self.info = self.save_info()
|
||||||
if self.metric:
|
|
||||||
self.verify_metric()
|
|
||||||
if not self.IS_DEPENDENCY:
|
if not self.IS_DEPENDENCY:
|
||||||
logger.info(
|
logger.debug(
|
||||||
"Output '{}' doesn't use cache. Skipping saving.".format(
|
"Output '%s' doesn't use cache. Skipping saving.", self
|
||||||
self
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
assert not self.IS_DEPENDENCY
|
assert not self.IS_DEPENDENCY
|
||||||
|
|
||||||
if not self.changed():
|
if not self.changed():
|
||||||
logger.info(
|
logger.debug("Output '%s' didn't change. Skipping saving.", self)
|
||||||
"Output '{}' didn't change. Skipping saving.".format(self)
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
self.info = self.save_info()
|
self.info = self.save_info()
|
||||||
|
|
||||||
def commit(self):
|
def commit(self):
|
||||||
if self.use_cache:
|
if self.use_cache:
|
||||||
self.cache.save(self.path_info, self.info)
|
self.cache.save(self.path_info, self.cache.tree, self.info)
|
||||||
|
|
||||||
def dumpd(self):
|
def dumpd(self):
|
||||||
ret = copy(self.info)
|
ret = copy(self.info)
|
||||||
@@ -258,7 +281,8 @@ class BaseOutput(object):
|
|||||||
if self.IS_DEPENDENCY:
|
if self.IS_DEPENDENCY:
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
ret[self.PARAM_CACHE] = self.use_cache
|
if not self.use_cache:
|
||||||
|
ret[self.PARAM_CACHE] = self.use_cache
|
||||||
|
|
||||||
if isinstance(self.metric, dict):
|
if isinstance(self.metric, dict):
|
||||||
if (
|
if (
|
||||||
@@ -267,18 +291,22 @@ class BaseOutput(object):
|
|||||||
):
|
):
|
||||||
del self.metric[self.PARAM_METRIC_XPATH]
|
del self.metric[self.PARAM_METRIC_XPATH]
|
||||||
|
|
||||||
ret[self.PARAM_METRIC] = self.metric
|
if self.metric:
|
||||||
ret[self.PARAM_PERSIST] = self.persist
|
ret[self.PARAM_METRIC] = self.metric
|
||||||
|
|
||||||
|
if self.plot:
|
||||||
|
ret[self.PARAM_PLOT] = self.plot
|
||||||
|
|
||||||
|
if self.persist:
|
||||||
|
ret[self.PARAM_PERSIST] = self.persist
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def verify_metric(self):
|
def verify_metric(self):
|
||||||
raise DvcException(
|
raise DvcException(f"verify metric is not supported for {self.scheme}")
|
||||||
"verify metric is not supported for {}".format(self.scheme)
|
|
||||||
)
|
|
||||||
|
|
||||||
def download(self, to):
|
def download(self, to):
|
||||||
self.remote.download(self.path_info, to.path_info)
|
self.remote.tree.download(self.path_info, to.path_info)
|
||||||
|
|
||||||
def checkout(
|
def checkout(
|
||||||
self,
|
self,
|
||||||
@@ -304,7 +332,7 @@ class BaseOutput(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def remove(self, ignore_remove=False):
|
def remove(self, ignore_remove=False):
|
||||||
self.remote.remove(self.path_info)
|
self.remote.tree.remove(self.path_info)
|
||||||
if self.scheme != "local":
|
if self.scheme != "local":
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -315,7 +343,7 @@ class BaseOutput(object):
|
|||||||
if self.scheme == "local" and self.use_scm_ignore:
|
if self.scheme == "local" and self.use_scm_ignore:
|
||||||
self.repo.scm.ignore_remove(self.fspath)
|
self.repo.scm.ignore_remove(self.fspath)
|
||||||
|
|
||||||
self.remote.move(self.path_info, out.path_info)
|
self.remote.tree.move(self.path_info, out.path_info)
|
||||||
self.def_path = out.def_path
|
self.def_path = out.def_path
|
||||||
self.path_info = out.path_info
|
self.path_info = out.path_info
|
||||||
self.save()
|
self.save()
|
||||||
@@ -334,9 +362,20 @@ class BaseOutput(object):
|
|||||||
|
|
||||||
def unprotect(self):
|
def unprotect(self):
|
||||||
if self.exists:
|
if self.exists:
|
||||||
self.remote.unprotect(self.path_info)
|
self.remote.tree.unprotect(self.path_info)
|
||||||
|
|
||||||
def _collect_used_dir_cache(
|
def get_dir_cache(self, **kwargs):
|
||||||
|
if not self.is_dir_checksum:
|
||||||
|
raise DvcException("cannot get dir cache for file checksum")
|
||||||
|
if self.cache.changed_cache_file(self.checksum):
|
||||||
|
self.repo.cloud.pull(
|
||||||
|
NamedCache.make("local", self.checksum, str(self)),
|
||||||
|
show_checksums=False,
|
||||||
|
**kwargs,
|
||||||
|
)
|
||||||
|
return self.dir_cache
|
||||||
|
|
||||||
|
def collect_used_dir_cache(
|
||||||
self, remote=None, force=False, jobs=None, filter_info=None
|
self, remote=None, force=False, jobs=None, filter_info=None
|
||||||
):
|
):
|
||||||
"""Get a list of `info`s related to the given directory.
|
"""Get a list of `info`s related to the given directory.
|
||||||
@@ -360,16 +399,10 @@ class BaseOutput(object):
|
|||||||
|
|
||||||
cache = NamedCache()
|
cache = NamedCache()
|
||||||
|
|
||||||
if self.cache.changed_cache_file(self.checksum):
|
try:
|
||||||
try:
|
self.get_dir_cache(jobs=jobs, remote=remote)
|
||||||
self.repo.cloud.pull(
|
except DvcException:
|
||||||
NamedCache.make("local", self.checksum, str(self)),
|
logger.debug(f"failed to pull cache for '{self}'")
|
||||||
jobs=jobs,
|
|
||||||
remote=remote,
|
|
||||||
show_checksums=False,
|
|
||||||
)
|
|
||||||
except DvcException:
|
|
||||||
logger.debug("failed to pull cache for '{}'".format(self))
|
|
||||||
|
|
||||||
if self.cache.changed_cache_file(self.checksum):
|
if self.cache.changed_cache_file(self.checksum):
|
||||||
msg = (
|
msg = (
|
||||||
@@ -389,8 +422,8 @@ class BaseOutput(object):
|
|||||||
filter_path = str(filter_info) if filter_info else None
|
filter_path = str(filter_info) if filter_info else None
|
||||||
is_win = os.name == "nt"
|
is_win = os.name == "nt"
|
||||||
for entry in self.dir_cache:
|
for entry in self.dir_cache:
|
||||||
checksum = entry[self.remote.PARAM_CHECKSUM]
|
checksum = entry[self.remote.tree.PARAM_CHECKSUM]
|
||||||
entry_relpath = entry[self.remote.PARAM_RELPATH]
|
entry_relpath = entry[self.remote.tree.PARAM_RELPATH]
|
||||||
if is_win:
|
if is_win:
|
||||||
entry_relpath = entry_relpath.replace("/", os.sep)
|
entry_relpath = entry_relpath.replace("/", os.sep)
|
||||||
entry_path = os.path.join(path, entry_relpath)
|
entry_path = os.path.join(path, entry_relpath)
|
||||||
@@ -446,7 +479,7 @@ class BaseOutput(object):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
ret.add_child_cache(
|
ret.add_child_cache(
|
||||||
self.checksum, self._collect_used_dir_cache(**kwargs),
|
self.checksum, self.collect_used_dir_cache(**kwargs),
|
||||||
)
|
)
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
from dvc.output.s3 import S3Output
|
from dvc.output.s3 import S3Output
|
||||||
from dvc.remote.gs import GSRemote
|
from dvc.remote.gs import GSRemoteTree
|
||||||
|
|
||||||
|
|
||||||
class GSOutput(S3Output):
|
class GSOutput(S3Output):
|
||||||
REMOTE = GSRemote
|
TREE_CLS = GSRemoteTree
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
from dvc.output.base import BaseOutput
|
from dvc.output.base import BaseOutput
|
||||||
from dvc.remote.hdfs import HDFSRemote
|
from dvc.remote.hdfs import HDFSRemoteTree
|
||||||
|
|
||||||
|
|
||||||
class HDFSOutput(BaseOutput):
|
class HDFSOutput(BaseOutput):
|
||||||
REMOTE = HDFSRemote
|
TREE_CLS = HDFSRemoteTree
|
||||||
|
|||||||
+15
-15
@@ -5,17 +5,16 @@ from urllib.parse import urlparse
|
|||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
from dvc.istextfile import istextfile
|
from dvc.istextfile import istextfile
|
||||||
from dvc.output.base import BaseOutput
|
from dvc.output.base import BaseOutput
|
||||||
from dvc.remote.local import LocalRemote
|
from dvc.remote.local import LocalRemote, LocalRemoteTree
|
||||||
from dvc.utils import relpath
|
from dvc.utils import relpath
|
||||||
from dvc.compat import fspath_py35
|
|
||||||
from dvc.utils.fs import path_isin
|
from dvc.utils.fs import path_isin
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class LocalOutput(BaseOutput):
|
class LocalOutput(BaseOutput):
|
||||||
REMOTE = LocalRemote
|
REMOTE_CLS = LocalRemote
|
||||||
|
TREE_CLS = LocalRemoteTree
|
||||||
sep = os.sep
|
sep = os.sep
|
||||||
|
|
||||||
def __init__(self, stage, path, *args, **kwargs):
|
def __init__(self, stage, path, *args, **kwargs):
|
||||||
@@ -35,15 +34,15 @@ class LocalOutput(BaseOutput):
|
|||||||
#
|
#
|
||||||
# FIXME: if we have Windows path containing / or posix one with \
|
# FIXME: if we have Windows path containing / or posix one with \
|
||||||
# then we have #2059 bug and can't really handle that.
|
# then we have #2059 bug and can't really handle that.
|
||||||
p = self.REMOTE.path_cls(path)
|
p = self.TREE_CLS.PATH_CLS(path)
|
||||||
if not p.is_absolute():
|
if self.stage and not p.is_absolute():
|
||||||
p = self.stage.wdir / p
|
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)
|
return self.TREE_CLS.PATH_CLS(abs_p)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if not self.is_in_repo:
|
if not self.repo or not self.is_in_repo:
|
||||||
return str(self.def_path)
|
return str(self.def_path)
|
||||||
|
|
||||||
cur_dir = os.getcwd()
|
cur_dir = os.getcwd()
|
||||||
@@ -73,17 +72,18 @@ class LocalOutput(BaseOutput):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
def verify_metric(self):
|
def verify_metric(self):
|
||||||
if not self.metric:
|
if not self.metric or self.plot:
|
||||||
return
|
return
|
||||||
|
|
||||||
path = fspath_py35(self.path_info)
|
path = os.fspath(self.path_info)
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
name = "metrics" if self.metric else "plot"
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
msg = "directory '{}' cannot be used as metrics."
|
msg = "directory '{}' cannot be used as {}."
|
||||||
raise DvcException(msg.format(self.path_info))
|
raise IsADirectoryError(msg.format(self.path_info, name))
|
||||||
|
|
||||||
if not istextfile(path):
|
if not istextfile(path):
|
||||||
msg = "binary file '{}' cannot be used as metrics."
|
msg = "binary file '{}' cannot be used as {}."
|
||||||
raise DvcException(msg.format(self.path_info))
|
raise DvcException(msg.format(self.path_info, name))
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
from dvc.output.base import BaseOutput
|
from dvc.output.base import BaseOutput
|
||||||
from dvc.remote.s3 import S3Remote
|
from dvc.remote.s3 import S3RemoteTree
|
||||||
|
|
||||||
|
|
||||||
class S3Output(BaseOutput):
|
class S3Output(BaseOutput):
|
||||||
REMOTE = S3Remote
|
TREE_CLS = S3RemoteTree
|
||||||
|
|||||||
+3
-2
@@ -1,6 +1,7 @@
|
|||||||
from dvc.output.base import BaseOutput
|
from dvc.output.base import BaseOutput
|
||||||
from dvc.remote.ssh import SSHRemote
|
from dvc.remote.ssh import SSHRemote, SSHRemoteTree
|
||||||
|
|
||||||
|
|
||||||
class SSHOutput(BaseOutput):
|
class SSHOutput(BaseOutput):
|
||||||
REMOTE = SSHRemote
|
REMOTE_CLS = SSHRemote
|
||||||
|
TREE_CLS = SSHRemoteTree
|
||||||
|
|||||||
+8
-9
@@ -1,6 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import posixpath
|
|
||||||
import pathlib
|
import pathlib
|
||||||
|
import posixpath
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from funcy import cached_property
|
from funcy import cached_property
|
||||||
@@ -8,7 +8,7 @@ from funcy import cached_property
|
|||||||
from dvc.utils import relpath
|
from dvc.utils import relpath
|
||||||
|
|
||||||
|
|
||||||
class _BasePath(object):
|
class _BasePath:
|
||||||
def overlaps(self, other):
|
def overlaps(self, other):
|
||||||
if isinstance(other, (str, bytes)):
|
if isinstance(other, (str, bytes)):
|
||||||
other = self.__class__(other)
|
other = self.__class__(other)
|
||||||
@@ -50,7 +50,6 @@ class PathInfo(pathlib.PurePath, _BasePath):
|
|||||||
return "{}: '{}'".format(type(self).__name__, self)
|
return "{}: '{}'".format(type(self).__name__, self)
|
||||||
|
|
||||||
# This permits passing it to file utils directly in Python 3.6+
|
# 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):
|
def __fspath__(self):
|
||||||
return pathlib.PurePath.__str__(self)
|
return pathlib.PurePath.__str__(self)
|
||||||
|
|
||||||
@@ -88,7 +87,7 @@ class _URLPathInfo(PosixPathInfo):
|
|||||||
__unicode__ = __str__
|
__unicode__ = __str__
|
||||||
|
|
||||||
|
|
||||||
class _URLPathParents(object):
|
class _URLPathParents:
|
||||||
def __init__(self, src):
|
def __init__(self, src):
|
||||||
self.src = src
|
self.src = src
|
||||||
self._parents = self.src._path.parents
|
self._parents = self.src._path.parents
|
||||||
@@ -100,7 +99,7 @@ class _URLPathParents(object):
|
|||||||
return self.src.replace(path=self._parents[idx])
|
return self.src.replace(path=self._parents[idx])
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<{}.parents>".format(self.src)
|
return f"<{self.src}.parents>"
|
||||||
|
|
||||||
|
|
||||||
class URLInfo(_BasePath):
|
class URLInfo(_BasePath):
|
||||||
@@ -120,7 +119,7 @@ class URLInfo(_BasePath):
|
|||||||
assert bool(host) ^ bool(netloc)
|
assert bool(host) ^ bool(netloc)
|
||||||
|
|
||||||
if netloc is not None:
|
if netloc is not None:
|
||||||
return cls("{}://{}{}".format(scheme, netloc, path))
|
return cls(f"{scheme}://{netloc}{path}")
|
||||||
|
|
||||||
obj = cls.__new__(cls)
|
obj = cls.__new__(cls)
|
||||||
obj._fill_parts(scheme, host, user, port, path)
|
obj._fill_parts(scheme, host, user, port, path)
|
||||||
@@ -154,7 +153,7 @@ class URLInfo(_BasePath):
|
|||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def url(self):
|
def url(self):
|
||||||
return "{}://{}{}".format(self.scheme, self.netloc, self._spath)
|
return f"{self.scheme}://{self.netloc}{self._spath}"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.url
|
return self.url
|
||||||
@@ -216,10 +215,10 @@ class URLInfo(_BasePath):
|
|||||||
if isinstance(other, (str, bytes)):
|
if isinstance(other, (str, bytes)):
|
||||||
other = self.__class__(other)
|
other = self.__class__(other)
|
||||||
if self.__class__ != other.__class__:
|
if self.__class__ != other.__class__:
|
||||||
msg = "'{}' has incompatible class with '{}'".format(self, other)
|
msg = f"'{self}' has incompatible class with '{other}'"
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
if self._base_parts != other._base_parts:
|
if self._base_parts != other._base_parts:
|
||||||
msg = "'{}' does not start with '{}'".format(self, other)
|
msg = f"'{self}' does not start with '{other}'"
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
return self._path.relative_to(other._path)
|
return self._path.relative_to(other._path)
|
||||||
|
|
||||||
|
|||||||
+23
-21
@@ -19,18 +19,17 @@ class Tqdm(tqdm):
|
|||||||
|
|
||||||
BAR_FMT_DEFAULT = (
|
BAR_FMT_DEFAULT = (
|
||||||
"{percentage:3.0f}% {desc}|{bar}|"
|
"{percentage:3.0f}% {desc}|{bar}|"
|
||||||
"{n_fmt}/{total_fmt}"
|
"{postfix[info]}{n_fmt}/{total_fmt}"
|
||||||
" [{elapsed}<{remaining}, {rate_fmt:>11}{postfix}]"
|
" [{elapsed}<{remaining}, {rate_fmt:>11}]"
|
||||||
)
|
)
|
||||||
# nested bars should have fixed bar widths to align nicely
|
# nested bars should have fixed bar widths to align nicely
|
||||||
BAR_FMT_DEFAULT_NESTED = (
|
BAR_FMT_DEFAULT_NESTED = (
|
||||||
"{percentage:3.0f}%|{bar:10}|{desc:{ncols_desc}.{ncols_desc}}"
|
"{percentage:3.0f}%|{bar:10}|{desc:{ncols_desc}.{ncols_desc}}"
|
||||||
"{n_fmt}/{total_fmt}"
|
"{postfix[info]}{n_fmt}/{total_fmt}"
|
||||||
" [{elapsed}<{remaining}, {rate_fmt:>11}{postfix}]"
|
" [{elapsed}<{remaining}, {rate_fmt:>11}]"
|
||||||
)
|
)
|
||||||
BAR_FMT_NOTOTAL = (
|
BAR_FMT_NOTOTAL = (
|
||||||
"{desc:{ncols_desc}.{ncols_desc}}{n_fmt}"
|
"{desc}{bar:b}|{postfix[info]}{n_fmt} [{elapsed}, {rate_fmt:>11}]"
|
||||||
" [{elapsed}, {rate_fmt:>11}{postfix}]"
|
|
||||||
)
|
)
|
||||||
BYTES_DEFAULTS = dict(
|
BYTES_DEFAULTS = dict(
|
||||||
unit="B", unit_scale=True, unit_divisor=1024, miniters=1
|
unit="B", unit_scale=True, unit_divisor=1024, miniters=1
|
||||||
@@ -47,6 +46,7 @@ class Tqdm(tqdm):
|
|||||||
bytes=False, # pylint: disable=W0622
|
bytes=False, # pylint: disable=W0622
|
||||||
file=None,
|
file=None,
|
||||||
total=None,
|
total=None,
|
||||||
|
postfix=None,
|
||||||
**kwargs
|
**kwargs
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
@@ -68,7 +68,6 @@ class Tqdm(tqdm):
|
|||||||
kwargs.setdefault("unit_scale", total > 999 if total else True)
|
kwargs.setdefault("unit_scale", total > 999 if total else True)
|
||||||
if file is None:
|
if file is None:
|
||||||
file = sys.stderr
|
file = sys.stderr
|
||||||
self.desc_persist = desc
|
|
||||||
# auto-disable based on `logger.level`
|
# auto-disable based on `logger.level`
|
||||||
if not disable:
|
if not disable:
|
||||||
disable = logger.getEffectiveLevel() > level
|
disable = logger.getEffectiveLevel() > level
|
||||||
@@ -89,6 +88,7 @@ class Tqdm(tqdm):
|
|||||||
total=total,
|
total=total,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
self.postfix = postfix or {"info": ""}
|
||||||
if bar_format is None:
|
if bar_format is None:
|
||||||
if self.__len__():
|
if self.__len__():
|
||||||
self.bar_format = (
|
self.bar_format = (
|
||||||
@@ -102,11 +102,11 @@ class Tqdm(tqdm):
|
|||||||
self.bar_format = bar_format
|
self.bar_format = bar_format
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
def update_desc(self, desc, n=1):
|
def update_msg(self, msg, n=1):
|
||||||
"""
|
"""
|
||||||
Calls `set_description_str(desc)` and `update(n)`
|
Sets `msg` as a postfix and calls `update(n)`.
|
||||||
"""
|
"""
|
||||||
self.set_description_str(desc, refresh=False)
|
self.postfix["info"] = " %s |" % msg
|
||||||
self.update(n)
|
self.update(n)
|
||||||
|
|
||||||
def update_to(self, current, total=None):
|
def update_to(self, current, total=None):
|
||||||
@@ -130,12 +130,11 @@ class Tqdm(tqdm):
|
|||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
if self.desc_persist is not None:
|
self.postfix["info"] = ""
|
||||||
self.set_description_str(self.desc_persist, refresh=False)
|
# remove ETA (either unknown or zero); remove completed bar
|
||||||
# unknown/zero ETA
|
self.bar_format = self.bar_format.replace("<{remaining}", "").replace(
|
||||||
self.bar_format = self.bar_format.replace("<{remaining}", "")
|
"|{bar:10}|", " "
|
||||||
# remove completed bar
|
)
|
||||||
self.bar_format = self.bar_format.replace("|{bar:10}|", " ")
|
|
||||||
super().close()
|
super().close()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -143,12 +142,15 @@ class Tqdm(tqdm):
|
|||||||
"""inject `ncols_desc` to fill the display width (`ncols`)"""
|
"""inject `ncols_desc` to fill the display width (`ncols`)"""
|
||||||
d = super().format_dict
|
d = super().format_dict
|
||||||
ncols = d["ncols"] or 80
|
ncols = d["ncols"] or 80
|
||||||
ncols_desc = ncols - len(self.format_meter(ncols_desc=1, **d)) + 1
|
# assumes `bar_format` has max one of ("ncols_desc" & "ncols_info")
|
||||||
ncols_desc = max(ncols_desc, 0)
|
ncols_left = (
|
||||||
if ncols_desc:
|
ncols - len(self.format_meter(ncols_desc=1, ncols_info=1, **d)) + 1
|
||||||
d["ncols_desc"] = ncols_desc
|
)
|
||||||
|
ncols_left = max(ncols_left, 0)
|
||||||
|
if ncols_left:
|
||||||
|
d["ncols_desc"] = d["ncols_info"] = ncols_left
|
||||||
else:
|
else:
|
||||||
# work-around for zero-width description
|
# work-around for zero-width description
|
||||||
d["ncols_desc"] = 1
|
d["ncols_desc"] = d["ncols_info"] = 1
|
||||||
d["prefix"] = ""
|
d["prefix"] = ""
|
||||||
return d
|
return d
|
||||||
|
|||||||
+2
-2
@@ -38,7 +38,7 @@ def confirm(statement):
|
|||||||
Returns:
|
Returns:
|
||||||
bool: whether or not specified statement was confirmed.
|
bool: whether or not specified statement was confirmed.
|
||||||
"""
|
"""
|
||||||
prompt = "{statement} [y/n]".format(statement=statement)
|
prompt = f"{statement} [y/n]"
|
||||||
answer = _ask(prompt, limited_to=["yes", "no", "y", "n"])
|
answer = _ask(prompt, limited_to=["yes", "no", "y", "n"])
|
||||||
return answer and answer.startswith("y")
|
return answer and answer.startswith("y")
|
||||||
|
|
||||||
@@ -52,5 +52,5 @@ def password(statement):
|
|||||||
Returns:
|
Returns:
|
||||||
str: password entered by the user.
|
str: password entered by the user.
|
||||||
"""
|
"""
|
||||||
logger.info("{statement}: ".format(statement=statement))
|
logger.info(f"{statement}: ")
|
||||||
return getpass("")
|
return getpass("")
|
||||||
|
|||||||
+43
-30
@@ -1,47 +1,46 @@
|
|||||||
import posixpath
|
import posixpath
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from dvc.remote.azure import AzureRemote
|
from dvc.remote.azure import AzureRemoteTree
|
||||||
from dvc.remote.gdrive import GDriveRemote
|
from dvc.remote.base import Remote
|
||||||
from dvc.remote.gs import GSRemote
|
from dvc.remote.gdrive import GDriveRemoteTree
|
||||||
from dvc.remote.hdfs import HDFSRemote
|
from dvc.remote.gs import GSRemoteTree
|
||||||
from dvc.remote.http import HTTPRemote
|
from dvc.remote.hdfs import HDFSRemoteTree
|
||||||
from dvc.remote.https import HTTPSRemote
|
from dvc.remote.http import HTTPRemoteTree
|
||||||
from dvc.remote.local import LocalRemote
|
from dvc.remote.https import HTTPSRemoteTree
|
||||||
from dvc.remote.oss import OSSRemote
|
from dvc.remote.local import LocalRemote, LocalRemoteTree
|
||||||
from dvc.remote.s3 import S3Remote
|
from dvc.remote.oss import OSSRemoteTree
|
||||||
from dvc.remote.ssh import SSHRemote
|
from dvc.remote.s3 import S3RemoteTree
|
||||||
|
from dvc.remote.ssh import SSHRemote, SSHRemoteTree
|
||||||
|
|
||||||
|
TREES = [
|
||||||
REMOTES = [
|
AzureRemoteTree,
|
||||||
AzureRemote,
|
GDriveRemoteTree,
|
||||||
GDriveRemote,
|
GSRemoteTree,
|
||||||
GSRemote,
|
HDFSRemoteTree,
|
||||||
HDFSRemote,
|
HTTPRemoteTree,
|
||||||
HTTPRemote,
|
HTTPSRemoteTree,
|
||||||
HTTPSRemote,
|
S3RemoteTree,
|
||||||
S3Remote,
|
SSHRemoteTree,
|
||||||
SSHRemote,
|
OSSRemoteTree,
|
||||||
OSSRemote,
|
# NOTE: LocalRemoteTree is the default
|
||||||
# NOTE: LocalRemote is the default
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def _get(remote_conf):
|
def _get_tree(remote_conf):
|
||||||
for remote in REMOTES:
|
for tree_cls in TREES:
|
||||||
if remote.supported(remote_conf):
|
if tree_cls.supported(remote_conf):
|
||||||
return remote
|
return tree_cls
|
||||||
return LocalRemote
|
return LocalRemoteTree
|
||||||
|
|
||||||
|
|
||||||
def Remote(repo, **kwargs):
|
def _get_conf(repo, **kwargs):
|
||||||
name = kwargs.get("name")
|
name = kwargs.get("name")
|
||||||
if name:
|
if name:
|
||||||
remote_conf = repo.config["remote"][name.lower()]
|
remote_conf = repo.config["remote"][name.lower()]
|
||||||
else:
|
else:
|
||||||
remote_conf = kwargs
|
remote_conf = kwargs
|
||||||
remote_conf = _resolve_remote_refs(repo.config, remote_conf)
|
return _resolve_remote_refs(repo.config, remote_conf)
|
||||||
return _get(remote_conf)(repo, remote_conf)
|
|
||||||
|
|
||||||
|
|
||||||
def _resolve_remote_refs(config, remote_conf):
|
def _resolve_remote_refs(config, remote_conf):
|
||||||
@@ -73,3 +72,17 @@ def _resolve_remote_refs(config, remote_conf):
|
|||||||
base = config["remote"][parsed.netloc]
|
base = config["remote"][parsed.netloc]
|
||||||
url = posixpath.join(base["url"], parsed.path.lstrip("/"))
|
url = posixpath.join(base["url"], parsed.path.lstrip("/"))
|
||||||
return {**base, **remote_conf, "url": url}
|
return {**base, **remote_conf, "url": url}
|
||||||
|
|
||||||
|
|
||||||
|
def get_cloud_tree(repo, **kwargs):
|
||||||
|
remote_conf = _get_conf(repo, **kwargs)
|
||||||
|
return _get_tree(remote_conf)(repo, remote_conf)
|
||||||
|
|
||||||
|
|
||||||
|
def get_remote(repo, **kwargs):
|
||||||
|
tree = get_cloud_tree(repo, **kwargs)
|
||||||
|
if tree.scheme == "local":
|
||||||
|
return LocalRemote(tree)
|
||||||
|
if tree.scheme == "ssh":
|
||||||
|
return SSHRemote(tree)
|
||||||
|
return Remote(tree)
|
||||||
|
|||||||
+56
-78
@@ -1,31 +1,21 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import posixpath
|
|
||||||
import re
|
|
||||||
from datetime import datetime, timedelta
|
|
||||||
from urllib.parse import urlparse
|
|
||||||
import threading
|
import threading
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from funcy import cached_property, wrap_prop
|
from funcy import cached_property, wrap_prop
|
||||||
|
|
||||||
from dvc.path_info import CloudURLInfo
|
from dvc.path_info import CloudURLInfo
|
||||||
from dvc.progress import Tqdm
|
from dvc.progress import Tqdm
|
||||||
from dvc.remote.base import BaseRemote
|
from dvc.remote.base import BaseRemoteTree
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class AzureRemote(BaseRemote):
|
class AzureRemoteTree(BaseRemoteTree):
|
||||||
scheme = Schemes.AZURE
|
scheme = Schemes.AZURE
|
||||||
path_cls = CloudURLInfo
|
PATH_CLS = CloudURLInfo
|
||||||
REGEX = (
|
|
||||||
r"azure://((?P<path>[^=;]*)?|("
|
|
||||||
# backward compatibility
|
|
||||||
r"(ContainerName=(?P<container_name>[^;]+);?)?"
|
|
||||||
r"(?P<connection_string>.+)?)?)$"
|
|
||||||
)
|
|
||||||
REQUIRES = {"azure-storage-blob": "azure.storage.blob"}
|
REQUIRES = {"azure-storage-blob": "azure.storage.blob"}
|
||||||
PARAM_CHECKSUM = "etag"
|
PARAM_CHECKSUM = "etag"
|
||||||
COPY_POLL_SECONDS = 5
|
COPY_POLL_SECONDS = 5
|
||||||
@@ -35,31 +25,14 @@ class AzureRemote(BaseRemote):
|
|||||||
super().__init__(repo, config)
|
super().__init__(repo, config)
|
||||||
|
|
||||||
url = config.get("url", "azure://")
|
url = config.get("url", "azure://")
|
||||||
|
self.path_info = self.PATH_CLS(url)
|
||||||
|
|
||||||
match = re.match(self.REGEX, url) # backward compatibility
|
if not self.path_info.bucket:
|
||||||
path = match.group("path")
|
container = os.getenv("AZURE_STORAGE_CONTAINER_NAME")
|
||||||
bucket = (
|
self.path_info = self.PATH_CLS(f"azure://{container}")
|
||||||
urlparse(url if path else "").netloc
|
|
||||||
or match.group("container_name") # backward compatibility
|
|
||||||
or os.getenv("AZURE_STORAGE_CONTAINER_NAME")
|
|
||||||
)
|
|
||||||
|
|
||||||
self.connection_string = (
|
self.connection_string = config.get("connection_string") or os.getenv(
|
||||||
config.get("connection_string")
|
"AZURE_STORAGE_CONNECTION_STRING"
|
||||||
or match.group("connection_string") # backward compatibility
|
|
||||||
or os.getenv("AZURE_STORAGE_CONNECTION_STRING")
|
|
||||||
)
|
|
||||||
|
|
||||||
if not bucket:
|
|
||||||
raise ValueError("azure storage container name missing")
|
|
||||||
|
|
||||||
if not self.connection_string:
|
|
||||||
raise ValueError("azure storage connection string missing")
|
|
||||||
|
|
||||||
self.path_info = (
|
|
||||||
self.path_cls(url)
|
|
||||||
if path
|
|
||||||
else self.path_cls.from_parts(scheme=self.scheme, netloc=bucket)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@wrap_prop(threading.Lock())
|
@wrap_prop(threading.Lock())
|
||||||
@@ -68,12 +41,12 @@ class AzureRemote(BaseRemote):
|
|||||||
from azure.storage.blob import BlockBlobService
|
from azure.storage.blob import BlockBlobService
|
||||||
from azure.common import AzureMissingResourceHttpError
|
from azure.common import AzureMissingResourceHttpError
|
||||||
|
|
||||||
logger.debug("URL {}".format(self.path_info))
|
logger.debug(f"URL {self.path_info}")
|
||||||
logger.debug("Connection string {}".format(self.connection_string))
|
logger.debug(f"Connection string {self.connection_string}")
|
||||||
blob_service = BlockBlobService(
|
blob_service = BlockBlobService(
|
||||||
connection_string=self.connection_string
|
connection_string=self.connection_string
|
||||||
)
|
)
|
||||||
logger.debug("Container name {}".format(self.path_info.bucket))
|
logger.debug(f"Container name {self.path_info.bucket}")
|
||||||
try: # verify that container exists
|
try: # verify that container exists
|
||||||
blob_service.list_blobs(
|
blob_service.list_blobs(
|
||||||
self.path_info.bucket, delimiter="/", num_results=1
|
self.path_info.bucket, delimiter="/", num_results=1
|
||||||
@@ -82,14 +55,33 @@ class AzureRemote(BaseRemote):
|
|||||||
blob_service.create_container(self.path_info.bucket)
|
blob_service.create_container(self.path_info.bucket)
|
||||||
return blob_service
|
return blob_service
|
||||||
|
|
||||||
def remove(self, path_info):
|
def get_etag(self, path_info):
|
||||||
if path_info.scheme != self.scheme:
|
etag = self.blob_service.get_blob_properties(
|
||||||
raise NotImplementedError
|
path_info.bucket, path_info.path
|
||||||
|
).properties.etag
|
||||||
|
return etag.strip('"')
|
||||||
|
|
||||||
logger.debug("Removing {}".format(path_info))
|
def _generate_download_url(self, path_info, expires=3600):
|
||||||
self.blob_service.delete_blob(path_info.bucket, path_info.path)
|
from azure.storage.blob import BlobPermissions
|
||||||
|
|
||||||
def _list_paths(self, bucket, prefix, progress_callback=None):
|
expires_at = datetime.utcnow() + timedelta(seconds=expires)
|
||||||
|
|
||||||
|
sas_token = self.blob_service.generate_blob_shared_access_signature(
|
||||||
|
path_info.bucket,
|
||||||
|
path_info.path,
|
||||||
|
permission=BlobPermissions.READ,
|
||||||
|
expiry=expires_at,
|
||||||
|
)
|
||||||
|
download_url = self.blob_service.make_blob_url(
|
||||||
|
path_info.bucket, path_info.path, sas_token=sas_token
|
||||||
|
)
|
||||||
|
return download_url
|
||||||
|
|
||||||
|
def exists(self, path_info):
|
||||||
|
paths = self._list_paths(path_info.bucket, path_info.path)
|
||||||
|
return any(path_info.path == path for path in paths)
|
||||||
|
|
||||||
|
def _list_paths(self, bucket, prefix):
|
||||||
blob_service = self.blob_service
|
blob_service = self.blob_service
|
||||||
next_marker = None
|
next_marker = None
|
||||||
while True:
|
while True:
|
||||||
@@ -98,8 +90,6 @@ class AzureRemote(BaseRemote):
|
|||||||
)
|
)
|
||||||
|
|
||||||
for blob in blobs:
|
for blob in blobs:
|
||||||
if progress_callback:
|
|
||||||
progress_callback()
|
|
||||||
yield blob.name
|
yield blob.name
|
||||||
|
|
||||||
if not blobs.next_marker:
|
if not blobs.next_marker:
|
||||||
@@ -107,16 +97,24 @@ class AzureRemote(BaseRemote):
|
|||||||
|
|
||||||
next_marker = blobs.next_marker
|
next_marker = blobs.next_marker
|
||||||
|
|
||||||
def list_cache_paths(self, prefix=None, progress_callback=None):
|
def walk_files(self, path_info, **kwargs):
|
||||||
if prefix:
|
for fname in self._list_paths(
|
||||||
prefix = posixpath.join(
|
path_info.bucket, path_info.path, **kwargs
|
||||||
self.path_info.path, prefix[:2], prefix[2:]
|
):
|
||||||
)
|
if fname.endswith("/"):
|
||||||
else:
|
continue
|
||||||
prefix = self.path_info.path
|
|
||||||
return self._list_paths(
|
yield path_info.replace(path=fname)
|
||||||
self.path_info.bucket, prefix, progress_callback
|
|
||||||
)
|
def remove(self, path_info):
|
||||||
|
if path_info.scheme != self.scheme:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
logger.debug(f"Removing {path_info}")
|
||||||
|
self.blob_service.delete_blob(path_info.bucket, path_info.path)
|
||||||
|
|
||||||
|
def get_file_hash(self, path_info):
|
||||||
|
return self.get_etag(path_info)
|
||||||
|
|
||||||
def _upload(
|
def _upload(
|
||||||
self, from_file, to_info, name=None, no_progress_bar=False, **_kwargs
|
self, from_file, to_info, name=None, no_progress_bar=False, **_kwargs
|
||||||
@@ -139,23 +137,3 @@ class AzureRemote(BaseRemote):
|
|||||||
to_file,
|
to_file,
|
||||||
progress_callback=pbar.update_to,
|
progress_callback=pbar.update_to,
|
||||||
)
|
)
|
||||||
|
|
||||||
def exists(self, path_info):
|
|
||||||
paths = self._list_paths(path_info.bucket, path_info.path)
|
|
||||||
return any(path_info.path == path for path in paths)
|
|
||||||
|
|
||||||
def _generate_download_url(self, path_info, expires=3600):
|
|
||||||
from azure.storage.blob import BlobPermissions
|
|
||||||
|
|
||||||
expires_at = datetime.utcnow() + timedelta(seconds=expires)
|
|
||||||
|
|
||||||
sas_token = self.blob_service.generate_blob_shared_access_signature(
|
|
||||||
path_info.bucket,
|
|
||||||
path_info.path,
|
|
||||||
permission=BlobPermissions.READ,
|
|
||||||
expiry=expires_at,
|
|
||||||
)
|
|
||||||
download_url = self.blob_service.make_blob_url(
|
|
||||||
path_info.bucket, path_info.path, sas_token=sas_token
|
|
||||||
)
|
|
||||||
return download_url
|
|
||||||
|
|||||||
+867
-760
File diff suppressed because it is too large
Load Diff
+94
-88
@@ -1,40 +1,35 @@
|
|||||||
from collections import defaultdict
|
import io
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import posixpath
|
import posixpath
|
||||||
import logging
|
|
||||||
import re
|
import re
|
||||||
import threading
|
import threading
|
||||||
|
from collections import defaultdict
|
||||||
|
from contextlib import contextmanager
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from funcy import retry, wrap_with, wrap_prop, cached_property
|
from funcy import cached_property, retry, wrap_prop, wrap_with
|
||||||
from funcy.py3 import cat
|
from funcy.py3 import cat
|
||||||
|
|
||||||
from dvc.progress import Tqdm
|
from dvc.exceptions import DvcException, FileMissingError
|
||||||
from dvc.scheme import Schemes
|
|
||||||
from dvc.path_info import CloudURLInfo
|
from dvc.path_info import CloudURLInfo
|
||||||
from dvc.remote.base import BaseRemote
|
from dvc.progress import Tqdm
|
||||||
from dvc.exceptions import DvcException
|
from dvc.remote.base import BaseRemoteTree
|
||||||
from dvc.utils import tmp_fname, format_link
|
from dvc.scheme import Schemes
|
||||||
|
from dvc.utils import format_link, tmp_fname
|
||||||
|
from dvc.utils.stream import IterStream
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
FOLDER_MIME_TYPE = "application/vnd.google-apps.folder"
|
FOLDER_MIME_TYPE = "application/vnd.google-apps.folder"
|
||||||
|
|
||||||
|
|
||||||
class GDrivePathNotFound(DvcException):
|
|
||||||
def __init__(self, path_info, hint):
|
|
||||||
hint = "" if hint is None else " {}".format(hint)
|
|
||||||
super().__init__(
|
|
||||||
"GDrive path '{}' not found.{}".format(path_info, hint)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class GDriveAuthError(DvcException):
|
class GDriveAuthError(DvcException):
|
||||||
def __init__(self, cred_location):
|
def __init__(self, cred_location):
|
||||||
|
|
||||||
if cred_location:
|
if cred_location:
|
||||||
message = (
|
message = (
|
||||||
"GDrive remote auth failed with credentials in '{}'.\n"
|
"GDrive remote auth failed with credentials in '{}'.\n"
|
||||||
"Backup first, remove of fix them, and run DVC again.\n"
|
"Backup first, remove or fix them, and run DVC again.\n"
|
||||||
"It should do auth again and refresh the credentials.\n\n"
|
"It should do auth again and refresh the credentials.\n\n"
|
||||||
"Details:".format(cred_location)
|
"Details:".format(cred_location)
|
||||||
)
|
)
|
||||||
@@ -44,17 +39,6 @@ class GDriveAuthError(DvcException):
|
|||||||
super().__init__(message)
|
super().__init__(message)
|
||||||
|
|
||||||
|
|
||||||
def _extract(exc, field):
|
|
||||||
from pydrive2.files import ApiRequestError
|
|
||||||
|
|
||||||
assert isinstance(exc, ApiRequestError)
|
|
||||||
|
|
||||||
# https://cloud.google.com/storage/docs/json_api/v1/status-codes#errorformat
|
|
||||||
return (
|
|
||||||
exc.error["errors"][0].get(field, "") if "errors" in exc.error else ""
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def _gdrive_retry(func):
|
def _gdrive_retry(func):
|
||||||
def should_retry(exc):
|
def should_retry(exc):
|
||||||
from pydrive2.files import ApiRequestError
|
from pydrive2.files import ApiRequestError
|
||||||
@@ -68,12 +52,12 @@ def _gdrive_retry(func):
|
|||||||
result = True
|
result = True
|
||||||
|
|
||||||
if error_code == 403:
|
if error_code == 403:
|
||||||
result = _extract(exc, "reason") in [
|
result = exc.GetField("reason") in [
|
||||||
"userRateLimitExceeded",
|
"userRateLimitExceeded",
|
||||||
"rateLimitExceeded",
|
"rateLimitExceeded",
|
||||||
]
|
]
|
||||||
if result:
|
if result:
|
||||||
logger.debug("Retrying GDrive API call, error: {}.".format(exc))
|
logger.debug(f"Retrying GDrive API call, error: {exc}.")
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -100,9 +84,9 @@ class GDriveURLInfo(CloudURLInfo):
|
|||||||
self._spath = re.sub("/{2,}", "/", self._spath.rstrip("/"))
|
self._spath = re.sub("/{2,}", "/", self._spath.rstrip("/"))
|
||||||
|
|
||||||
|
|
||||||
class GDriveRemote(BaseRemote):
|
class GDriveRemoteTree(BaseRemoteTree):
|
||||||
scheme = Schemes.GDRIVE
|
scheme = Schemes.GDRIVE
|
||||||
path_cls = GDriveURLInfo
|
PATH_CLS = GDriveURLInfo
|
||||||
REQUIRES = {"pydrive2": "pydrive2"}
|
REQUIRES = {"pydrive2": "pydrive2"}
|
||||||
DEFAULT_VERIFY = True
|
DEFAULT_VERIFY = True
|
||||||
# Always prefer traverse for GDrive since API usage quotas are a concern.
|
# Always prefer traverse for GDrive since API usage quotas are a concern.
|
||||||
@@ -117,7 +101,8 @@ class GDriveRemote(BaseRemote):
|
|||||||
|
|
||||||
def __init__(self, repo, config):
|
def __init__(self, repo, config):
|
||||||
super().__init__(repo, config)
|
super().__init__(repo, config)
|
||||||
self.path_info = self.path_cls(config["url"])
|
|
||||||
|
self.path_info = self.PATH_CLS(config["url"])
|
||||||
|
|
||||||
if not self.path_info.bucket:
|
if not self.path_info.bucket:
|
||||||
raise DvcException(
|
raise DvcException(
|
||||||
@@ -144,11 +129,11 @@ class GDriveRemote(BaseRemote):
|
|||||||
self._validate_config()
|
self._validate_config()
|
||||||
self._gdrive_user_credentials_path = (
|
self._gdrive_user_credentials_path = (
|
||||||
tmp_fname(os.path.join(self.repo.tmp_dir, ""))
|
tmp_fname(os.path.join(self.repo.tmp_dir, ""))
|
||||||
if os.getenv(GDriveRemote.GDRIVE_CREDENTIALS_DATA)
|
if os.getenv(GDriveRemoteTree.GDRIVE_CREDENTIALS_DATA)
|
||||||
else config.get(
|
else config.get(
|
||||||
"gdrive_user_credentials_file",
|
"gdrive_user_credentials_file",
|
||||||
os.path.join(
|
os.path.join(
|
||||||
self.repo.tmp_dir, self.DEFAULT_USER_CREDENTIALS_FILE
|
self.repo.tmp_dir, self.DEFAULT_USER_CREDENTIALS_FILE,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -186,8 +171,8 @@ class GDriveRemote(BaseRemote):
|
|||||||
Useful for tests, exception messages, etc. Returns either env variable
|
Useful for tests, exception messages, etc. Returns either env variable
|
||||||
name if it's set or actual path to the credentials file.
|
name if it's set or actual path to the credentials file.
|
||||||
"""
|
"""
|
||||||
if os.getenv(GDriveRemote.GDRIVE_CREDENTIALS_DATA):
|
if os.getenv(GDriveRemoteTree.GDRIVE_CREDENTIALS_DATA):
|
||||||
return GDriveRemote.GDRIVE_CREDENTIALS_DATA
|
return GDriveRemoteTree.GDRIVE_CREDENTIALS_DATA
|
||||||
if os.path.exists(self._gdrive_user_credentials_path):
|
if os.path.exists(self._gdrive_user_credentials_path):
|
||||||
return self._gdrive_user_credentials_path
|
return self._gdrive_user_credentials_path
|
||||||
return None
|
return None
|
||||||
@@ -201,7 +186,7 @@ class GDriveRemote(BaseRemote):
|
|||||||
DVC config client id or secret but forgets to remove the cached
|
DVC config client id or secret but forgets to remove the cached
|
||||||
credentials file.
|
credentials file.
|
||||||
"""
|
"""
|
||||||
if not os.getenv(GDriveRemote.GDRIVE_CREDENTIALS_DATA):
|
if not os.getenv(GDriveRemoteTree.GDRIVE_CREDENTIALS_DATA):
|
||||||
if (
|
if (
|
||||||
settings["client_config"]["client_id"]
|
settings["client_config"]["client_id"]
|
||||||
!= auth.credentials.client_id
|
!= auth.credentials.client_id
|
||||||
@@ -224,10 +209,10 @@ class GDriveRemote(BaseRemote):
|
|||||||
from pydrive2.auth import GoogleAuth
|
from pydrive2.auth import GoogleAuth
|
||||||
from pydrive2.drive import GoogleDrive
|
from pydrive2.drive import GoogleDrive
|
||||||
|
|
||||||
if os.getenv(GDriveRemote.GDRIVE_CREDENTIALS_DATA):
|
if os.getenv(GDriveRemoteTree.GDRIVE_CREDENTIALS_DATA):
|
||||||
with open(self._gdrive_user_credentials_path, "w") as cred_file:
|
with open(self._gdrive_user_credentials_path, "w") as cred_file:
|
||||||
cred_file.write(
|
cred_file.write(
|
||||||
os.getenv(GDriveRemote.GDRIVE_CREDENTIALS_DATA)
|
os.getenv(GDriveRemoteTree.GDRIVE_CREDENTIALS_DATA)
|
||||||
)
|
)
|
||||||
|
|
||||||
auth_settings = {
|
auth_settings = {
|
||||||
@@ -274,7 +259,7 @@ class GDriveRemote(BaseRemote):
|
|||||||
gauth.ServiceAuth()
|
gauth.ServiceAuth()
|
||||||
else:
|
else:
|
||||||
gauth.CommandLineAuth()
|
gauth.CommandLineAuth()
|
||||||
GDriveRemote._validate_credentials(gauth, auth_settings)
|
GDriveRemoteTree._validate_credentials(gauth, auth_settings)
|
||||||
|
|
||||||
# Handle AuthenticationError, RefreshError and other auth failures
|
# Handle AuthenticationError, RefreshError and other auth failures
|
||||||
# It's hard to come up with a narrow exception, since PyDrive throws
|
# It's hard to come up with a narrow exception, since PyDrive throws
|
||||||
@@ -283,7 +268,7 @@ class GDriveRemote(BaseRemote):
|
|||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise GDriveAuthError(self.credentials_location) from exc
|
raise GDriveAuthError(self.credentials_location) from exc
|
||||||
finally:
|
finally:
|
||||||
if os.getenv(GDriveRemote.GDRIVE_CREDENTIALS_DATA):
|
if os.getenv(GDriveRemoteTree.GDRIVE_CREDENTIALS_DATA):
|
||||||
os.remove(self._gdrive_user_credentials_path)
|
os.remove(self._gdrive_user_credentials_path)
|
||||||
|
|
||||||
return GoogleDrive(gauth)
|
return GoogleDrive(gauth)
|
||||||
@@ -353,7 +338,7 @@ class GDriveRemote(BaseRemote):
|
|||||||
"use the `gdrive_user_credentials_file` config\n"
|
"use the `gdrive_user_credentials_file` config\n"
|
||||||
" option if you use multiple GDrive remotes with "
|
" option if you use multiple GDrive remotes with "
|
||||||
"different email accounts.\n\nDetails".format(
|
"different email accounts.\n\nDetails".format(
|
||||||
item_id, self.path_info, self._credentials_location
|
item_id, self.path_info, self.credentials_location
|
||||||
)
|
)
|
||||||
) from exc
|
) from exc
|
||||||
raise
|
raise
|
||||||
@@ -396,17 +381,35 @@ class GDriveRemote(BaseRemote):
|
|||||||
param = {"id": item_id}
|
param = {"id": item_id}
|
||||||
# it does not create a file on the remote
|
# it does not create a file on the remote
|
||||||
gdrive_file = self._drive.CreateFile(param)
|
gdrive_file = self._drive.CreateFile(param)
|
||||||
bar_format = (
|
|
||||||
"Downloading {desc:{ncols_desc}.{ncols_desc}}... "
|
|
||||||
+ Tqdm.format_sizeof(int(gdrive_file["fileSize"]), "B", 1024)
|
|
||||||
)
|
|
||||||
with Tqdm(
|
with Tqdm(
|
||||||
bar_format=bar_format, desc=progress_desc, disable=no_progress_bar
|
desc=progress_desc,
|
||||||
):
|
disable=no_progress_bar,
|
||||||
gdrive_file.GetContentFile(to_file)
|
bytes=True,
|
||||||
|
# explicit `bar_format` as `total` will be set by `update_to`
|
||||||
|
bar_format=Tqdm.BAR_FMT_DEFAULT,
|
||||||
|
) as pbar:
|
||||||
|
gdrive_file.GetContentFile(to_file, callback=pbar.update_to)
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
@_gdrive_retry
|
||||||
|
def open(self, path_info, mode="r", encoding=None):
|
||||||
|
assert mode in {"r", "rt", "rb"}
|
||||||
|
|
||||||
|
item_id = self._get_item_id(path_info)
|
||||||
|
param = {"id": item_id}
|
||||||
|
# it does not create a file on the remote
|
||||||
|
gdrive_file = self._drive.CreateFile(param)
|
||||||
|
fd = gdrive_file.GetContentIOBuffer()
|
||||||
|
stream = IterStream(iter(fd))
|
||||||
|
|
||||||
|
if mode != "rb":
|
||||||
|
stream = io.TextIOWrapper(stream, encoding=encoding)
|
||||||
|
|
||||||
|
yield stream
|
||||||
|
|
||||||
@_gdrive_retry
|
@_gdrive_retry
|
||||||
def _gdrive_delete_file(self, item_id):
|
def gdrive_delete_file(self, item_id):
|
||||||
from pydrive2.files import ApiRequestError
|
from pydrive2.files import ApiRequestError
|
||||||
|
|
||||||
param = {"id": item_id}
|
param = {"id": item_id}
|
||||||
@@ -420,7 +423,7 @@ class GDriveRemote(BaseRemote):
|
|||||||
if (
|
if (
|
||||||
http_error_code == 403
|
http_error_code == 403
|
||||||
and self._list_params["corpora"] == "drive"
|
and self._list_params["corpora"] == "drive"
|
||||||
and _extract(exc, "location") == "file.permissions"
|
and exc.GetField("location") == "file.permissions"
|
||||||
):
|
):
|
||||||
raise DvcException(
|
raise DvcException(
|
||||||
"Insufficient permissions to {}. You should have {} "
|
"Insufficient permissions to {}. You should have {} "
|
||||||
@@ -475,7 +478,7 @@ class GDriveRemote(BaseRemote):
|
|||||||
return None
|
return None
|
||||||
query = "trashed=false and ({})".format(
|
query = "trashed=false and ({})".format(
|
||||||
" or ".join(
|
" or ".join(
|
||||||
"'{}' in parents".format(parent_id) for parent_id in parent_ids
|
f"'{parent_id}' in parents" for parent_id in parent_ids
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
query += " and title='{}'".format(title.replace("'", "\\'"))
|
query += " and title='{}'".format(title.replace("'", "\\'"))
|
||||||
@@ -518,16 +521,52 @@ class GDriveRemote(BaseRemote):
|
|||||||
return min(item_ids)
|
return min(item_ids)
|
||||||
|
|
||||||
assert not create
|
assert not create
|
||||||
raise GDrivePathNotFound(path_info, hint)
|
raise FileMissingError(path_info, hint)
|
||||||
|
|
||||||
def exists(self, path_info):
|
def exists(self, path_info):
|
||||||
try:
|
try:
|
||||||
self._get_item_id(path_info)
|
self._get_item_id(path_info)
|
||||||
except GDrivePathNotFound:
|
except FileMissingError:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _list_paths(self, prefix=None):
|
||||||
|
if not self._ids_cache["ids"]:
|
||||||
|
return
|
||||||
|
|
||||||
|
if prefix:
|
||||||
|
dir_ids = self._ids_cache["dirs"].get(prefix[:2])
|
||||||
|
if not dir_ids:
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
dir_ids = self._ids_cache["ids"]
|
||||||
|
parents_query = " or ".join(
|
||||||
|
f"'{dir_id}' in parents" for dir_id in dir_ids
|
||||||
|
)
|
||||||
|
query = f"({parents_query}) and trashed=false"
|
||||||
|
|
||||||
|
for item in self._gdrive_list(query):
|
||||||
|
parent_id = item["parents"][0]["id"]
|
||||||
|
yield posixpath.join(
|
||||||
|
self._ids_cache["ids"][parent_id], item["title"]
|
||||||
|
)
|
||||||
|
|
||||||
|
def walk_files(self, path_info, **kwargs):
|
||||||
|
if path_info == self.path_info:
|
||||||
|
prefix = None
|
||||||
|
else:
|
||||||
|
prefix = path_info.path
|
||||||
|
for fname in self._list_paths(prefix=prefix, **kwargs):
|
||||||
|
yield path_info.replace(fname)
|
||||||
|
|
||||||
|
def remove(self, path_info):
|
||||||
|
item_id = self._get_item_id(path_info)
|
||||||
|
self.gdrive_delete_file(item_id)
|
||||||
|
|
||||||
|
def get_file_hash(self, path_info):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
def _upload(self, from_file, to_info, name=None, no_progress_bar=False):
|
def _upload(self, from_file, to_info, name=None, no_progress_bar=False):
|
||||||
dirname = to_info.parent
|
dirname = to_info.parent
|
||||||
assert dirname
|
assert dirname
|
||||||
@@ -540,36 +579,3 @@ class GDriveRemote(BaseRemote):
|
|||||||
def _download(self, from_info, to_file, name=None, no_progress_bar=False):
|
def _download(self, from_info, to_file, name=None, no_progress_bar=False):
|
||||||
item_id = self._get_item_id(from_info)
|
item_id = self._get_item_id(from_info)
|
||||||
self._gdrive_download_file(item_id, to_file, name, no_progress_bar)
|
self._gdrive_download_file(item_id, to_file, name, no_progress_bar)
|
||||||
|
|
||||||
def list_cache_paths(self, prefix=None, progress_callback=None):
|
|
||||||
if not self._ids_cache["ids"]:
|
|
||||||
return
|
|
||||||
|
|
||||||
if prefix:
|
|
||||||
dir_ids = self._ids_cache["dirs"].get(prefix[:2])
|
|
||||||
if not dir_ids:
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
dir_ids = self._ids_cache["ids"]
|
|
||||||
parents_query = " or ".join(
|
|
||||||
"'{}' in parents".format(dir_id) for dir_id in dir_ids
|
|
||||||
)
|
|
||||||
query = "({}) and trashed=false".format(parents_query)
|
|
||||||
|
|
||||||
for item in self._gdrive_list(query):
|
|
||||||
if progress_callback:
|
|
||||||
progress_callback()
|
|
||||||
parent_id = item["parents"][0]["id"]
|
|
||||||
yield posixpath.join(
|
|
||||||
self._ids_cache["ids"][parent_id], item["title"]
|
|
||||||
)
|
|
||||||
|
|
||||||
def remove(self, path_info):
|
|
||||||
item_id = self._get_item_id(path_info)
|
|
||||||
self._gdrive_delete_file(item_id)
|
|
||||||
|
|
||||||
def get_file_checksum(self, path_info):
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def walk_files(self, path_info):
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|||||||
+75
-90
@@ -1,17 +1,15 @@
|
|||||||
import logging
|
import logging
|
||||||
|
import os.path
|
||||||
|
import threading
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
import io
|
|
||||||
import os.path
|
|
||||||
import posixpath
|
|
||||||
import threading
|
|
||||||
|
|
||||||
from funcy import cached_property, wrap_prop
|
from funcy import cached_property, wrap_prop
|
||||||
|
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
from dvc.path_info import CloudURLInfo
|
from dvc.path_info import CloudURLInfo
|
||||||
from dvc.progress import Tqdm
|
from dvc.progress import Tqdm
|
||||||
from dvc.remote.base import BaseRemote
|
from dvc.remote.base import BaseRemoteTree
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -55,7 +53,7 @@ def _upload_to_bucket(
|
|||||||
no_progress_bar=False,
|
no_progress_bar=False,
|
||||||
):
|
):
|
||||||
blob = bucket.blob(to_info.path, chunk_size=chunk_size)
|
blob = bucket.blob(to_info.path, chunk_size=chunk_size)
|
||||||
with io.open(from_file, mode="rb") as fobj:
|
with open(from_file, mode="rb") as fobj:
|
||||||
with Tqdm.wrapattr(
|
with Tqdm.wrapattr(
|
||||||
fobj,
|
fobj,
|
||||||
"read",
|
"read",
|
||||||
@@ -66,9 +64,9 @@ def _upload_to_bucket(
|
|||||||
blob.upload_from_file(wrapped)
|
blob.upload_from_file(wrapped)
|
||||||
|
|
||||||
|
|
||||||
class GSRemote(BaseRemote):
|
class GSRemoteTree(BaseRemoteTree):
|
||||||
scheme = Schemes.GS
|
scheme = Schemes.GS
|
||||||
path_cls = CloudURLInfo
|
PATH_CLS = CloudURLInfo
|
||||||
REQUIRES = {"google-cloud-storage": "google.cloud.storage"}
|
REQUIRES = {"google-cloud-storage": "google.cloud.storage"}
|
||||||
PARAM_CHECKSUM = "md5"
|
PARAM_CHECKSUM = "md5"
|
||||||
|
|
||||||
@@ -76,7 +74,7 @@ class GSRemote(BaseRemote):
|
|||||||
super().__init__(repo, config)
|
super().__init__(repo, config)
|
||||||
|
|
||||||
url = config.get("url", "gs:///")
|
url = config.get("url", "gs:///")
|
||||||
self.path_info = self.path_cls(url)
|
self.path_info = self.PATH_CLS(url)
|
||||||
|
|
||||||
self.projectname = config.get("projectname", None)
|
self.projectname = config.get("projectname", None)
|
||||||
self.credentialpath = config.get("credentialpath")
|
self.credentialpath = config.get("credentialpath")
|
||||||
@@ -92,74 +90,22 @@ class GSRemote(BaseRemote):
|
|||||||
else Client(self.projectname)
|
else Client(self.projectname)
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_file_checksum(self, path_info):
|
def _generate_download_url(self, path_info, expires=3600):
|
||||||
import base64
|
expiration = timedelta(seconds=int(expires))
|
||||||
import codecs
|
|
||||||
|
|
||||||
bucket = path_info.bucket
|
bucket = self.gs.bucket(path_info.bucket)
|
||||||
path = path_info.path
|
blob = bucket.get_blob(path_info.path)
|
||||||
blob = self.gs.bucket(bucket).get_blob(path)
|
if blob is None:
|
||||||
if not blob:
|
raise FileNotFoundError
|
||||||
return None
|
return blob.generate_signed_url(expiration=expiration)
|
||||||
|
|
||||||
b64_md5 = blob.md5_hash
|
def exists(self, path_info):
|
||||||
md5 = base64.b64decode(b64_md5)
|
"""Check if the blob exists. If it does not exist,
|
||||||
return codecs.getencoder("hex")(md5)[0].decode("utf-8")
|
it could be a part of a directory path.
|
||||||
|
|
||||||
def copy(self, from_info, to_info):
|
eg: if `data/file.txt` exists, check for `data` should return True
|
||||||
from_bucket = self.gs.bucket(from_info.bucket)
|
"""
|
||||||
blob = from_bucket.get_blob(from_info.path)
|
return self.isfile(path_info) or self.isdir(path_info)
|
||||||
if not blob:
|
|
||||||
msg = "'{}' doesn't exist in the cloud".format(from_info.path)
|
|
||||||
raise DvcException(msg)
|
|
||||||
|
|
||||||
to_bucket = self.gs.bucket(to_info.bucket)
|
|
||||||
from_bucket.copy_blob(blob, to_bucket, new_name=to_info.path)
|
|
||||||
|
|
||||||
def remove(self, path_info):
|
|
||||||
if path_info.scheme != "gs":
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
logger.debug("Removing gs://{}".format(path_info))
|
|
||||||
blob = self.gs.bucket(path_info.bucket).get_blob(path_info.path)
|
|
||||||
if not blob:
|
|
||||||
return
|
|
||||||
|
|
||||||
blob.delete()
|
|
||||||
|
|
||||||
def _list_paths(
|
|
||||||
self, path_info, max_items=None, prefix=None, progress_callback=None
|
|
||||||
):
|
|
||||||
if prefix:
|
|
||||||
prefix = posixpath.join(path_info.path, prefix[:2], prefix[2:])
|
|
||||||
else:
|
|
||||||
prefix = path_info.path
|
|
||||||
for blob in self.gs.bucket(path_info.bucket).list_blobs(
|
|
||||||
prefix=path_info.path, max_results=max_items
|
|
||||||
):
|
|
||||||
if progress_callback:
|
|
||||||
progress_callback()
|
|
||||||
yield blob.name
|
|
||||||
|
|
||||||
def list_cache_paths(self, prefix=None, progress_callback=None):
|
|
||||||
return self._list_paths(
|
|
||||||
self.path_info, prefix=prefix, progress_callback=progress_callback
|
|
||||||
)
|
|
||||||
|
|
||||||
def walk_files(self, path_info):
|
|
||||||
for fname in self._list_paths(path_info / ""):
|
|
||||||
# skip nested empty directories
|
|
||||||
if fname.endswith("/"):
|
|
||||||
continue
|
|
||||||
yield path_info.replace(fname)
|
|
||||||
|
|
||||||
def makedirs(self, path_info):
|
|
||||||
if not path_info.path:
|
|
||||||
return
|
|
||||||
|
|
||||||
self.gs.bucket(path_info.bucket).blob(
|
|
||||||
(path_info / "").path
|
|
||||||
).upload_from_string("")
|
|
||||||
|
|
||||||
def isdir(self, path_info):
|
def isdir(self, path_info):
|
||||||
dir_path = path_info / ""
|
dir_path = path_info / ""
|
||||||
@@ -172,13 +118,61 @@ class GSRemote(BaseRemote):
|
|||||||
blob = self.gs.bucket(path_info.bucket).blob(path_info.path)
|
blob = self.gs.bucket(path_info.bucket).blob(path_info.path)
|
||||||
return blob.exists()
|
return blob.exists()
|
||||||
|
|
||||||
def exists(self, path_info):
|
def _list_paths(self, path_info, max_items=None):
|
||||||
"""Check if the blob exists. If it does not exist,
|
for blob in self.gs.bucket(path_info.bucket).list_blobs(
|
||||||
it could be a part of a directory path.
|
prefix=path_info.path, max_results=max_items
|
||||||
|
):
|
||||||
|
yield blob.name
|
||||||
|
|
||||||
eg: if `data/file.txt` exists, check for `data` should return True
|
def walk_files(self, path_info, **kwargs):
|
||||||
"""
|
for fname in self._list_paths(path_info / "", **kwargs):
|
||||||
return self.isfile(path_info) or self.isdir(path_info)
|
# skip nested empty directories
|
||||||
|
if fname.endswith("/"):
|
||||||
|
continue
|
||||||
|
yield path_info.replace(fname)
|
||||||
|
|
||||||
|
def remove(self, path_info):
|
||||||
|
if path_info.scheme != "gs":
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
logger.debug(f"Removing gs://{path_info}")
|
||||||
|
blob = self.gs.bucket(path_info.bucket).get_blob(path_info.path)
|
||||||
|
if not blob:
|
||||||
|
return
|
||||||
|
|
||||||
|
blob.delete()
|
||||||
|
|
||||||
|
def makedirs(self, path_info):
|
||||||
|
if not path_info.path:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.gs.bucket(path_info.bucket).blob(
|
||||||
|
(path_info / "").path
|
||||||
|
).upload_from_string("")
|
||||||
|
|
||||||
|
def copy(self, from_info, to_info):
|
||||||
|
from_bucket = self.gs.bucket(from_info.bucket)
|
||||||
|
blob = from_bucket.get_blob(from_info.path)
|
||||||
|
if not blob:
|
||||||
|
msg = f"'{from_info.path}' doesn't exist in the cloud"
|
||||||
|
raise DvcException(msg)
|
||||||
|
|
||||||
|
to_bucket = self.gs.bucket(to_info.bucket)
|
||||||
|
from_bucket.copy_blob(blob, to_bucket, new_name=to_info.path)
|
||||||
|
|
||||||
|
def get_file_hash(self, path_info):
|
||||||
|
import base64
|
||||||
|
import codecs
|
||||||
|
|
||||||
|
bucket = path_info.bucket
|
||||||
|
path = path_info.path
|
||||||
|
blob = self.gs.bucket(bucket).get_blob(path)
|
||||||
|
if not blob:
|
||||||
|
return None
|
||||||
|
|
||||||
|
b64_md5 = blob.md5_hash
|
||||||
|
md5 = base64.b64decode(b64_md5)
|
||||||
|
return codecs.getencoder("hex")(md5)[0].decode("utf-8")
|
||||||
|
|
||||||
def _upload(self, from_file, to_info, name=None, no_progress_bar=False):
|
def _upload(self, from_file, to_info, name=None, no_progress_bar=False):
|
||||||
bucket = self.gs.bucket(to_info.bucket)
|
bucket = self.gs.bucket(to_info.bucket)
|
||||||
@@ -193,7 +187,7 @@ class GSRemote(BaseRemote):
|
|||||||
def _download(self, from_info, to_file, name=None, no_progress_bar=False):
|
def _download(self, from_info, to_file, name=None, no_progress_bar=False):
|
||||||
bucket = self.gs.bucket(from_info.bucket)
|
bucket = self.gs.bucket(from_info.bucket)
|
||||||
blob = bucket.get_blob(from_info.path)
|
blob = bucket.get_blob(from_info.path)
|
||||||
with io.open(to_file, mode="wb") as fobj:
|
with open(to_file, mode="wb") as fobj:
|
||||||
with Tqdm.wrapattr(
|
with Tqdm.wrapattr(
|
||||||
fobj,
|
fobj,
|
||||||
"write",
|
"write",
|
||||||
@@ -202,12 +196,3 @@ class GSRemote(BaseRemote):
|
|||||||
disable=no_progress_bar,
|
disable=no_progress_bar,
|
||||||
) as wrapped:
|
) as wrapped:
|
||||||
blob.download_to_file(wrapped)
|
blob.download_to_file(wrapped)
|
||||||
|
|
||||||
def _generate_download_url(self, path_info, expires=3600):
|
|
||||||
expiration = timedelta(seconds=int(expires))
|
|
||||||
|
|
||||||
bucket = self.gs.bucket(path_info.bucket)
|
|
||||||
blob = bucket.get_blob(path_info.path)
|
|
||||||
if blob is None:
|
|
||||||
raise FileNotFoundError
|
|
||||||
return blob.generate_signed_url(expiration=expiration)
|
|
||||||
|
|||||||
+86
-86
@@ -8,23 +8,25 @@ from collections import deque
|
|||||||
from contextlib import closing, contextmanager
|
from contextlib import closing, contextmanager
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from .base import BaseRemote, RemoteCmdError
|
|
||||||
from .pool import get_connection
|
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
from dvc.utils import fix_env, tmp_fname
|
from dvc.utils import fix_env, tmp_fname
|
||||||
|
|
||||||
|
from .base import BaseRemoteTree, RemoteCmdError
|
||||||
|
from .pool import get_connection
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class HDFSRemote(BaseRemote):
|
class HDFSRemoteTree(BaseRemoteTree):
|
||||||
scheme = Schemes.HDFS
|
scheme = Schemes.HDFS
|
||||||
|
REQUIRES = {"pyarrow": "pyarrow"}
|
||||||
REGEX = r"^hdfs://((?P<user>.*)@)?.*$"
|
REGEX = r"^hdfs://((?P<user>.*)@)?.*$"
|
||||||
PARAM_CHECKSUM = "checksum"
|
PARAM_CHECKSUM = "checksum"
|
||||||
REQUIRES = {"pyarrow": "pyarrow"}
|
|
||||||
TRAVERSE_PREFIX_LEN = 2
|
TRAVERSE_PREFIX_LEN = 2
|
||||||
|
|
||||||
def __init__(self, repo, config):
|
def __init__(self, repo, config):
|
||||||
super().__init__(repo, config)
|
super().__init__(repo, config)
|
||||||
|
|
||||||
self.path_info = None
|
self.path_info = None
|
||||||
url = config.get("url")
|
url = config.get("url")
|
||||||
if not url:
|
if not url:
|
||||||
@@ -33,7 +35,7 @@ class HDFSRemote(BaseRemote):
|
|||||||
parsed = urlparse(url)
|
parsed = urlparse(url)
|
||||||
user = parsed.username or config.get("user")
|
user = parsed.username or config.get("user")
|
||||||
|
|
||||||
self.path_info = self.path_cls.from_parts(
|
self.path_info = self.PATH_CLS.from_parts(
|
||||||
scheme=self.scheme,
|
scheme=self.scheme,
|
||||||
host=parsed.hostname,
|
host=parsed.hostname,
|
||||||
user=user,
|
user=user,
|
||||||
@@ -41,7 +43,8 @@ class HDFSRemote(BaseRemote):
|
|||||||
path=parsed.path,
|
path=parsed.path,
|
||||||
)
|
)
|
||||||
|
|
||||||
def hdfs(self, path_info):
|
@staticmethod
|
||||||
|
def hdfs(path_info):
|
||||||
import pyarrow
|
import pyarrow
|
||||||
|
|
||||||
return get_connection(
|
return get_connection(
|
||||||
@@ -51,10 +54,84 @@ class HDFSRemote(BaseRemote):
|
|||||||
user=path_info.user,
|
user=path_info.user,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def open(self, path_info, mode="r", encoding=None):
|
||||||
|
assert mode in {"r", "rt", "rb"}
|
||||||
|
|
||||||
|
try:
|
||||||
|
with self.hdfs(path_info) as hdfs, closing(
|
||||||
|
hdfs.open(path_info.path, mode="rb")
|
||||||
|
) as fd:
|
||||||
|
if mode == "rb":
|
||||||
|
yield fd
|
||||||
|
else:
|
||||||
|
yield io.TextIOWrapper(fd, encoding=encoding)
|
||||||
|
except OSError as e:
|
||||||
|
# Empty .errno and not specific enough error class in pyarrow,
|
||||||
|
# see https://issues.apache.org/jira/browse/ARROW-6248
|
||||||
|
if "file does not exist" in str(e):
|
||||||
|
raise FileNotFoundError(*e.args)
|
||||||
|
raise
|
||||||
|
|
||||||
|
def exists(self, path_info):
|
||||||
|
assert not isinstance(path_info, list)
|
||||||
|
assert path_info.scheme == "hdfs"
|
||||||
|
with self.hdfs(path_info) as hdfs:
|
||||||
|
return hdfs.exists(path_info.path)
|
||||||
|
|
||||||
|
def walk_files(self, path_info, **kwargs):
|
||||||
|
if not self.exists(path_info):
|
||||||
|
return
|
||||||
|
|
||||||
|
root = path_info.path
|
||||||
|
dirs = deque([root])
|
||||||
|
|
||||||
|
with self.hdfs(self.path_info) as hdfs:
|
||||||
|
if not hdfs.exists(root):
|
||||||
|
return
|
||||||
|
while dirs:
|
||||||
|
try:
|
||||||
|
entries = hdfs.ls(dirs.pop(), detail=True)
|
||||||
|
for entry in entries:
|
||||||
|
if entry["kind"] == "directory":
|
||||||
|
dirs.append(urlparse(entry["name"]).path)
|
||||||
|
elif entry["kind"] == "file":
|
||||||
|
path = urlparse(entry["name"]).path
|
||||||
|
yield path_info.replace(path=path)
|
||||||
|
except OSError:
|
||||||
|
# When searching for a specific prefix pyarrow raises an
|
||||||
|
# exception if the specified cache dir does not exist
|
||||||
|
pass
|
||||||
|
|
||||||
|
def remove(self, path_info):
|
||||||
|
if path_info.scheme != "hdfs":
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
if self.exists(path_info):
|
||||||
|
logger.debug(f"Removing {path_info.path}")
|
||||||
|
with self.hdfs(path_info) as hdfs:
|
||||||
|
hdfs.rm(path_info.path)
|
||||||
|
|
||||||
|
def copy(self, from_info, to_info, **_kwargs):
|
||||||
|
dname = posixpath.dirname(to_info.path)
|
||||||
|
with self.hdfs(to_info) as hdfs:
|
||||||
|
hdfs.mkdir(dname)
|
||||||
|
# NOTE: this is how `hadoop fs -cp` works too: it copies through
|
||||||
|
# your local machine.
|
||||||
|
with hdfs.open(from_info.path, "rb") as from_fobj:
|
||||||
|
tmp_info = to_info.parent / tmp_fname(to_info.name)
|
||||||
|
try:
|
||||||
|
with hdfs.open(tmp_info.path, "wb") as tmp_fobj:
|
||||||
|
tmp_fobj.upload(from_fobj)
|
||||||
|
hdfs.rename(tmp_info.path, to_info.path)
|
||||||
|
except Exception:
|
||||||
|
self.remove(tmp_info)
|
||||||
|
raise
|
||||||
|
|
||||||
def hadoop_fs(self, cmd, user=None):
|
def hadoop_fs(self, cmd, user=None):
|
||||||
cmd = "hadoop fs -" + cmd
|
cmd = "hadoop fs -" + cmd
|
||||||
if user:
|
if user:
|
||||||
cmd = "HADOOP_USER_NAME={} ".format(user) + cmd
|
cmd = f"HADOOP_USER_NAME={user} " + cmd
|
||||||
|
|
||||||
# NOTE: close_fds doesn't work with redirected stdin/stdout/stderr.
|
# NOTE: close_fds doesn't work with redirected stdin/stdout/stderr.
|
||||||
# See https://github.com/iterative/dvc/issues/1197.
|
# See https://github.com/iterative/dvc/issues/1197.
|
||||||
@@ -82,45 +159,14 @@ class HDFSRemote(BaseRemote):
|
|||||||
assert match is not None
|
assert match is not None
|
||||||
return match.group(gname)
|
return match.group(gname)
|
||||||
|
|
||||||
def get_file_checksum(self, path_info):
|
def get_file_hash(self, path_info):
|
||||||
# NOTE: pyarrow doesn't support checksum, so we need to use hadoop
|
# NOTE: pyarrow doesn't support checksum, so we need to use hadoop
|
||||||
regex = r".*\t.*\t(?P<checksum>.*)"
|
regex = r".*\t.*\t(?P<checksum>.*)"
|
||||||
stdout = self.hadoop_fs(
|
stdout = self.hadoop_fs(
|
||||||
"checksum {}".format(path_info.path), user=path_info.user
|
f"checksum {path_info.path}", user=path_info.user
|
||||||
)
|
)
|
||||||
return self._group(regex, stdout, "checksum")
|
return self._group(regex, stdout, "checksum")
|
||||||
|
|
||||||
def copy(self, from_info, to_info, **_kwargs):
|
|
||||||
dname = posixpath.dirname(to_info.path)
|
|
||||||
with self.hdfs(to_info) as hdfs:
|
|
||||||
hdfs.mkdir(dname)
|
|
||||||
# NOTE: this is how `hadoop fs -cp` works too: it copies through
|
|
||||||
# your local machine.
|
|
||||||
with hdfs.open(from_info.path, "rb") as from_fobj:
|
|
||||||
tmp_info = to_info.parent / tmp_fname(to_info.name)
|
|
||||||
try:
|
|
||||||
with hdfs.open(tmp_info.path, "wb") as tmp_fobj:
|
|
||||||
tmp_fobj.upload(from_fobj)
|
|
||||||
hdfs.rename(tmp_info.path, to_info.path)
|
|
||||||
except Exception:
|
|
||||||
self.remove(tmp_info)
|
|
||||||
raise
|
|
||||||
|
|
||||||
def remove(self, path_info):
|
|
||||||
if path_info.scheme != "hdfs":
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
if self.exists(path_info):
|
|
||||||
logger.debug("Removing {}".format(path_info.path))
|
|
||||||
with self.hdfs(path_info) as hdfs:
|
|
||||||
hdfs.rm(path_info.path)
|
|
||||||
|
|
||||||
def exists(self, path_info):
|
|
||||||
assert not isinstance(path_info, list)
|
|
||||||
assert path_info.scheme == "hdfs"
|
|
||||||
with self.hdfs(path_info) as hdfs:
|
|
||||||
return hdfs.exists(path_info.path)
|
|
||||||
|
|
||||||
def _upload(self, from_file, to_info, **_kwargs):
|
def _upload(self, from_file, to_info, **_kwargs):
|
||||||
with self.hdfs(to_info) as hdfs:
|
with self.hdfs(to_info) as hdfs:
|
||||||
hdfs.mkdir(posixpath.dirname(to_info.path))
|
hdfs.mkdir(posixpath.dirname(to_info.path))
|
||||||
@@ -133,49 +179,3 @@ class HDFSRemote(BaseRemote):
|
|||||||
with self.hdfs(from_info) as hdfs:
|
with self.hdfs(from_info) as hdfs:
|
||||||
with open(to_file, "wb+") as fobj:
|
with open(to_file, "wb+") as fobj:
|
||||||
hdfs.download(from_info.path, fobj)
|
hdfs.download(from_info.path, fobj)
|
||||||
|
|
||||||
@contextmanager
|
|
||||||
def open(self, path_info, mode="r", encoding=None):
|
|
||||||
assert mode in {"r", "rt", "rb"}
|
|
||||||
|
|
||||||
try:
|
|
||||||
with self.hdfs(path_info) as hdfs, closing(
|
|
||||||
hdfs.open(path_info.path, mode="rb")
|
|
||||||
) as fd:
|
|
||||||
if mode == "rb":
|
|
||||||
yield fd
|
|
||||||
else:
|
|
||||||
yield io.TextIOWrapper(fd, encoding=encoding)
|
|
||||||
except IOError as e:
|
|
||||||
# Empty .errno and not specific enough error class in pyarrow,
|
|
||||||
# see https://issues.apache.org/jira/browse/ARROW-6248
|
|
||||||
if "file does not exist" in str(e):
|
|
||||||
raise FileNotFoundError(*e.args)
|
|
||||||
raise
|
|
||||||
|
|
||||||
def list_cache_paths(self, prefix=None, progress_callback=None):
|
|
||||||
if not self.exists(self.path_info):
|
|
||||||
return
|
|
||||||
|
|
||||||
if prefix:
|
|
||||||
root = posixpath.join(self.path_info.path, prefix[:2])
|
|
||||||
else:
|
|
||||||
root = self.path_info.path
|
|
||||||
dirs = deque([root])
|
|
||||||
|
|
||||||
with self.hdfs(self.path_info) as hdfs:
|
|
||||||
while dirs:
|
|
||||||
try:
|
|
||||||
entries = hdfs.ls(dirs.pop(), detail=True)
|
|
||||||
for entry in entries:
|
|
||||||
if entry["kind"] == "directory":
|
|
||||||
dirs.append(urlparse(entry["name"]).path)
|
|
||||||
elif entry["kind"] == "file":
|
|
||||||
if progress_callback:
|
|
||||||
progress_callback()
|
|
||||||
yield urlparse(entry["name"]).path
|
|
||||||
except IOError as e:
|
|
||||||
# When searching for a specific prefix pyarrow raises an
|
|
||||||
# exception if the specified cache dir does not exist
|
|
||||||
if not prefix:
|
|
||||||
raise e
|
|
||||||
|
|||||||
+79
-80
@@ -4,11 +4,11 @@ import threading
|
|||||||
|
|
||||||
from funcy import cached_property, memoize, wrap_prop, wrap_with
|
from funcy import cached_property, memoize, wrap_prop, wrap_with
|
||||||
|
|
||||||
from dvc.path_info import HTTPURLInfo
|
|
||||||
import dvc.prompt as prompt
|
import dvc.prompt as prompt
|
||||||
from dvc.exceptions import DvcException, HTTPError
|
from dvc.exceptions import DvcException, HTTPError
|
||||||
|
from dvc.path_info import HTTPURLInfo
|
||||||
from dvc.progress import Tqdm
|
from dvc.progress import Tqdm
|
||||||
from dvc.remote.base import BaseRemote
|
from dvc.remote.base import BaseRemoteTree
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -23,22 +23,23 @@ def ask_password(host, user):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class HTTPRemote(BaseRemote):
|
class HTTPRemoteTree(BaseRemoteTree):
|
||||||
scheme = Schemes.HTTP
|
scheme = Schemes.HTTP
|
||||||
path_cls = HTTPURLInfo
|
PATH_CLS = HTTPURLInfo
|
||||||
|
PARAM_CHECKSUM = "etag"
|
||||||
|
CAN_TRAVERSE = False
|
||||||
|
|
||||||
SESSION_RETRIES = 5
|
SESSION_RETRIES = 5
|
||||||
SESSION_BACKOFF_FACTOR = 0.1
|
SESSION_BACKOFF_FACTOR = 0.1
|
||||||
REQUEST_TIMEOUT = 10
|
REQUEST_TIMEOUT = 10
|
||||||
CHUNK_SIZE = 2 ** 16
|
CHUNK_SIZE = 2 ** 16
|
||||||
PARAM_CHECKSUM = "etag"
|
|
||||||
CAN_TRAVERSE = False
|
|
||||||
|
|
||||||
def __init__(self, repo, config):
|
def __init__(self, repo, config):
|
||||||
super().__init__(repo, config)
|
super().__init__(repo, config)
|
||||||
|
|
||||||
url = config.get("url")
|
url = config.get("url")
|
||||||
if url:
|
if url:
|
||||||
self.path_info = self.path_cls(url)
|
self.path_info = self.PATH_CLS(url)
|
||||||
user = config.get("user", None)
|
user = config.get("user", None)
|
||||||
if user:
|
if user:
|
||||||
self.path_info.user = user
|
self.path_info.user = user
|
||||||
@@ -51,74 +52,7 @@ class HTTPRemote(BaseRemote):
|
|||||||
self.ask_password = config.get("ask_password", False)
|
self.ask_password = config.get("ask_password", False)
|
||||||
self.headers = {}
|
self.headers = {}
|
||||||
|
|
||||||
def _download(self, from_info, to_file, name=None, no_progress_bar=False):
|
def _auth_method(self, path_info=None):
|
||||||
response = self._request("GET", from_info.url, stream=True)
|
|
||||||
if response.status_code != 200:
|
|
||||||
raise HTTPError(response.status_code, response.reason)
|
|
||||||
with open(to_file, "wb") as fd:
|
|
||||||
with Tqdm.wrapattr(
|
|
||||||
fd,
|
|
||||||
"write",
|
|
||||||
total=None
|
|
||||||
if no_progress_bar
|
|
||||||
else self._content_length(response),
|
|
||||||
leave=False,
|
|
||||||
desc=from_info.url if name is None else name,
|
|
||||||
disable=no_progress_bar,
|
|
||||||
) as fd_wrapped:
|
|
||||||
for chunk in response.iter_content(chunk_size=self.CHUNK_SIZE):
|
|
||||||
fd_wrapped.write(chunk)
|
|
||||||
|
|
||||||
def _upload(self, from_file, to_info, name=None, no_progress_bar=False):
|
|
||||||
def chunks():
|
|
||||||
with open(from_file, "rb") as fd:
|
|
||||||
with Tqdm.wrapattr(
|
|
||||||
fd,
|
|
||||||
"read",
|
|
||||||
total=None
|
|
||||||
if no_progress_bar
|
|
||||||
else os.path.getsize(from_file),
|
|
||||||
leave=False,
|
|
||||||
desc=to_info.url if name is None else name,
|
|
||||||
disable=no_progress_bar,
|
|
||||||
) as fd_wrapped:
|
|
||||||
while True:
|
|
||||||
chunk = fd_wrapped.read(self.CHUNK_SIZE)
|
|
||||||
if not chunk:
|
|
||||||
break
|
|
||||||
yield chunk
|
|
||||||
|
|
||||||
response = self._request("POST", to_info.url, data=chunks())
|
|
||||||
if response.status_code not in (200, 201):
|
|
||||||
raise HTTPError(response.status_code, response.reason)
|
|
||||||
|
|
||||||
def exists(self, path_info):
|
|
||||||
return bool(self._request("HEAD", path_info.url))
|
|
||||||
|
|
||||||
def _content_length(self, response):
|
|
||||||
res = response.headers.get("Content-Length")
|
|
||||||
return int(res) if res else None
|
|
||||||
|
|
||||||
def get_file_checksum(self, path_info):
|
|
||||||
url = path_info.url
|
|
||||||
headers = self._request("HEAD", url).headers
|
|
||||||
etag = headers.get("ETag") or headers.get("Content-MD5")
|
|
||||||
|
|
||||||
if not etag:
|
|
||||||
raise DvcException(
|
|
||||||
"could not find an ETag or "
|
|
||||||
"Content-MD5 header for '{url}'".format(url=url)
|
|
||||||
)
|
|
||||||
|
|
||||||
if etag.startswith("W/"):
|
|
||||||
raise DvcException(
|
|
||||||
"Weak ETags are not supported."
|
|
||||||
" (Etag: '{etag}', URL: '{url}')".format(etag=etag, url=url)
|
|
||||||
)
|
|
||||||
|
|
||||||
return etag
|
|
||||||
|
|
||||||
def auth_method(self, path_info=None):
|
|
||||||
from requests.auth import HTTPBasicAuth, HTTPDigestAuth
|
from requests.auth import HTTPBasicAuth, HTTPDigestAuth
|
||||||
|
|
||||||
if path_info is None:
|
if path_info is None:
|
||||||
@@ -155,7 +89,7 @@ class HTTPRemote(BaseRemote):
|
|||||||
|
|
||||||
return session
|
return session
|
||||||
|
|
||||||
def _request(self, method, url, **kwargs):
|
def request(self, method, url, **kwargs):
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
kwargs.setdefault("allow_redirects", True)
|
kwargs.setdefault("allow_redirects", True)
|
||||||
@@ -165,7 +99,7 @@ class HTTPRemote(BaseRemote):
|
|||||||
res = self._session.request(
|
res = self._session.request(
|
||||||
method,
|
method,
|
||||||
url,
|
url,
|
||||||
auth=self.auth_method(),
|
auth=self._auth_method(),
|
||||||
headers=self.headers,
|
headers=self.headers,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
@@ -185,7 +119,72 @@ class HTTPRemote(BaseRemote):
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
except requests.exceptions.RequestException:
|
except requests.exceptions.RequestException:
|
||||||
raise DvcException("could not perform a {} request".format(method))
|
raise DvcException(f"could not perform a {method} request")
|
||||||
|
|
||||||
def gc(self):
|
def exists(self, path_info):
|
||||||
raise NotImplementedError
|
return bool(self.request("HEAD", path_info.url))
|
||||||
|
|
||||||
|
def get_file_hash(self, path_info):
|
||||||
|
url = path_info.url
|
||||||
|
headers = self.request("HEAD", url).headers
|
||||||
|
etag = headers.get("ETag") or headers.get("Content-MD5")
|
||||||
|
|
||||||
|
if not etag:
|
||||||
|
raise DvcException(
|
||||||
|
"could not find an ETag or "
|
||||||
|
"Content-MD5 header for '{url}'".format(url=url)
|
||||||
|
)
|
||||||
|
|
||||||
|
if etag.startswith("W/"):
|
||||||
|
raise DvcException(
|
||||||
|
"Weak ETags are not supported."
|
||||||
|
" (Etag: '{etag}', URL: '{url}')".format(etag=etag, url=url)
|
||||||
|
)
|
||||||
|
|
||||||
|
return etag
|
||||||
|
|
||||||
|
def _download(self, from_info, to_file, name=None, no_progress_bar=False):
|
||||||
|
response = self.request("GET", from_info.url, stream=True)
|
||||||
|
if response.status_code != 200:
|
||||||
|
raise HTTPError(response.status_code, response.reason)
|
||||||
|
with open(to_file, "wb") as fd:
|
||||||
|
with Tqdm.wrapattr(
|
||||||
|
fd,
|
||||||
|
"write",
|
||||||
|
total=None
|
||||||
|
if no_progress_bar
|
||||||
|
else self._content_length(response),
|
||||||
|
leave=False,
|
||||||
|
desc=from_info.url if name is None else name,
|
||||||
|
disable=no_progress_bar,
|
||||||
|
) as fd_wrapped:
|
||||||
|
for chunk in response.iter_content(chunk_size=self.CHUNK_SIZE):
|
||||||
|
fd_wrapped.write(chunk)
|
||||||
|
|
||||||
|
def _upload(self, from_file, to_info, name=None, no_progress_bar=False):
|
||||||
|
def chunks():
|
||||||
|
with open(from_file, "rb") as fd:
|
||||||
|
with Tqdm.wrapattr(
|
||||||
|
fd,
|
||||||
|
"read",
|
||||||
|
total=None
|
||||||
|
if no_progress_bar
|
||||||
|
else os.path.getsize(from_file),
|
||||||
|
leave=False,
|
||||||
|
desc=to_info.url if name is None else name,
|
||||||
|
disable=no_progress_bar,
|
||||||
|
) as fd_wrapped:
|
||||||
|
while True:
|
||||||
|
chunk = fd_wrapped.read(self.CHUNK_SIZE)
|
||||||
|
if not chunk:
|
||||||
|
break
|
||||||
|
yield chunk
|
||||||
|
|
||||||
|
response = self.request("POST", to_info.url, data=chunks())
|
||||||
|
if response.status_code not in (200, 201):
|
||||||
|
raise HTTPError(response.status_code, response.reason)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _content_length(response):
|
||||||
|
res = response.headers.get("Content-Length")
|
||||||
|
return int(res) if res else None
|
||||||
|
|||||||
+3
-2
@@ -1,6 +1,7 @@
|
|||||||
from .http import HTTPRemote
|
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
|
|
||||||
|
from .http import HTTPRemoteTree
|
||||||
|
|
||||||
class HTTPSRemote(HTTPRemote):
|
|
||||||
|
class HTTPSRemoteTree(HTTPRemoteTree):
|
||||||
scheme = Schemes.HTTPS
|
scheme = Schemes.HTTPS
|
||||||
|
|||||||
+31
-37
@@ -25,15 +25,15 @@ class RemoteIndexNoop:
|
|||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return iter([])
|
return iter([])
|
||||||
|
|
||||||
def __contains__(self, checksum):
|
def __contains__(self, hash_):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def checksums():
|
def hashes():
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def dir_checksums():
|
def dir_hashes():
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
@@ -54,13 +54,13 @@ class RemoteIndexNoop:
|
|||||||
|
|
||||||
|
|
||||||
class RemoteIndex:
|
class RemoteIndex:
|
||||||
"""Class for indexing remote checksums in a sqlite3 database.
|
"""Class for indexing remote hashes in a sqlite3 database.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
repo: repo for this remote index.
|
repo: repo for this remote index.
|
||||||
name: name for this index. Index db will be loaded from and saved to
|
name: name for this index. Index db will be loaded from and saved to
|
||||||
``.dvc/tmp/index/{name}.idx``.
|
``.dvc/tmp/index/{name}.idx``.
|
||||||
dir_suffix: suffix used for naming directory checksums
|
dir_suffix: suffix used for naming directory hashes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
INDEX_SUFFIX = ".idx"
|
INDEX_SUFFIX = ".idx"
|
||||||
@@ -69,9 +69,7 @@ class RemoteIndex:
|
|||||||
INDEX_TABLE_LAYOUT = "checksum TEXT PRIMARY KEY, " "dir INTEGER NOT NULL"
|
INDEX_TABLE_LAYOUT = "checksum TEXT PRIMARY KEY, " "dir INTEGER NOT NULL"
|
||||||
|
|
||||||
def __init__(self, repo, name, dir_suffix=".dir"):
|
def __init__(self, repo, name, dir_suffix=".dir"):
|
||||||
self.path = os.path.join(
|
self.path = os.path.join(repo.index_dir, f"{name}{self.INDEX_SUFFIX}")
|
||||||
repo.index_dir, "{}{}".format(name, self.INDEX_SUFFIX)
|
|
||||||
)
|
|
||||||
|
|
||||||
self.dir_suffix = dir_suffix
|
self.dir_suffix = dir_suffix
|
||||||
self.database = None
|
self.database = None
|
||||||
@@ -80,9 +78,9 @@ class RemoteIndex:
|
|||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
cmd = "SELECT checksum FROM {}".format(self.INDEX_TABLE)
|
cmd = f"SELECT checksum FROM {self.INDEX_TABLE}"
|
||||||
for (checksum,) in self._execute(cmd):
|
for (hash_,) in self._execute(cmd):
|
||||||
yield checksum
|
yield hash_
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
@@ -92,25 +90,25 @@ class RemoteIndex:
|
|||||||
self.dump()
|
self.dump()
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
|
|
||||||
def __contains__(self, checksum):
|
def __contains__(self, hash_):
|
||||||
cmd = "SELECT checksum FROM {} WHERE checksum = (?)".format(
|
cmd = "SELECT checksum FROM {} WHERE checksum = (?)".format(
|
||||||
self.INDEX_TABLE
|
self.INDEX_TABLE
|
||||||
)
|
)
|
||||||
self._execute(cmd, (checksum,))
|
self._execute(cmd, (hash_,))
|
||||||
return self.cursor.fetchone() is not None
|
return self.cursor.fetchone() is not None
|
||||||
|
|
||||||
def checksums(self):
|
def hashes(self):
|
||||||
"""Iterate over checksums stored in the index."""
|
"""Iterate over hashes stored in the index."""
|
||||||
return iter(self)
|
return iter(self)
|
||||||
|
|
||||||
def dir_checksums(self):
|
def dir_hashes(self):
|
||||||
"""Iterate over .dir checksums stored in the index."""
|
"""Iterate over .dir hashes stored in the index."""
|
||||||
cmd = "SELECT checksum FROM {} WHERE dir = 1".format(self.INDEX_TABLE)
|
cmd = f"SELECT checksum FROM {self.INDEX_TABLE} WHERE dir = 1"
|
||||||
for (checksum,) in self._execute(cmd):
|
for (hash_,) in self._execute(cmd):
|
||||||
yield checksum
|
yield hash_
|
||||||
|
|
||||||
def is_dir_checksum(self, checksum):
|
def is_dir_hash(self, hash_):
|
||||||
return checksum.endswith(self.dir_suffix)
|
return hash_.endswith(self.dir_suffix)
|
||||||
|
|
||||||
def _execute(self, cmd, parameters=()):
|
def _execute(self, cmd, parameters=()):
|
||||||
return self.cursor.execute(cmd, parameters)
|
return self.cursor.execute(cmd, parameters)
|
||||||
@@ -184,31 +182,27 @@ class RemoteIndex:
|
|||||||
|
|
||||||
Changes to the index will not committed until dump() is called.
|
Changes to the index will not committed until dump() is called.
|
||||||
"""
|
"""
|
||||||
cmd = "DELETE FROM {}".format(self.INDEX_TABLE)
|
cmd = f"DELETE FROM {self.INDEX_TABLE}"
|
||||||
self._execute(cmd)
|
self._execute(cmd)
|
||||||
|
|
||||||
def update(self, dir_checksums, file_checksums):
|
def update(self, dir_hashes, file_hashes):
|
||||||
"""Update this index, adding the specified checksums.
|
"""Update this index, adding the specified hashes.
|
||||||
|
|
||||||
Changes to the index will not committed until dump() is called.
|
Changes to the index will not committed until dump() is called.
|
||||||
"""
|
"""
|
||||||
cmd = "INSERT OR IGNORE INTO {} (checksum, dir) VALUES (?, ?)".format(
|
cmd = "INSERT OR IGNORE INTO {} (checksum, dir) VALUES (?, ?)".format(
|
||||||
self.INDEX_TABLE
|
self.INDEX_TABLE
|
||||||
)
|
)
|
||||||
self._executemany(
|
self._executemany(cmd, ((hash_, True) for hash_ in dir_hashes))
|
||||||
cmd, ((checksum, True) for checksum in dir_checksums)
|
self._executemany(cmd, ((hash_, False) for hash_ in file_hashes))
|
||||||
)
|
|
||||||
self._executemany(
|
|
||||||
cmd, ((checksum, False) for checksum in file_checksums)
|
|
||||||
)
|
|
||||||
|
|
||||||
def intersection(self, checksums):
|
def intersection(self, hashes):
|
||||||
"""Iterate over values from `checksums` which exist in the index."""
|
"""Iterate over values from `hashes` which exist in the index."""
|
||||||
# sqlite has a compile time limit of 999, see:
|
# sqlite has a compile time limit of 999, see:
|
||||||
# https://www.sqlite.org/c3ref/c_limit_attached.html#sqlitelimitvariablenumber
|
# https://www.sqlite.org/c3ref/c_limit_attached.html#sqlitelimitvariablenumber
|
||||||
for chunk in lchunks(999, checksums):
|
for chunk in lchunks(999, hashes):
|
||||||
cmd = "SELECT checksum FROM {} WHERE checksum IN ({})".format(
|
cmd = "SELECT checksum FROM {} WHERE checksum IN ({})".format(
|
||||||
self.INDEX_TABLE, ",".join("?" for checksum in chunk)
|
self.INDEX_TABLE, ",".join("?" for hash_ in chunk)
|
||||||
)
|
)
|
||||||
for (checksum,) in self._execute(cmd, chunk):
|
for (hash_,) in self._execute(cmd, chunk):
|
||||||
yield checksum
|
yield hash_
|
||||||
|
|||||||
+315
-313
@@ -2,120 +2,101 @@ import errno
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import stat
|
import stat
|
||||||
from concurrent.futures import as_completed, ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
from functools import partial
|
from functools import partial, wraps
|
||||||
|
|
||||||
from funcy import cached_property, concat
|
from funcy import cached_property, concat
|
||||||
|
|
||||||
from shortuuid import uuid
|
from shortuuid import uuid
|
||||||
|
|
||||||
from dvc.compat import fspath_py35
|
from dvc.exceptions import DownloadError, DvcException, UploadError
|
||||||
from dvc.exceptions import DvcException, DownloadError, UploadError
|
|
||||||
from dvc.path_info import PathInfo
|
from dvc.path_info import PathInfo
|
||||||
from dvc.progress import Tqdm
|
from dvc.progress import Tqdm
|
||||||
from dvc.remote.base import (
|
from dvc.remote.base import (
|
||||||
index_locked,
|
|
||||||
BaseRemote,
|
|
||||||
STATUS_MAP,
|
|
||||||
STATUS_DELETED,
|
STATUS_DELETED,
|
||||||
|
STATUS_MAP,
|
||||||
STATUS_MISSING,
|
STATUS_MISSING,
|
||||||
STATUS_NEW,
|
STATUS_NEW,
|
||||||
|
BaseRemoteTree,
|
||||||
|
CloudCache,
|
||||||
|
Remote,
|
||||||
|
index_locked,
|
||||||
)
|
)
|
||||||
from dvc.remote.index import RemoteIndexNoop
|
from dvc.remote.index import RemoteIndexNoop
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
from dvc.scm.tree import is_working_tree
|
from dvc.scm.tree import WorkingTree, is_working_tree
|
||||||
from dvc.system import System
|
from dvc.system import System
|
||||||
from dvc.utils import file_md5, relpath, tmp_fname
|
from dvc.utils import file_md5, relpath, tmp_fname
|
||||||
from dvc.utils.fs import copyfile, move, makedirs, remove, walk_files
|
from dvc.utils.fs import (
|
||||||
|
copy_fobj_to_file,
|
||||||
|
copyfile,
|
||||||
|
makedirs,
|
||||||
|
move,
|
||||||
|
remove,
|
||||||
|
walk_files,
|
||||||
|
)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class LocalRemote(BaseRemote):
|
class LocalRemoteTree(BaseRemoteTree):
|
||||||
scheme = Schemes.LOCAL
|
scheme = Schemes.LOCAL
|
||||||
path_cls = PathInfo
|
PATH_CLS = PathInfo
|
||||||
PARAM_CHECKSUM = "md5"
|
PARAM_CHECKSUM = "md5"
|
||||||
PARAM_PATH = "path"
|
PARAM_PATH = "path"
|
||||||
TRAVERSE_PREFIX_LEN = 2
|
TRAVERSE_PREFIX_LEN = 2
|
||||||
INDEX_CLS = RemoteIndexNoop
|
|
||||||
|
|
||||||
UNPACKED_DIR_SUFFIX = ".unpacked"
|
UNPACKED_DIR_SUFFIX = ".unpacked"
|
||||||
|
|
||||||
DEFAULT_CACHE_TYPES = ["reflink", "copy"]
|
|
||||||
|
|
||||||
CACHE_MODE = 0o444
|
CACHE_MODE = 0o444
|
||||||
SHARED_MODE_MAP = {None: (0o644, 0o755), "group": (0o664, 0o775)}
|
SHARED_MODE_MAP = {None: (0o644, 0o755), "group": (0o664, 0o775)}
|
||||||
|
|
||||||
def __init__(self, repo, config):
|
def __init__(self, repo, config):
|
||||||
super().__init__(repo, config)
|
super().__init__(repo, config)
|
||||||
self.cache_dir = config.get("url")
|
url = config.get("url")
|
||||||
self._dir_info = {}
|
self.path_info = self.PATH_CLS(url) if url else None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
return self.repo.state
|
from dvc.state import StateNoop
|
||||||
|
|
||||||
@property
|
return self.repo.state if self.repo else StateNoop()
|
||||||
def cache_dir(self):
|
|
||||||
return self.path_info.fspath if self.path_info else None
|
|
||||||
|
|
||||||
@cache_dir.setter
|
|
||||||
def cache_dir(self, value):
|
|
||||||
self.path_info = PathInfo(value) if value else None
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def supported(cls, config):
|
|
||||||
return True
|
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def cache_path(self):
|
def work_tree(self):
|
||||||
return os.path.abspath(self.cache_dir)
|
# When using repo.brancher, repo.tree may change to/from WorkingTree to
|
||||||
|
# GitTree arbitarily. When repo.tree is GitTree, local cache needs to
|
||||||
|
# use its own WorkingTree instance.
|
||||||
|
if self.repo:
|
||||||
|
return WorkingTree(self.repo.root_dir)
|
||||||
|
return None
|
||||||
|
|
||||||
def checksum_to_path(self, checksum):
|
@staticmethod
|
||||||
return os.path.join(self.cache_path, checksum[0:2], checksum[2:])
|
def open(path_info, mode="r", encoding=None):
|
||||||
|
return open(path_info, mode=mode, encoding=encoding)
|
||||||
def list_cache_paths(self, prefix=None, progress_callback=None):
|
|
||||||
assert self.path_info is not None
|
|
||||||
if prefix:
|
|
||||||
path_info = self.path_info / prefix[:2]
|
|
||||||
else:
|
|
||||||
path_info = self.path_info
|
|
||||||
if progress_callback:
|
|
||||||
for path in walk_files(path_info):
|
|
||||||
progress_callback()
|
|
||||||
yield path
|
|
||||||
else:
|
|
||||||
yield from walk_files(path_info)
|
|
||||||
|
|
||||||
def get(self, md5):
|
|
||||||
if not md5:
|
|
||||||
return None
|
|
||||||
|
|
||||||
return self.checksum_to_path_info(md5).url
|
|
||||||
|
|
||||||
def exists(self, path_info):
|
def exists(self, path_info):
|
||||||
assert is_working_tree(self.repo.tree)
|
|
||||||
assert isinstance(path_info, str) or path_info.scheme == "local"
|
assert isinstance(path_info, str) or path_info.scheme == "local"
|
||||||
return self.repo.tree.exists(fspath_py35(path_info))
|
if not self.repo:
|
||||||
|
return os.path.exists(path_info)
|
||||||
|
return self.work_tree.exists(path_info)
|
||||||
|
|
||||||
def makedirs(self, path_info):
|
def isfile(self, path_info):
|
||||||
makedirs(path_info, exist_ok=True, mode=self._dir_mode)
|
if not self.repo:
|
||||||
|
return os.path.isfile(path_info)
|
||||||
|
return self.work_tree.isfile(path_info)
|
||||||
|
|
||||||
def already_cached(self, path_info):
|
def isdir(self, path_info):
|
||||||
assert path_info.scheme in ["", "local"]
|
if not self.repo:
|
||||||
|
return os.path.isdir(path_info)
|
||||||
|
return self.work_tree.isdir(path_info)
|
||||||
|
|
||||||
current_md5 = self.get_checksum(path_info)
|
def iscopy(self, path_info):
|
||||||
|
return not (
|
||||||
|
System.is_symlink(path_info) or System.is_hardlink(path_info)
|
||||||
|
)
|
||||||
|
|
||||||
if not current_md5:
|
def walk_files(self, path_info, **kwargs):
|
||||||
return False
|
for fname in self.work_tree.walk_files(path_info):
|
||||||
|
yield PathInfo(fname)
|
||||||
return not self.changed_cache(current_md5)
|
|
||||||
|
|
||||||
def _verify_link(self, path_info, link_type):
|
|
||||||
if link_type == "hardlink" and self.getsize(path_info) == 0:
|
|
||||||
return
|
|
||||||
|
|
||||||
super()._verify_link(path_info, link_type)
|
|
||||||
|
|
||||||
def is_empty(self, path_info):
|
def is_empty(self, path_info):
|
||||||
path = path_info.fspath
|
path = path_info.fspath
|
||||||
@@ -128,32 +109,6 @@ class LocalRemote(BaseRemote):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def isfile(path_info):
|
|
||||||
return os.path.isfile(fspath_py35(path_info))
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def isdir(path_info):
|
|
||||||
return os.path.isdir(fspath_py35(path_info))
|
|
||||||
|
|
||||||
def iscopy(self, path_info):
|
|
||||||
return not (
|
|
||||||
System.is_symlink(path_info) or System.is_hardlink(path_info)
|
|
||||||
)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def getsize(path_info):
|
|
||||||
return os.path.getsize(fspath_py35(path_info))
|
|
||||||
|
|
||||||
def walk_files(self, path_info):
|
|
||||||
assert is_working_tree(self.repo.tree)
|
|
||||||
|
|
||||||
for fname in self.repo.tree.walk_files(path_info):
|
|
||||||
yield PathInfo(fname)
|
|
||||||
|
|
||||||
def get_file_checksum(self, path_info):
|
|
||||||
return file_md5(path_info)[0]
|
|
||||||
|
|
||||||
def remove(self, path_info):
|
def remove(self, path_info):
|
||||||
if isinstance(path_info, PathInfo):
|
if isinstance(path_info, PathInfo):
|
||||||
if path_info.scheme != "local":
|
if path_info.scheme != "local":
|
||||||
@@ -165,6 +120,9 @@ class LocalRemote(BaseRemote):
|
|||||||
if self.exists(path):
|
if self.exists(path):
|
||||||
remove(path)
|
remove(path)
|
||||||
|
|
||||||
|
def makedirs(self, path_info):
|
||||||
|
makedirs(path_info, exist_ok=True, mode=self.dir_mode)
|
||||||
|
|
||||||
def move(self, from_info, to_info, mode=None):
|
def move(self, from_info, to_info, mode=None):
|
||||||
if from_info.scheme != "local" or to_info.scheme != "local":
|
if from_info.scheme != "local" or to_info.scheme != "local":
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
@@ -173,9 +131,9 @@ class LocalRemote(BaseRemote):
|
|||||||
|
|
||||||
if mode is None:
|
if mode is None:
|
||||||
if self.isfile(from_info):
|
if self.isfile(from_info):
|
||||||
mode = self._file_mode
|
mode = self.file_mode
|
||||||
else:
|
else:
|
||||||
mode = self._dir_mode
|
mode = self.dir_mode
|
||||||
|
|
||||||
move(from_info, to_info, mode=mode)
|
move(from_info, to_info, mode=mode)
|
||||||
|
|
||||||
@@ -183,8 +141,19 @@ class LocalRemote(BaseRemote):
|
|||||||
tmp_info = to_info.parent / tmp_fname(to_info.name)
|
tmp_info = to_info.parent / tmp_fname(to_info.name)
|
||||||
try:
|
try:
|
||||||
System.copy(from_info, tmp_info)
|
System.copy(from_info, tmp_info)
|
||||||
os.chmod(fspath_py35(tmp_info), self._file_mode)
|
os.chmod(tmp_info, self.file_mode)
|
||||||
os.rename(fspath_py35(tmp_info), fspath_py35(to_info))
|
os.rename(tmp_info, to_info)
|
||||||
|
except Exception:
|
||||||
|
self.remove(tmp_info)
|
||||||
|
raise
|
||||||
|
|
||||||
|
def copy_fobj(self, fobj, to_info):
|
||||||
|
self.makedirs(to_info.parent)
|
||||||
|
tmp_info = to_info.parent / tmp_fname(to_info.name)
|
||||||
|
try:
|
||||||
|
copy_fobj_to_file(fobj, tmp_info)
|
||||||
|
os.chmod(tmp_info, self.file_mode)
|
||||||
|
os.rename(tmp_info, to_info)
|
||||||
except Exception:
|
except Exception:
|
||||||
self.remove(tmp_info)
|
self.remove(tmp_info)
|
||||||
raise
|
raise
|
||||||
@@ -202,7 +171,7 @@ class LocalRemote(BaseRemote):
|
|||||||
# and the cache type is `hardlink`, we might reach link limits and
|
# and the cache type is `hardlink`, we might reach link limits and
|
||||||
# will get something like: `too many links error`
|
# will get something like: `too many links error`
|
||||||
#
|
#
|
||||||
# This is because all those empty files will have the same checksum
|
# This is because all those empty files will have the same hash
|
||||||
# (i.e. 68b329da9893e34099c7d8ad5cb9c940), therefore, they will be
|
# (i.e. 68b329da9893e34099c7d8ad5cb9c940), therefore, they will be
|
||||||
# linked to the same file in the cache.
|
# linked to the same file in the cache.
|
||||||
#
|
#
|
||||||
@@ -232,20 +201,81 @@ class LocalRemote(BaseRemote):
|
|||||||
System.reflink(from_info, tmp_info)
|
System.reflink(from_info, tmp_info)
|
||||||
# NOTE: reflink has its own separate inode, so you can set permissions
|
# NOTE: reflink has its own separate inode, so you can set permissions
|
||||||
# that are different from the source.
|
# that are different from the source.
|
||||||
os.chmod(fspath_py35(tmp_info), self._file_mode)
|
os.chmod(tmp_info, self.file_mode)
|
||||||
os.rename(fspath_py35(tmp_info), fspath_py35(to_info))
|
os.rename(tmp_info, to_info)
|
||||||
|
|
||||||
def cache_exists(self, checksums, jobs=None, name=None):
|
def _unprotect_file(self, path):
|
||||||
return [
|
if System.is_symlink(path) or System.is_hardlink(path):
|
||||||
checksum
|
logger.debug(f"Unprotecting '{path}'")
|
||||||
for checksum in Tqdm(
|
tmp = os.path.join(os.path.dirname(path), "." + uuid())
|
||||||
checksums,
|
|
||||||
unit="file",
|
# The operations order is important here - if some application
|
||||||
desc="Querying "
|
# would access the file during the process of copyfile then it
|
||||||
+ ("cache in " + name if name else "local cache"),
|
# would get only the part of file. So, at first, the file should be
|
||||||
|
# copied with the temporary name, and then original file should be
|
||||||
|
# replaced by new.
|
||||||
|
copyfile(path, tmp, name="Unprotecting '{}'".format(relpath(path)))
|
||||||
|
remove(path)
|
||||||
|
os.rename(tmp, path)
|
||||||
|
|
||||||
|
else:
|
||||||
|
logger.debug(
|
||||||
|
"Skipping copying for '{}', since it is not "
|
||||||
|
"a symlink or a hardlink.".format(path)
|
||||||
)
|
)
|
||||||
if not self.changed_cache_file(checksum)
|
|
||||||
]
|
os.chmod(path, self.file_mode)
|
||||||
|
|
||||||
|
def _unprotect_dir(self, path):
|
||||||
|
assert is_working_tree(self.repo.tree)
|
||||||
|
|
||||||
|
for fname in self.repo.tree.walk_files(path):
|
||||||
|
self._unprotect_file(fname)
|
||||||
|
|
||||||
|
def unprotect(self, path_info):
|
||||||
|
path = path_info.fspath
|
||||||
|
if not os.path.exists(path):
|
||||||
|
raise DvcException(f"can't unprotect non-existing data '{path}'")
|
||||||
|
|
||||||
|
if os.path.isdir(path):
|
||||||
|
self._unprotect_dir(path)
|
||||||
|
else:
|
||||||
|
self._unprotect_file(path)
|
||||||
|
|
||||||
|
def protect(self, path_info):
|
||||||
|
path = os.fspath(path_info)
|
||||||
|
mode = self.CACHE_MODE
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.chmod(path, mode)
|
||||||
|
except OSError as exc:
|
||||||
|
# There is nothing we need to do in case of a read-only file system
|
||||||
|
if exc.errno == errno.EROFS:
|
||||||
|
return
|
||||||
|
|
||||||
|
# In shared cache scenario, we might not own the cache file, so we
|
||||||
|
# need to check if cache file is already protected.
|
||||||
|
if exc.errno not in [errno.EPERM, errno.EACCES]:
|
||||||
|
raise
|
||||||
|
|
||||||
|
actual = stat.S_IMODE(os.stat(path).st_mode)
|
||||||
|
if actual != mode:
|
||||||
|
raise
|
||||||
|
|
||||||
|
def is_protected(self, path_info):
|
||||||
|
try:
|
||||||
|
mode = os.stat(path_info).st_mode
|
||||||
|
except FileNotFoundError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return stat.S_IMODE(mode) == self.CACHE_MODE
|
||||||
|
|
||||||
|
def get_file_hash(self, path_info):
|
||||||
|
return file_md5(path_info)[0]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def getsize(path_info):
|
||||||
|
return os.path.getsize(path_info)
|
||||||
|
|
||||||
def _upload(
|
def _upload(
|
||||||
self, from_file, to_info, name=None, no_progress_bar=False, **_kwargs
|
self, from_file, to_info, name=None, no_progress_bar=False, **_kwargs
|
||||||
@@ -256,18 +286,122 @@ class LocalRemote(BaseRemote):
|
|||||||
copyfile(
|
copyfile(
|
||||||
from_file, tmp_file, name=name, no_progress_bar=no_progress_bar
|
from_file, tmp_file, name=name, no_progress_bar=no_progress_bar
|
||||||
)
|
)
|
||||||
os.rename(tmp_file, fspath_py35(to_info))
|
|
||||||
|
|
||||||
|
self.protect(tmp_file)
|
||||||
|
os.rename(tmp_file, to_info)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def _download(
|
def _download(
|
||||||
self, from_info, to_file, name=None, no_progress_bar=False, **_kwargs
|
from_info, to_file, name=None, no_progress_bar=False, **_kwargs
|
||||||
):
|
):
|
||||||
copyfile(
|
copyfile(
|
||||||
from_info, to_file, no_progress_bar=no_progress_bar, name=name
|
from_info, to_file, no_progress_bar=no_progress_bar, name=name
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
def list_paths(self, prefix=None, progress_callback=None):
|
||||||
def open(path_info, mode="r", encoding=None):
|
assert self.path_info is not None
|
||||||
return open(fspath_py35(path_info), mode=mode, encoding=encoding)
|
if prefix:
|
||||||
|
path_info = self.path_info / prefix[:2]
|
||||||
|
if not self.exists(path_info):
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
path_info = self.path_info
|
||||||
|
# NOTE: use utils.fs walk_files since tree.walk_files will not follow
|
||||||
|
# symlinks
|
||||||
|
if progress_callback:
|
||||||
|
for path in walk_files(path_info):
|
||||||
|
progress_callback()
|
||||||
|
yield path
|
||||||
|
else:
|
||||||
|
yield from walk_files(path_info)
|
||||||
|
|
||||||
|
def _remove_unpacked_dir(self, hash_):
|
||||||
|
info = self.hash_to_path_info(hash_)
|
||||||
|
path_info = info.with_name(info.name + self.UNPACKED_DIR_SUFFIX)
|
||||||
|
self.remove(path_info)
|
||||||
|
|
||||||
|
|
||||||
|
def _log_exceptions(func, operation):
|
||||||
|
@wraps(func)
|
||||||
|
def wrapper(from_info, to_info, *args, **kwargs):
|
||||||
|
try:
|
||||||
|
func(from_info, to_info, *args, **kwargs)
|
||||||
|
return 0
|
||||||
|
except Exception as exc:
|
||||||
|
# NOTE: this means we ran out of file descriptors and there is no
|
||||||
|
# reason to try to proceed, as we will hit this error anyways.
|
||||||
|
if isinstance(exc, OSError) and exc.errno == errno.EMFILE:
|
||||||
|
raise
|
||||||
|
|
||||||
|
logger.exception(
|
||||||
|
"failed to %s '%s' to '%s'", operation, from_info, to_info
|
||||||
|
)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
class LocalRemote(Remote):
|
||||||
|
INDEX_CLS = RemoteIndexNoop
|
||||||
|
|
||||||
|
|
||||||
|
class LocalCache(CloudCache):
|
||||||
|
DEFAULT_CACHE_TYPES = ["reflink", "copy"]
|
||||||
|
CACHE_MODE = LocalRemoteTree.CACHE_MODE
|
||||||
|
|
||||||
|
def __init__(self, tree):
|
||||||
|
super().__init__(tree)
|
||||||
|
self.cache_dir = tree.config.get("url")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def cache_dir(self):
|
||||||
|
return self.tree.path_info.fspath if self.tree.path_info else None
|
||||||
|
|
||||||
|
@cache_dir.setter
|
||||||
|
def cache_dir(self, value):
|
||||||
|
self.tree.path_info = PathInfo(value) if value else None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def supported(cls, config):
|
||||||
|
return True
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def cache_path(self):
|
||||||
|
return os.path.abspath(self.cache_dir)
|
||||||
|
|
||||||
|
def hash_to_path(self, hash_):
|
||||||
|
# NOTE: `self.cache_path` is already normalized so we can simply use
|
||||||
|
# `os.sep` instead of `os.path.join`. This results in this helper
|
||||||
|
# being ~5.5 times faster.
|
||||||
|
return f"{self.cache_path}{os.sep}{hash_[0:2]}{os.sep}{hash_[2:]}"
|
||||||
|
|
||||||
|
def hashes_exist(self, hashes, jobs=None, name=None):
|
||||||
|
return [
|
||||||
|
hash_
|
||||||
|
for hash_ in Tqdm(
|
||||||
|
hashes,
|
||||||
|
unit="file",
|
||||||
|
desc="Querying "
|
||||||
|
+ ("cache in " + name if name else "local cache"),
|
||||||
|
)
|
||||||
|
if not self.changed_cache_file(hash_)
|
||||||
|
]
|
||||||
|
|
||||||
|
def already_cached(self, path_info):
|
||||||
|
assert path_info.scheme in ["", "local"]
|
||||||
|
|
||||||
|
current_md5 = self.get_hash(path_info)
|
||||||
|
|
||||||
|
if not current_md5:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return not self.changed_cache(current_md5)
|
||||||
|
|
||||||
|
def _verify_link(self, path_info, link_type):
|
||||||
|
if link_type == "hardlink" and self.tree.getsize(path_info) == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
super()._verify_link(path_info, link_type)
|
||||||
|
|
||||||
@index_locked
|
@index_locked
|
||||||
def status(
|
def status(
|
||||||
@@ -300,17 +434,15 @@ class LocalRemote(BaseRemote):
|
|||||||
|
|
||||||
dir_status_info contains status for .dir files, file_status_info
|
dir_status_info contains status for .dir files, file_status_info
|
||||||
contains status for all other files, and dir_contents is a dict of
|
contains status for all other files, and dir_contents is a dict of
|
||||||
{dir_checksum: set(file_checksum, ...)} which can be used to map
|
{dir_hash: set(file_hash, ...)} which can be used to map
|
||||||
a .dir file to its file contents.
|
a .dir file to its file contents.
|
||||||
"""
|
"""
|
||||||
logger.debug(
|
logger.debug(f"Preparing to collect status from {remote.path_info}")
|
||||||
"Preparing to collect status from {}".format(remote.path_info)
|
|
||||||
)
|
|
||||||
md5s = set(named_cache.scheme_keys(self.scheme))
|
md5s = set(named_cache.scheme_keys(self.scheme))
|
||||||
|
|
||||||
logger.debug("Collecting information from local cache...")
|
logger.debug("Collecting information from local cache...")
|
||||||
local_exists = frozenset(
|
local_exists = frozenset(
|
||||||
self.cache_exists(md5s, jobs=jobs, name=self.cache_dir)
|
self.hashes_exist(md5s, jobs=jobs, name=self.cache_dir)
|
||||||
)
|
)
|
||||||
|
|
||||||
# This is a performance optimization. We can safely assume that,
|
# This is a performance optimization. We can safely assume that,
|
||||||
@@ -325,12 +457,12 @@ class LocalRemote(BaseRemote):
|
|||||||
dir_md5s = set(named_cache.dir_keys(self.scheme))
|
dir_md5s = set(named_cache.dir_keys(self.scheme))
|
||||||
if dir_md5s:
|
if dir_md5s:
|
||||||
remote_exists.update(
|
remote_exists.update(
|
||||||
self._indexed_dir_checksums(named_cache, remote, dir_md5s)
|
self._indexed_dir_hashes(named_cache, remote, dir_md5s)
|
||||||
)
|
)
|
||||||
md5s.difference_update(remote_exists)
|
md5s.difference_update(remote_exists)
|
||||||
if md5s:
|
if md5s:
|
||||||
remote_exists.update(
|
remote_exists.update(
|
||||||
remote.cache_exists(
|
remote.hashes_exist(
|
||||||
md5s, jobs=jobs, name=str(remote.path_info)
|
md5s, jobs=jobs, name=str(remote.path_info)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -341,23 +473,23 @@ class LocalRemote(BaseRemote):
|
|||||||
def _make_status(
|
def _make_status(
|
||||||
self, named_cache, show_checksums, local_exists, remote_exists
|
self, named_cache, show_checksums, local_exists, remote_exists
|
||||||
):
|
):
|
||||||
def make_names(checksum, names):
|
def make_names(hash_, names):
|
||||||
return {"name": checksum if show_checksums else " ".join(names)}
|
return {"name": hash_ if show_checksums else " ".join(names)}
|
||||||
|
|
||||||
dir_status = {}
|
dir_status = {}
|
||||||
file_status = {}
|
file_status = {}
|
||||||
dir_contents = {}
|
dir_contents = {}
|
||||||
for checksum, item in named_cache[self.scheme].items():
|
for hash_, item in named_cache[self.scheme].items():
|
||||||
if item.children:
|
if item.children:
|
||||||
dir_status[checksum] = make_names(checksum, item.names)
|
dir_status[hash_] = make_names(hash_, item.names)
|
||||||
dir_contents[checksum] = set()
|
dir_contents[hash_] = set()
|
||||||
for child_checksum, child in item.children.items():
|
for child_hash, child in item.children.items():
|
||||||
file_status[child_checksum] = make_names(
|
file_status[child_hash] = make_names(
|
||||||
child_checksum, child.names
|
child_hash, child.names
|
||||||
)
|
)
|
||||||
dir_contents[checksum].add(child_checksum)
|
dir_contents[hash_].add(child_hash)
|
||||||
else:
|
else:
|
||||||
file_status[checksum] = make_names(checksum, item.names)
|
file_status[hash_] = make_names(hash_, item.names)
|
||||||
|
|
||||||
self._fill_statuses(dir_status, local_exists, remote_exists)
|
self._fill_statuses(dir_status, local_exists, remote_exists)
|
||||||
self._fill_statuses(file_status, local_exists, remote_exists)
|
self._fill_statuses(file_status, local_exists, remote_exists)
|
||||||
@@ -366,50 +498,50 @@ class LocalRemote(BaseRemote):
|
|||||||
|
|
||||||
return dir_status, file_status, dir_contents
|
return dir_status, file_status, dir_contents
|
||||||
|
|
||||||
def _indexed_dir_checksums(self, named_cache, remote, dir_md5s):
|
def _indexed_dir_hashes(self, named_cache, remote, dir_md5s):
|
||||||
# Validate our index by verifying all indexed .dir checksums
|
# Validate our index by verifying all indexed .dir hashes
|
||||||
# still exist on the remote
|
# still exist on the remote
|
||||||
indexed_dirs = set(remote.index.dir_checksums())
|
indexed_dirs = set(remote.index.dir_hashes())
|
||||||
indexed_dir_exists = set()
|
indexed_dir_exists = set()
|
||||||
if indexed_dirs:
|
if indexed_dirs:
|
||||||
indexed_dir_exists.update(
|
indexed_dir_exists.update(
|
||||||
remote._cache_object_exists(indexed_dirs)
|
remote.tree.list_hashes_exists(indexed_dirs)
|
||||||
)
|
)
|
||||||
missing_dirs = indexed_dirs.difference(indexed_dir_exists)
|
missing_dirs = indexed_dirs.difference(indexed_dir_exists)
|
||||||
if missing_dirs:
|
if missing_dirs:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Remote cache missing indexed .dir checksums '{}', "
|
"Remote cache missing indexed .dir hashes '{}', "
|
||||||
"clearing remote index".format(", ".join(missing_dirs))
|
"clearing remote index".format(", ".join(missing_dirs))
|
||||||
)
|
)
|
||||||
remote.index.clear()
|
remote.index.clear()
|
||||||
|
|
||||||
# Check if non-indexed (new) dir checksums exist on remote
|
# Check if non-indexed (new) dir hashes exist on remote
|
||||||
dir_exists = dir_md5s.intersection(indexed_dir_exists)
|
dir_exists = dir_md5s.intersection(indexed_dir_exists)
|
||||||
dir_exists.update(remote._cache_object_exists(dir_md5s - dir_exists))
|
dir_exists.update(
|
||||||
|
remote.tree.list_hashes_exists(dir_md5s - dir_exists)
|
||||||
|
)
|
||||||
|
|
||||||
# If .dir checksum exists on the remote, assume directory contents
|
# If .dir hash exists on the remote, assume directory contents
|
||||||
# still exists on the remote
|
# still exists on the remote
|
||||||
for dir_checksum in dir_exists:
|
for dir_hash in dir_exists:
|
||||||
file_checksums = list(
|
file_hashes = list(named_cache.child_keys(self.scheme, dir_hash))
|
||||||
named_cache.child_keys(self.scheme, dir_checksum)
|
if dir_hash not in remote.index:
|
||||||
)
|
|
||||||
if dir_checksum not in remote.index:
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Indexing new .dir '{}' with '{}' nested files".format(
|
"Indexing new .dir '{}' with '{}' nested files".format(
|
||||||
dir_checksum, len(file_checksums)
|
dir_hash, len(file_hashes)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
remote.index.update([dir_checksum], file_checksums)
|
remote.index.update([dir_hash], file_hashes)
|
||||||
yield dir_checksum
|
yield dir_hash
|
||||||
yield from file_checksums
|
yield from file_hashes
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _fill_statuses(checksum_info_dir, local_exists, remote_exists):
|
def _fill_statuses(hash_info_dir, local_exists, remote_exists):
|
||||||
# Using sets because they are way faster for lookups
|
# Using sets because they are way faster for lookups
|
||||||
local = set(local_exists)
|
local = set(local_exists)
|
||||||
remote = set(remote_exists)
|
remote = set(remote_exists)
|
||||||
|
|
||||||
for md5, info in checksum_info_dir.items():
|
for md5, info in hash_info_dir.items():
|
||||||
status = STATUS_MAP[(md5 in local, md5 in remote)]
|
status = STATUS_MAP[(md5 in local, md5 in remote)]
|
||||||
info["status"] = status
|
info["status"] = status
|
||||||
|
|
||||||
@@ -417,15 +549,15 @@ class LocalRemote(BaseRemote):
|
|||||||
cache = []
|
cache = []
|
||||||
path_infos = []
|
path_infos = []
|
||||||
names = []
|
names = []
|
||||||
checksums = []
|
hashes = []
|
||||||
for md5, info in Tqdm(
|
for md5, info in Tqdm(
|
||||||
status_info.items(), desc="Analysing status", unit="file"
|
status_info.items(), desc="Analysing status", unit="file"
|
||||||
):
|
):
|
||||||
if info["status"] == status:
|
if info["status"] == status:
|
||||||
cache.append(self.checksum_to_path_info(md5))
|
cache.append(self.hash_to_path_info(md5))
|
||||||
path_infos.append(remote.checksum_to_path_info(md5))
|
path_infos.append(remote.hash_to_path_info(md5))
|
||||||
names.append(info["name"])
|
names.append(info["name"])
|
||||||
checksums.append(md5)
|
hashes.append(md5)
|
||||||
|
|
||||||
if download:
|
if download:
|
||||||
to_infos = cache
|
to_infos = cache
|
||||||
@@ -434,7 +566,7 @@ class LocalRemote(BaseRemote):
|
|||||||
to_infos = path_infos
|
to_infos = path_infos
|
||||||
from_infos = cache
|
from_infos = cache
|
||||||
|
|
||||||
return from_infos, to_infos, names, checksums
|
return from_infos, to_infos, names, hashes
|
||||||
|
|
||||||
def _process(
|
def _process(
|
||||||
self,
|
self,
|
||||||
@@ -453,19 +585,19 @@ class LocalRemote(BaseRemote):
|
|||||||
|
|
||||||
if download:
|
if download:
|
||||||
func = partial(
|
func = partial(
|
||||||
remote.download,
|
_log_exceptions(remote.tree.download, "download"),
|
||||||
dir_mode=self._dir_mode,
|
dir_mode=self.tree.dir_mode,
|
||||||
file_mode=self._file_mode,
|
file_mode=self.tree.file_mode,
|
||||||
)
|
)
|
||||||
status = STATUS_DELETED
|
status = STATUS_DELETED
|
||||||
desc = "Downloading"
|
desc = "Downloading"
|
||||||
else:
|
else:
|
||||||
func = remote.upload
|
func = _log_exceptions(remote.tree.upload, "upload")
|
||||||
status = STATUS_NEW
|
status = STATUS_NEW
|
||||||
desc = "Uploading"
|
desc = "Uploading"
|
||||||
|
|
||||||
if jobs is None:
|
if jobs is None:
|
||||||
jobs = remote.JOBS
|
jobs = remote.tree.JOBS
|
||||||
|
|
||||||
dir_status, file_status, dir_contents = self._status(
|
dir_status, file_status, dir_contents = self._status(
|
||||||
named_cache,
|
named_cache,
|
||||||
@@ -486,26 +618,28 @@ class LocalRemote(BaseRemote):
|
|||||||
func = pbar.wrap_fn(func)
|
func = pbar.wrap_fn(func)
|
||||||
with ThreadPoolExecutor(max_workers=jobs) as executor:
|
with ThreadPoolExecutor(max_workers=jobs) as executor:
|
||||||
if download:
|
if download:
|
||||||
fails = sum(executor.map(func, *dir_plans))
|
from_infos, to_infos, names, _ = (
|
||||||
fails += sum(executor.map(func, *file_plans))
|
d + f for d, f in zip(dir_plans, file_plans)
|
||||||
|
)
|
||||||
|
fails = sum(
|
||||||
|
executor.map(func, from_infos, to_infos, names)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
# for uploads, push files first, and any .dir files last
|
# for uploads, push files first, and any .dir files last
|
||||||
|
|
||||||
file_futures = {}
|
file_futures = {}
|
||||||
for from_info, to_info, name, checksum in zip(*file_plans):
|
for from_info, to_info, name, hash_ in zip(*file_plans):
|
||||||
file_futures[checksum] = executor.submit(
|
file_futures[hash_] = executor.submit(
|
||||||
func, from_info, to_info, name
|
func, from_info, to_info, name
|
||||||
)
|
)
|
||||||
dir_futures = {}
|
dir_futures = {}
|
||||||
for from_info, to_info, name, dir_checksum in zip(
|
for from_info, to_info, name, dir_hash in zip(*dir_plans):
|
||||||
*dir_plans
|
|
||||||
):
|
|
||||||
wait_futures = {
|
wait_futures = {
|
||||||
future
|
future
|
||||||
for file_checksum, future in file_futures.items()
|
for file_hash, future in file_futures.items()
|
||||||
if file_checksum in dir_contents[dir_checksum]
|
if file_hash in dir_contents[dir_hash]
|
||||||
}
|
}
|
||||||
dir_futures[dir_checksum] = executor.submit(
|
dir_futures[dir_hash] = executor.submit(
|
||||||
self._dir_upload,
|
self._dir_upload,
|
||||||
func,
|
func,
|
||||||
wait_futures,
|
wait_futures,
|
||||||
@@ -528,16 +662,14 @@ class LocalRemote(BaseRemote):
|
|||||||
|
|
||||||
if not download:
|
if not download:
|
||||||
# index successfully pushed dirs
|
# index successfully pushed dirs
|
||||||
for dir_checksum, future in dir_futures.items():
|
for dir_hash, future in dir_futures.items():
|
||||||
if future.result() == 0:
|
if future.result() == 0:
|
||||||
file_checksums = dir_contents[dir_checksum]
|
file_hashes = dir_contents[dir_hash]
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Indexing pushed dir '{}' with "
|
"Indexing pushed dir '{}' with "
|
||||||
"'{}' nested files".format(
|
"'{}' nested files".format(dir_hash, len(file_hashes))
|
||||||
dir_checksum, len(file_checksums)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
remote.index.update([dir_checksum], file_checksums)
|
remote.index.update([dir_hash], file_hashes)
|
||||||
|
|
||||||
return len(dir_plans[0]) + len(file_plans[0])
|
return len(dir_plans[0]) + len(file_plans[0])
|
||||||
|
|
||||||
@@ -551,9 +683,7 @@ class LocalRemote(BaseRemote):
|
|||||||
"failed to upload full contents of '{}', "
|
"failed to upload full contents of '{}', "
|
||||||
"aborting .dir file upload".format(name)
|
"aborting .dir file upload".format(name)
|
||||||
)
|
)
|
||||||
logger.error(
|
logger.error(f"failed to upload '{from_info}' to '{to_info}'")
|
||||||
"failed to upload '{}' to '{}'".format(from_info, to_info)
|
|
||||||
)
|
|
||||||
return 1
|
return 1
|
||||||
return func(from_info, to_info, name)
|
return func(from_info, to_info, name)
|
||||||
|
|
||||||
@@ -578,10 +708,10 @@ class LocalRemote(BaseRemote):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _log_missing_caches(checksum_info_dict):
|
def _log_missing_caches(hash_info_dict):
|
||||||
missing_caches = [
|
missing_caches = [
|
||||||
(md5, info)
|
(md5, info)
|
||||||
for md5, info in checksum_info_dict.items()
|
for md5, info in hash_info_dict.items()
|
||||||
if info["status"] == STATUS_MISSING
|
if info["status"] == STATUS_MISSING
|
||||||
]
|
]
|
||||||
if missing_caches:
|
if missing_caches:
|
||||||
@@ -594,131 +724,3 @@ class LocalRemote(BaseRemote):
|
|||||||
"nor on remote. Missing cache files: {}".format(missing_desc)
|
"nor on remote. Missing cache files: {}".format(missing_desc)
|
||||||
)
|
)
|
||||||
logger.warning(msg)
|
logger.warning(msg)
|
||||||
|
|
||||||
def _unprotect_file(self, path):
|
|
||||||
if System.is_symlink(path) or System.is_hardlink(path):
|
|
||||||
logger.debug("Unprotecting '{}'".format(path))
|
|
||||||
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
|
|
||||||
# would get only the part of file. So, at first, the file should be
|
|
||||||
# copied with the temporary name, and then original file should be
|
|
||||||
# replaced by new.
|
|
||||||
copyfile(path, tmp, name="Unprotecting '{}'".format(relpath(path)))
|
|
||||||
remove(path)
|
|
||||||
os.rename(tmp, path)
|
|
||||||
|
|
||||||
else:
|
|
||||||
logger.debug(
|
|
||||||
"Skipping copying for '{}', since it is not "
|
|
||||||
"a symlink or a hardlink.".format(path)
|
|
||||||
)
|
|
||||||
|
|
||||||
os.chmod(path, self._file_mode)
|
|
||||||
|
|
||||||
def _unprotect_dir(self, path):
|
|
||||||
assert is_working_tree(self.repo.tree)
|
|
||||||
|
|
||||||
for fname in self.repo.tree.walk_files(path):
|
|
||||||
self._unprotect_file(fname)
|
|
||||||
|
|
||||||
def unprotect(self, path_info):
|
|
||||||
path = path_info.fspath
|
|
||||||
if not os.path.exists(path):
|
|
||||||
raise DvcException(
|
|
||||||
"can't unprotect non-existing data '{}'".format(path)
|
|
||||||
)
|
|
||||||
|
|
||||||
if os.path.isdir(path):
|
|
||||||
self._unprotect_dir(path)
|
|
||||||
else:
|
|
||||||
self._unprotect_file(path)
|
|
||||||
|
|
||||||
def protect(self, path_info):
|
|
||||||
path = fspath_py35(path_info)
|
|
||||||
mode = self.CACHE_MODE
|
|
||||||
|
|
||||||
try:
|
|
||||||
os.chmod(path, mode)
|
|
||||||
except OSError as exc:
|
|
||||||
# There is nothing we need to do in case of a read-only file system
|
|
||||||
if exc.errno == errno.EROFS:
|
|
||||||
return
|
|
||||||
|
|
||||||
# In shared cache scenario, we might not own the cache file, so we
|
|
||||||
# need to check if cache file is already protected.
|
|
||||||
if exc.errno not in [errno.EPERM, errno.EACCES]:
|
|
||||||
raise
|
|
||||||
|
|
||||||
actual = stat.S_IMODE(os.stat(path).st_mode)
|
|
||||||
if actual != mode:
|
|
||||||
raise
|
|
||||||
|
|
||||||
def _get_unpacked_dir_path_info(self, checksum):
|
|
||||||
info = self.checksum_to_path_info(checksum)
|
|
||||||
return info.with_name(info.name + self.UNPACKED_DIR_SUFFIX)
|
|
||||||
|
|
||||||
def _remove_unpacked_dir(self, checksum):
|
|
||||||
path_info = self._get_unpacked_dir_path_info(checksum)
|
|
||||||
self.remove(path_info)
|
|
||||||
|
|
||||||
def _path_info_changed(self, path_info):
|
|
||||||
if self.exists(path_info) and self.state.get(path_info):
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def _update_unpacked_dir(self, checksum):
|
|
||||||
unpacked_dir_info = self._get_unpacked_dir_path_info(checksum)
|
|
||||||
|
|
||||||
if not self._path_info_changed(unpacked_dir_info):
|
|
||||||
return
|
|
||||||
|
|
||||||
self.remove(unpacked_dir_info)
|
|
||||||
|
|
||||||
try:
|
|
||||||
dir_info = self.get_dir_cache(checksum)
|
|
||||||
self._create_unpacked_dir(checksum, dir_info, unpacked_dir_info)
|
|
||||||
except DvcException:
|
|
||||||
logger.warning("Could not create '{}'".format(unpacked_dir_info))
|
|
||||||
|
|
||||||
self.remove(unpacked_dir_info)
|
|
||||||
|
|
||||||
def _create_unpacked_dir(self, checksum, dir_info, unpacked_dir_info):
|
|
||||||
self.makedirs(unpacked_dir_info)
|
|
||||||
|
|
||||||
for entry in Tqdm(dir_info, desc="Creating unpacked dir", unit="file"):
|
|
||||||
entry_cache_info = self.checksum_to_path_info(
|
|
||||||
entry[self.PARAM_CHECKSUM]
|
|
||||||
)
|
|
||||||
relative_path = entry[self.PARAM_RELPATH]
|
|
||||||
# In shared cache mode some cache files might not be owned by the
|
|
||||||
# user, so we need to use symlinks because, unless
|
|
||||||
# /proc/sys/fs/protected_hardlinks is disabled, the user is not
|
|
||||||
# allowed to create hardlinks to files that he doesn't own.
|
|
||||||
link_types = ["hardlink", "symlink"]
|
|
||||||
self._link(
|
|
||||||
entry_cache_info, unpacked_dir_info / relative_path, link_types
|
|
||||||
)
|
|
||||||
|
|
||||||
self.state.save(unpacked_dir_info, checksum)
|
|
||||||
|
|
||||||
def _changed_unpacked_dir(self, checksum):
|
|
||||||
status_unpacked_dir_info = self._get_unpacked_dir_path_info(checksum)
|
|
||||||
|
|
||||||
return not self.state.get(status_unpacked_dir_info)
|
|
||||||
|
|
||||||
def _get_unpacked_dir_names(self, checksums):
|
|
||||||
unpacked = set()
|
|
||||||
for c in checksums:
|
|
||||||
if self.is_dir_checksum(c):
|
|
||||||
unpacked.add(c + self.UNPACKED_DIR_SUFFIX)
|
|
||||||
return unpacked
|
|
||||||
|
|
||||||
def is_protected(self, path_info):
|
|
||||||
if not self.exists(path_info):
|
|
||||||
return False
|
|
||||||
|
|
||||||
mode = os.stat(fspath_py35(path_info)).st_mode
|
|
||||||
|
|
||||||
return stat.S_IMODE(mode) == self.CACHE_MODE
|
|
||||||
|
|||||||
+32
-36
@@ -1,20 +1,18 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import posixpath
|
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
from funcy import cached_property, wrap_prop
|
from funcy import cached_property, wrap_prop
|
||||||
|
|
||||||
from dvc.path_info import CloudURLInfo
|
from dvc.path_info import CloudURLInfo
|
||||||
from dvc.progress import Tqdm
|
from dvc.progress import Tqdm
|
||||||
from dvc.remote.base import BaseRemote
|
from dvc.remote.base import BaseRemoteTree
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class OSSRemote(BaseRemote):
|
class OSSRemoteTree(BaseRemoteTree):
|
||||||
"""
|
"""
|
||||||
oss2 document:
|
oss2 document:
|
||||||
https://www.alibabacloud.com/help/doc-detail/32026.htm
|
https://www.alibabacloud.com/help/doc-detail/32026.htm
|
||||||
@@ -34,7 +32,7 @@ class OSSRemote(BaseRemote):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
scheme = Schemes.OSS
|
scheme = Schemes.OSS
|
||||||
path_cls = CloudURLInfo
|
PATH_CLS = CloudURLInfo
|
||||||
REQUIRES = {"oss2": "oss2"}
|
REQUIRES = {"oss2": "oss2"}
|
||||||
PARAM_CHECKSUM = "etag"
|
PARAM_CHECKSUM = "etag"
|
||||||
COPY_POLL_SECONDS = 5
|
COPY_POLL_SECONDS = 5
|
||||||
@@ -44,7 +42,7 @@ class OSSRemote(BaseRemote):
|
|||||||
super().__init__(repo, config)
|
super().__init__(repo, config)
|
||||||
|
|
||||||
url = config.get("url")
|
url = config.get("url")
|
||||||
self.path_info = self.path_cls(url) if url else None
|
self.path_info = self.PATH_CLS(url) if url else None
|
||||||
|
|
||||||
self.endpoint = config.get("oss_endpoint") or os.getenv("OSS_ENDPOINT")
|
self.endpoint = config.get("oss_endpoint") or os.getenv("OSS_ENDPOINT")
|
||||||
|
|
||||||
@@ -65,9 +63,9 @@ class OSSRemote(BaseRemote):
|
|||||||
def oss_service(self):
|
def oss_service(self):
|
||||||
import oss2
|
import oss2
|
||||||
|
|
||||||
logger.debug("URL: {}".format(self.path_info))
|
logger.debug(f"URL: {self.path_info}")
|
||||||
logger.debug("key id: {}".format(self.key_id))
|
logger.debug(f"key id: {self.key_id}")
|
||||||
logger.debug("key secret: {}".format(self.key_secret))
|
logger.debug(f"key secret: {self.key_secret}")
|
||||||
|
|
||||||
auth = oss2.Auth(self.key_id, self.key_secret)
|
auth = oss2.Auth(self.key_id, self.key_secret)
|
||||||
bucket = oss2.Bucket(auth, self.endpoint, self.path_info.bucket)
|
bucket = oss2.Bucket(auth, self.endpoint, self.path_info.bucket)
|
||||||
@@ -84,30 +82,37 @@ class OSSRemote(BaseRemote):
|
|||||||
)
|
)
|
||||||
return bucket
|
return bucket
|
||||||
|
|
||||||
|
def _generate_download_url(self, path_info, expires=3600):
|
||||||
|
assert path_info.bucket == self.path_info.bucket
|
||||||
|
|
||||||
|
return self.oss_service.sign_url("GET", path_info.path, expires)
|
||||||
|
|
||||||
|
def exists(self, path_info):
|
||||||
|
paths = self._list_paths(path_info)
|
||||||
|
return any(path_info.path == path for path in paths)
|
||||||
|
|
||||||
|
def _list_paths(self, path_info):
|
||||||
|
import oss2
|
||||||
|
|
||||||
|
for blob in oss2.ObjectIterator(
|
||||||
|
self.oss_service, prefix=path_info.path
|
||||||
|
):
|
||||||
|
yield blob.key
|
||||||
|
|
||||||
|
def walk_files(self, path_info, **kwargs):
|
||||||
|
for fname in self._list_paths(path_info):
|
||||||
|
if fname.endswith("/"):
|
||||||
|
continue
|
||||||
|
|
||||||
|
yield path_info.replace(path=fname)
|
||||||
|
|
||||||
def remove(self, path_info):
|
def remove(self, path_info):
|
||||||
if path_info.scheme != self.scheme:
|
if path_info.scheme != self.scheme:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
logger.debug("Removing oss://{}".format(path_info))
|
logger.debug(f"Removing oss://{path_info}")
|
||||||
self.oss_service.delete_object(path_info.path)
|
self.oss_service.delete_object(path_info.path)
|
||||||
|
|
||||||
def _list_paths(self, prefix, progress_callback=None):
|
|
||||||
import oss2
|
|
||||||
|
|
||||||
for blob in oss2.ObjectIterator(self.oss_service, prefix=prefix):
|
|
||||||
if progress_callback:
|
|
||||||
progress_callback()
|
|
||||||
yield blob.key
|
|
||||||
|
|
||||||
def list_cache_paths(self, prefix=None, progress_callback=None):
|
|
||||||
if prefix:
|
|
||||||
prefix = posixpath.join(
|
|
||||||
self.path_info.path, prefix[:2], prefix[2:]
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
prefix = self.path_info.path
|
|
||||||
return self._list_paths(prefix, progress_callback)
|
|
||||||
|
|
||||||
def _upload(
|
def _upload(
|
||||||
self, from_file, to_info, name=None, no_progress_bar=False, **_kwargs
|
self, from_file, to_info, name=None, no_progress_bar=False, **_kwargs
|
||||||
):
|
):
|
||||||
@@ -123,12 +128,3 @@ class OSSRemote(BaseRemote):
|
|||||||
self.oss_service.get_object_to_file(
|
self.oss_service.get_object_to_file(
|
||||||
from_info.path, to_file, progress_callback=pbar.update_to
|
from_info.path, to_file, progress_callback=pbar.update_to
|
||||||
)
|
)
|
||||||
|
|
||||||
def _generate_download_url(self, path_info, expires=3600):
|
|
||||||
assert path_info.bucket == self.path_info.bucket
|
|
||||||
|
|
||||||
return self.oss_service.sign_url("GET", path_info.path, expires)
|
|
||||||
|
|
||||||
def exists(self, path_info):
|
|
||||||
paths = self._list_paths(path_info.path)
|
|
||||||
return any(path_info.path == path for path in paths)
|
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
|
import threading
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
import threading
|
|
||||||
|
|
||||||
from funcy import memoize, wrap_with
|
from funcy import memoize, wrap_with
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ def close_pools():
|
|||||||
get_pool.memory.clear()
|
get_pool.memory.clear()
|
||||||
|
|
||||||
|
|
||||||
class Pool(object):
|
class Pool:
|
||||||
def __init__(self, conn_func, *conn_args, **conn_kwargs):
|
def __init__(self, conn_func, *conn_args, **conn_kwargs):
|
||||||
self._conn_func = conn_func
|
self._conn_func = conn_func
|
||||||
self._conn_args = conn_args
|
self._conn_args = conn_args
|
||||||
|
|||||||
+148
-167
@@ -1,26 +1,22 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import posixpath
|
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
from funcy import cached_property, wrap_prop
|
from funcy import cached_property, wrap_prop
|
||||||
|
|
||||||
from dvc.config import ConfigError
|
from dvc.config import ConfigError
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException, ETagMismatchError
|
||||||
from dvc.exceptions import ETagMismatchError
|
|
||||||
from dvc.path_info import CloudURLInfo
|
from dvc.path_info import CloudURLInfo
|
||||||
from dvc.progress import Tqdm
|
from dvc.progress import Tqdm
|
||||||
from dvc.remote.base import BaseRemote
|
from dvc.remote.base import BaseRemoteTree
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class S3Remote(BaseRemote):
|
class S3RemoteTree(BaseRemoteTree):
|
||||||
scheme = Schemes.S3
|
scheme = Schemes.S3
|
||||||
path_cls = CloudURLInfo
|
PATH_CLS = CloudURLInfo
|
||||||
REQUIRES = {"boto3": "boto3"}
|
REQUIRES = {"boto3": "boto3"}
|
||||||
PARAM_CHECKSUM = "etag"
|
PARAM_CHECKSUM = "etag"
|
||||||
|
|
||||||
@@ -28,7 +24,7 @@ class S3Remote(BaseRemote):
|
|||||||
super().__init__(repo, config)
|
super().__init__(repo, config)
|
||||||
|
|
||||||
url = config.get("url", "s3://")
|
url = config.get("url", "s3://")
|
||||||
self.path_info = self.path_cls(url)
|
self.path_info = self.PATH_CLS(url)
|
||||||
|
|
||||||
self.region = config.get("region")
|
self.region = config.get("region")
|
||||||
self.profile = config.get("profile")
|
self.profile = config.get("profile")
|
||||||
@@ -47,6 +43,10 @@ class S3Remote(BaseRemote):
|
|||||||
if self.sse:
|
if self.sse:
|
||||||
self.extra_args["ServerSideEncryption"] = self.sse
|
self.extra_args["ServerSideEncryption"] = self.sse
|
||||||
|
|
||||||
|
self.sse_kms_key_id = config.get("sse_kms_key_id")
|
||||||
|
if self.sse_kms_key_id:
|
||||||
|
self.extra_args["SSEKMSKeyId"] = self.sse_kms_key_id
|
||||||
|
|
||||||
self.acl = config.get("acl")
|
self.acl = config.get("acl")
|
||||||
if self.acl:
|
if self.acl:
|
||||||
self.extra_args["ACL"] = self.acl
|
self.extra_args["ACL"] = self.acl
|
||||||
@@ -76,20 +76,145 @@ class S3Remote(BaseRemote):
|
|||||||
|
|
||||||
return obj["ETag"].strip('"')
|
return obj["ETag"].strip('"')
|
||||||
|
|
||||||
def get_file_checksum(self, path_info):
|
|
||||||
return self.get_etag(self.s3, path_info.bucket, path_info.path)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_head_object(s3, bucket, path, *args, **kwargs):
|
def get_head_object(s3, bucket, path, *args, **kwargs):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
obj = s3.head_object(Bucket=bucket, Key=path, *args, **kwargs)
|
obj = s3.head_object(Bucket=bucket, Key=path, *args, **kwargs)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise DvcException(
|
raise DvcException(f"s3://{bucket}/{path} does not exist") from exc
|
||||||
"s3://{}/{} does not exist".format(bucket, path)
|
|
||||||
) from exc
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
def _append_aws_grants_to_extra_args(self, config):
|
||||||
|
# Keys for extra_args can be one of the following list:
|
||||||
|
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/customizations/s3.html#boto3.s3.transfer.S3Transfer.ALLOWED_UPLOAD_ARGS
|
||||||
|
"""
|
||||||
|
ALLOWED_UPLOAD_ARGS = [
|
||||||
|
'ACL', 'CacheControl', 'ContentDisposition', 'ContentEncoding',
|
||||||
|
'ContentLanguage', 'ContentType', 'Expires', 'GrantFullControl',
|
||||||
|
'GrantRead', 'GrantReadACP', 'GrantWriteACP', 'Metadata',
|
||||||
|
'RequestPayer', 'ServerSideEncryption', 'StorageClass',
|
||||||
|
'SSECustomerAlgorithm', 'SSECustomerKey', 'SSECustomerKeyMD5',
|
||||||
|
'SSEKMSKeyId', 'WebsiteRedirectLocation'
|
||||||
|
]
|
||||||
|
"""
|
||||||
|
|
||||||
|
grants = {
|
||||||
|
"grant_full_control": "GrantFullControl",
|
||||||
|
"grant_read": "GrantRead",
|
||||||
|
"grant_read_acp": "GrantReadACP",
|
||||||
|
"grant_write_acp": "GrantWriteACP",
|
||||||
|
}
|
||||||
|
|
||||||
|
for grant_option, extra_args_key in grants.items():
|
||||||
|
if config.get(grant_option):
|
||||||
|
if self.acl:
|
||||||
|
raise ConfigError(
|
||||||
|
"`acl` and `grant_*` AWS S3 config options "
|
||||||
|
"are mutually exclusive"
|
||||||
|
)
|
||||||
|
|
||||||
|
self.extra_args[extra_args_key] = config.get(grant_option)
|
||||||
|
|
||||||
|
def _generate_download_url(self, path_info, expires=3600):
|
||||||
|
params = {"Bucket": path_info.bucket, "Key": path_info.path}
|
||||||
|
return self.s3.generate_presigned_url(
|
||||||
|
ClientMethod="get_object", Params=params, ExpiresIn=int(expires)
|
||||||
|
)
|
||||||
|
|
||||||
|
def exists(self, path_info):
|
||||||
|
"""Check if the blob exists. If it does not exist,
|
||||||
|
it could be a part of a directory path.
|
||||||
|
|
||||||
|
eg: if `data/file.txt` exists, check for `data` should return True
|
||||||
|
"""
|
||||||
|
return self.isfile(path_info) or self.isdir(path_info)
|
||||||
|
|
||||||
|
def isdir(self, path_info):
|
||||||
|
# S3 doesn't have a concept for directories.
|
||||||
|
#
|
||||||
|
# Using `head_object` with a path pointing to a directory
|
||||||
|
# will throw a 404 error.
|
||||||
|
#
|
||||||
|
# A reliable way to know if a given path is a directory is by
|
||||||
|
# checking if there are more files sharing the same prefix
|
||||||
|
# with a `list_objects` call.
|
||||||
|
#
|
||||||
|
# We need to make sure that the path ends with a forward slash,
|
||||||
|
# since we can end with false-positives like the following example:
|
||||||
|
#
|
||||||
|
# bucket
|
||||||
|
# └── data
|
||||||
|
# ├── alice
|
||||||
|
# └── alpha
|
||||||
|
#
|
||||||
|
# Using `data/al` as prefix will return `[data/alice, data/alpha]`,
|
||||||
|
# While `data/al/` will return nothing.
|
||||||
|
#
|
||||||
|
dir_path = path_info / ""
|
||||||
|
return bool(list(self._list_paths(dir_path, max_items=1)))
|
||||||
|
|
||||||
|
def isfile(self, path_info):
|
||||||
|
from botocore.exceptions import ClientError
|
||||||
|
|
||||||
|
if path_info.path.endswith("/"):
|
||||||
|
return False
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.s3.head_object(Bucket=path_info.bucket, Key=path_info.path)
|
||||||
|
except ClientError as exc:
|
||||||
|
if exc.response["Error"]["Code"] != "404":
|
||||||
|
raise
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def _list_objects(self, path_info, max_items=None):
|
||||||
|
""" Read config for list object api, paginate through list objects."""
|
||||||
|
kwargs = {
|
||||||
|
"Bucket": path_info.bucket,
|
||||||
|
"Prefix": path_info.path,
|
||||||
|
"PaginationConfig": {"MaxItems": max_items},
|
||||||
|
}
|
||||||
|
paginator = self.s3.get_paginator(self.list_objects_api)
|
||||||
|
for page in paginator.paginate(**kwargs):
|
||||||
|
contents = page.get("Contents", ())
|
||||||
|
yield from contents
|
||||||
|
|
||||||
|
def _list_paths(self, path_info, max_items=None):
|
||||||
|
return (
|
||||||
|
item["Key"] for item in self._list_objects(path_info, max_items)
|
||||||
|
)
|
||||||
|
|
||||||
|
def walk_files(self, path_info, **kwargs):
|
||||||
|
for fname in self._list_paths(path_info / "", **kwargs):
|
||||||
|
if fname.endswith("/"):
|
||||||
|
continue
|
||||||
|
|
||||||
|
yield path_info.replace(path=fname)
|
||||||
|
|
||||||
|
def remove(self, path_info):
|
||||||
|
if path_info.scheme != "s3":
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
logger.debug(f"Removing {path_info}")
|
||||||
|
self.s3.delete_object(Bucket=path_info.bucket, Key=path_info.path)
|
||||||
|
|
||||||
|
def makedirs(self, path_info):
|
||||||
|
# We need to support creating empty directories, which means
|
||||||
|
# creating an object with an empty body and a trailing slash `/`.
|
||||||
|
#
|
||||||
|
# We are not creating directory objects for every parent prefix,
|
||||||
|
# as it is not required.
|
||||||
|
if not path_info.path:
|
||||||
|
return
|
||||||
|
|
||||||
|
dir_path = path_info / ""
|
||||||
|
self.s3.put_object(Bucket=path_info.bucket, Key=dir_path.path, Body="")
|
||||||
|
|
||||||
|
def copy(self, from_info, to_info):
|
||||||
|
self._copy(self.s3, from_info, to_info, self.extra_args)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _copy_multipart(
|
def _copy_multipart(
|
||||||
cls, s3, from_info, to_info, size, n_parts, extra_args
|
cls, s3, from_info, to_info, size, n_parts, extra_args
|
||||||
@@ -102,7 +227,7 @@ class S3Remote(BaseRemote):
|
|||||||
parts = []
|
parts = []
|
||||||
byte_position = 0
|
byte_position = 0
|
||||||
for i in range(1, n_parts + 1):
|
for i in range(1, n_parts + 1):
|
||||||
obj = cls.get_head_object(
|
obj = S3RemoteTree.get_head_object(
|
||||||
s3, from_info.bucket, from_info.path, PartNumber=i
|
s3, from_info.bucket, from_info.path, PartNumber=i
|
||||||
)
|
)
|
||||||
part_size = obj["ContentLength"]
|
part_size = obj["ContentLength"]
|
||||||
@@ -110,7 +235,7 @@ class S3Remote(BaseRemote):
|
|||||||
if lastbyte > size:
|
if lastbyte > size:
|
||||||
lastbyte = size - 1
|
lastbyte = size - 1
|
||||||
|
|
||||||
srange = "bytes={}-{}".format(byte_position, lastbyte)
|
srange = f"bytes={byte_position}-{lastbyte}"
|
||||||
|
|
||||||
part = s3.upload_part_copy(
|
part = s3.upload_part_copy(
|
||||||
Bucket=to_info.bucket,
|
Bucket=to_info.bucket,
|
||||||
@@ -157,7 +282,9 @@ class S3Remote(BaseRemote):
|
|||||||
# object is transfered in the same chunks as it was originally.
|
# object is transfered in the same chunks as it was originally.
|
||||||
from boto3.s3.transfer import TransferConfig
|
from boto3.s3.transfer import TransferConfig
|
||||||
|
|
||||||
obj = cls.get_head_object(s3, from_info.bucket, from_info.path)
|
obj = S3RemoteTree.get_head_object(
|
||||||
|
s3, from_info.bucket, from_info.path
|
||||||
|
)
|
||||||
etag = obj["ETag"].strip('"')
|
etag = obj["ETag"].strip('"')
|
||||||
size = obj["ContentLength"]
|
size = obj["ContentLength"]
|
||||||
|
|
||||||
@@ -177,114 +304,12 @@ class S3Remote(BaseRemote):
|
|||||||
Config=TransferConfig(multipart_threshold=size + 1),
|
Config=TransferConfig(multipart_threshold=size + 1),
|
||||||
)
|
)
|
||||||
|
|
||||||
cached_etag = cls.get_etag(s3, to_info.bucket, to_info.path)
|
cached_etag = S3RemoteTree.get_etag(s3, to_info.bucket, to_info.path)
|
||||||
if etag != cached_etag:
|
if etag != cached_etag:
|
||||||
raise ETagMismatchError(etag, cached_etag)
|
raise ETagMismatchError(etag, cached_etag)
|
||||||
|
|
||||||
def copy(self, from_info, to_info):
|
def get_file_hash(self, path_info):
|
||||||
self._copy(self.s3, from_info, to_info, self.extra_args)
|
return self.get_etag(self.s3, path_info.bucket, path_info.path)
|
||||||
|
|
||||||
def remove(self, path_info):
|
|
||||||
if path_info.scheme != "s3":
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
logger.debug("Removing {}".format(path_info))
|
|
||||||
self.s3.delete_object(Bucket=path_info.bucket, Key=path_info.path)
|
|
||||||
|
|
||||||
def _list_objects(
|
|
||||||
self, path_info, max_items=None, prefix=None, progress_callback=None
|
|
||||||
):
|
|
||||||
""" Read config for list object api, paginate through list objects."""
|
|
||||||
kwargs = {
|
|
||||||
"Bucket": path_info.bucket,
|
|
||||||
"Prefix": path_info.path,
|
|
||||||
"PaginationConfig": {"MaxItems": max_items},
|
|
||||||
}
|
|
||||||
if prefix:
|
|
||||||
kwargs["Prefix"] = posixpath.join(path_info.path, prefix[:2])
|
|
||||||
paginator = self.s3.get_paginator(self.list_objects_api)
|
|
||||||
for page in paginator.paginate(**kwargs):
|
|
||||||
contents = page.get("Contents", ())
|
|
||||||
if progress_callback:
|
|
||||||
for item in contents:
|
|
||||||
progress_callback()
|
|
||||||
yield item
|
|
||||||
else:
|
|
||||||
yield from contents
|
|
||||||
|
|
||||||
def _list_paths(
|
|
||||||
self, path_info, max_items=None, prefix=None, progress_callback=None
|
|
||||||
):
|
|
||||||
return (
|
|
||||||
item["Key"]
|
|
||||||
for item in self._list_objects(
|
|
||||||
path_info, max_items, prefix, progress_callback
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def list_cache_paths(self, prefix=None, progress_callback=None):
|
|
||||||
return self._list_paths(
|
|
||||||
self.path_info, prefix=prefix, progress_callback=progress_callback
|
|
||||||
)
|
|
||||||
|
|
||||||
def isfile(self, path_info):
|
|
||||||
from botocore.exceptions import ClientError
|
|
||||||
|
|
||||||
if path_info.path.endswith("/"):
|
|
||||||
return False
|
|
||||||
|
|
||||||
try:
|
|
||||||
self.s3.head_object(Bucket=path_info.bucket, Key=path_info.path)
|
|
||||||
except ClientError as exc:
|
|
||||||
if exc.response["Error"]["Code"] != "404":
|
|
||||||
raise
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def exists(self, path_info):
|
|
||||||
"""Check if the blob exists. If it does not exist,
|
|
||||||
it could be a part of a directory path.
|
|
||||||
|
|
||||||
eg: if `data/file.txt` exists, check for `data` should return True
|
|
||||||
"""
|
|
||||||
return self.isfile(path_info) or self.isdir(path_info)
|
|
||||||
|
|
||||||
def makedirs(self, path_info):
|
|
||||||
# We need to support creating empty directories, which means
|
|
||||||
# creating an object with an empty body and a trailing slash `/`.
|
|
||||||
#
|
|
||||||
# We are not creating directory objects for every parent prefix,
|
|
||||||
# as it is not required.
|
|
||||||
if not path_info.path:
|
|
||||||
return
|
|
||||||
|
|
||||||
dir_path = path_info / ""
|
|
||||||
self.s3.put_object(Bucket=path_info.bucket, Key=dir_path.path, Body="")
|
|
||||||
|
|
||||||
def isdir(self, path_info):
|
|
||||||
# S3 doesn't have a concept for directories.
|
|
||||||
#
|
|
||||||
# Using `head_object` with a path pointing to a directory
|
|
||||||
# will throw a 404 error.
|
|
||||||
#
|
|
||||||
# A reliable way to know if a given path is a directory is by
|
|
||||||
# checking if there are more files sharing the same prefix
|
|
||||||
# with a `list_objects` call.
|
|
||||||
#
|
|
||||||
# We need to make sure that the path ends with a forward slash,
|
|
||||||
# since we can end with false-positives like the following example:
|
|
||||||
#
|
|
||||||
# bucket
|
|
||||||
# └── data
|
|
||||||
# ├── alice
|
|
||||||
# └── alpha
|
|
||||||
#
|
|
||||||
# Using `data/al` as prefix will return `[data/alice, data/alpha]`,
|
|
||||||
# While `data/al/` will return nothing.
|
|
||||||
#
|
|
||||||
dir_path = path_info / ""
|
|
||||||
return bool(list(self._list_paths(dir_path, max_items=1)))
|
|
||||||
|
|
||||||
def _upload(self, from_file, to_info, name=None, no_progress_bar=False):
|
def _upload(self, from_file, to_info, name=None, no_progress_bar=False):
|
||||||
total = os.path.getsize(from_file)
|
total = os.path.getsize(from_file)
|
||||||
@@ -312,47 +337,3 @@ class S3Remote(BaseRemote):
|
|||||||
self.s3.download_file(
|
self.s3.download_file(
|
||||||
from_info.bucket, from_info.path, to_file, Callback=pbar.update
|
from_info.bucket, from_info.path, to_file, Callback=pbar.update
|
||||||
)
|
)
|
||||||
|
|
||||||
def _generate_download_url(self, path_info, expires=3600):
|
|
||||||
params = {"Bucket": path_info.bucket, "Key": path_info.path}
|
|
||||||
return self.s3.generate_presigned_url(
|
|
||||||
ClientMethod="get_object", Params=params, ExpiresIn=int(expires)
|
|
||||||
)
|
|
||||||
|
|
||||||
def walk_files(self, path_info, max_items=None):
|
|
||||||
for fname in self._list_paths(path_info / "", max_items):
|
|
||||||
if fname.endswith("/"):
|
|
||||||
continue
|
|
||||||
|
|
||||||
yield path_info.replace(path=fname)
|
|
||||||
|
|
||||||
def _append_aws_grants_to_extra_args(self, config):
|
|
||||||
# Keys for extra_args can be one of the following list:
|
|
||||||
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/customizations/s3.html#boto3.s3.transfer.S3Transfer.ALLOWED_UPLOAD_ARGS
|
|
||||||
"""
|
|
||||||
ALLOWED_UPLOAD_ARGS = [
|
|
||||||
'ACL', 'CacheControl', 'ContentDisposition', 'ContentEncoding',
|
|
||||||
'ContentLanguage', 'ContentType', 'Expires', 'GrantFullControl',
|
|
||||||
'GrantRead', 'GrantReadACP', 'GrantWriteACP', 'Metadata',
|
|
||||||
'RequestPayer', 'ServerSideEncryption', 'StorageClass',
|
|
||||||
'SSECustomerAlgorithm', 'SSECustomerKey', 'SSECustomerKeyMD5',
|
|
||||||
'SSEKMSKeyId', 'WebsiteRedirectLocation'
|
|
||||||
]
|
|
||||||
"""
|
|
||||||
|
|
||||||
grants = {
|
|
||||||
"grant_full_control": "GrantFullControl",
|
|
||||||
"grant_read": "GrantRead",
|
|
||||||
"grant_read_acp": "GrantReadACP",
|
|
||||||
"grant_write_acp": "GrantWriteACP",
|
|
||||||
}
|
|
||||||
|
|
||||||
for grant_option, extra_args_key in grants.items():
|
|
||||||
if config.get(grant_option):
|
|
||||||
if self.acl:
|
|
||||||
raise ConfigError(
|
|
||||||
"`acl` and `grant_*` AWS S3 config options "
|
|
||||||
"are mutually exclusive"
|
|
||||||
)
|
|
||||||
|
|
||||||
self.extra_args[extra_args_key] = config.get(grant_option)
|
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
import colorama
|
|
||||||
|
|
||||||
|
import colorama
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
this = sys.modules[__name__]
|
this = sys.modules[__name__]
|
||||||
|
|||||||
+66
-60
@@ -10,11 +10,11 @@ from concurrent.futures import ThreadPoolExecutor
|
|||||||
from contextlib import closing, contextmanager
|
from contextlib import closing, contextmanager
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from funcy import memoize, wrap_with, silent, first
|
from funcy import first, memoize, silent, wrap_with
|
||||||
|
|
||||||
import dvc.prompt as prompt
|
import dvc.prompt as prompt
|
||||||
from dvc.progress import Tqdm
|
from dvc.progress import Tqdm
|
||||||
from dvc.remote.base import BaseRemote
|
from dvc.remote.base import BaseRemoteTree, Remote
|
||||||
from dvc.remote.pool import get_connection
|
from dvc.remote.pool import get_connection
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
from dvc.utils import to_chunks
|
from dvc.utils import to_chunks
|
||||||
@@ -33,21 +33,21 @@ def ask_password(host, user, port):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class SSHRemote(BaseRemote):
|
class SSHRemoteTree(BaseRemoteTree):
|
||||||
scheme = Schemes.SSH
|
scheme = Schemes.SSH
|
||||||
REQUIRES = {"paramiko": "paramiko"}
|
REQUIRES = {"paramiko": "paramiko"}
|
||||||
|
|
||||||
JOBS = 4
|
JOBS = 4
|
||||||
|
|
||||||
PARAM_CHECKSUM = "md5"
|
PARAM_CHECKSUM = "md5"
|
||||||
DEFAULT_PORT = 22
|
|
||||||
TIMEOUT = 1800
|
|
||||||
# At any given time some of the connections will go over network and
|
# At any given time some of the connections will go over network and
|
||||||
# paramiko stuff, so we would ideally have it double of server processors.
|
# paramiko stuff, so we would ideally have it double of server processors.
|
||||||
# We use conservative setting of 4 instead to not exhaust max sessions.
|
# We use conservative setting of 4 instead to not exhaust max sessions.
|
||||||
CHECKSUM_JOBS = 4
|
CHECKSUM_JOBS = 4
|
||||||
|
DEFAULT_CACHE_TYPES = ["copy"]
|
||||||
TRAVERSE_PREFIX_LEN = 2
|
TRAVERSE_PREFIX_LEN = 2
|
||||||
|
|
||||||
DEFAULT_CACHE_TYPES = ["copy"]
|
DEFAULT_PORT = 22
|
||||||
|
TIMEOUT = 1800
|
||||||
|
|
||||||
def __init__(self, repo, config):
|
def __init__(self, repo, config):
|
||||||
super().__init__(repo, config)
|
super().__init__(repo, config)
|
||||||
@@ -69,7 +69,7 @@ class SSHRemote(BaseRemote):
|
|||||||
or self._try_get_ssh_config_port(user_ssh_config)
|
or self._try_get_ssh_config_port(user_ssh_config)
|
||||||
or self.DEFAULT_PORT
|
or self.DEFAULT_PORT
|
||||||
)
|
)
|
||||||
self.path_info = self.path_cls.from_parts(
|
self.path_info = self.PATH_CLS.from_parts(
|
||||||
scheme=self.scheme,
|
scheme=self.scheme,
|
||||||
host=host,
|
host=host,
|
||||||
user=user,
|
user=user,
|
||||||
@@ -103,7 +103,7 @@ class SSHRemote(BaseRemote):
|
|||||||
def _load_user_ssh_config(hostname):
|
def _load_user_ssh_config(hostname):
|
||||||
import paramiko
|
import paramiko
|
||||||
|
|
||||||
user_config_file = SSHRemote.ssh_config_filename()
|
user_config_file = SSHRemoteTree.ssh_config_filename()
|
||||||
user_ssh_config = {}
|
user_ssh_config = {}
|
||||||
if hostname and os.path.exists(user_config_file):
|
if hostname and os.path.exists(user_config_file):
|
||||||
ssh_config = paramiko.SSHConfig()
|
ssh_config = paramiko.SSHConfig()
|
||||||
@@ -148,17 +148,22 @@ class SSHRemote(BaseRemote):
|
|||||||
sock=self.sock,
|
sock=self.sock,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def open(self, path_info, mode="r", encoding=None):
|
||||||
|
assert mode in {"r", "rt", "rb", "wb"}
|
||||||
|
|
||||||
|
with self.ssh(path_info) as ssh, closing(
|
||||||
|
ssh.sftp.open(path_info.path, mode)
|
||||||
|
) as fd:
|
||||||
|
if "b" in mode:
|
||||||
|
yield fd
|
||||||
|
else:
|
||||||
|
yield io.TextIOWrapper(fd, encoding=encoding)
|
||||||
|
|
||||||
def exists(self, path_info):
|
def exists(self, path_info):
|
||||||
with self.ssh(path_info) as ssh:
|
with self.ssh(path_info) as ssh:
|
||||||
return ssh.exists(path_info.path)
|
return ssh.exists(path_info.path)
|
||||||
|
|
||||||
def get_file_checksum(self, path_info):
|
|
||||||
if path_info.scheme != self.scheme:
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
with self.ssh(path_info) as ssh:
|
|
||||||
return ssh.md5(path_info.path)
|
|
||||||
|
|
||||||
def isdir(self, path_info):
|
def isdir(self, path_info):
|
||||||
with self.ssh(path_info) as ssh:
|
with self.ssh(path_info) as ssh:
|
||||||
return ssh.isdir(path_info.path)
|
return ssh.isdir(path_info.path)
|
||||||
@@ -167,9 +172,29 @@ class SSHRemote(BaseRemote):
|
|||||||
with self.ssh(path_info) as ssh:
|
with self.ssh(path_info) as ssh:
|
||||||
return ssh.isfile(path_info.path)
|
return ssh.isfile(path_info.path)
|
||||||
|
|
||||||
def getsize(self, path_info):
|
def walk_files(self, path_info, **kwargs):
|
||||||
with self.ssh(path_info) as ssh:
|
with self.ssh(path_info) as ssh:
|
||||||
return ssh.getsize(path_info.path)
|
for fname in ssh.walk_files(path_info.path):
|
||||||
|
yield path_info.replace(path=fname)
|
||||||
|
|
||||||
|
def remove(self, path_info):
|
||||||
|
if path_info.scheme != self.scheme:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
with self.ssh(path_info) as ssh:
|
||||||
|
ssh.remove(path_info.path)
|
||||||
|
|
||||||
|
def makedirs(self, path_info):
|
||||||
|
with self.ssh(path_info) as ssh:
|
||||||
|
ssh.makedirs(path_info.path)
|
||||||
|
|
||||||
|
def move(self, from_info, to_info, mode=None):
|
||||||
|
assert mode is None
|
||||||
|
if from_info.scheme != self.scheme or to_info.scheme != self.scheme:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
with self.ssh(from_info) as ssh:
|
||||||
|
ssh.move(from_info.path, to_info.path)
|
||||||
|
|
||||||
def copy(self, from_info, to_info):
|
def copy(self, from_info, to_info):
|
||||||
if not from_info.scheme == to_info.scheme == self.scheme:
|
if not from_info.scheme == to_info.scheme == self.scheme:
|
||||||
@@ -212,20 +237,16 @@ class SSHRemote(BaseRemote):
|
|||||||
with self.ssh(from_info) as ssh:
|
with self.ssh(from_info) as ssh:
|
||||||
ssh.reflink(from_info.path, to_info.path)
|
ssh.reflink(from_info.path, to_info.path)
|
||||||
|
|
||||||
def remove(self, path_info):
|
def get_file_hash(self, path_info):
|
||||||
if path_info.scheme != self.scheme:
|
if path_info.scheme != self.scheme:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
with self.ssh(path_info) as ssh:
|
with self.ssh(path_info) as ssh:
|
||||||
ssh.remove(path_info.path)
|
return ssh.md5(path_info.path)
|
||||||
|
|
||||||
def move(self, from_info, to_info, mode=None):
|
def getsize(self, path_info):
|
||||||
assert mode is None
|
with self.ssh(path_info) as ssh:
|
||||||
if from_info.scheme != self.scheme or to_info.scheme != self.scheme:
|
return ssh.getsize(path_info.path)
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
with self.ssh(from_info) as ssh:
|
|
||||||
ssh.move(from_info.path, to_info.path)
|
|
||||||
|
|
||||||
def _download(self, from_info, to_file, name=None, no_progress_bar=False):
|
def _download(self, from_info, to_file, name=None, no_progress_bar=False):
|
||||||
assert from_info.isin(self.path_info)
|
assert from_info.isin(self.path_info)
|
||||||
@@ -247,24 +268,14 @@ class SSHRemote(BaseRemote):
|
|||||||
no_progress_bar=no_progress_bar,
|
no_progress_bar=no_progress_bar,
|
||||||
)
|
)
|
||||||
|
|
||||||
@contextmanager
|
def list_paths(self, prefix=None, progress_callback=None):
|
||||||
def open(self, path_info, mode="r", encoding=None):
|
|
||||||
assert mode in {"r", "rt", "rb", "wb"}
|
|
||||||
|
|
||||||
with self.ssh(path_info) as ssh, closing(
|
|
||||||
ssh.sftp.open(path_info.path, mode)
|
|
||||||
) as fd:
|
|
||||||
if "b" in mode:
|
|
||||||
yield fd
|
|
||||||
else:
|
|
||||||
yield io.TextIOWrapper(fd, encoding=encoding)
|
|
||||||
|
|
||||||
def list_cache_paths(self, prefix=None, progress_callback=None):
|
|
||||||
if prefix:
|
if prefix:
|
||||||
root = posixpath.join(self.path_info.path, prefix[:2])
|
root = posixpath.join(self.path_info.path, prefix[:2])
|
||||||
else:
|
else:
|
||||||
root = self.path_info.path
|
root = self.path_info.path
|
||||||
with self.ssh(self.path_info) as ssh:
|
with self.ssh(self.path_info) as ssh:
|
||||||
|
if prefix and not ssh.exists(root):
|
||||||
|
return
|
||||||
# If we simply return an iterator then with above closes instantly
|
# If we simply return an iterator then with above closes instantly
|
||||||
if progress_callback:
|
if progress_callback:
|
||||||
for path in ssh.walk_files(root):
|
for path in ssh.walk_files(root):
|
||||||
@@ -273,15 +284,8 @@ class SSHRemote(BaseRemote):
|
|||||||
else:
|
else:
|
||||||
yield from ssh.walk_files(root)
|
yield from ssh.walk_files(root)
|
||||||
|
|
||||||
def walk_files(self, path_info):
|
|
||||||
with self.ssh(path_info) as ssh:
|
|
||||||
for fname in ssh.walk_files(path_info.path):
|
|
||||||
yield path_info.replace(path=fname)
|
|
||||||
|
|
||||||
def makedirs(self, path_info):
|
|
||||||
with self.ssh(path_info) as ssh:
|
|
||||||
ssh.makedirs(path_info.path)
|
|
||||||
|
|
||||||
|
class SSHRemote(Remote):
|
||||||
def batch_exists(self, path_infos, callback):
|
def batch_exists(self, path_infos, callback):
|
||||||
def _exists(chunk_and_channel):
|
def _exists(chunk_and_channel):
|
||||||
chunk, channel = chunk_and_channel
|
chunk, channel = chunk_and_channel
|
||||||
@@ -290,14 +294,14 @@ class SSHRemote(BaseRemote):
|
|||||||
try:
|
try:
|
||||||
channel.stat(path)
|
channel.stat(path)
|
||||||
ret.append(True)
|
ret.append(True)
|
||||||
except IOError as exc:
|
except OSError as exc:
|
||||||
if exc.errno != errno.ENOENT:
|
if exc.errno != errno.ENOENT:
|
||||||
raise
|
raise
|
||||||
ret.append(False)
|
ret.append(False)
|
||||||
callback(path)
|
callback(path)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
with self.ssh(path_infos[0]) as ssh:
|
with self.tree.ssh(path_infos[0]) as ssh:
|
||||||
channels = ssh.open_max_sftp_channels()
|
channels = ssh.open_max_sftp_channels()
|
||||||
max_workers = len(channels)
|
max_workers = len(channels)
|
||||||
|
|
||||||
@@ -310,32 +314,34 @@ class SSHRemote(BaseRemote):
|
|||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def cache_exists(self, checksums, jobs=None, name=None):
|
def hashes_exist(self, hashes, jobs=None, name=None):
|
||||||
"""This is older implementation used in remote/base.py
|
"""This is older implementation used in remote/base.py
|
||||||
We are reusing it in RemoteSSH, because SSH's batch_exists proved to be
|
We are reusing it in RemoteSSH, because SSH's batch_exists proved to be
|
||||||
faster than current approach (relying on exists(path_info)) applied in
|
faster than current approach (relying on exists(path_info)) applied in
|
||||||
remote/base.
|
remote/base.
|
||||||
"""
|
"""
|
||||||
if not self.CAN_TRAVERSE:
|
if not self.tree.CAN_TRAVERSE:
|
||||||
return list(set(checksums) & set(self.all()))
|
return list(set(hashes) & set(self.tree.all()))
|
||||||
|
|
||||||
# possibly prompt for credentials before "Querying" progress output
|
# possibly prompt for credentials before "Querying" progress output
|
||||||
self.ensure_credentials()
|
self.tree.ensure_credentials()
|
||||||
|
|
||||||
with Tqdm(
|
with Tqdm(
|
||||||
desc="Querying "
|
desc="Querying "
|
||||||
+ ("cache in " + name if name else "remote cache"),
|
+ ("cache in " + name if name else "remote cache"),
|
||||||
total=len(checksums),
|
total=len(hashes),
|
||||||
unit="file",
|
unit="file",
|
||||||
) as pbar:
|
) as pbar:
|
||||||
|
|
||||||
def exists_with_progress(chunks):
|
def exists_with_progress(chunks):
|
||||||
return self.batch_exists(chunks, callback=pbar.update_desc)
|
return self.batch_exists(chunks, callback=pbar.update_msg)
|
||||||
|
|
||||||
with ThreadPoolExecutor(max_workers=jobs or self.JOBS) as executor:
|
with ThreadPoolExecutor(
|
||||||
path_infos = [self.checksum_to_path_info(x) for x in checksums]
|
max_workers=jobs or self.tree.JOBS
|
||||||
chunks = to_chunks(path_infos, num_chunks=self.JOBS)
|
) as executor:
|
||||||
|
path_infos = [self.hash_to_path_info(x) for x in hashes]
|
||||||
|
chunks = to_chunks(path_infos, num_chunks=self.tree.JOBS)
|
||||||
results = executor.map(exists_with_progress, chunks)
|
results = executor.map(exists_with_progress, chunks)
|
||||||
in_remote = itertools.chain.from_iterable(results)
|
in_remote = itertools.chain.from_iterable(results)
|
||||||
ret = list(itertools.compress(checksums, in_remote))
|
ret = list(itertools.compress(hashes, in_remote))
|
||||||
return ret
|
return ret
|
||||||
|
|||||||
@@ -7,16 +7,16 @@ from contextlib import suppress
|
|||||||
|
|
||||||
from funcy import cached_property
|
from funcy import cached_property
|
||||||
|
|
||||||
|
from dvc.exceptions import DvcException
|
||||||
|
from dvc.progress import Tqdm
|
||||||
|
from dvc.remote.base import RemoteCmdError
|
||||||
|
from dvc.utils import tmp_fname
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import paramiko
|
import paramiko
|
||||||
except ImportError:
|
except ImportError:
|
||||||
paramiko = None
|
paramiko = None
|
||||||
|
|
||||||
from dvc.utils import tmp_fname
|
|
||||||
from dvc.progress import Tqdm
|
|
||||||
from dvc.exceptions import DvcException
|
|
||||||
from dvc.remote.base import RemoteCmdError
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -25,9 +25,9 @@ def sizeof_fmt(num, suffix="B"):
|
|||||||
""" Convert number of bytes to human-readable string """
|
""" Convert number of bytes to human-readable string """
|
||||||
for unit in ["", "K", "M", "G", "T", "P", "E", "Z"]:
|
for unit in ["", "K", "M", "G", "T", "P", "E", "Z"]:
|
||||||
if abs(num) < 1024.0:
|
if abs(num) < 1024.0:
|
||||||
return "%3.1f%s%s" % (num, unit, suffix)
|
return f"{num:3.1f}{unit}{suffix}"
|
||||||
num /= 1024.0
|
num /= 1024.0
|
||||||
return "%.1f%s%s" % (num, "Y", suffix)
|
return "{:.1f}{}{}".format(num, "Y", suffix)
|
||||||
|
|
||||||
|
|
||||||
class SSHConnection:
|
class SSHConnection:
|
||||||
@@ -100,7 +100,7 @@ class SSHConnection:
|
|||||||
|
|
||||||
if stat.S_ISREG(st_mode) or stat.S_ISLNK(st_mode):
|
if stat.S_ISREG(st_mode) or stat.S_ISLNK(st_mode):
|
||||||
raise DvcException(
|
raise DvcException(
|
||||||
"a file with the same name '{}' already exists".format(path)
|
f"a file with the same name '{path}' already exists"
|
||||||
)
|
)
|
||||||
|
|
||||||
head, tail = posixpath.split(path)
|
head, tail = posixpath.split(path)
|
||||||
@@ -111,12 +111,12 @@ class SSHConnection:
|
|||||||
if tail:
|
if tail:
|
||||||
try:
|
try:
|
||||||
self.sftp.mkdir(path)
|
self.sftp.mkdir(path)
|
||||||
except IOError as exc:
|
except OSError as exc:
|
||||||
# Since paramiko errors are very vague we need to recheck
|
# Since paramiko errors are very vague we need to recheck
|
||||||
# whether it's because path already exists or something else
|
# whether it's because path already exists or something else
|
||||||
if exc.errno == errno.EACCES or not self.exists(path):
|
if exc.errno == errno.EACCES or not self.exists(path):
|
||||||
raise DvcException(
|
raise DvcException(
|
||||||
"unable to create remote directory '{}'".format(path)
|
f"unable to create remote directory '{path}'"
|
||||||
) from exc
|
) from exc
|
||||||
|
|
||||||
def walk(self, directory, topdown=True):
|
def walk(self, directory, topdown=True):
|
||||||
@@ -126,7 +126,7 @@ class SSHConnection:
|
|||||||
# [1] https://github.com/python/cpython/blob/master/Lib/os.py
|
# [1] https://github.com/python/cpython/blob/master/Lib/os.py
|
||||||
try:
|
try:
|
||||||
dir_entries = self.sftp.listdir_attr(directory)
|
dir_entries = self.sftp.listdir_attr(directory)
|
||||||
except IOError as exc:
|
except OSError as exc:
|
||||||
raise DvcException(
|
raise DvcException(
|
||||||
"couldn't get the '{}' remote directory files list".format(
|
"couldn't get the '{}' remote directory files list".format(
|
||||||
directory
|
directory
|
||||||
@@ -237,11 +237,15 @@ class SSHConnection:
|
|||||||
or channel.recv_ready()
|
or channel.recv_ready()
|
||||||
or channel.recv_stderr_ready()
|
or channel.recv_stderr_ready()
|
||||||
):
|
):
|
||||||
import select
|
import selectors
|
||||||
|
|
||||||
|
selector = selectors.DefaultSelector()
|
||||||
|
selector.register(stdout.channel, selectors.EVENT_READ)
|
||||||
|
|
||||||
got_chunk = False
|
got_chunk = False
|
||||||
readq, _, _ = select.select([stdout.channel], [], [], self.timeout)
|
events = selector.select(self.timeout)
|
||||||
for c in readq:
|
for key, _ in events:
|
||||||
|
c = key.fileobj
|
||||||
if c.recv_ready():
|
if c.recv_ready():
|
||||||
stdout_chunks.append(stdout.channel.recv(len(c.in_buffer)))
|
stdout_chunks.append(stdout.channel.recv(len(c.in_buffer)))
|
||||||
got_chunk = True
|
got_chunk = True
|
||||||
@@ -292,14 +296,14 @@ class SSHConnection:
|
|||||||
md5 = self.execute("md5 " + path).split()[-1]
|
md5 = self.execute("md5 " + path).split()[-1]
|
||||||
else:
|
else:
|
||||||
raise DvcException(
|
raise DvcException(
|
||||||
"'{}' is not supported as a SSH remote".format(self.uname)
|
f"'{self.uname}' is not supported as a SSH remote"
|
||||||
)
|
)
|
||||||
|
|
||||||
assert len(md5) == 32
|
assert len(md5) == 32
|
||||||
return md5
|
return md5
|
||||||
|
|
||||||
def copy(self, src, dest):
|
def copy(self, src, dest):
|
||||||
self.execute("cp {} {}".format(src, dest))
|
self.execute(f"cp {src} {dest}")
|
||||||
|
|
||||||
def open_max_sftp_channels(self):
|
def open_max_sftp_channels(self):
|
||||||
# If there are more than 1 it means we've already opened max amount
|
# If there are more than 1 it means we've already opened max amount
|
||||||
@@ -321,14 +325,12 @@ class SSHConnection:
|
|||||||
|
|
||||||
def reflink(self, src, dest):
|
def reflink(self, src, dest):
|
||||||
if self.uname == "Linux":
|
if self.uname == "Linux":
|
||||||
return self.execute("cp --reflink {} {}".format(src, dest))
|
return self.execute(f"cp --reflink {src} {dest}")
|
||||||
|
|
||||||
if self.uname == "Darwin":
|
if self.uname == "Darwin":
|
||||||
return self.execute("cp -c {} {}".format(src, dest))
|
return self.execute(f"cp -c {src} {dest}")
|
||||||
|
|
||||||
raise DvcException(
|
raise DvcException(f"'{self.uname}' is not supported as a SSH remote")
|
||||||
"'{}' is not supported as a SSH remote".format(self.uname)
|
|
||||||
)
|
|
||||||
|
|
||||||
def hardlink(self, src, dest):
|
def hardlink(self, src, dest):
|
||||||
self.execute("ln {} {}".format(src, dest))
|
self.execute(f"ln {src} {dest}")
|
||||||
|
|||||||
+178
-112
@@ -3,23 +3,28 @@ import os
|
|||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
from dvc.ignore import CleanTree
|
|
||||||
from dvc.compat import fspath_py35
|
|
||||||
|
|
||||||
from funcy import cached_property, cat, first
|
from funcy import cached_property, cat, first
|
||||||
|
|
||||||
from dvc.config import Config
|
from dvc.config import Config
|
||||||
|
from dvc.dvcfile import PIPELINE_FILE, Dvcfile, is_valid_filename
|
||||||
|
from dvc.exceptions import FileMissingError
|
||||||
|
from dvc.exceptions import IsADirectoryError as DvcIsADirectoryError
|
||||||
from dvc.exceptions import (
|
from dvc.exceptions import (
|
||||||
FileMissingError,
|
NoOutputOrStageError,
|
||||||
IsADirectoryError,
|
|
||||||
NotDvcRepoError,
|
NotDvcRepoError,
|
||||||
OutputNotFoundError,
|
OutputNotFoundError,
|
||||||
)
|
)
|
||||||
|
from dvc.ignore import CleanTree
|
||||||
from dvc.path_info import PathInfo
|
from dvc.path_info import PathInfo
|
||||||
from dvc.remote.base import RemoteActionNotImplemented
|
from dvc.repo.tree import RepoTree
|
||||||
|
from dvc.scm.tree import is_working_tree
|
||||||
from dvc.utils.fs import path_isin
|
from dvc.utils.fs import path_isin
|
||||||
from .graph import check_acyclic, get_pipeline, get_pipelines
|
|
||||||
|
from ..stage.exceptions import StageFileDoesNotExistError, StageNotFound
|
||||||
from ..utils import parse_target
|
from ..utils import parse_target
|
||||||
|
from .graph import check_acyclic, get_pipeline, get_pipelines
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def locked(f):
|
def locked(f):
|
||||||
@@ -35,7 +40,7 @@ def locked(f):
|
|||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
class Repo(object):
|
class Repo:
|
||||||
DVC_DIR = ".dvc"
|
DVC_DIR = ".dvc"
|
||||||
|
|
||||||
from dvc.repo.destroy import destroy
|
from dvc.repo.destroy import destroy
|
||||||
@@ -43,7 +48,7 @@ class Repo(object):
|
|||||||
from dvc.repo.add import add
|
from dvc.repo.add import add
|
||||||
from dvc.repo.remove import remove
|
from dvc.repo.remove import remove
|
||||||
from dvc.repo.ls import ls
|
from dvc.repo.ls import ls
|
||||||
from dvc.repo.lock import lock as lock_stage
|
from dvc.repo.freeze import freeze, unfreeze
|
||||||
from dvc.repo.move import move
|
from dvc.repo.move import move
|
||||||
from dvc.repo.run import run
|
from dvc.repo.run import run
|
||||||
from dvc.repo.imp import imp
|
from dvc.repo.imp import imp
|
||||||
@@ -62,28 +67,37 @@ class Repo(object):
|
|||||||
from dvc.repo.get_url import get_url
|
from dvc.repo.get_url import get_url
|
||||||
from dvc.repo.update import update
|
from dvc.repo.update import update
|
||||||
|
|
||||||
def __init__(self, root_dir=None):
|
def __init__(self, root_dir=None, scm=None, rev=None):
|
||||||
from dvc.state import State
|
from dvc.state import State, StateNoop
|
||||||
from dvc.lock import make_lock
|
from dvc.lock import make_lock
|
||||||
from dvc.scm import SCM
|
from dvc.scm import SCM
|
||||||
from dvc.cache import Cache
|
from dvc.cache import Cache
|
||||||
from dvc.data_cloud import DataCloud
|
from dvc.data_cloud import DataCloud
|
||||||
from dvc.repo.metrics import Metrics
|
from dvc.repo.metrics import Metrics
|
||||||
|
from dvc.repo.plots import Plots
|
||||||
from dvc.repo.params import Params
|
from dvc.repo.params import Params
|
||||||
from dvc.scm.tree import WorkingTree
|
from dvc.scm.tree import WorkingTree
|
||||||
from dvc.utils.fs import makedirs
|
from dvc.utils.fs import makedirs
|
||||||
|
from dvc.stage.cache import StageCache
|
||||||
|
|
||||||
root_dir = self.find_root(root_dir)
|
if scm:
|
||||||
|
# use GitTree instead of WorkingTree as default repo tree instance
|
||||||
|
tree = scm.get_tree(rev)
|
||||||
|
self.root_dir = self.find_root(root_dir, tree)
|
||||||
|
self.scm = scm
|
||||||
|
self.tree = tree
|
||||||
|
self.state = StateNoop()
|
||||||
|
else:
|
||||||
|
root_dir = self.find_root(root_dir)
|
||||||
|
self.root_dir = os.path.abspath(os.path.realpath(root_dir))
|
||||||
|
|
||||||
self.root_dir = os.path.abspath(os.path.realpath(root_dir))
|
|
||||||
self.dvc_dir = os.path.join(self.root_dir, self.DVC_DIR)
|
self.dvc_dir = os.path.join(self.root_dir, self.DVC_DIR)
|
||||||
|
|
||||||
self.config = Config(self.dvc_dir)
|
self.config = Config(self.dvc_dir)
|
||||||
|
|
||||||
no_scm = self.config["core"].get("no_scm", False)
|
if not scm:
|
||||||
self.scm = SCM(self.root_dir, no_scm=no_scm)
|
no_scm = self.config["core"].get("no_scm", False)
|
||||||
|
self.scm = SCM(self.root_dir, no_scm=no_scm)
|
||||||
self.tree = WorkingTree(self.root_dir)
|
self.tree = WorkingTree(self.root_dir)
|
||||||
|
|
||||||
self.tmp_dir = os.path.join(self.dvc_dir, "tmp")
|
self.tmp_dir = os.path.join(self.dvc_dir, "tmp")
|
||||||
self.index_dir = os.path.join(self.tmp_dir, "index")
|
self.index_dir = os.path.join(self.tmp_dir, "index")
|
||||||
@@ -91,20 +105,25 @@ class Repo(object):
|
|||||||
|
|
||||||
hardlink_lock = self.config["core"].get("hardlink_lock", False)
|
hardlink_lock = self.config["core"].get("hardlink_lock", False)
|
||||||
self.lock = make_lock(
|
self.lock = make_lock(
|
||||||
os.path.join(self.dvc_dir, "lock"),
|
os.path.join(self.tmp_dir, "lock"),
|
||||||
tmp_dir=os.path.join(self.dvc_dir, "tmp"),
|
tmp_dir=self.tmp_dir,
|
||||||
hardlink_lock=hardlink_lock,
|
hardlink_lock=hardlink_lock,
|
||||||
friendly=True,
|
friendly=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# NOTE: storing state and link_state in the repository itself to avoid
|
|
||||||
# any possible state corruption in 'shared cache dir' scenario.
|
|
||||||
self.state = State(self)
|
|
||||||
|
|
||||||
self.cache = Cache(self)
|
self.cache = Cache(self)
|
||||||
self.cloud = DataCloud(self)
|
self.cloud = DataCloud(self)
|
||||||
|
|
||||||
|
if not scm:
|
||||||
|
# NOTE: storing state and link_state in the repository itself to
|
||||||
|
# avoid any possible state corruption in 'shared cache dir'
|
||||||
|
# scenario.
|
||||||
|
self.state = State(self.cache.local)
|
||||||
|
|
||||||
|
self.stage_cache = StageCache(self)
|
||||||
|
|
||||||
self.metrics = Metrics(self)
|
self.metrics = Metrics(self)
|
||||||
|
self.plots = Plots(self)
|
||||||
self.params = Params(self)
|
self.params = Params(self)
|
||||||
|
|
||||||
self._ignore()
|
self._ignore()
|
||||||
@@ -115,20 +134,31 @@ class Repo(object):
|
|||||||
|
|
||||||
@tree.setter
|
@tree.setter
|
||||||
def tree(self, tree):
|
def tree(self, tree):
|
||||||
self._tree = tree if isinstance(tree, CleanTree) else CleanTree(tree)
|
if is_working_tree(tree) or tree.tree_root == self.root_dir:
|
||||||
|
root = None
|
||||||
|
else:
|
||||||
|
root = self.root_dir
|
||||||
|
self._tree = (
|
||||||
|
tree if isinstance(tree, CleanTree) else CleanTree(tree, root)
|
||||||
|
)
|
||||||
# Our graph cache is no longer valid, as it was based on the previous
|
# Our graph cache is no longer valid, as it was based on the previous
|
||||||
# tree.
|
# tree.
|
||||||
self._reset()
|
self._reset()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "{}: '{}'".format(self.__class__.__name__, self.root_dir)
|
return f"{self.__class__.__name__}: '{self.root_dir}'"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def find_root(cls, root=None):
|
def find_root(cls, root=None, tree=None):
|
||||||
root_dir = os.path.realpath(root or os.curdir)
|
root_dir = os.path.realpath(root or os.curdir)
|
||||||
|
|
||||||
|
if tree:
|
||||||
|
if tree.isdir(os.path.join(root_dir, cls.DVC_DIR)):
|
||||||
|
return root_dir
|
||||||
|
raise NotDvcRepoError(f"'{root}' does not contain DVC directory")
|
||||||
|
|
||||||
if not os.path.isdir(root_dir):
|
if not os.path.isdir(root_dir):
|
||||||
raise NotDvcRepoError("directory '{}' does not exist".format(root))
|
raise NotDvcRepoError(f"directory '{root}' does not exist")
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
dvc_dir = os.path.join(root_dir, cls.DVC_DIR)
|
dvc_dir = os.path.join(root_dir, cls.DVC_DIR)
|
||||||
@@ -157,24 +187,35 @@ class Repo(object):
|
|||||||
return Repo(root_dir)
|
return Repo(root_dir)
|
||||||
|
|
||||||
def unprotect(self, target):
|
def unprotect(self, target):
|
||||||
return self.cache.local.unprotect(PathInfo(target))
|
return self.cache.local.tree.unprotect(PathInfo(target))
|
||||||
|
|
||||||
def _ignore(self):
|
def _ignore(self):
|
||||||
from dvc.updater import Updater
|
flist = [self.config.files["local"], self.tmp_dir]
|
||||||
|
|
||||||
updater = Updater(self.dvc_dir)
|
|
||||||
|
|
||||||
flist = (
|
|
||||||
[self.config.files["local"], updater.updater_file]
|
|
||||||
+ [self.lock.lockfile, updater.lock.lockfile, self.tmp_dir]
|
|
||||||
+ self.state.files
|
|
||||||
)
|
|
||||||
|
|
||||||
if path_isin(self.cache.local.cache_dir, self.root_dir):
|
if path_isin(self.cache.local.cache_dir, self.root_dir):
|
||||||
flist += [self.cache.local.cache_dir]
|
flist += [self.cache.local.cache_dir]
|
||||||
|
|
||||||
self.scm.ignore_list(flist)
|
self.scm.ignore_list(flist)
|
||||||
|
|
||||||
|
def get_stage(self, path=None, name=None):
|
||||||
|
if not path:
|
||||||
|
path = PIPELINE_FILE
|
||||||
|
logger.debug("Assuming '%s' to be a stage inside '%s'", name, path)
|
||||||
|
|
||||||
|
dvcfile = Dvcfile(self, path)
|
||||||
|
return dvcfile.stages[name]
|
||||||
|
|
||||||
|
def get_stages(self, path=None, name=None):
|
||||||
|
if not path:
|
||||||
|
path = PIPELINE_FILE
|
||||||
|
logger.debug("Assuming '%s' to be a stage inside '%s'", name, path)
|
||||||
|
|
||||||
|
if name:
|
||||||
|
return [self.get_stage(path, name)]
|
||||||
|
|
||||||
|
dvcfile = Dvcfile(self, path)
|
||||||
|
return list(dvcfile.stages.values())
|
||||||
|
|
||||||
def check_modified_graph(self, new_stages):
|
def check_modified_graph(self, new_stages):
|
||||||
"""Generate graph including the new stage to check for errors"""
|
"""Generate graph including the new stage to check for errors"""
|
||||||
# Building graph might be costly for the ones with many DVC-files,
|
# Building graph might be costly for the ones with many DVC-files,
|
||||||
@@ -198,10 +239,9 @@ class Repo(object):
|
|||||||
stages = nx.dfs_postorder_nodes(graph)
|
stages = nx.dfs_postorder_nodes(graph)
|
||||||
return [stage for stage in stages if path_isin(stage.path, path)]
|
return [stage for stage in stages if path_isin(stage.path, path)]
|
||||||
|
|
||||||
def collect(self, target, with_deps=False, recursive=False, graph=None):
|
def collect(
|
||||||
import networkx as nx
|
self, target=None, with_deps=False, recursive=False, graph=None
|
||||||
from ..dvcfile import Dvcfile
|
):
|
||||||
|
|
||||||
if not target:
|
if not target:
|
||||||
return list(graph) if graph else self.stages
|
return list(graph) if graph else self.stages
|
||||||
|
|
||||||
@@ -211,36 +251,81 @@ class Repo(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
path, name = parse_target(target)
|
path, name = parse_target(target)
|
||||||
dvcfile = Dvcfile(self, path)
|
stages = self.get_stages(path, name)
|
||||||
stages = list(dvcfile.stages.filter(name).values())
|
|
||||||
if not with_deps:
|
if not with_deps:
|
||||||
return stages
|
return stages
|
||||||
|
|
||||||
res = set()
|
res = set()
|
||||||
for stage in stages:
|
for stage in stages:
|
||||||
pipeline = get_pipeline(get_pipelines(graph or self.graph), stage)
|
res.update(self._collect_pipeline(stage, graph=graph))
|
||||||
res.update(nx.dfs_postorder_nodes(pipeline, stage))
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def collect_granular(self, target, *args, **kwargs):
|
def _collect_pipeline(self, stage, graph=None):
|
||||||
from ..dvcfile import Dvcfile, is_valid_filename
|
import networkx as nx
|
||||||
|
|
||||||
|
pipeline = get_pipeline(get_pipelines(graph or self.graph), stage)
|
||||||
|
return nx.dfs_postorder_nodes(pipeline, stage)
|
||||||
|
|
||||||
|
def _collect_from_default_dvcfile(self, target):
|
||||||
|
dvcfile = Dvcfile(self, PIPELINE_FILE)
|
||||||
|
if dvcfile.exists():
|
||||||
|
return dvcfile.stages.get(target)
|
||||||
|
|
||||||
|
def collect_granular(
|
||||||
|
self, target=None, with_deps=False, recursive=False, graph=None
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Priority is in the order of following in case of ambiguity:
|
||||||
|
- .dvc file or .yaml file
|
||||||
|
- dir if recursive and directory exists
|
||||||
|
- stage_name
|
||||||
|
- output file
|
||||||
|
"""
|
||||||
if not target:
|
if not target:
|
||||||
return [(stage, None) for stage in self.stages]
|
return [(stage, None) for stage in self.stages]
|
||||||
|
|
||||||
file, name = parse_target(target)
|
file, name = parse_target(target)
|
||||||
if is_valid_filename(file) and not kwargs.get("with_deps"):
|
stages = []
|
||||||
# Optimization: do not collect the graph for a specific .dvc target
|
|
||||||
stages = Dvcfile(self, file).stages.filter(name)
|
|
||||||
return [(stage, None) for stage in stages.values()]
|
|
||||||
|
|
||||||
try:
|
# Optimization: do not collect the graph for a specific target
|
||||||
(out,) = self.find_outs_by_path(file, strict=False)
|
if not file:
|
||||||
filter_info = PathInfo(os.path.abspath(file))
|
# parsing is ambiguous when it does not have a colon
|
||||||
return [(out.stage, filter_info)]
|
# or if it's not a dvcfile, as it can be a stage name
|
||||||
except OutputNotFoundError:
|
# in `dvc.yaml` or, an output in a stage.
|
||||||
stages = self.collect(target, *args, **kwargs)
|
logger.debug(
|
||||||
return [(stage, None) for stage in stages]
|
"Checking if stage '%s' is in '%s'", target, PIPELINE_FILE
|
||||||
|
)
|
||||||
|
if not (recursive and os.path.isdir(target)):
|
||||||
|
stage = self._collect_from_default_dvcfile(target)
|
||||||
|
if stage:
|
||||||
|
stages = (
|
||||||
|
self._collect_pipeline(stage) if with_deps else [stage]
|
||||||
|
)
|
||||||
|
elif not with_deps and is_valid_filename(file):
|
||||||
|
stages = self.get_stages(file, name)
|
||||||
|
|
||||||
|
if not stages:
|
||||||
|
if not (recursive and os.path.isdir(target)):
|
||||||
|
try:
|
||||||
|
(out,) = self.find_outs_by_path(target, strict=False)
|
||||||
|
filter_info = PathInfo(os.path.abspath(target))
|
||||||
|
return [(out.stage, filter_info)]
|
||||||
|
except OutputNotFoundError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
stages = self.collect(target, with_deps, recursive, graph)
|
||||||
|
except StageFileDoesNotExistError as exc:
|
||||||
|
# collect() might try to use `target` as a stage name
|
||||||
|
# and throw error that dvc.yaml does not exist, whereas it
|
||||||
|
# should say that both stage name and file does not exist.
|
||||||
|
if file and is_valid_filename(file):
|
||||||
|
raise
|
||||||
|
raise NoOutputOrStageError(target, exc.file) from exc
|
||||||
|
except StageNotFound as exc:
|
||||||
|
raise NoOutputOrStageError(target, exc.file) from exc
|
||||||
|
|
||||||
|
return [(stage, None) for stage in stages]
|
||||||
|
|
||||||
def used_cache(
|
def used_cache(
|
||||||
self,
|
self,
|
||||||
@@ -253,6 +338,7 @@ class Repo(object):
|
|||||||
force=False,
|
force=False,
|
||||||
jobs=None,
|
jobs=None,
|
||||||
recursive=False,
|
recursive=False,
|
||||||
|
used_run_cache=None,
|
||||||
):
|
):
|
||||||
"""Get the stages related to the given target and collect
|
"""Get the stages related to the given target and collect
|
||||||
the `info` of its outputs.
|
the `info` of its outputs.
|
||||||
@@ -286,7 +372,7 @@ class Repo(object):
|
|||||||
for target in targets
|
for target in targets
|
||||||
)
|
)
|
||||||
|
|
||||||
suffix = "({})".format(branch) if branch else ""
|
suffix = f"({branch})" if branch else ""
|
||||||
for stage, filter_info in pairs:
|
for stage, filter_info in pairs:
|
||||||
used_cache = stage.get_used_cache(
|
used_cache = stage.get_used_cache(
|
||||||
remote=remote,
|
remote=remote,
|
||||||
@@ -296,6 +382,12 @@ class Repo(object):
|
|||||||
)
|
)
|
||||||
cache.update(used_cache, suffix=suffix)
|
cache.update(used_cache, suffix=suffix)
|
||||||
|
|
||||||
|
if used_run_cache:
|
||||||
|
used_cache = self.stage_cache.get_used_cache(
|
||||||
|
used_run_cache, remote=remote, force=force, jobs=jobs,
|
||||||
|
)
|
||||||
|
cache.update(used_cache)
|
||||||
|
|
||||||
return cache
|
return cache
|
||||||
|
|
||||||
def _collect_graph(self, stages):
|
def _collect_graph(self, stages):
|
||||||
@@ -349,7 +441,7 @@ class Repo(object):
|
|||||||
stages = stages or self.stages
|
stages = stages or self.stages
|
||||||
outs = Trie() # Use trie to efficiently find overlapping outs and deps
|
outs = Trie() # Use trie to efficiently find overlapping outs and deps
|
||||||
|
|
||||||
for stage in filter(bool, stages):
|
for stage in filter(bool, stages): # bug? not using it later
|
||||||
for out in stage.outs:
|
for out in stage.outs:
|
||||||
out_key = out.path_info.parts
|
out_key = out.path_info.parts
|
||||||
|
|
||||||
@@ -423,24 +515,25 @@ class Repo(object):
|
|||||||
"""
|
"""
|
||||||
return self._collect_stages()
|
return self._collect_stages()
|
||||||
|
|
||||||
def _collect_stages(self):
|
@cached_property
|
||||||
from dvc.dvcfile import Dvcfile, is_valid_filename
|
def plot_templates(self):
|
||||||
|
from .plots.template import PlotTemplates
|
||||||
|
|
||||||
|
return PlotTemplates(self.dvc_dir)
|
||||||
|
|
||||||
|
def _collect_stages(self):
|
||||||
stages = []
|
stages = []
|
||||||
outs = set()
|
outs = set()
|
||||||
|
|
||||||
for root, dirs, files in self.tree.walk(self.root_dir):
|
for root, dirs, files in self.tree.walk(self.root_dir):
|
||||||
for file_name in filter(is_valid_filename, files):
|
for file_name in filter(is_valid_filename, files):
|
||||||
path = os.path.join(root, file_name)
|
new_stages = self.get_stages(os.path.join(root, file_name))
|
||||||
stage_loader = Dvcfile(self, path).stages
|
stages.extend(new_stages)
|
||||||
with stage_loader.log_level(at=logging.DEBUG):
|
|
||||||
stages.extend(stage_loader.values())
|
|
||||||
outs.update(
|
outs.update(
|
||||||
out.fspath
|
out.fspath
|
||||||
for stage in stages
|
for stage in new_stages
|
||||||
for out in (
|
for out in stage.outs
|
||||||
out for out in stage.outs if out.scheme == "local"
|
if out.scheme == "local"
|
||||||
)
|
|
||||||
)
|
)
|
||||||
dirs[:] = [d for d in dirs if os.path.join(root, d) not in outs]
|
dirs[:] = [d for d in dirs if os.path.join(root, d) not in outs]
|
||||||
return stages
|
return stages
|
||||||
@@ -480,49 +573,22 @@ class Repo(object):
|
|||||||
@contextmanager
|
@contextmanager
|
||||||
def open_by_relpath(self, path, remote=None, mode="r", encoding=None):
|
def open_by_relpath(self, path, remote=None, mode="r", encoding=None):
|
||||||
"""Opens a specified resource as a file descriptor"""
|
"""Opens a specified resource as a file descriptor"""
|
||||||
cause = None
|
|
||||||
|
tree = RepoTree(self, stream=True)
|
||||||
|
path = os.path.join(self.root_dir, path)
|
||||||
try:
|
try:
|
||||||
out = self.find_out_by_relpath(path)
|
|
||||||
except OutputNotFoundError as exc:
|
|
||||||
out = None
|
|
||||||
cause = exc
|
|
||||||
|
|
||||||
if out and out.use_cache:
|
|
||||||
try:
|
|
||||||
with self._open_cached(out, remote, mode, encoding) as fd:
|
|
||||||
yield fd
|
|
||||||
return
|
|
||||||
except FileNotFoundError as exc:
|
|
||||||
raise FileMissingError(path) from exc
|
|
||||||
|
|
||||||
abs_path = os.path.join(self.root_dir, path)
|
|
||||||
if os.path.exists(abs_path):
|
|
||||||
with open(abs_path, mode=mode, encoding=encoding) as fd:
|
|
||||||
yield fd
|
|
||||||
return
|
|
||||||
|
|
||||||
raise FileMissingError(path) from cause
|
|
||||||
|
|
||||||
def _open_cached(self, out, remote=None, mode="r", encoding=None):
|
|
||||||
if out.isdir():
|
|
||||||
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)
|
|
||||||
|
|
||||||
try:
|
|
||||||
remote_obj = self.cloud.get_remote(remote)
|
|
||||||
remote_info = remote_obj.checksum_to_path_info(out.checksum)
|
|
||||||
return remote_obj.open(remote_info, mode=mode, encoding=encoding)
|
|
||||||
except RemoteActionNotImplemented:
|
|
||||||
with self.state:
|
with self.state:
|
||||||
cache_info = out.get_used_cache(remote=remote)
|
with tree.open(
|
||||||
self.cloud.pull(cache_info, remote=remote)
|
os.path.join(self.root_dir, path),
|
||||||
|
mode=mode,
|
||||||
return open(cache_file, mode=mode, encoding=encoding)
|
encoding=encoding,
|
||||||
|
remote=remote,
|
||||||
|
) as fobj:
|
||||||
|
yield fobj
|
||||||
|
except FileNotFoundError as exc:
|
||||||
|
raise FileMissingError(path) from exc
|
||||||
|
except IsADirectoryError as exc:
|
||||||
|
raise DvcIsADirectoryError(f"'{path}' is a directory") from exc
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.scm.close()
|
self.scm.close()
|
||||||
|
|||||||
+21
-9
@@ -3,24 +3,27 @@ import os
|
|||||||
|
|
||||||
import colorama
|
import colorama
|
||||||
|
|
||||||
from . import locked
|
|
||||||
from dvc.dvcfile import Dvcfile, is_dvc_file
|
from dvc.dvcfile import Dvcfile, is_dvc_file
|
||||||
|
|
||||||
from ..exceptions import (
|
from ..exceptions import (
|
||||||
RecursiveAddingWhileUsingFilename,
|
|
||||||
OverlappingOutputPathsError,
|
|
||||||
OutputDuplicationError,
|
OutputDuplicationError,
|
||||||
|
OverlappingOutputPathsError,
|
||||||
|
RecursiveAddingWhileUsingFilename,
|
||||||
)
|
)
|
||||||
from ..output.base import OutputDoesNotExistError
|
from ..output.base import OutputDoesNotExistError
|
||||||
from ..progress import Tqdm
|
from ..progress import Tqdm
|
||||||
from ..repo.scm_context import scm_context
|
from ..repo.scm_context import scm_context
|
||||||
from ..utils import LARGE_DIR_SIZE, resolve_paths
|
from ..utils import LARGE_DIR_SIZE, resolve_paths
|
||||||
|
from . import locked
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@locked
|
@locked
|
||||||
@scm_context
|
@scm_context
|
||||||
def add(repo, targets, recursive=False, no_commit=False, fname=None):
|
def add(
|
||||||
|
repo, targets, recursive=False, no_commit=False, fname=None, external=False
|
||||||
|
):
|
||||||
if recursive and fname:
|
if recursive and fname:
|
||||||
raise RecursiveAddingWhileUsingFilename()
|
raise RecursiveAddingWhileUsingFilename()
|
||||||
|
|
||||||
@@ -51,7 +54,9 @@ def add(repo, targets, recursive=False, no_commit=False, fname=None):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
stages = _create_stages(repo, sub_targets, fname, pbar=pbar)
|
stages = _create_stages(
|
||||||
|
repo, sub_targets, fname, pbar=pbar, external=external
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
repo.check_modified_graph(stages)
|
repo.check_modified_graph(stages)
|
||||||
@@ -119,7 +124,7 @@ def _find_all_targets(repo, target, recursive):
|
|||||||
return [target]
|
return [target]
|
||||||
|
|
||||||
|
|
||||||
def _create_stages(repo, targets, fname, pbar=None):
|
def _create_stages(repo, targets, fname, pbar=None, external=False):
|
||||||
from dvc.stage import Stage, create_stage
|
from dvc.stage import Stage, create_stage
|
||||||
|
|
||||||
stages = []
|
stages = []
|
||||||
@@ -131,9 +136,16 @@ def _create_stages(repo, targets, fname, pbar=None):
|
|||||||
unit="file",
|
unit="file",
|
||||||
):
|
):
|
||||||
path, wdir, out = resolve_paths(repo, out)
|
path, wdir, out = resolve_paths(repo, out)
|
||||||
stage = create_stage(Stage, repo, fname or path, wdir=wdir, outs=[out])
|
stage = create_stage(
|
||||||
|
Stage,
|
||||||
|
repo,
|
||||||
|
fname or path,
|
||||||
|
wdir=wdir,
|
||||||
|
outs=[out],
|
||||||
|
external=external,
|
||||||
|
)
|
||||||
if stage:
|
if stage:
|
||||||
Dvcfile(repo, stage.path).remove_with_prompt(force=True)
|
Dvcfile(repo, stage.path).remove()
|
||||||
|
|
||||||
repo._reset()
|
repo._reset()
|
||||||
|
|
||||||
@@ -144,6 +156,6 @@ def _create_stages(repo, targets, fname, pbar=None):
|
|||||||
|
|
||||||
stages.append(stage)
|
stages.append(stage)
|
||||||
if pbar is not None:
|
if pbar is not None:
|
||||||
pbar.update_desc(out)
|
pbar.update_msg(out)
|
||||||
|
|
||||||
return stages
|
return stages
|
||||||
|
|||||||
+10
-4
@@ -18,19 +18,22 @@ def brancher( # noqa: E302
|
|||||||
str: the display name for the currently selected tree, it could be:
|
str: the display name for the currently selected tree, it could be:
|
||||||
- a git revision identifier
|
- a git revision identifier
|
||||||
- empty string it there is no branches to iterate over
|
- empty string it there is no branches to iterate over
|
||||||
- "Working Tree" if there are uncommitted changes in the SCM repo
|
- "workspace" if there are uncommitted changes in the SCM repo
|
||||||
"""
|
"""
|
||||||
if not any([revs, all_branches, all_tags, all_commits]):
|
if not any([revs, all_branches, all_tags, all_commits]):
|
||||||
yield ""
|
yield ""
|
||||||
return
|
return
|
||||||
|
|
||||||
saved_tree = self.tree
|
saved_tree = self.tree
|
||||||
revs = revs or []
|
revs = revs.copy() if revs else []
|
||||||
|
|
||||||
scm = self.scm
|
scm = self.scm
|
||||||
|
|
||||||
self.tree = WorkingTree(self.root_dir)
|
self.tree = WorkingTree(self.root_dir)
|
||||||
yield "working tree"
|
yield "workspace"
|
||||||
|
|
||||||
|
if revs and "workspace" in revs:
|
||||||
|
revs.remove("workspace")
|
||||||
|
|
||||||
if all_commits:
|
if all_commits:
|
||||||
revs = scm.list_all_commits()
|
revs = scm.list_all_commits()
|
||||||
@@ -45,6 +48,9 @@ def brancher( # noqa: E302
|
|||||||
if revs:
|
if revs:
|
||||||
for sha, names in group_by(scm.resolve_rev, revs).items():
|
for sha, names in group_by(scm.resolve_rev, revs).items():
|
||||||
self.tree = scm.get_tree(sha)
|
self.tree = scm.get_tree(sha)
|
||||||
yield ", ".join(names)
|
# ignore revs that don't contain repo root
|
||||||
|
# (i.e. revs from before a subdir=True repo was init'ed)
|
||||||
|
if self.tree.exists(self.root_dir):
|
||||||
|
yield ", ".join(names)
|
||||||
finally:
|
finally:
|
||||||
self.tree = saved_tree
|
self.tree = saved_tree
|
||||||
|
|||||||
+19
-11
@@ -1,8 +1,11 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from dvc.compat import fspath
|
from dvc.exceptions import (
|
||||||
from dvc.exceptions import CheckoutError, CheckoutErrorSuggestGit
|
CheckoutError,
|
||||||
|
CheckoutErrorSuggestGit,
|
||||||
|
NoOutputOrStageError,
|
||||||
|
)
|
||||||
from dvc.progress import Tqdm
|
from dvc.progress import Tqdm
|
||||||
from dvc.utils import relpath
|
from dvc.utils import relpath
|
||||||
|
|
||||||
@@ -19,11 +22,11 @@ def _get_unused_links(repo):
|
|||||||
return repo.state.get_unused_links(used)
|
return repo.state.get_unused_links(used)
|
||||||
|
|
||||||
|
|
||||||
def _fspath_dir(path, root):
|
def _fspath_dir(path):
|
||||||
if not os.path.exists(str(path)):
|
if not os.path.exists(str(path)):
|
||||||
return str(path)
|
return str(path)
|
||||||
|
|
||||||
path = relpath(fspath(path), root)
|
path = relpath(path)
|
||||||
return os.path.join(path, "") if os.path.isdir(path) else path
|
return os.path.join(path, "") if os.path.isdir(path) else path
|
||||||
|
|
||||||
|
|
||||||
@@ -57,9 +60,12 @@ def _checkout(
|
|||||||
targets = [None]
|
targets = [None]
|
||||||
unused = _get_unused_links(self)
|
unused = _get_unused_links(self)
|
||||||
|
|
||||||
stats["deleted"] = [_fspath_dir(u, self.root_dir) for u in unused]
|
stats["deleted"] = [_fspath_dir(u) for u in unused]
|
||||||
self.state.remove_links(unused)
|
self.state.remove_links(unused)
|
||||||
|
|
||||||
|
if isinstance(targets, str):
|
||||||
|
targets = [targets]
|
||||||
|
|
||||||
pairs = set()
|
pairs = set()
|
||||||
for target in targets:
|
for target in targets:
|
||||||
try:
|
try:
|
||||||
@@ -68,7 +74,11 @@ def _checkout(
|
|||||||
target, with_deps=with_deps, recursive=recursive
|
target, with_deps=with_deps, recursive=recursive
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
except (StageFileDoesNotExistError, StageFileBadNameError) as exc:
|
except (
|
||||||
|
StageFileDoesNotExistError,
|
||||||
|
StageFileBadNameError,
|
||||||
|
NoOutputOrStageError,
|
||||||
|
) as exc:
|
||||||
if not target:
|
if not target:
|
||||||
raise
|
raise
|
||||||
raise CheckoutErrorSuggestGit(target) from exc
|
raise CheckoutErrorSuggestGit(target) from exc
|
||||||
@@ -80,14 +90,12 @@ def _checkout(
|
|||||||
for stage, filter_info in pairs:
|
for stage, filter_info in pairs:
|
||||||
result = stage.checkout(
|
result = stage.checkout(
|
||||||
force=force,
|
force=force,
|
||||||
progress_callback=pbar.update_desc,
|
progress_callback=pbar.update_msg,
|
||||||
relink=relink,
|
relink=relink,
|
||||||
filter_info=filter_info,
|
filter_info=filter_info,
|
||||||
)
|
)
|
||||||
for data in ["failed", "added", "modified"]:
|
for key, items in result.items():
|
||||||
stats[data].extend(
|
stats[key].extend(_fspath_dir(path) for path in items)
|
||||||
_fspath_dir(path, self.root_dir) for path in result[data]
|
|
||||||
)
|
|
||||||
|
|
||||||
if stats.get("failed"):
|
if stats.get("failed"):
|
||||||
raise CheckoutError(stats["failed"], stats)
|
raise CheckoutError(stats["failed"], stats)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user