mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-26 15:28:28 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
8aefbac223 | ||
|
|
40c6b567e3 | ||
|
|
907853b985 | ||
|
|
31fe77848f | ||
|
|
7edee84306 | ||
|
|
1e65098819 | ||
|
|
4fdf7ca7fd | ||
|
|
a7b77672e6 | ||
|
|
6d8499ea6d | ||
|
|
6d698eab08 | ||
|
|
1937527249 | ||
|
|
e03128a8de | ||
|
|
fefbcc0b4c | ||
|
|
b312895e77 | ||
|
|
e2981d2743 | ||
|
|
ae9bc914d6 | ||
|
|
6167702345 | ||
|
|
7e9ff62d89 | ||
|
|
a8b7e33010 | ||
|
|
a2de48bdfb | ||
|
|
d1640cf10f | ||
|
|
45944ddde7 | ||
|
|
52369bdf47 | ||
|
|
254cf83310 | ||
|
|
bca5edf108 | ||
|
|
b04964f4b7 | ||
|
|
63c466d821 | ||
|
|
224b0fc2ce | ||
|
|
14b213adec | ||
|
|
f0c81bcef5 | ||
|
|
128fa7f887 | ||
|
|
11e56dbdf9 | ||
|
|
c60f364774 | ||
|
|
45c2c72b60 | ||
|
|
d3d471c0a5 | ||
|
|
8455b7bece | ||
|
|
7275843c08 | ||
|
|
65854c4946 | ||
|
|
211f56c043 | ||
|
|
fc6a10f486 | ||
|
|
63fe2893a8 | ||
|
|
43dcc97512 | ||
|
|
ce2481bbe8 | ||
|
|
e05157f8e0 | ||
|
|
0e854f9534 | ||
|
|
cdef709e8a | ||
|
|
c1ac6bb06b | ||
|
|
290a9fd434 | ||
|
|
26980ae45b | ||
|
|
f325921315 | ||
|
|
dfe184f149 | ||
|
|
ca60c8e0c6 | ||
|
|
6ab06bbf9e | ||
|
|
1b8e0725d8 | ||
|
|
7b1dbd6109 | ||
|
|
7bd473371c | ||
|
|
b9d560c584 | ||
|
|
f4bec650ed | ||
|
|
8e675a9d42 | ||
|
|
a338fad036 | ||
|
|
ee0066fae4 | ||
|
|
b02babee9e | ||
|
|
f4d91b35d7 | ||
|
|
60ace79305 | ||
|
|
d2ea180a9a | ||
|
|
55644f376b | ||
|
|
38e818bb1d | ||
|
|
d276ba4acc | ||
|
|
f6077d06c4 | ||
|
|
0c2e4d0b72 | ||
|
|
617014ffbb | ||
|
|
eeb6b60fe6 | ||
|
|
1ff4706f3a | ||
|
|
acdc8763c6 | ||
|
|
af6c4291b9 | ||
|
|
3190480c12 | ||
|
|
8a4827017e | ||
|
|
d8ac973362 | ||
|
|
a7aecf7c82 | ||
|
|
eee3d7674f | ||
|
|
f69cb7a902 | ||
|
|
02f92b3ac8 | ||
|
|
974f81791f | ||
|
|
912a98e05e | ||
|
|
42e3b8aa25 | ||
|
|
9de8d1e0fa | ||
|
|
0bf6fdae14 | ||
|
|
9b38aa4680 | ||
|
|
28748ff345 | ||
|
|
1ddab1077b | ||
|
|
1455e9551e | ||
|
|
9fd7d747c1 | ||
|
|
a4094f0a7f | ||
|
|
ee26afe65e | ||
|
|
9e7740572c | ||
|
|
205a605887 | ||
|
|
8f546f253b | ||
|
|
65d22c7dbd | ||
|
|
caf5b931b9 | ||
|
|
84760dc738 | ||
|
|
93246f0658 | ||
|
|
4489f98dc3 | ||
|
|
de19d15332 | ||
|
|
a1fe6c6f44 | ||
|
|
7edee656da | ||
|
|
498ee509da | ||
|
|
55f86df5b1 | ||
|
|
eae432818a |
@@ -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,19 @@
|
|||||||
---
|
---
|
||||||
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
|
||||||
|
labels: bug, triage
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## 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,6 @@
|
|||||||
---
|
---
|
||||||
name: Feature request
|
name: "\U0001F680 Feature Request"
|
||||||
about: Suggest an idea for this project
|
about: Suggest an idea for this project
|
||||||
|
labels: feature request, triage
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
+36
-8
@@ -4,11 +4,20 @@ 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
|
||||||
repo: https://gitlab.com/pycqa/flake8
|
repo: https://gitlab.com/pycqa/flake8
|
||||||
rev: master
|
rev: 3.7.9
|
||||||
- hooks:
|
- hooks:
|
||||||
- args:
|
- args:
|
||||||
- -i
|
- -i
|
||||||
@@ -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,8 +6,10 @@
|
|||||||
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
|
||||||
- args:
|
- args:
|
||||||
- git-hook
|
- git-hook
|
||||||
- pre-push
|
- pre-push
|
||||||
@@ -16,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
|
||||||
@@ -28,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
|
||||||
|
|||||||
+3
-6
@@ -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
|
||||||
@@ -106,6 +103,7 @@ jobs:
|
|||||||
- 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
|
||||||
|
- git fetch --tags
|
||||||
script:
|
script:
|
||||||
- ./scripts/build_snap.sh
|
- ./scripts/build_snap.sh
|
||||||
after_failure:
|
after_failure:
|
||||||
@@ -151,10 +149,9 @@ deploy:
|
|||||||
tags: true
|
tags: true
|
||||||
repo: iterative/dvc
|
repo: iterative/dvc
|
||||||
stage: build
|
stage: build
|
||||||
- provider: snap
|
- provider: script
|
||||||
snap: dvc_*.snap
|
|
||||||
channel: $SNAP_CHANNEL
|
|
||||||
skip_cleanup: true
|
skip_cleanup: true
|
||||||
|
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)"
|
||||||
|
|||||||
+5
-4
@@ -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)
|
||||||
--------------------------
|
--------------------------
|
||||||
@@ -255,7 +256,7 @@ Citation
|
|||||||
Iterative, *DVC: Data Version Control - Git for Data & Models* (2020)
|
Iterative, *DVC: Data Version Control - Git for Data & Models* (2020)
|
||||||
`DOI:10.5281/zenodo.012345 <https://doi.org/10.5281/zenodo.3677553>`_.
|
`DOI:10.5281/zenodo.012345 <https://doi.org/10.5281/zenodo.3677553>`_.
|
||||||
|
|
||||||
.. |Banner| image:: https://dvc.org/static/img/logo-github-readme.png
|
.. |Banner| image:: https://dvc.org/img/logo-github-readme.png
|
||||||
:target: https://dvc.org
|
:target: https://dvc.org
|
||||||
:alt: DVC logo
|
:alt: DVC logo
|
||||||
|
|
||||||
@@ -307,6 +308,6 @@ Iterative, *DVC: Data Version Control - Git for Data & Models* (2020)
|
|||||||
:target: https://doi.org/10.5281/zenodo.3677553
|
:target: https://doi.org/10.5281/zenodo.3677553
|
||||||
:alt: DOI
|
:alt: DOI
|
||||||
|
|
||||||
.. |Flowchart| image:: https://dvc.org/static/img/flow.gif
|
.. |Flowchart| image:: https://dvc.org/img/flow.gif
|
||||||
:target: https://dvc.org/static/img/flow.gif
|
:target: https://dvc.org/img/flow.gif
|
||||||
:alt: how_dvc_works
|
:alt: how_dvc_works
|
||||||
|
|||||||
@@ -3,17 +3,7 @@ DVC
|
|||||||
----
|
----
|
||||||
Make your data science projects reproducible and shareable.
|
Make your data science projects reproducible and shareable.
|
||||||
"""
|
"""
|
||||||
import warnings
|
|
||||||
|
|
||||||
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()
|
||||||
|
|
||||||
# Ignore numpy's runtime warnings: https://github.com/numpy/numpy/pull/432.
|
|
||||||
# We don't directly import numpy, but our dependency networkx does, causing
|
|
||||||
# these warnings in some environments. Luckily these warnings are benign and
|
|
||||||
# we can simply ignore them so that they don't show up when you are using dvc.
|
|
||||||
warnings.filterwarnings("ignore", message="numpy.dtype size changed")
|
|
||||||
warnings.filterwarnings("ignore", message="numpy.ufunc size changed")
|
|
||||||
|
|||||||
+15
-14
@@ -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__)
|
||||||
|
|
||||||
|
|
||||||
@@ -36,7 +35,7 @@ def collect_and_send_report(args=None, return_code=None):
|
|||||||
report as a JSON, where the _collector_ generates it and the _sender_
|
report as a JSON, where the _collector_ generates it and the _sender_
|
||||||
removes it after sending it.
|
removes it after sending it.
|
||||||
"""
|
"""
|
||||||
report = _runtime_info()
|
report = {}
|
||||||
|
|
||||||
# Include command execution information on the report only when available.
|
# Include command execution information on the report only when available.
|
||||||
if args and hasattr(args, "func"):
|
if args and hasattr(args, "func"):
|
||||||
@@ -62,7 +61,7 @@ def is_enabled():
|
|||||||
return enabled
|
return enabled
|
||||||
|
|
||||||
|
|
||||||
def send(report):
|
def send(path):
|
||||||
"""
|
"""
|
||||||
Side effect: Removes the report after sending it.
|
Side effect: Removes the report after sending it.
|
||||||
|
|
||||||
@@ -73,13 +72,17 @@ def send(report):
|
|||||||
url = "https://analytics.dvc.org"
|
url = "https://analytics.dvc.org"
|
||||||
headers = {"content-type": "application/json"}
|
headers = {"content-type": "application/json"}
|
||||||
|
|
||||||
with open(report, "rb") as fobj:
|
with open(path) as fobj:
|
||||||
try:
|
report = json.load(fobj)
|
||||||
requests.post(url, data=fobj, headers=headers, timeout=5)
|
|
||||||
except requests.exceptions.RequestException:
|
|
||||||
logger.debug("failed to send analytics report", exc_info=True)
|
|
||||||
|
|
||||||
os.remove(report)
|
report.update(_runtime_info())
|
||||||
|
|
||||||
|
try:
|
||||||
|
requests.post(url, json=report, headers=headers, timeout=5)
|
||||||
|
except requests.exceptions.RequestException:
|
||||||
|
logger.debug("failed to send analytics report", exc_info=True)
|
||||||
|
|
||||||
|
os.remove(path)
|
||||||
|
|
||||||
|
|
||||||
def _scm_in_use():
|
def _scm_in_use():
|
||||||
@@ -155,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):
|
||||||
@@ -167,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)
|
|
||||||
)
|
|
||||||
|
|||||||
+4
-3
@@ -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):
|
||||||
|
|||||||
+71
-9
@@ -40,7 +40,7 @@ def _make_remote_property(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:
|
||||||
@@ -71,9 +71,39 @@ class Cache(object):
|
|||||||
azure = _make_remote_property("azure")
|
azure = _make_remote_property("azure")
|
||||||
|
|
||||||
|
|
||||||
class NamedCache(object):
|
class NamedCacheItem:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._items = defaultdict(lambda: defaultdict(set))
|
self.names = set()
|
||||||
|
self.children = defaultdict(NamedCacheItem)
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return self.names == other.names and self.children == other.children
|
||||||
|
|
||||||
|
def child_keys(self):
|
||||||
|
for key, child in self.children.items():
|
||||||
|
yield key
|
||||||
|
yield from child.child_keys()
|
||||||
|
|
||||||
|
def child_names(self):
|
||||||
|
for key, child in self.children.items():
|
||||||
|
yield key, child.names
|
||||||
|
yield from child.child_names()
|
||||||
|
|
||||||
|
def add(self, checksum, item):
|
||||||
|
self.children[checksum].update(item)
|
||||||
|
|
||||||
|
def update(self, item, suffix=""):
|
||||||
|
if suffix:
|
||||||
|
self.names.update(n + suffix for n in item.names)
|
||||||
|
else:
|
||||||
|
self.names.update(item.names)
|
||||||
|
for checksum, child_item in item.children.items():
|
||||||
|
self.children[checksum].update(child_item)
|
||||||
|
|
||||||
|
|
||||||
|
class NamedCache:
|
||||||
|
def __init__(self):
|
||||||
|
self._items = defaultdict(lambda: defaultdict(NamedCacheItem))
|
||||||
self.external = defaultdict(set)
|
self.external = defaultdict(set)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -86,7 +116,18 @@ class NamedCache(object):
|
|||||||
return self._items[key]
|
return self._items[key]
|
||||||
|
|
||||||
def add(self, scheme, checksum, name):
|
def add(self, scheme, checksum, name):
|
||||||
self._items[scheme][checksum].add(name)
|
"""Add a mapped name for the specified checksum."""
|
||||||
|
self._items[scheme][checksum].names.add(name)
|
||||||
|
|
||||||
|
def add_child_cache(self, checksum, cache, suffix=""):
|
||||||
|
"""Add/update child cache for the specified checksum."""
|
||||||
|
for scheme, src in cache._items.items():
|
||||||
|
dst = self._items[scheme][checksum].children
|
||||||
|
for child_checksum, item in src.items():
|
||||||
|
dst[child_checksum].update(item, suffix=suffix)
|
||||||
|
|
||||||
|
for repo_pair, files in cache.external.items():
|
||||||
|
self.external[repo_pair].update(files)
|
||||||
|
|
||||||
def add_external(self, url, rev, path):
|
def add_external(self, url, rev, path):
|
||||||
self.external[url, rev].add(path)
|
self.external[url, rev].add(path)
|
||||||
@@ -94,11 +135,32 @@ class NamedCache(object):
|
|||||||
def update(self, cache, suffix=""):
|
def update(self, cache, suffix=""):
|
||||||
for scheme, src in cache._items.items():
|
for scheme, src in cache._items.items():
|
||||||
dst = self._items[scheme]
|
dst = self._items[scheme]
|
||||||
for checksum, names in src.items():
|
for checksum, item in src.items():
|
||||||
if suffix:
|
dst[checksum].update(item, suffix=suffix)
|
||||||
dst[checksum].update(n + suffix for n in names)
|
|
||||||
else:
|
|
||||||
dst[checksum].update(names)
|
|
||||||
|
|
||||||
for repo_pair, files in cache.external.items():
|
for repo_pair, files in cache.external.items():
|
||||||
self.external[repo_pair].update(files)
|
self.external[repo_pair].update(files)
|
||||||
|
|
||||||
|
def scheme_keys(self, scheme):
|
||||||
|
"""Iterate over a flat list of all keys for the specified scheme,
|
||||||
|
including children.
|
||||||
|
"""
|
||||||
|
for key, item in self._items[scheme].items():
|
||||||
|
yield key
|
||||||
|
yield from item.child_keys()
|
||||||
|
|
||||||
|
def scheme_names(self, scheme):
|
||||||
|
"""Iterate over a flat list of checksum, names items for the specified
|
||||||
|
scheme, including children.
|
||||||
|
"""
|
||||||
|
for key, item in self._items[scheme].items():
|
||||||
|
yield key, item.names
|
||||||
|
yield from item.child_names()
|
||||||
|
|
||||||
|
def dir_keys(self, scheme):
|
||||||
|
return (
|
||||||
|
key for key, item in self._items[scheme].items() if item.children
|
||||||
|
)
|
||||||
|
|
||||||
|
def child_keys(self, scheme, checksum):
|
||||||
|
return self._items[scheme][checksum].child_keys()
|
||||||
|
|||||||
+11
-14
@@ -10,36 +10,36 @@ 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,
|
||||||
move,
|
move,
|
||||||
pipeline,
|
params,
|
||||||
|
plots,
|
||||||
remote,
|
remote,
|
||||||
remove,
|
remove,
|
||||||
repro,
|
repro,
|
||||||
root,
|
root,
|
||||||
run,
|
run,
|
||||||
tag,
|
|
||||||
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 = [
|
||||||
@@ -62,18 +62,19 @@ COMMANDS = [
|
|||||||
remote,
|
remote,
|
||||||
cache,
|
cache,
|
||||||
metrics,
|
metrics,
|
||||||
|
params,
|
||||||
install,
|
install,
|
||||||
root,
|
root,
|
||||||
ls,
|
ls,
|
||||||
lock,
|
freeze,
|
||||||
pipeline,
|
dag,
|
||||||
daemon,
|
daemon,
|
||||||
commit,
|
commit,
|
||||||
tag,
|
|
||||||
diff,
|
diff,
|
||||||
version,
|
version,
|
||||||
update,
|
update,
|
||||||
git_hook,
|
git_hook,
|
||||||
|
plots,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -115,14 +116,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
|
||||||
|
|||||||
+2
-1
@@ -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__)
|
||||||
@@ -53,6 +53,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"-f",
|
"-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>",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"targets", nargs="+", help="Input files/directories to add."
|
"targets", nargs="+", help="Input files/directories to add."
|
||||||
|
|||||||
+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.stage import Stage
|
from dvc.dvcfile import PIPELINE_FILE
|
||||||
|
|
||||||
msg = "assuming default target '{}'.".format(Stage.STAGE_FILE)
|
logger.debug(f"assuming default target '{PIPELINE_FILE}'.")
|
||||||
logger.warning(msg)
|
return [PIPELINE_FILE]
|
||||||
return [Stage.STAGE_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))
|
|
||||||
|
|
||||||
|
|
||||||
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__)
|
||||||
|
|||||||
@@ -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)
|
||||||
+98
-29
@@ -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(
|
||||||
@@ -26,17 +28,18 @@ class CmdDataPull(CmdDataBase):
|
|||||||
remote=self.args.remote,
|
remote=self.args.remote,
|
||||||
all_branches=self.args.all_branches,
|
all_branches=self.args.all_branches,
|
||||||
all_tags=self.args.all_tags,
|
all_tags=self.args.all_tags,
|
||||||
|
all_commits=self.args.all_commits,
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
@@ -49,13 +52,15 @@ class CmdDataPush(CmdDataBase):
|
|||||||
remote=self.args.remote,
|
remote=self.args.remote,
|
||||||
all_branches=self.args.all_branches,
|
all_branches=self.args.all_branches,
|
||||||
all_tags=self.args.all_tags,
|
all_tags=self.args.all_tags,
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
@@ -68,13 +73,15 @@ class CmdDataFetch(CmdDataBase):
|
|||||||
remote=self.args.remote,
|
remote=self.args.remote,
|
||||||
all_branches=self.args.all_branches,
|
all_branches=self.args.all_branches,
|
||||||
all_tags=self.args.all_tags,
|
all_tags=self.args.all_tags,
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
@@ -82,27 +89,31 @@ 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", "--jobs", type=int, help="Number of jobs to run simultaneously."
|
"-j",
|
||||||
|
"--jobs",
|
||||||
|
type=int,
|
||||||
|
help="Number of jobs to run simultaneously.",
|
||||||
|
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):
|
||||||
from dvc.command.status import CmdDataStatus
|
from dvc.command.status import CmdDataStatus
|
||||||
|
|
||||||
# Pull
|
# Pull
|
||||||
PULL_HELP = "Pull data files from a DVC remote storage."
|
PULL_HELP = "Download tracked files or directories from remote storage."
|
||||||
|
|
||||||
pull_parser = subparsers.add_parser(
|
pull_parser = subparsers.add_parser(
|
||||||
"pull",
|
"pull",
|
||||||
@@ -112,7 +123,7 @@ def add_parser(subparsers, _parent_parser):
|
|||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
)
|
)
|
||||||
pull_parser.add_argument(
|
pull_parser.add_argument(
|
||||||
"-r", "--remote", help="Remote repository to pull from."
|
"-r", "--remote", help="Remote storage to pull from", metavar="<name>",
|
||||||
)
|
)
|
||||||
pull_parser.add_argument(
|
pull_parser.add_argument(
|
||||||
"-a",
|
"-a",
|
||||||
@@ -128,6 +139,12 @@ def add_parser(subparsers, _parent_parser):
|
|||||||
default=False,
|
default=False,
|
||||||
help="Fetch cache for all tags.",
|
help="Fetch cache for all tags.",
|
||||||
)
|
)
|
||||||
|
pull_parser.add_argument(
|
||||||
|
"--all-commits",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Fetch cache for all commits.",
|
||||||
|
)
|
||||||
pull_parser.add_argument(
|
pull_parser.add_argument(
|
||||||
"-f",
|
"-f",
|
||||||
"--force",
|
"--force",
|
||||||
@@ -149,11 +166,16 @@ 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
|
||||||
PUSH_HELP = "Uploads files or directories tracked by DVC"
|
PUSH_HELP = "Upload tracked files or directories to remote storage."
|
||||||
" to remote storage."
|
|
||||||
|
|
||||||
push_parser = subparsers.add_parser(
|
push_parser = subparsers.add_parser(
|
||||||
"push",
|
"push",
|
||||||
@@ -163,7 +185,7 @@ def add_parser(subparsers, _parent_parser):
|
|||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
)
|
)
|
||||||
push_parser.add_argument(
|
push_parser.add_argument(
|
||||||
"-r", "--remote", help="Remote repository to push to."
|
"-r", "--remote", help="Remote storage to push to", metavar="<name>",
|
||||||
)
|
)
|
||||||
push_parser.add_argument(
|
push_parser.add_argument(
|
||||||
"-a",
|
"-a",
|
||||||
@@ -179,6 +201,12 @@ def add_parser(subparsers, _parent_parser):
|
|||||||
default=False,
|
default=False,
|
||||||
help="Push cache for all tags.",
|
help="Push cache for all tags.",
|
||||||
)
|
)
|
||||||
|
push_parser.add_argument(
|
||||||
|
"--all-commits",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Push cache for all commits.",
|
||||||
|
)
|
||||||
push_parser.add_argument(
|
push_parser.add_argument(
|
||||||
"-d",
|
"-d",
|
||||||
"--with-deps",
|
"--with-deps",
|
||||||
@@ -191,13 +219,21 @@ def add_parser(subparsers, _parent_parser):
|
|||||||
"--recursive",
|
"--recursive",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
help="Push cache from 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
|
||||||
FETCH_HELP = "Get files or directories tracked by DVC from remote storage"
|
FETCH_HELP = (
|
||||||
" into the cache."
|
"Get tracked files or directories from remote storage"
|
||||||
|
" into the cache."
|
||||||
|
)
|
||||||
|
|
||||||
fetch_parser = subparsers.add_parser(
|
fetch_parser = subparsers.add_parser(
|
||||||
"fetch",
|
"fetch",
|
||||||
@@ -207,7 +243,10 @@ def add_parser(subparsers, _parent_parser):
|
|||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
)
|
)
|
||||||
fetch_parser.add_argument(
|
fetch_parser.add_argument(
|
||||||
"-r", "--remote", help="Remote repository to fetch from."
|
"-r",
|
||||||
|
"--remote",
|
||||||
|
help="Remote storage to fetch from",
|
||||||
|
metavar="<name>",
|
||||||
)
|
)
|
||||||
fetch_parser.add_argument(
|
fetch_parser.add_argument(
|
||||||
"-a",
|
"-a",
|
||||||
@@ -223,6 +262,12 @@ def add_parser(subparsers, _parent_parser):
|
|||||||
default=False,
|
default=False,
|
||||||
help="Fetch cache for all tags.",
|
help="Fetch cache for all tags.",
|
||||||
)
|
)
|
||||||
|
fetch_parser.add_argument(
|
||||||
|
"--all-commits",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Fetch cache for all commits.",
|
||||||
|
)
|
||||||
fetch_parser.add_argument(
|
fetch_parser.add_argument(
|
||||||
"-d",
|
"-d",
|
||||||
"--with-deps",
|
"--with-deps",
|
||||||
@@ -237,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
|
||||||
@@ -270,7 +321,10 @@ def add_parser(subparsers, _parent_parser):
|
|||||||
help="Show status of a local cache compared to a remote repository.",
|
help="Show status of a local cache compared to a remote repository.",
|
||||||
)
|
)
|
||||||
status_parser.add_argument(
|
status_parser.add_argument(
|
||||||
"-r", "--remote", help="Remote repository to compare local cache to."
|
"-r",
|
||||||
|
"--remote",
|
||||||
|
help="Remote storage to compare local cache to",
|
||||||
|
metavar="<name>",
|
||||||
)
|
)
|
||||||
status_parser.add_argument(
|
status_parser.add_argument(
|
||||||
"-a",
|
"-a",
|
||||||
@@ -288,6 +342,13 @@ def add_parser(subparsers, _parent_parser):
|
|||||||
help="Show status of a local cache compared to a remote repository "
|
help="Show status of a local cache compared to a remote repository "
|
||||||
"for all tags.",
|
"for all tags.",
|
||||||
)
|
)
|
||||||
|
status_parser.add_argument(
|
||||||
|
"--all-commits",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Show status of a local cache compared to a remote repository "
|
||||||
|
"for all commits.",
|
||||||
|
)
|
||||||
status_parser.add_argument(
|
status_parser.add_argument(
|
||||||
"-d",
|
"-d",
|
||||||
"--with-deps",
|
"--with-deps",
|
||||||
@@ -295,4 +356,12 @@ 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.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__)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+28
-12
@@ -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")
|
||||||
@@ -120,9 +131,8 @@ class CmdDiff(CmdBase):
|
|||||||
|
|
||||||
def add_parser(subparsers, parent_parser):
|
def add_parser(subparsers, parent_parser):
|
||||||
DIFF_DESCRIPTION = (
|
DIFF_DESCRIPTION = (
|
||||||
"Show changes between commits in the DVC repository,"
|
"Show added, modified, or deleted data between commits in the DVC"
|
||||||
" or between a commit and the workspace."
|
" repository, or between a commit and the workspace."
|
||||||
"Prints the list of paths added, modified, or deleted."
|
|
||||||
)
|
)
|
||||||
diff_parser = subparsers.add_parser(
|
diff_parser = subparsers.add_parser(
|
||||||
"diff",
|
"diff",
|
||||||
@@ -154,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)
|
||||||
+13
-7
@@ -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",
|
||||||
@@ -109,7 +107,10 @@ def add_parser(subparsers, parent_parser):
|
|||||||
help="Collect garbage in remote repository.",
|
help="Collect garbage in remote repository.",
|
||||||
)
|
)
|
||||||
gc_parser.add_argument(
|
gc_parser.add_argument(
|
||||||
"-r", "--remote", help="Remote storage to collect garbage in."
|
"-r",
|
||||||
|
"--remote",
|
||||||
|
help="Remote storage to collect garbage in",
|
||||||
|
metavar="<name>",
|
||||||
)
|
)
|
||||||
gc_parser.add_argument(
|
gc_parser.add_argument(
|
||||||
"-f",
|
"-f",
|
||||||
@@ -119,7 +120,11 @@ def add_parser(subparsers, parent_parser):
|
|||||||
help="Force garbage collection - automatically agree to all prompts.",
|
help="Force garbage collection - automatically agree to all prompts.",
|
||||||
)
|
)
|
||||||
gc_parser.add_argument(
|
gc_parser.add_argument(
|
||||||
"-j", "--jobs", type=int, help="Number of jobs to run simultaneously."
|
"-j",
|
||||||
|
"--jobs",
|
||||||
|
type=int,
|
||||||
|
help="Number of jobs to run simultaneously.",
|
||||||
|
metavar="<number>",
|
||||||
)
|
)
|
||||||
gc_parser.add_argument(
|
gc_parser.add_argument(
|
||||||
"-p",
|
"-p",
|
||||||
@@ -130,5 +135,6 @@ def add_parser(subparsers, parent_parser):
|
|||||||
help="Keep data files required by these projects "
|
help="Keep data files required by these projects "
|
||||||
"in addition to the current one. "
|
"in addition to the current one. "
|
||||||
"Useful if you share a single cache across repos.",
|
"Useful if you share a single cache across repos.",
|
||||||
|
metavar="<paths>",
|
||||||
)
|
)
|
||||||
gc_parser.set_defaults(func=CmdGC)
|
gc_parser.set_defaults(func=CmdGC)
|
||||||
|
|||||||
+10
-4
@@ -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__)
|
||||||
|
|
||||||
@@ -66,10 +65,17 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"path", help="Path to a file or directory within the repository"
|
"path", help="Path to a file or directory within the repository"
|
||||||
)
|
)
|
||||||
get_parser.add_argument(
|
get_parser.add_argument(
|
||||||
"-o", "--out", nargs="?", help="Destination path to download files to"
|
"-o",
|
||||||
|
"--out",
|
||||||
|
nargs="?",
|
||||||
|
help="Destination path to download files to",
|
||||||
|
metavar="<path>",
|
||||||
)
|
)
|
||||||
get_parser.add_argument(
|
get_parser.add_argument(
|
||||||
"--rev", nargs="?", help="Git revision (e.g. SHA, branch, tag)"
|
"--rev",
|
||||||
|
nargs="?",
|
||||||
|
help="Git revision (e.g. SHA, branch, tag)",
|
||||||
|
metavar="<commit>",
|
||||||
)
|
)
|
||||||
get_parser.add_argument(
|
get_parser.add_argument(
|
||||||
"--show-url",
|
"--show-url",
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+10
-5
@@ -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__)
|
||||||
|
|
||||||
|
|
||||||
@@ -48,9 +46,16 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"path", help="Path to a file or directory within the repository"
|
"path", help="Path to a file or directory within the repository"
|
||||||
)
|
)
|
||||||
import_parser.add_argument(
|
import_parser.add_argument(
|
||||||
"-o", "--out", nargs="?", help="Destination path to download files to"
|
"-o",
|
||||||
|
"--out",
|
||||||
|
nargs="?",
|
||||||
|
help="Destination path to download files to",
|
||||||
|
metavar="<path>",
|
||||||
)
|
)
|
||||||
import_parser.add_argument(
|
import_parser.add_argument(
|
||||||
"--rev", nargs="?", help="Git revision (e.g. SHA, branch, tag)"
|
"--rev",
|
||||||
|
nargs="?",
|
||||||
|
help="Git revision (e.g. SHA, branch, tag)",
|
||||||
|
metavar="<commit>",
|
||||||
)
|
)
|
||||||
import_parser.set_defaults(func=CmdImport)
|
import_parser.set_defaults(func=CmdImport)
|
||||||
|
|||||||
@@ -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,6 +57,9 @@ 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", help="Specify name of the DVC-file it generates."
|
"-f",
|
||||||
|
"--file",
|
||||||
|
help="Specify name of the DVC-file this command will generate.",
|
||||||
|
metavar="<filename>",
|
||||||
)
|
)
|
||||||
import_parser.set_defaults(func=CmdImportUrl)
|
import_parser.set_defaults(func=CmdImportUrl)
|
||||||
|
|||||||
+2
-4
@@ -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__)
|
||||||
|
|
||||||
@@ -47,7 +45,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
action="store_true",
|
action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
help="Initiate DVC in directory that is "
|
help="Initiate DVC in directory that is "
|
||||||
"not tracked by any scm tool (e.g. git).",
|
"not tracked by any SCM tool (e.g. Git).",
|
||||||
)
|
)
|
||||||
init_parser.add_argument(
|
init_parser.add_argument(
|
||||||
"-f",
|
"-f",
|
||||||
|
|||||||
@@ -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,10 +62,13 @@ 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", nargs="?", help="Git revision (e.g. branch, tag, SHA)"
|
"--rev",
|
||||||
|
nargs="?",
|
||||||
|
help="Git revision (e.g. SHA, branch, tag)",
|
||||||
|
metavar="<commit>",
|
||||||
)
|
)
|
||||||
list_parser.add_argument(
|
list_parser.add_argument(
|
||||||
"path",
|
"path",
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
+96
-166
@@ -1,46 +1,34 @@
|
|||||||
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__)
|
||||||
|
|
||||||
|
|
||||||
def show_metrics(metrics, all_branches=False, all_tags=False):
|
def show_metrics(
|
||||||
"""
|
metrics, all_branches=False, all_tags=False, all_commits=False
|
||||||
Args:
|
):
|
||||||
metrics (list): Where each element is either a `list`
|
from flatten_json import flatten
|
||||||
if an xpath was specified, otherwise a `str`
|
from dvc.utils.diff import format_dict
|
||||||
"""
|
|
||||||
# When `metrics` contains a `None` key, it means that some files
|
# When `metrics` contains a `None` key, it means that some files
|
||||||
# specified as `targets` in `repo.metrics.show` didn't contain any metrics.
|
# specified as `targets` in `repo.metrics.show` didn't contain any metrics.
|
||||||
missing = metrics.pop(None, None)
|
missing = metrics.pop(None, None)
|
||||||
|
|
||||||
for branch, val in metrics.items():
|
for branch, val in metrics.items():
|
||||||
if all_branches or all_tags:
|
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 isinstance(metric, dict):
|
if not isinstance(metric, dict):
|
||||||
lines = list(metric.values())
|
logger.info("\t{}: {}".format(fname, str(metric)))
|
||||||
elif isinstance(metric, list):
|
continue
|
||||||
lines = metric
|
|
||||||
else:
|
|
||||||
lines = metric.splitlines()
|
|
||||||
|
|
||||||
if len(lines) > 1:
|
logger.info(f"\t{fname}:")
|
||||||
logger.info("\t{fname}:".format(fname=fname))
|
for key, value in flatten(format_dict(metric), ".").items():
|
||||||
|
logger.info(f"\t\t{key}: {value}")
|
||||||
for line in lines:
|
|
||||||
logger.info("\t\t{content}".format(content=line))
|
|
||||||
|
|
||||||
else:
|
|
||||||
logger.info("\t{}: {}".format(fname, metric))
|
|
||||||
|
|
||||||
if missing:
|
if missing:
|
||||||
raise BadMetricError(missing)
|
raise BadMetricError(missing)
|
||||||
@@ -51,14 +39,23 @@ class CmdMetricsShow(CmdBase):
|
|||||||
try:
|
try:
|
||||||
metrics = self.repo.metrics.show(
|
metrics = self.repo.metrics.show(
|
||||||
self.args.targets,
|
self.args.targets,
|
||||||
typ=self.args.type,
|
|
||||||
xpath=self.args.xpath,
|
|
||||||
all_branches=self.args.all_branches,
|
all_branches=self.args.all_branches,
|
||||||
all_tags=self.args.all_tags,
|
all_tags=self.args.all_tags,
|
||||||
|
all_commits=self.args.all_commits,
|
||||||
recursive=self.args.recursive,
|
recursive=self.args.recursive,
|
||||||
)
|
)
|
||||||
|
|
||||||
show_metrics(metrics, self.args.all_branches, self.args.all_tags)
|
if self.args.show_json:
|
||||||
|
import json
|
||||||
|
|
||||||
|
logger.info(json.dumps(metrics))
|
||||||
|
else:
|
||||||
|
show_metrics(
|
||||||
|
metrics,
|
||||||
|
self.args.all_branches,
|
||||||
|
self.args.all_tags,
|
||||||
|
self.args.all_commits,
|
||||||
|
)
|
||||||
except DvcException:
|
except DvcException:
|
||||||
logger.exception("failed to show metrics")
|
logger.exception("failed to show metrics")
|
||||||
return 1
|
return 1
|
||||||
@@ -66,70 +63,32 @@ class CmdMetricsShow(CmdBase):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
class CmdMetricsModify(CmdBase):
|
def _show_diff(diff, markdown=False, no_path=False, old=False):
|
||||||
def run(self):
|
from collections import OrderedDict
|
||||||
try:
|
|
||||||
self.repo.metrics.modify(
|
|
||||||
self.args.path, typ=self.args.type, xpath=self.args.xpath
|
|
||||||
)
|
|
||||||
except DvcException:
|
|
||||||
logger.exception("failed to modify metric file settings")
|
|
||||||
return 1
|
|
||||||
|
|
||||||
return 0
|
from dvc.utils.diff import table
|
||||||
|
|
||||||
|
rows = []
|
||||||
class CmdMetricsAdd(CmdBase):
|
|
||||||
def run(self):
|
|
||||||
try:
|
|
||||||
self.repo.metrics.add(
|
|
||||||
self.args.path, self.args.type, self.args.xpath
|
|
||||||
)
|
|
||||||
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 texttable import Texttable
|
|
||||||
|
|
||||||
if not diff:
|
|
||||||
return "No changes."
|
|
||||||
|
|
||||||
table = Texttable()
|
|
||||||
|
|
||||||
# remove borders to make it easier for users to copy stuff
|
|
||||||
table.set_chars(("", "", "", ""))
|
|
||||||
table.set_deco(0)
|
|
||||||
|
|
||||||
rows = [["Path", "Metric", "Value", "Change"]]
|
|
||||||
for fname, mdiff in diff.items():
|
for fname, mdiff in diff.items():
|
||||||
for metric, change in mdiff.items():
|
sorted_mdiff = OrderedDict(sorted(mdiff.items()))
|
||||||
rows.append(
|
for metric, change in sorted_mdiff.items():
|
||||||
[
|
row = [] if no_path else [fname]
|
||||||
fname,
|
row.append(metric)
|
||||||
metric,
|
if old:
|
||||||
change["new"],
|
row.append(change.get("old"))
|
||||||
change.get("diff", "diff not supported"),
|
row.append(change["new"])
|
||||||
]
|
row.append(change.get("diff", "diff not supported"))
|
||||||
)
|
rows.append(row)
|
||||||
table.add_rows(rows)
|
|
||||||
return table.draw()
|
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):
|
||||||
@@ -139,9 +98,8 @@ class CmdMetricsDiff(CmdBase):
|
|||||||
a_rev=self.args.a_rev,
|
a_rev=self.args.a_rev,
|
||||||
b_rev=self.args.b_rev,
|
b_rev=self.args.b_rev,
|
||||||
targets=self.args.targets,
|
targets=self.args.targets,
|
||||||
typ=self.args.type,
|
|
||||||
xpath=self.args.xpath,
|
|
||||||
recursive=self.args.recursive,
|
recursive=self.args.recursive,
|
||||||
|
all=self.args.all,
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.args.show_json:
|
if self.args.show_json:
|
||||||
@@ -149,7 +107,11 @@ class CmdMetricsDiff(CmdBase):
|
|||||||
|
|
||||||
logger.info(json.dumps(diff))
|
logger.info(json.dumps(diff))
|
||||||
else:
|
else:
|
||||||
logger.info(_show_diff(diff))
|
table = _show_diff(
|
||||||
|
diff, self.args.show_md, self.args.no_path, self.args.old
|
||||||
|
)
|
||||||
|
if table:
|
||||||
|
logger.info(table)
|
||||||
|
|
||||||
except DvcException:
|
except DvcException:
|
||||||
logger.exception("failed to show metrics diff")
|
logger.exception("failed to show metrics diff")
|
||||||
@@ -159,7 +121,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",
|
||||||
@@ -176,7 +138,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
|
|
||||||
fix_subparsers(metrics_subparsers)
|
fix_subparsers(metrics_subparsers)
|
||||||
|
|
||||||
METRICS_SHOW_HELP = "Output metric values."
|
METRICS_SHOW_HELP = "Print metrics, with optional formatting."
|
||||||
metrics_show_parser = metrics_subparsers.add_parser(
|
metrics_show_parser = metrics_subparsers.add_parser(
|
||||||
"show",
|
"show",
|
||||||
parents=[parent_parser],
|
parents=[parent_parser],
|
||||||
@@ -189,18 +151,6 @@ def add_parser(subparsers, parent_parser):
|
|||||||
nargs="*",
|
nargs="*",
|
||||||
help="Metric files or directories (see -R) to show",
|
help="Metric files or directories (see -R) to show",
|
||||||
)
|
)
|
||||||
metrics_show_parser.add_argument(
|
|
||||||
"-t",
|
|
||||||
"--type",
|
|
||||||
help=(
|
|
||||||
"Type of metrics (json/tsv/htsv/csv/hcsv). "
|
|
||||||
"It can be detected by the file extension automatically. "
|
|
||||||
"Unsupported types will be treated as raw."
|
|
||||||
),
|
|
||||||
)
|
|
||||||
metrics_show_parser.add_argument(
|
|
||||||
"-x", "--xpath", help="json/tsv/htsv/csv/hcsv path."
|
|
||||||
)
|
|
||||||
metrics_show_parser.add_argument(
|
metrics_show_parser.add_argument(
|
||||||
"-a",
|
"-a",
|
||||||
"--all-branches",
|
"--all-branches",
|
||||||
@@ -215,6 +165,12 @@ def add_parser(subparsers, parent_parser):
|
|||||||
default=False,
|
default=False,
|
||||||
help="Show metrics for all tags.",
|
help="Show metrics for all tags.",
|
||||||
)
|
)
|
||||||
|
metrics_show_parser.add_argument(
|
||||||
|
"--all-commits",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Show metrics for all commits.",
|
||||||
|
)
|
||||||
metrics_show_parser.add_argument(
|
metrics_show_parser.add_argument(
|
||||||
"-R",
|
"-R",
|
||||||
"--recursive",
|
"--recursive",
|
||||||
@@ -225,53 +181,14 @@ 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_ADD_HELP = "Tag file as a metric file."
|
|
||||||
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(
|
|
||||||
"-t", "--type", help="Type of metrics (raw/json/tsv/htsv/csv/hcsv)."
|
|
||||||
)
|
|
||||||
metrics_add_parser.add_argument(
|
|
||||||
"-x", "--xpath", help="json/tsv/htsv/csv/hcsv path."
|
|
||||||
)
|
|
||||||
metrics_add_parser.add_argument("path", help="Path to a metric file.")
|
|
||||||
metrics_add_parser.set_defaults(func=CmdMetricsAdd)
|
|
||||||
|
|
||||||
METRICS_MODIFY_HELP = "Modify metric file options."
|
|
||||||
metrics_modify_parser = metrics_subparsers.add_parser(
|
|
||||||
"modify",
|
|
||||||
parents=[parent_parser],
|
|
||||||
description=append_doc_link(METRICS_MODIFY_HELP, "metrics/modify"),
|
|
||||||
help=METRICS_MODIFY_HELP,
|
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
||||||
)
|
|
||||||
metrics_modify_parser.add_argument(
|
|
||||||
"-t", "--type", help="Type of metrics (raw/json/tsv/htsv/csv/hcsv)."
|
|
||||||
)
|
|
||||||
metrics_modify_parser.add_argument(
|
|
||||||
"-x", "--xpath", help="json/tsv/htsv/csv/hcsv path."
|
|
||||||
)
|
|
||||||
metrics_modify_parser.add_argument("path", help="Path to a metric file.")
|
|
||||||
metrics_modify_parser.set_defaults(func=CmdMetricsModify)
|
|
||||||
|
|
||||||
METRICS_REMOVE_HELP = "Remove files's metric tag."
|
|
||||||
metrics_remove_parser = metrics_subparsers.add_parser(
|
|
||||||
"remove",
|
|
||||||
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_remove_parser.set_defaults(func=CmdMetricsRemove)
|
|
||||||
|
|
||||||
METRICS_DIFF_HELP = "Show changes in metrics between commits"
|
METRICS_DIFF_HELP = "Show changes in metrics between commits"
|
||||||
" in the DVC repository, or between a commit and the workspace."
|
" 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(
|
||||||
@@ -296,18 +213,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"Metric files or directories (see -R) to show diff for. "
|
"Metric files or directories (see -R) to show diff for. "
|
||||||
"Shows diff for all metric files by default."
|
"Shows diff for all metric files by default."
|
||||||
),
|
),
|
||||||
)
|
metavar="<paths>",
|
||||||
metrics_diff_parser.add_argument(
|
|
||||||
"-t",
|
|
||||||
"--type",
|
|
||||||
help=(
|
|
||||||
"Type of metrics (json/tsv/htsv/csv/hcsv). "
|
|
||||||
"It can be detected by the file extension automatically. "
|
|
||||||
"Unsupported types will be treated as raw."
|
|
||||||
),
|
|
||||||
)
|
|
||||||
metrics_diff_parser.add_argument(
|
|
||||||
"-x", "--xpath", help="json/tsv/htsv/csv/hcsv path."
|
|
||||||
)
|
)
|
||||||
metrics_diff_parser.add_argument(
|
metrics_diff_parser.add_argument(
|
||||||
"-R",
|
"-R",
|
||||||
@@ -319,10 +225,34 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"metric files."
|
"metric files."
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
metrics_diff_parser.add_argument(
|
||||||
|
"--all",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Show unchanged metrics as well.",
|
||||||
|
)
|
||||||
metrics_diff_parser.add_argument(
|
metrics_diff_parser.add_argument(
|
||||||
"--show-json",
|
"--show-json",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
help="Show output in JSON format.",
|
help="Show output in JSON format.",
|
||||||
)
|
)
|
||||||
|
metrics_diff_parser.add_argument(
|
||||||
|
"--show-md",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Show tabulated output in the Markdown format (GFM).",
|
||||||
|
)
|
||||||
|
metrics_diff_parser.add_argument(
|
||||||
|
"--no-path",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Don't show metric path.",
|
||||||
|
)
|
||||||
|
metrics_diff_parser.add_argument(
|
||||||
|
"--old",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Show old metric value.",
|
||||||
|
)
|
||||||
metrics_diff_parser.set_defaults(func=CmdMetricsDiff)
|
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__)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,118 @@
|
|||||||
|
import argparse
|
||||||
|
import logging
|
||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
from dvc.command.base import CmdBase, append_doc_link, fix_subparsers
|
||||||
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def _show_diff(diff, markdown=False, no_path=False):
|
||||||
|
from dvc.utils.diff import table
|
||||||
|
|
||||||
|
rows = []
|
||||||
|
for fname, pdiff in diff.items():
|
||||||
|
sorted_pdiff = OrderedDict(sorted(pdiff.items()))
|
||||||
|
for param, change in sorted_pdiff.items():
|
||||||
|
row = [] if no_path else [fname]
|
||||||
|
row.append(param)
|
||||||
|
row.append(change["old"])
|
||||||
|
row.append(change["new"])
|
||||||
|
rows.append(row)
|
||||||
|
|
||||||
|
header = [] if no_path else ["Path"]
|
||||||
|
header.append("Param")
|
||||||
|
header.append("Old")
|
||||||
|
header.append("New")
|
||||||
|
|
||||||
|
return table(header, rows, markdown)
|
||||||
|
|
||||||
|
|
||||||
|
class CmdParamsDiff(CmdBase):
|
||||||
|
def run(self):
|
||||||
|
try:
|
||||||
|
diff = self.repo.params.diff(
|
||||||
|
a_rev=self.args.a_rev,
|
||||||
|
b_rev=self.args.b_rev,
|
||||||
|
all=self.args.all,
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.args.show_json:
|
||||||
|
import json
|
||||||
|
|
||||||
|
logger.info(json.dumps(diff))
|
||||||
|
else:
|
||||||
|
table = _show_diff(diff, self.args.show_md, self.args.no_path)
|
||||||
|
if table:
|
||||||
|
logger.info(table)
|
||||||
|
|
||||||
|
except DvcException:
|
||||||
|
logger.exception("failed to show params diff")
|
||||||
|
return 1
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def add_parser(subparsers, parent_parser):
|
||||||
|
PARAMS_HELP = "Commands to display params."
|
||||||
|
|
||||||
|
params_parser = subparsers.add_parser(
|
||||||
|
"params",
|
||||||
|
parents=[parent_parser],
|
||||||
|
description=append_doc_link(PARAMS_HELP, "params"),
|
||||||
|
help=PARAMS_HELP,
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
)
|
||||||
|
|
||||||
|
params_subparsers = params_parser.add_subparsers(
|
||||||
|
dest="cmd",
|
||||||
|
help="Use `dvc params CMD --help` to display command-specific help.",
|
||||||
|
)
|
||||||
|
|
||||||
|
fix_subparsers(params_subparsers)
|
||||||
|
|
||||||
|
PARAMS_DIFF_HELP = (
|
||||||
|
"Show changes in params between commits in the DVC repository, or "
|
||||||
|
"between a commit and the workspace."
|
||||||
|
)
|
||||||
|
params_diff_parser = params_subparsers.add_parser(
|
||||||
|
"diff",
|
||||||
|
parents=[parent_parser],
|
||||||
|
description=append_doc_link(PARAMS_DIFF_HELP, "params/diff"),
|
||||||
|
help=PARAMS_DIFF_HELP,
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
)
|
||||||
|
params_diff_parser.add_argument(
|
||||||
|
"a_rev", nargs="?", help="Old Git commit to compare (defaults to HEAD)"
|
||||||
|
)
|
||||||
|
params_diff_parser.add_argument(
|
||||||
|
"b_rev",
|
||||||
|
nargs="?",
|
||||||
|
help=("New Git commit to compare (defaults to the current workspace)"),
|
||||||
|
)
|
||||||
|
params_diff_parser.add_argument(
|
||||||
|
"--all",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Show unchanged params as well.",
|
||||||
|
)
|
||||||
|
params_diff_parser.add_argument(
|
||||||
|
"--show-json",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
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)
|
||||||
@@ -1,247 +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.stage import Stage
|
|
||||||
|
|
||||||
stage = Stage.load(self.repo, target)
|
|
||||||
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.path_in_repo)
|
|
||||||
|
|
||||||
def _build_graph(self, target, commands, outs):
|
|
||||||
import networkx
|
|
||||||
from dvc.stage import Stage
|
|
||||||
from dvc.repo.graph import get_pipeline
|
|
||||||
|
|
||||||
target_stage = Stage.load(self.repo, target)
|
|
||||||
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))
|
|
||||||
for dep in stage.deps:
|
|
||||||
nodes.add(str(dep))
|
|
||||||
else:
|
|
||||||
nodes.add(stage.relpath)
|
|
||||||
|
|
||||||
edges = []
|
|
||||||
|
|
||||||
if outs:
|
|
||||||
for stage in networkx.dfs_preorder_nodes(G, target_stage):
|
|
||||||
for dep in stage.deps:
|
|
||||||
for out in stage.outs:
|
|
||||||
edges.append((str(out), str(dep)))
|
|
||||||
else:
|
|
||||||
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))
|
|
||||||
else:
|
|
||||||
edges.append((from_stage.relpath, to_stage.relpath))
|
|
||||||
|
|
||||||
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.relpath)
|
|
||||||
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_SHOW_HELP = "Show pipelines."
|
|
||||||
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)
|
|
||||||
|
|
||||||
PIPELINE_LIST_HELP = "List 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)
|
|
||||||
@@ -0,0 +1,213 @@
|
|||||||
|
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 = (
|
||||||
|
"Generating plots for metrics stored in structured files "
|
||||||
|
"(JSON, 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 a plots image file from a metrics file."
|
||||||
|
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 = (
|
||||||
|
"Plot differences in metrics between commits in the DVC "
|
||||||
|
"repository, or between the last commit and the workspace."
|
||||||
|
)
|
||||||
|
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.",
|
||||||
|
)
|
||||||
|
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 plot props associated with a target file."
|
||||||
|
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="Plot file to set props to.",
|
||||||
|
)
|
||||||
|
_add_props_arguments(plots_modify_parser)
|
||||||
|
plots_modify_parser.add_argument(
|
||||||
|
"--unset", nargs="*", help="Props to unset.",
|
||||||
|
)
|
||||||
|
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")
|
||||||
|
)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
parser.add_argument("-x", default=None, help="Field name for x axis.")
|
||||||
|
parser.add_argument("-y", default=None, help="Field name for y axis.")
|
||||||
|
parser.add_argument(
|
||||||
|
"--no-csv-header",
|
||||||
|
action="store_false",
|
||||||
|
dest="csv_header",
|
||||||
|
default=None, # Use default None to distinguish when it's not used
|
||||||
|
help="Provided CSV ot TSV datafile does not have a header.",
|
||||||
|
)
|
||||||
|
parser.add_argument("--title", default=None, help="Plot title.")
|
||||||
|
parser.add_argument("--xlab", default=None, help="X axis title.")
|
||||||
|
parser.add_argument("--ylab", default=None, help="Y axis title.")
|
||||||
|
|
||||||
|
|
||||||
|
def _add_output_arguments(parser):
|
||||||
|
parser.add_argument(
|
||||||
|
"-o", "--out", default=None, help="Destination path to save plots to.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--show-vega",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Show output in VEGA format.",
|
||||||
|
)
|
||||||
+73
-26
@@ -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:
|
||||||
@@ -85,7 +81,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,10 +104,39 @@ 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
|
||||||
|
|
||||||
REMOTE_HELP = "Manage remote storage configuration."
|
REMOTE_HELP = "Set up and manage data remotes."
|
||||||
remote_parser = subparsers.add_parser(
|
remote_parser = subparsers.add_parser(
|
||||||
"remote",
|
"remote",
|
||||||
parents=[parent_parser],
|
parents=[parent_parser],
|
||||||
@@ -116,7 +152,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
|
|
||||||
fix_subparsers(remote_subparsers)
|
fix_subparsers(remote_subparsers)
|
||||||
|
|
||||||
REMOTE_ADD_HELP = "Add remote."
|
REMOTE_ADD_HELP = "Add a new data remote."
|
||||||
remote_add_parser = remote_subparsers.add_parser(
|
remote_add_parser = remote_subparsers.add_parser(
|
||||||
"add",
|
"add",
|
||||||
parents=[parent_config_parser, parent_parser],
|
parents=[parent_config_parser, parent_parser],
|
||||||
@@ -147,7 +183,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
)
|
)
|
||||||
remote_add_parser.set_defaults(func=CmdRemoteAdd)
|
remote_add_parser.set_defaults(func=CmdRemoteAdd)
|
||||||
|
|
||||||
REMOTE_DEFAULT_HELP = "Set/unset default remote."
|
REMOTE_DEFAULT_HELP = "Set/unset the default data remote."
|
||||||
remote_default_parser = remote_subparsers.add_parser(
|
remote_default_parser = remote_subparsers.add_parser(
|
||||||
"default",
|
"default",
|
||||||
parents=[parent_config_parser, parent_parser],
|
parents=[parent_config_parser, parent_parser],
|
||||||
@@ -167,20 +203,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
)
|
)
|
||||||
remote_default_parser.set_defaults(func=CmdRemoteDefault)
|
remote_default_parser.set_defaults(func=CmdRemoteDefault)
|
||||||
|
|
||||||
REMOTE_REMOVE_HELP = "Remove remote."
|
REMOTE_MODIFY_HELP = "Modify the configuration of a data remote."
|
||||||
remote_remove_parser = remote_subparsers.add_parser(
|
|
||||||
"remove",
|
|
||||||
parents=[parent_config_parser, parent_parser],
|
|
||||||
description=append_doc_link(REMOTE_REMOVE_HELP, "remote/remove"),
|
|
||||||
help=REMOTE_REMOVE_HELP,
|
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
||||||
)
|
|
||||||
remote_remove_parser.add_argument(
|
|
||||||
"name", help="Name of the remote to remove."
|
|
||||||
)
|
|
||||||
remote_remove_parser.set_defaults(func=CmdRemoteRemove)
|
|
||||||
|
|
||||||
REMOTE_MODIFY_HELP = "Modify remote."
|
|
||||||
remote_modify_parser = remote_subparsers.add_parser(
|
remote_modify_parser = remote_subparsers.add_parser(
|
||||||
"modify",
|
"modify",
|
||||||
parents=[parent_config_parser, parent_parser],
|
parents=[parent_config_parser, parent_parser],
|
||||||
@@ -204,7 +227,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
)
|
)
|
||||||
remote_modify_parser.set_defaults(func=CmdRemoteModify)
|
remote_modify_parser.set_defaults(func=CmdRemoteModify)
|
||||||
|
|
||||||
REMOTE_LIST_HELP = "List available remotes."
|
REMOTE_LIST_HELP = "List all available data remotes."
|
||||||
remote_list_parser = remote_subparsers.add_parser(
|
remote_list_parser = remote_subparsers.add_parser(
|
||||||
"list",
|
"list",
|
||||||
parents=[parent_config_parser, parent_parser],
|
parents=[parent_config_parser, parent_parser],
|
||||||
@@ -213,3 +236,27 @@ def add_parser(subparsers, parent_parser):
|
|||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
)
|
)
|
||||||
remote_list_parser.set_defaults(func=CmdRemoteList)
|
remote_list_parser.set_defaults(func=CmdRemoteList)
|
||||||
|
|
||||||
|
REMOTE_REMOVE_HELP = "Remove a data remote."
|
||||||
|
remote_remove_parser = remote_subparsers.add_parser(
|
||||||
|
"remove",
|
||||||
|
parents=[parent_config_parser, parent_parser],
|
||||||
|
description=append_doc_link(REMOTE_REMOVE_HELP, "remote/remove"),
|
||||||
|
help=REMOTE_REMOVE_HELP,
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
)
|
||||||
|
remote_remove_parser.add_argument(
|
||||||
|
"name", help="Name of the remote to remove."
|
||||||
|
)
|
||||||
|
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-file outputs."
|
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."
|
||||||
|
|||||||
+19
-7
@@ -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:
|
||||||
@@ -57,7 +57,9 @@ class CmdRepro(CmdBase):
|
|||||||
|
|
||||||
|
|
||||||
def add_parser(subparsers, parent_parser):
|
def add_parser(subparsers, parent_parser):
|
||||||
REPRO_HELP = "Check for changes and reproduce stages and dependencies."
|
REPRO_HELP = (
|
||||||
|
"Reproduce complete or partial pipelines by executing their stages."
|
||||||
|
)
|
||||||
repro_parser = subparsers.add_parser(
|
repro_parser = subparsers.add_parser(
|
||||||
"repro",
|
"repro",
|
||||||
parents=[parent_parser],
|
parents=[parent_parser],
|
||||||
@@ -68,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",
|
||||||
@@ -90,6 +92,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"--cwd",
|
"--cwd",
|
||||||
default=os.path.curdir,
|
default=os.path.curdir,
|
||||||
help="Directory within your repo to reproduce from.",
|
help="Directory within your repo to reproduce from.",
|
||||||
|
metavar="<path>",
|
||||||
)
|
)
|
||||||
repro_parser.add_argument(
|
repro_parser.add_argument(
|
||||||
"-m",
|
"-m",
|
||||||
@@ -135,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 "
|
||||||
|
|||||||
+2
-3
@@ -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__)
|
||||||
@@ -17,7 +16,7 @@ class CmdRoot(CmdBaseNoRepo):
|
|||||||
|
|
||||||
|
|
||||||
def add_parser(subparsers, parent_parser):
|
def add_parser(subparsers, parent_parser):
|
||||||
ROOT_HELP = "Relative path to the repository's directory."
|
ROOT_HELP = "Return the relative path to the root of the DVC project."
|
||||||
root_parser = subparsers.add_parser(
|
root_parser = subparsers.add_parser(
|
||||||
"root",
|
"root",
|
||||||
parents=[parent_parser],
|
parents=[parent_parser],
|
||||||
|
|||||||
+63
-33
@@ -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,15 +16,18 @@ 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.command,
|
self.args.command,
|
||||||
]
|
]
|
||||||
): # 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`, `--outs-persist`, `--outs-persist-no-cache`, "
|
"`-m`, `-M`, `-p`, `--plots`, `--plots-no-cache`, "
|
||||||
"`command`."
|
"`--outs-persist`, `--outs-persist-no-cache`, `command`."
|
||||||
)
|
)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
@@ -39,21 +38,24 @@ 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,
|
||||||
fname=self.args.file,
|
fname=self.args.file,
|
||||||
cwd=self.args.cwd,
|
|
||||||
wdir=self.args.wdir,
|
wdir=self.args.wdir,
|
||||||
no_exec=self.args.no_exec,
|
no_exec=self.args.no_exec,
|
||||||
overwrite=overwrite,
|
overwrite=self.args.overwrite,
|
||||||
ignore_build_cache=self.args.ignore_build_cache,
|
run_cache=not self.args.no_run_cache,
|
||||||
remove_outs=self.args.remove_outs,
|
|
||||||
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,
|
||||||
|
single_stage=self.args.single_stage,
|
||||||
)
|
)
|
||||||
except DvcException:
|
except DvcException:
|
||||||
logger.exception("failed to run command")
|
logger.exception("")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@@ -77,7 +79,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):
|
||||||
@@ -95,6 +97,10 @@ def add_parser(subparsers, parent_parser):
|
|||||||
action="append",
|
action="append",
|
||||||
default=[],
|
default=[],
|
||||||
help="Declare dependencies for reproducible cmd.",
|
help="Declare dependencies for reproducible cmd.",
|
||||||
|
metavar="<path>",
|
||||||
|
)
|
||||||
|
run_parser.add_argument(
|
||||||
|
"-n", "--name", help="Stage name.",
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
"-o",
|
"-o",
|
||||||
@@ -102,6 +108,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
action="append",
|
action="append",
|
||||||
default=[],
|
default=[],
|
||||||
help="Declare output file or directory.",
|
help="Declare output file or directory.",
|
||||||
|
metavar="<filename>",
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
"-O",
|
"-O",
|
||||||
@@ -110,6 +117,15 @@ def add_parser(subparsers, parent_parser):
|
|||||||
default=[],
|
default=[],
|
||||||
help="Declare output file or directory "
|
help="Declare output file or directory "
|
||||||
"(do not put into DVC cache).",
|
"(do not put into DVC cache).",
|
||||||
|
metavar="<filename>",
|
||||||
|
)
|
||||||
|
run_parser.add_argument(
|
||||||
|
"-p",
|
||||||
|
"--params",
|
||||||
|
action="append",
|
||||||
|
default=[],
|
||||||
|
help="Declare parameter to use as additional dependency.",
|
||||||
|
metavar="[<filename>:]<params_list>",
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
"-m",
|
"-m",
|
||||||
@@ -117,6 +133,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
action="append",
|
action="append",
|
||||||
default=[],
|
default=[],
|
||||||
help="Declare output metric file or directory.",
|
help="Declare output metric file or directory.",
|
||||||
|
metavar="<path>",
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
"-M",
|
"-M",
|
||||||
@@ -125,17 +142,33 @@ def add_parser(subparsers, parent_parser):
|
|||||||
default=[],
|
default=[],
|
||||||
help="Declare output metric file or directory "
|
help="Declare output metric file or directory "
|
||||||
"(do not put into DVC cache).",
|
"(do not put into DVC cache).",
|
||||||
|
metavar="<path>",
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
"-f", "--file", help="Specify name of the DVC-file it generates."
|
"--plots",
|
||||||
|
action="append",
|
||||||
|
default=[],
|
||||||
|
help="Declare output plot file.",
|
||||||
|
metavar="<path>",
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
"-c", "--cwd", help="Deprecated, use -w and -f instead."
|
"--plots-no-cache",
|
||||||
|
action="append",
|
||||||
|
default=[],
|
||||||
|
help="Declare output plot file (do not put into DVC cache).",
|
||||||
|
metavar="<path>",
|
||||||
|
)
|
||||||
|
run_parser.add_argument(
|
||||||
|
"-f",
|
||||||
|
"--file",
|
||||||
|
help="Specify name of the DVC-file this command will generate.",
|
||||||
|
metavar="<filename>",
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
"-w",
|
"-w",
|
||||||
"--wdir",
|
"--wdir",
|
||||||
help="Directory within your repo to run your command in.",
|
help="Directory within your repo to run your command in.",
|
||||||
|
metavar="<path>",
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
"--no-exec",
|
"--no-exec",
|
||||||
@@ -144,30 +177,19 @@ 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",
|
"--overwrite",
|
||||||
"--yes",
|
|
||||||
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(
|
|
||||||
"--remove-outs",
|
|
||||||
action="store_true",
|
|
||||||
default=False,
|
|
||||||
help="Deprecated, this is now the default behavior",
|
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
"--no-commit",
|
"--no-commit",
|
||||||
@@ -181,6 +203,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
default=[],
|
default=[],
|
||||||
help="Declare output file or directory that will not be "
|
help="Declare output file or directory that will not be "
|
||||||
"removed upon repro.",
|
"removed upon repro.",
|
||||||
|
metavar="<filename>",
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
"--outs-persist-no-cache",
|
"--outs-persist-no-cache",
|
||||||
@@ -188,6 +211,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
default=[],
|
default=[],
|
||||||
help="Declare output file or directory that will not be "
|
help="Declare output file or directory that will not be "
|
||||||
"removed upon repro (do not put into DVC cache).",
|
"removed upon repro (do not put into DVC cache).",
|
||||||
|
metavar="<filename>",
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
"--always-changed",
|
"--always-changed",
|
||||||
@@ -195,6 +219,12 @@ 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(
|
run_parser.add_argument(
|
||||||
"command", nargs=argparse.REMAINDER, help="Command to execute."
|
"command", nargs=argparse.REMAINDER, help="Command to execute."
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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):
|
||||||
@@ -47,7 +46,9 @@ class CmdDataStatus(CmdDataBase):
|
|||||||
remote=self.args.remote,
|
remote=self.args.remote,
|
||||||
all_branches=self.args.all_branches,
|
all_branches=self.args.all_branches,
|
||||||
all_tags=self.args.all_tags,
|
all_tags=self.args.all_tags,
|
||||||
|
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 st:
|
||||||
if self.args.quiet:
|
if self.args.quiet:
|
||||||
|
|||||||
@@ -1,156 +0,0 @@
|
|||||||
import logging
|
|
||||||
|
|
||||||
from dvc.command.base import append_doc_link
|
|
||||||
from dvc.command.base import CmdBase
|
|
||||||
from dvc.command.base import fix_subparsers
|
|
||||||
from dvc.exceptions import DvcException
|
|
||||||
from dvc.utils import to_yaml_string
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class CmdTagAdd(CmdBase):
|
|
||||||
def run(self):
|
|
||||||
for target in self.args.targets:
|
|
||||||
try:
|
|
||||||
self.repo.tag.add(
|
|
||||||
self.args.tag,
|
|
||||||
target=target,
|
|
||||||
with_deps=self.args.with_deps,
|
|
||||||
recursive=self.args.recursive,
|
|
||||||
)
|
|
||||||
except DvcException:
|
|
||||||
logger.exception("failed to add tag")
|
|
||||||
return 1
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
class CmdTagRemove(CmdBase):
|
|
||||||
def run(self):
|
|
||||||
for target in self.args.targets:
|
|
||||||
try:
|
|
||||||
self.repo.tag.remove(
|
|
||||||
self.args.tag,
|
|
||||||
target=target,
|
|
||||||
with_deps=self.args.with_deps,
|
|
||||||
recursive=self.args.recursive,
|
|
||||||
)
|
|
||||||
except DvcException:
|
|
||||||
logger.exception("failed to remove tag")
|
|
||||||
return 1
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
class CmdTagList(CmdBase):
|
|
||||||
def run(self):
|
|
||||||
for target in self.args.targets:
|
|
||||||
try:
|
|
||||||
tags = self.repo.tag.list(
|
|
||||||
target,
|
|
||||||
with_deps=self.args.with_deps,
|
|
||||||
recursive=self.args.recursive,
|
|
||||||
)
|
|
||||||
if tags:
|
|
||||||
logger.info(to_yaml_string(tags))
|
|
||||||
except DvcException:
|
|
||||||
logger.exception("failed list tags")
|
|
||||||
return 1
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
def add_parser(subparsers, parent_parser):
|
|
||||||
TAG_HELP = "A set of commands to manage DVC tags."
|
|
||||||
tag_parser = subparsers.add_parser(
|
|
||||||
"tag",
|
|
||||||
parents=[parent_parser],
|
|
||||||
description=append_doc_link(TAG_HELP, "tag"),
|
|
||||||
add_help=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
tag_subparsers = tag_parser.add_subparsers(
|
|
||||||
dest="cmd",
|
|
||||||
help="Use DVC tag CMD --help to display command-specific help.",
|
|
||||||
)
|
|
||||||
|
|
||||||
fix_subparsers(tag_subparsers)
|
|
||||||
|
|
||||||
TAG_ADD_HELP = "Add DVC tag."
|
|
||||||
tag_add_parser = tag_subparsers.add_parser(
|
|
||||||
"add",
|
|
||||||
parents=[parent_parser],
|
|
||||||
description=append_doc_link(TAG_ADD_HELP, "tag-add"),
|
|
||||||
help=TAG_ADD_HELP,
|
|
||||||
)
|
|
||||||
tag_add_parser.add_argument("tag", help="Dvc tag.")
|
|
||||||
tag_add_parser.add_argument(
|
|
||||||
"targets", nargs="*", default=[None], help="DVC-files."
|
|
||||||
)
|
|
||||||
tag_add_parser.add_argument(
|
|
||||||
"-d",
|
|
||||||
"--with-deps",
|
|
||||||
action="store_true",
|
|
||||||
default=False,
|
|
||||||
help="Add tag for all dependencies of the specified DVC-file.",
|
|
||||||
)
|
|
||||||
tag_add_parser.add_argument(
|
|
||||||
"-R",
|
|
||||||
"--recursive",
|
|
||||||
action="store_true",
|
|
||||||
default=False,
|
|
||||||
help="Add tag for subdirectories of the specified directory.",
|
|
||||||
)
|
|
||||||
tag_add_parser.set_defaults(func=CmdTagAdd)
|
|
||||||
|
|
||||||
TAG_REMOVE_HELP = "Remove DVC tag."
|
|
||||||
tag_remove_parser = tag_subparsers.add_parser(
|
|
||||||
"remove",
|
|
||||||
parents=[parent_parser],
|
|
||||||
description=append_doc_link(TAG_REMOVE_HELP, "tag-remove"),
|
|
||||||
help=TAG_REMOVE_HELP,
|
|
||||||
)
|
|
||||||
tag_remove_parser.add_argument("tag", help="Dvc tag.")
|
|
||||||
tag_remove_parser.add_argument(
|
|
||||||
"targets", nargs="*", default=[None], help="DVC-files."
|
|
||||||
)
|
|
||||||
tag_remove_parser.add_argument(
|
|
||||||
"-d",
|
|
||||||
"--with-deps",
|
|
||||||
action="store_true",
|
|
||||||
default=False,
|
|
||||||
help="Remove tag for all dependencies of the specified DVC-file.",
|
|
||||||
)
|
|
||||||
tag_remove_parser.add_argument(
|
|
||||||
"-R",
|
|
||||||
"--recursive",
|
|
||||||
action="store_true",
|
|
||||||
default=False,
|
|
||||||
help="Remove tag for subdirectories of the specified directory.",
|
|
||||||
)
|
|
||||||
tag_remove_parser.set_defaults(func=CmdTagRemove)
|
|
||||||
|
|
||||||
TAG_LIST_HELP = "List DVC tags."
|
|
||||||
tag_list_parser = tag_subparsers.add_parser(
|
|
||||||
"list",
|
|
||||||
parents=[parent_parser],
|
|
||||||
description=append_doc_link(TAG_LIST_HELP, "tag-list"),
|
|
||||||
help=TAG_LIST_HELP,
|
|
||||||
)
|
|
||||||
tag_list_parser.add_argument(
|
|
||||||
"targets", nargs="*", default=[None], help="DVC-files."
|
|
||||||
)
|
|
||||||
tag_list_parser.add_argument(
|
|
||||||
"-d",
|
|
||||||
"--with-deps",
|
|
||||||
action="store_true",
|
|
||||||
default=False,
|
|
||||||
help="List tags for all dependencies of the specified DVC-file.",
|
|
||||||
)
|
|
||||||
tag_list_parser.add_argument(
|
|
||||||
"-R",
|
|
||||||
"--recursive",
|
|
||||||
action="store_true",
|
|
||||||
default=False,
|
|
||||||
help="List tags for subdirectories of the specified directory.",
|
|
||||||
)
|
|
||||||
tag_list_parser.set_defaults(func=CmdTagList)
|
|
||||||
@@ -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
|
||||||
|
|||||||
+21
-10
@@ -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
|
||||||
|
|
||||||
|
|
||||||
@@ -34,6 +35,16 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"targets", nargs="+", help="DVC-files to update."
|
"targets", nargs="+", help="DVC-files to update."
|
||||||
)
|
)
|
||||||
update_parser.add_argument(
|
update_parser.add_argument(
|
||||||
"--rev", nargs="?", help="Git revision (e.g. SHA, branch, tag)"
|
"--rev",
|
||||||
|
nargs="?",
|
||||||
|
help="Git revision (e.g. SHA, branch, tag)",
|
||||||
|
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)
|
||||||
|
|||||||
+36
-18
@@ -2,21 +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.system import System
|
|
||||||
from dvc.utils.pkg import PKG
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -26,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:
|
||||||
@@ -49,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(
|
||||||
@@ -62,10 +64,15 @@ class CmdVersion(CmdBaseNoRepo):
|
|||||||
|
|
||||||
except NotDvcRepoError:
|
except NotDvcRepoError:
|
||||||
root_directory = os.getcwd()
|
root_directory = os.getcwd()
|
||||||
|
except SCMError:
|
||||||
|
root_directory = os.getcwd()
|
||||||
|
info.append("Repo: dvc, git (broken)")
|
||||||
|
else:
|
||||||
|
info.append("Repo: {}".format(_get_dvc_repo_info(repo)))
|
||||||
|
|
||||||
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
|
||||||
@@ -108,7 +115,7 @@ 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)
|
||||||
@@ -125,9 +132,20 @@ class CmdVersion(CmdBaseNoRepo):
|
|||||||
return ", ".join(supported_remotes)
|
return ", ".join(supported_remotes)
|
||||||
|
|
||||||
|
|
||||||
def add_parser(subparsers, parent_parser):
|
def _get_dvc_repo_info(repo):
|
||||||
VERSION_HELP = "Show DVC version and system/environment information."
|
if repo.config.get("core", {}).get("no_scm", False):
|
||||||
|
return "dvc (no_scm)"
|
||||||
|
|
||||||
|
if repo.root_dir != repo.scm.root_dir:
|
||||||
|
return "dvc (subdir), git"
|
||||||
|
|
||||||
|
return "dvc, git"
|
||||||
|
|
||||||
|
|
||||||
|
def add_parser(subparsers, parent_parser):
|
||||||
|
VERSION_HELP = (
|
||||||
|
"Display the DVC version and system/environment information."
|
||||||
|
)
|
||||||
version_parser = subparsers.add_parser(
|
version_parser = subparsers.add_parser(
|
||||||
"version",
|
"version",
|
||||||
parents=[parent_parser],
|
parents=[parent_parser],
|
||||||
|
|||||||
@@ -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
|
|
||||||
+55
-23
@@ -1,16 +1,27 @@
|
|||||||
"""DVC config objects."""
|
"""DVC config objects."""
|
||||||
from contextlib import contextmanager
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
from contextlib import contextmanager
|
||||||
|
from functools import partial
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from funcy import cached_property, re_find, walk_values, compact
|
|
||||||
import configobj
|
import configobj
|
||||||
from voluptuous import Schema, Optional, Invalid, ALLOW_EXTRA
|
from funcy import cached_property, compact, re_find, walk_values
|
||||||
from voluptuous import All, Any, Lower, Range, Coerce
|
from voluptuous import (
|
||||||
|
ALLOW_EXTRA,
|
||||||
|
All,
|
||||||
|
Any,
|
||||||
|
Coerce,
|
||||||
|
Invalid,
|
||||||
|
Lower,
|
||||||
|
Optional,
|
||||||
|
Range,
|
||||||
|
Schema,
|
||||||
|
)
|
||||||
|
|
||||||
from dvc.exceptions import DvcException, NotDvcRepoError
|
from dvc.exceptions import DvcException, NotDvcRepoError
|
||||||
|
from dvc.path_info import PathInfo
|
||||||
from dvc.utils import relpath
|
from dvc.utils import relpath
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -20,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):
|
||||||
@@ -78,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)
|
||||||
|
|
||||||
@@ -92,7 +103,7 @@ class RelPath(str):
|
|||||||
REMOTE_COMMON = {
|
REMOTE_COMMON = {
|
||||||
"url": str,
|
"url": str,
|
||||||
"checksum_jobs": All(Coerce(int), Range(1)),
|
"checksum_jobs": All(Coerce(int), Range(1)),
|
||||||
"no_traverse": Bool,
|
Optional("no_traverse"): Bool, # obsoleted
|
||||||
"verify": Bool,
|
"verify": Bool,
|
||||||
}
|
}
|
||||||
LOCAL_COMMON = {
|
LOCAL_COMMON = {
|
||||||
@@ -140,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,
|
||||||
@@ -179,6 +191,7 @@ SCHEMA = {
|
|||||||
"gdrive_service_account_email": str,
|
"gdrive_service_account_email": str,
|
||||||
"gdrive_service_account_user_email": str,
|
"gdrive_service_account_user_email": str,
|
||||||
"gdrive_service_account_p12_file_path": str,
|
"gdrive_service_account_p12_file_path": str,
|
||||||
|
Optional("gdrive_trash_only", default=False): Bool,
|
||||||
**REMOTE_COMMON,
|
**REMOTE_COMMON,
|
||||||
},
|
},
|
||||||
"http": {**HTTP_COMMON, **REMOTE_COMMON},
|
"http": {**HTTP_COMMON, **REMOTE_COMMON},
|
||||||
@@ -277,10 +290,7 @@ class Config(dict):
|
|||||||
Raises:
|
Raises:
|
||||||
ConfigError: thrown if config has an invalid format.
|
ConfigError: thrown if config has an invalid format.
|
||||||
"""
|
"""
|
||||||
conf = {}
|
conf = self.load_config_to_level()
|
||||||
for level in self.LEVELS:
|
|
||||||
if level in self.files:
|
|
||||||
_merge(conf, self.load_one(level))
|
|
||||||
|
|
||||||
if validate:
|
if validate:
|
||||||
conf = self.validate(conf)
|
conf = self.validate(conf)
|
||||||
@@ -296,7 +306,7 @@ class Config(dict):
|
|||||||
conf = _load_config(self.files[level])
|
conf = _load_config(self.files[level])
|
||||||
conf = self._load_paths(conf, self.files[level])
|
conf = self._load_paths(conf, self.files[level])
|
||||||
|
|
||||||
# Autovivify sections
|
# Auto-verify sections
|
||||||
for key in COMPILED_SCHEMA.schema:
|
for key in COMPILED_SCHEMA.schema:
|
||||||
conf.setdefault(key, {})
|
conf.setdefault(key, {})
|
||||||
|
|
||||||
@@ -313,25 +323,42 @@ class Config(dict):
|
|||||||
|
|
||||||
return Config._map_dirs(conf, resolve)
|
return Config._map_dirs(conf, resolve)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _to_relpath(conf_dir, path):
|
||||||
|
if re.match(r"\w+://", path):
|
||||||
|
return path
|
||||||
|
|
||||||
|
if isinstance(path, RelPath) or not os.path.isabs(path):
|
||||||
|
path = relpath(path, conf_dir)
|
||||||
|
|
||||||
|
return PathInfo(path).as_posix()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _save_paths(conf, filename):
|
def _save_paths(conf, filename):
|
||||||
conf_dir = os.path.dirname(filename)
|
conf_dir = os.path.dirname(filename)
|
||||||
|
rel = partial(Config._to_relpath, conf_dir)
|
||||||
def rel(path):
|
|
||||||
if re.match(r"\w+://", path):
|
|
||||||
return path
|
|
||||||
|
|
||||||
if isinstance(path, RelPath) or not os.path.isabs(path):
|
|
||||||
return relpath(path, conf_dir)
|
|
||||||
return path
|
|
||||||
|
|
||||||
return Config._map_dirs(conf, rel)
|
return Config._map_dirs(conf, rel)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _map_dirs(conf, func):
|
def _map_dirs(conf, func):
|
||||||
dirs_schema = {"cache": {"dir": func}, "remote": {str: {"url": func}}}
|
dirs_schema = {
|
||||||
|
"cache": {"dir": func},
|
||||||
|
"remote": {
|
||||||
|
str: {"url": func, "gdrive_user_credentials_file": func}
|
||||||
|
},
|
||||||
|
}
|
||||||
return Schema(dirs_schema, extra=ALLOW_EXTRA)(conf)
|
return Schema(dirs_schema, extra=ALLOW_EXTRA)(conf)
|
||||||
|
|
||||||
|
def load_config_to_level(self, level=None):
|
||||||
|
merged_conf = {}
|
||||||
|
for merge_level in self.LEVELS:
|
||||||
|
if merge_level == level:
|
||||||
|
break
|
||||||
|
if merge_level in self.files:
|
||||||
|
_merge(merged_conf, self.load_one(merge_level))
|
||||||
|
return merged_conf
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def edit(self, level="repo"):
|
def edit(self, level="repo"):
|
||||||
if level in {"repo", "local"} and self.dvc_dir is None:
|
if level in {"repo", "local"} and self.dvc_dir is None:
|
||||||
@@ -341,6 +368,11 @@ class Config(dict):
|
|||||||
yield conf
|
yield conf
|
||||||
|
|
||||||
conf = self._save_paths(conf, self.files[level])
|
conf = self._save_paths(conf, self.files[level])
|
||||||
|
|
||||||
|
merged_conf = self.load_config_to_level(level)
|
||||||
|
_merge(merged_conf, conf)
|
||||||
|
self.validate(merged_conf)
|
||||||
|
|
||||||
_save_config(self.files[level], conf)
|
_save_config(self.files[level], conf)
|
||||||
self.load()
|
self.load()
|
||||||
|
|
||||||
@@ -358,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))
|
||||||
@@ -385,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
-5
@@ -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__)
|
||||||
|
|
||||||
@@ -68,7 +66,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 +75,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):
|
||||||
|
|||||||
+12
-16
@@ -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:
|
||||||
@@ -95,14 +92,13 @@ class AsciiCanvas(object):
|
|||||||
self.cols = cols
|
self.cols = cols
|
||||||
self.lines = lines
|
self.lines = lines
|
||||||
|
|
||||||
self.canvas = [[" "] * cols for l in range(lines)]
|
self.canvas = [[" "] * cols for line in range(lines)]
|
||||||
|
|
||||||
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()
|
||||||
|
|||||||
+26
-22
@@ -5,11 +5,10 @@ import logging
|
|||||||
from dvc.config import NoRemoteError
|
from dvc.config import NoRemoteError
|
||||||
from dvc.remote import Remote
|
from dvc.remote import 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:
|
||||||
@@ -23,12 +22,12 @@ class DataCloud(object):
|
|||||||
def __init__(self, repo):
|
def __init__(self, repo):
|
||||||
self.repo = repo
|
self.repo = repo
|
||||||
|
|
||||||
def get_remote(self, remote=None, command="<command>"):
|
def get_remote(self, name=None, command="<command>"):
|
||||||
if not remote:
|
if not name:
|
||||||
remote = self.repo.config["core"].get("remote")
|
name = self.repo.config["core"].get("remote")
|
||||||
|
|
||||||
if remote:
|
if name:
|
||||||
return self._init_remote(remote)
|
return self._init_remote(name)
|
||||||
|
|
||||||
if bool(self.repo.config["remote"]):
|
if bool(self.repo.config["remote"]):
|
||||||
error_msg = (
|
error_msg = (
|
||||||
@@ -45,39 +44,43 @@ class DataCloud(object):
|
|||||||
|
|
||||||
raise NoRemoteError(error_msg)
|
raise NoRemoteError(error_msg)
|
||||||
|
|
||||||
def _init_remote(self, remote):
|
def _init_remote(self, name):
|
||||||
return Remote(self.repo, name=remote)
|
return 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:
|
||||||
cache (NamedCache): named checksums to push to the cloud.
|
cache (NamedCache): named checksums to push to the cloud.
|
||||||
jobs (int): number of jobs that can be running simultaneously.
|
jobs (int): number of jobs that can be running simultaneously.
|
||||||
remote (dvc.remote.base.RemoteBASE): optional remote to push to.
|
remote (dvc.remote.base.BaseRemote): optional remote to push to.
|
||||||
By default remote from core.remote config option is used.
|
By default remote from core.remote config option is used.
|
||||||
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:
|
||||||
cache (NamedCache): named checksums to pull from the cloud.
|
cache (NamedCache): named checksums to pull from the cloud.
|
||||||
jobs (int): number of jobs that can be running simultaneously.
|
jobs (int): number of jobs that can be running simultaneously.
|
||||||
remote (dvc.remote.base.RemoteBASE): optional remote to pull from.
|
remote (dvc.remote.base.BaseRemote): optional remote to pull from.
|
||||||
By default remote from core.remote config option is used.
|
By default remote from core.remote config option is used.
|
||||||
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, "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
|
||||||
)
|
)
|
||||||
@@ -88,12 +91,13 @@ class DataCloud(object):
|
|||||||
return downloaded_items_num
|
return downloaded_items_num
|
||||||
|
|
||||||
def _save_pulled_checksums(self, cache):
|
def _save_pulled_checksums(self, cache):
|
||||||
for checksum in cache["local"].keys():
|
for checksum in cache.scheme_keys("local"):
|
||||||
cache_file = self.repo.cache.local.checksum_to_path_info(checksum)
|
cache_file = self.repo.cache.local.checksum_to_path_info(checksum)
|
||||||
if self.repo.cache.local.exists(cache_file):
|
if self.repo.cache.local.exists(cache_file):
|
||||||
# We can safely save here, as existing corrupted files will be
|
# We can safely save here, as existing corrupted files will
|
||||||
# removed upon status, while files corrupted during download
|
# be removed upon status, while files corrupted during
|
||||||
# will not be moved from tmp_file (see `RemoteBASE.download()`)
|
# download will not be moved from tmp_file
|
||||||
|
# (see `RemoteBASE.download()`)
|
||||||
self.repo.state.save(cache_file, checksum)
|
self.repo.state.save(cache_file, checksum)
|
||||||
|
|
||||||
def status(self, cache, jobs=None, remote=None, show_checksums=False):
|
def status(self, cache, jobs=None, remote=None, show_checksums=False):
|
||||||
@@ -102,7 +106,7 @@ class DataCloud(object):
|
|||||||
Args:
|
Args:
|
||||||
cache (NamedCache): named checksums to check status for.
|
cache (NamedCache): named checksums to check status for.
|
||||||
jobs (int): number of jobs that can be running simultaneously.
|
jobs (int): number of jobs that can be running simultaneously.
|
||||||
remote (dvc.remote.base.RemoteBASE): optional remote to compare
|
remote (dvc.remote.base.BaseRemote): optional remote to compare
|
||||||
cache to. By default remote from core.remote config option
|
cache to. By default remote from core.remote config option
|
||||||
is used.
|
is used.
|
||||||
show_checksums (bool): show checksums instead of file names in
|
show_checksums (bool): show checksums instead of file names in
|
||||||
|
|||||||
+69
-35
@@ -1,37 +1,42 @@
|
|||||||
|
from collections import defaultdict
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import dvc.output as output
|
import dvc.output as output
|
||||||
from dvc.dependency.gs import DependencyGS
|
from dvc.dependency.azure import AzureDependency
|
||||||
from dvc.dependency.hdfs import DependencyHDFS
|
from dvc.dependency.gs import GSDependency
|
||||||
from dvc.dependency.http import DependencyHTTP
|
from dvc.dependency.hdfs import HDFSDependency
|
||||||
from dvc.dependency.https import DependencyHTTPS
|
from dvc.dependency.http import HTTPDependency
|
||||||
from dvc.dependency.local import DependencyLOCAL
|
from dvc.dependency.https import HTTPSDependency
|
||||||
from dvc.dependency.s3 import DependencyS3
|
from dvc.dependency.local import LocalDependency
|
||||||
from dvc.dependency.ssh import DependencySSH
|
from dvc.dependency.param import ParamsDependency
|
||||||
from dvc.output.base import OutputBase
|
from dvc.dependency.s3 import S3Dependency
|
||||||
|
from dvc.dependency.ssh import SSHDependency
|
||||||
|
from dvc.output.base import BaseOutput
|
||||||
from dvc.remote import Remote
|
from dvc.remote import Remote
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
from .repo import DependencyREPO
|
|
||||||
|
|
||||||
|
from .repo import RepoDependency
|
||||||
|
|
||||||
DEPS = [
|
DEPS = [
|
||||||
DependencyGS,
|
AzureDependency,
|
||||||
DependencyHDFS,
|
GSDependency,
|
||||||
DependencyHTTP,
|
HDFSDependency,
|
||||||
DependencyHTTPS,
|
HTTPDependency,
|
||||||
DependencyS3,
|
HTTPSDependency,
|
||||||
DependencySSH,
|
S3Dependency,
|
||||||
# NOTE: DependencyLOCAL is the default choice
|
SSHDependency,
|
||||||
|
# NOTE: LocalDependency is the default choice
|
||||||
]
|
]
|
||||||
|
|
||||||
DEP_MAP = {
|
DEP_MAP = {
|
||||||
Schemes.LOCAL: DependencyLOCAL,
|
Schemes.LOCAL: LocalDependency,
|
||||||
Schemes.SSH: DependencySSH,
|
Schemes.SSH: SSHDependency,
|
||||||
Schemes.S3: DependencyS3,
|
Schemes.S3: S3Dependency,
|
||||||
Schemes.GS: DependencyGS,
|
Schemes.AZURE: AzureDependency,
|
||||||
Schemes.HDFS: DependencyHDFS,
|
Schemes.GS: GSDependency,
|
||||||
Schemes.HTTP: DependencyHTTP,
|
Schemes.HDFS: HDFSDependency,
|
||||||
Schemes.HTTPS: DependencyHTTPS,
|
Schemes.HTTP: HTTPDependency,
|
||||||
|
Schemes.HTTPS: HTTPSDependency,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -40,32 +45,36 @@ DEP_MAP = {
|
|||||||
# cached, see -o and -O flags for `dvc run`) and 'metric' (whether or not
|
# cached, see -o and -O flags for `dvc run`) and 'metric' (whether or not
|
||||||
# output is a metric file and how to parse it, see `-M` flag for `dvc run`).
|
# output is a metric file and how to parse it, see `-M` flag for `dvc run`).
|
||||||
SCHEMA = output.SCHEMA.copy()
|
SCHEMA = output.SCHEMA.copy()
|
||||||
del SCHEMA[OutputBase.PARAM_CACHE]
|
del SCHEMA[BaseOutput.PARAM_CACHE]
|
||||||
del SCHEMA[OutputBase.PARAM_METRIC]
|
del SCHEMA[BaseOutput.PARAM_METRIC]
|
||||||
SCHEMA[DependencyREPO.PARAM_REPO] = DependencyREPO.REPO_SCHEMA
|
SCHEMA.update(RepoDependency.REPO_SCHEMA)
|
||||||
|
SCHEMA.update(ParamsDependency.PARAM_SCHEMA)
|
||||||
|
|
||||||
|
|
||||||
def _get(stage, p, info):
|
def _get(stage, p, info):
|
||||||
parsed = urlparse(p)
|
parsed = urlparse(p) if p else None
|
||||||
|
if parsed and parsed.scheme == "remote":
|
||||||
if parsed.scheme == "remote":
|
|
||||||
remote = Remote(stage.repo, name=parsed.netloc)
|
remote = 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(DependencyREPO.PARAM_REPO):
|
if info and info.get(RepoDependency.PARAM_REPO):
|
||||||
repo = info.pop(DependencyREPO.PARAM_REPO)
|
repo = info.pop(RepoDependency.PARAM_REPO)
|
||||||
return DependencyREPO(repo, stage, p, info)
|
return RepoDependency(repo, stage, p, info)
|
||||||
|
|
||||||
|
if info and info.get(ParamsDependency.PARAM_PARAMS):
|
||||||
|
params = info.pop(ParamsDependency.PARAM_PARAMS)
|
||||||
|
return ParamsDependency(stage, p, params)
|
||||||
|
|
||||||
for d in DEPS:
|
for d in DEPS:
|
||||||
if d.supported(p):
|
if d.supported(p):
|
||||||
return d(stage, p, info)
|
return d(stage, p, info)
|
||||||
return DependencyLOCAL(stage, p, info)
|
return LocalDependency(stage, p, info)
|
||||||
|
|
||||||
|
|
||||||
def loadd_from(stage, d_list):
|
def loadd_from(stage, d_list):
|
||||||
ret = []
|
ret = []
|
||||||
for d in d_list:
|
for d in d_list:
|
||||||
p = d.pop(OutputBase.PARAM_PATH)
|
p = d.pop(BaseOutput.PARAM_PATH, None)
|
||||||
ret.append(_get(stage, p, d))
|
ret.append(_get(stage, p, d))
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@@ -73,6 +82,31 @@ def loadd_from(stage, d_list):
|
|||||||
def loads_from(stage, s_list, erepo=None):
|
def loads_from(stage, s_list, erepo=None):
|
||||||
ret = []
|
ret = []
|
||||||
for s in s_list:
|
for s in s_list:
|
||||||
info = {DependencyREPO.PARAM_REPO: erepo} if erepo else {}
|
info = {RepoDependency.PARAM_REPO: erepo} if erepo else {}
|
||||||
ret.append(_get(stage, s, info))
|
ret.append(_get(stage, s, info))
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
def _parse_params(path_params):
|
||||||
|
path, _, params_str = path_params.rpartition(":")
|
||||||
|
params = params_str.split(",")
|
||||||
|
return path, params
|
||||||
|
|
||||||
|
|
||||||
|
def loads_params(stage, s_list):
|
||||||
|
# Creates an object for each unique file that is referenced in the list
|
||||||
|
params_by_path = defaultdict(list)
|
||||||
|
for s in s_list:
|
||||||
|
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 AzureRemote
|
||||||
|
|
||||||
|
|
||||||
|
class AzureDependency(BaseDependency, BaseOutput):
|
||||||
|
REMOTE = AzureRemote
|
||||||
@@ -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 DependencyBase(object):
|
class BaseDependency:
|
||||||
IS_DEPENDENCY = True
|
IS_DEPENDENCY = True
|
||||||
|
|
||||||
DoesNotExistError = DependencyDoesNotExistError
|
DoesNotExistError = DependencyDoesNotExistError
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from dvc.dependency.base import DependencyBase
|
from dvc.dependency.base import BaseDependency
|
||||||
from dvc.output.gs import OutputGS
|
from dvc.output.gs import GSOutput
|
||||||
|
|
||||||
|
|
||||||
class DependencyGS(DependencyBase, OutputGS):
|
class GSDependency(BaseDependency, GSOutput):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from dvc.dependency.base import DependencyBase
|
from dvc.dependency.base import BaseDependency
|
||||||
from dvc.output.hdfs import OutputHDFS
|
from dvc.output.hdfs import HDFSOutput
|
||||||
|
|
||||||
|
|
||||||
class DependencyHDFS(DependencyBase, OutputHDFS):
|
class HDFSDependency(BaseDependency, HDFSOutput):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from dvc.dependency.base import DependencyBase
|
from dvc.dependency.base import BaseDependency
|
||||||
from dvc.output.base import OutputBase
|
from dvc.output.base import BaseOutput
|
||||||
from dvc.remote.http import RemoteHTTP
|
from dvc.remote.http import HTTPRemote
|
||||||
|
|
||||||
|
|
||||||
class DependencyHTTP(DependencyBase, OutputBase):
|
class HTTPDependency(BaseDependency, BaseOutput):
|
||||||
REMOTE = RemoteHTTP
|
REMOTE = HTTPRemote
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from .http import DependencyHTTP
|
from dvc.remote.https import HTTPSRemote
|
||||||
from dvc.remote.https import RemoteHTTPS
|
|
||||||
|
from .http import HTTPDependency
|
||||||
|
|
||||||
|
|
||||||
class DependencyHTTPS(DependencyHTTP):
|
class HTTPSDependency(HTTPDependency):
|
||||||
REMOTE = RemoteHTTPS
|
REMOTE = HTTPSRemote
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from dvc.dependency.base import DependencyBase
|
from dvc.dependency.base import BaseDependency
|
||||||
from dvc.output.local import OutputLOCAL
|
from dvc.output.local import LocalOutput
|
||||||
|
|
||||||
|
|
||||||
class DependencyLOCAL(DependencyBase, OutputLOCAL):
|
class LocalDependency(BaseDependency, LocalOutput):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -0,0 +1,116 @@
|
|||||||
|
import os
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
|
import dpath.util
|
||||||
|
import yaml
|
||||||
|
from voluptuous import Any
|
||||||
|
|
||||||
|
from dvc.dependency.local import LocalDependency
|
||||||
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
|
|
||||||
|
class MissingParamsError(DvcException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class BadParamFileError(DvcException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ParamsDependency(LocalDependency):
|
||||||
|
PARAM_PARAMS = "params"
|
||||||
|
PARAM_SCHEMA = {PARAM_PARAMS: Any(dict, list, None)}
|
||||||
|
DEFAULT_PARAMS_FILE = "params.yaml"
|
||||||
|
|
||||||
|
def __init__(self, stage, path, params):
|
||||||
|
info = {}
|
||||||
|
self.params = []
|
||||||
|
if params:
|
||||||
|
if isinstance(params, list):
|
||||||
|
self.params = params
|
||||||
|
else:
|
||||||
|
assert isinstance(params, dict)
|
||||||
|
self.params = list(params.keys())
|
||||||
|
info = params
|
||||||
|
|
||||||
|
super().__init__(
|
||||||
|
stage,
|
||||||
|
path
|
||||||
|
or os.path.join(stage.repo.root_dir, self.DEFAULT_PARAMS_FILE),
|
||||||
|
info=info,
|
||||||
|
)
|
||||||
|
|
||||||
|
def _dyn_load(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):
|
||||||
|
super().save()
|
||||||
|
self.info = self.save_info()
|
||||||
|
|
||||||
|
def status(self):
|
||||||
|
status = super().status()
|
||||||
|
|
||||||
|
if status[str(self)] == "deleted":
|
||||||
|
return status
|
||||||
|
|
||||||
|
status = defaultdict(dict)
|
||||||
|
info = self.read_params()
|
||||||
|
for param in self.params:
|
||||||
|
if param not in info.keys():
|
||||||
|
st = "deleted"
|
||||||
|
elif param not in self.info:
|
||||||
|
st = "new"
|
||||||
|
elif info[param] != self.info[param]:
|
||||||
|
st = "modified"
|
||||||
|
else:
|
||||||
|
assert info[param] == self.info[param]
|
||||||
|
continue
|
||||||
|
|
||||||
|
status[str(self)][param] = st
|
||||||
|
|
||||||
|
return status
|
||||||
|
|
||||||
|
def dumpd(self):
|
||||||
|
return {
|
||||||
|
self.PARAM_PATH: self.def_path,
|
||||||
|
self.PARAM_PARAMS: self.info or self.params,
|
||||||
|
}
|
||||||
|
|
||||||
|
def read_params(self):
|
||||||
|
if not self.exists:
|
||||||
|
return {}
|
||||||
|
|
||||||
|
with self.repo.tree.open(self.path_info, "r") as fobj:
|
||||||
|
try:
|
||||||
|
config = yaml.safe_load(fobj)
|
||||||
|
except yaml.YAMLError as exc:
|
||||||
|
raise BadParamFileError(
|
||||||
|
f"Unable to read parameters from '{self}'"
|
||||||
|
) from exc
|
||||||
|
|
||||||
|
ret = {}
|
||||||
|
for param in self.params:
|
||||||
|
try:
|
||||||
|
ret[param] = dpath.util.get(config, param, separator=".")
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def save_info(self):
|
||||||
|
info = self.read_params()
|
||||||
|
|
||||||
|
missing_params = set(self.params) - set(info.keys())
|
||||||
|
if missing_params:
|
||||||
|
raise MissingParamsError(
|
||||||
|
"Parameters '{}' are missing from '{}'.".format(
|
||||||
|
", ".join(missing_params), self,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return info
|
||||||
+26
-12
@@ -2,21 +2,24 @@ import os
|
|||||||
|
|
||||||
from voluptuous import Required
|
from voluptuous import Required
|
||||||
|
|
||||||
from .local import DependencyLOCAL
|
|
||||||
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 DependencyREPO(DependencyLOCAL):
|
|
||||||
|
class RepoDependency(LocalDependency):
|
||||||
PARAM_REPO = "repo"
|
PARAM_REPO = "repo"
|
||||||
PARAM_URL = "url"
|
PARAM_URL = "url"
|
||||||
PARAM_REV = "rev"
|
PARAM_REV = "rev"
|
||||||
PARAM_REV_LOCK = "rev_lock"
|
PARAM_REV_LOCK = "rev_lock"
|
||||||
|
|
||||||
REPO_SCHEMA = {
|
REPO_SCHEMA = {
|
||||||
Required(PARAM_URL): str,
|
PARAM_REPO: {
|
||||||
PARAM_REV: str,
|
Required(PARAM_URL): str,
|
||||||
PARAM_REV_LOCK: str,
|
PARAM_REV: str,
|
||||||
|
PARAM_REV_LOCK: str,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, def_repo, stage, *args, **kwargs):
|
def __init__(self, def_repo, stage, *args, **kwargs):
|
||||||
@@ -47,13 +50,24 @@ class DependencyREPO(DependencyLOCAL):
|
|||||||
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_dir_checksum(
|
||||||
|
path, tree=tree
|
||||||
|
)
|
||||||
|
return tree.get_file_checksum(path)
|
||||||
|
|
||||||
def status(self):
|
def status(self):
|
||||||
current_checksum = self._get_checksum(locked=True)
|
current_checksum = self._get_checksum(locked=True)
|
||||||
@@ -73,16 +87,16 @@ class DependencyREPO(DependencyLOCAL):
|
|||||||
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()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from dvc.dependency.base import DependencyBase
|
from dvc.dependency.base import BaseDependency
|
||||||
from dvc.output.s3 import OutputS3
|
from dvc.output.s3 import S3Output
|
||||||
|
|
||||||
|
|
||||||
class DependencyS3(DependencyBase, OutputS3):
|
class S3Dependency(BaseDependency, S3Output):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from dvc.dependency.base import DependencyBase
|
from dvc.dependency.base import BaseDependency
|
||||||
from dvc.output.ssh import OutputSSH
|
from dvc.output.ssh import SSHOutput
|
||||||
|
|
||||||
|
|
||||||
class DependencySSH(DependencyBase, OutputSSH):
|
class SSHDependency(BaseDependency, SSHOutput):
|
||||||
pass
|
pass
|
||||||
|
|||||||
+315
@@ -0,0 +1,315 @@
|
|||||||
|
import contextlib
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
from voluptuous import MultipleInvalid
|
||||||
|
|
||||||
|
import dvc.prompt as prompt
|
||||||
|
from dvc import serialize
|
||||||
|
from dvc.exceptions import DvcException
|
||||||
|
from dvc.stage.exceptions import (
|
||||||
|
StageFileAlreadyExistsError,
|
||||||
|
StageFileBadNameError,
|
||||||
|
StageFileDoesNotExistError,
|
||||||
|
StageFileFormatError,
|
||||||
|
StageFileIsNotDvcFileError,
|
||||||
|
)
|
||||||
|
from dvc.stage.loader import SingleStageLoader, StageLoader
|
||||||
|
from dvc.utils import relpath
|
||||||
|
from dvc.utils.collections import apply_diff
|
||||||
|
from dvc.utils.yaml import dump_yaml, parse_yaml, parse_yaml_for_update
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
DVC_FILE = "Dvcfile"
|
||||||
|
DVC_FILE_SUFFIX = ".dvc"
|
||||||
|
PIPELINE_FILE = "dvc.yaml"
|
||||||
|
PIPELINE_LOCK = "dvc.lock"
|
||||||
|
|
||||||
|
|
||||||
|
class LockfileCorruptedError(DvcException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def is_valid_filename(path):
|
||||||
|
return path.endswith(DVC_FILE_SUFFIX) or os.path.basename(path) in [
|
||||||
|
DVC_FILE,
|
||||||
|
PIPELINE_FILE,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def is_dvc_file(path):
|
||||||
|
return os.path.isfile(path) and (
|
||||||
|
is_valid_filename(path) or os.path.basename(path) == PIPELINE_LOCK
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def check_dvc_filename(path):
|
||||||
|
if not is_valid_filename(path):
|
||||||
|
raise StageFileBadNameError(
|
||||||
|
"bad DVC-file name '{}'. DVC-files should be named "
|
||||||
|
"'Dvcfile' or have a '.dvc' suffix (e.g. '{}.dvc').".format(
|
||||||
|
relpath(path), os.path.basename(path)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class FileMixin:
|
||||||
|
SCHEMA = None
|
||||||
|
|
||||||
|
def __init__(self, repo, path, **kwargs):
|
||||||
|
self.repo = repo
|
||||||
|
self.path = path
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "{}: {}".format(
|
||||||
|
self.__class__.__name__, relpath(self.path, self.repo.root_dir)
|
||||||
|
)
|
||||||
|
|
||||||
|
def __hash__(self):
|
||||||
|
return hash(self.path)
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return self.repo == other.repo and os.path.abspath(
|
||||||
|
self.path
|
||||||
|
) == os.path.abspath(other.path)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.__class__.__name__}: {self.relpath}"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def relpath(self):
|
||||||
|
return relpath(self.path)
|
||||||
|
|
||||||
|
def exists(self):
|
||||||
|
return self.repo.tree.exists(self.path)
|
||||||
|
|
||||||
|
def _load(self):
|
||||||
|
# it raises the proper exceptions by priority:
|
||||||
|
# 1. when the file doesn't exists
|
||||||
|
# 2. filename is not a DVC-file
|
||||||
|
# 3. path doesn't represent a regular file
|
||||||
|
if not self.exists():
|
||||||
|
raise StageFileDoesNotExistError(self.path)
|
||||||
|
check_dvc_filename(self.path)
|
||||||
|
if not self.repo.tree.isfile(self.path):
|
||||||
|
raise StageFileIsNotDvcFileError(self.path)
|
||||||
|
|
||||||
|
with self.repo.tree.open(self.path) as fd:
|
||||||
|
stage_text = fd.read()
|
||||||
|
d = parse_yaml(stage_text, self.path)
|
||||||
|
self.validate(d, self.relpath)
|
||||||
|
return d, stage_text
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def validate(cls, d, fname=None):
|
||||||
|
assert cls.SCHEMA
|
||||||
|
try:
|
||||||
|
cls.SCHEMA(d)
|
||||||
|
except MultipleInvalid as exc:
|
||||||
|
raise StageFileFormatError(f"'{fname}' format error: {exc}")
|
||||||
|
|
||||||
|
def remove_with_prompt(self, force=False):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def remove(self, force=False):
|
||||||
|
with contextlib.suppress(FileNotFoundError):
|
||||||
|
os.unlink(self.path)
|
||||||
|
|
||||||
|
def dump(self, stage, **kwargs):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
|
class SingleStageFile(FileMixin):
|
||||||
|
from dvc.schema import COMPILED_SINGLE_STAGE_SCHEMA as SCHEMA
|
||||||
|
|
||||||
|
def __init__(self, repo, path):
|
||||||
|
super().__init__(repo, path)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def stage(self):
|
||||||
|
data, raw = self._load()
|
||||||
|
return SingleStageLoader.load_stage(self, data, raw)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def stages(self):
|
||||||
|
data, raw = self._load()
|
||||||
|
return SingleStageLoader(self, data, raw)
|
||||||
|
|
||||||
|
def dump(self, stage, **kwargs):
|
||||||
|
"""Dumps given stage appropriately in the dvcfile."""
|
||||||
|
from dvc.stage import PipelineStage
|
||||||
|
|
||||||
|
assert not isinstance(stage, PipelineStage)
|
||||||
|
check_dvc_filename(self.path)
|
||||||
|
logger.debug(
|
||||||
|
"Saving information to '{file}'.".format(file=relpath(self.path))
|
||||||
|
)
|
||||||
|
dump_yaml(self.path, serialize.to_single_stage_file(stage))
|
||||||
|
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)
|
||||||
|
|
||||||
|
self.remove()
|
||||||
|
|
||||||
|
def remove_stage(self, stage):
|
||||||
|
self.remove()
|
||||||
|
|
||||||
|
|
||||||
|
class PipelineFile(FileMixin):
|
||||||
|
"""Abstraction for pipelines file, .yaml + .lock combined."""
|
||||||
|
|
||||||
|
from dvc.schema import COMPILED_MULTI_STAGE_SCHEMA as SCHEMA
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _lockfile(self):
|
||||||
|
return Lockfile(self.repo, os.path.splitext(self.path)[0] + ".lock")
|
||||||
|
|
||||||
|
def dump(self, stage, update_pipeline=False, no_lock=False):
|
||||||
|
"""Dumps given stage appropriately in the dvcfile."""
|
||||||
|
from dvc.stage import PipelineStage
|
||||||
|
|
||||||
|
assert isinstance(stage, PipelineStage)
|
||||||
|
check_dvc_filename(self.path)
|
||||||
|
|
||||||
|
if update_pipeline and not stage.is_data_source:
|
||||||
|
self._dump_pipeline_file(stage)
|
||||||
|
|
||||||
|
if not no_lock:
|
||||||
|
self._dump_lockfile(stage)
|
||||||
|
|
||||||
|
def _dump_lockfile(self, stage):
|
||||||
|
self._lockfile.dump(stage)
|
||||||
|
|
||||||
|
def _dump_pipeline_file(self, stage):
|
||||||
|
data = {}
|
||||||
|
if self.exists():
|
||||||
|
with open(self.path) as fd:
|
||||||
|
data = parse_yaml_for_update(fd.read(), self.path)
|
||||||
|
else:
|
||||||
|
logger.info("Creating '%s'", self.relpath)
|
||||||
|
open(self.path, "w+").close()
|
||||||
|
|
||||||
|
data["stages"] = data.get("stages", {})
|
||||||
|
stage_data = serialize.to_pipeline_file(stage)
|
||||||
|
if data["stages"].get(stage.name):
|
||||||
|
orig_stage_data = data["stages"][stage.name]
|
||||||
|
apply_diff(stage_data[stage.name], orig_stage_data)
|
||||||
|
else:
|
||||||
|
data["stages"].update(stage_data)
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
"Adding stage '%s' to '%s'", stage.name, self.relpath,
|
||||||
|
)
|
||||||
|
dump_yaml(self.path, data)
|
||||||
|
self.repo.scm.track_file(self.relpath)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def stage(self):
|
||||||
|
raise DvcException(
|
||||||
|
"PipelineFile has multiple stages. Please specify it's name."
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def stages(self):
|
||||||
|
data, _ = self._load()
|
||||||
|
lockfile_data = self._lockfile.load()
|
||||||
|
return StageLoader(self, data.get("stages", {}), lockfile_data)
|
||||||
|
|
||||||
|
def remove(self, force=False):
|
||||||
|
if not force:
|
||||||
|
logger.warning("Cannot remove pipeline file.")
|
||||||
|
return
|
||||||
|
|
||||||
|
super().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):
|
||||||
|
from dvc.schema import COMPILED_LOCKFILE_SCHEMA as SCHEMA
|
||||||
|
|
||||||
|
def load(self):
|
||||||
|
if not self.exists():
|
||||||
|
return {}
|
||||||
|
with self.repo.tree.open(self.path) as fd:
|
||||||
|
data = parse_yaml(fd.read(), self.path)
|
||||||
|
try:
|
||||||
|
self.validate(data, fname=self.relpath)
|
||||||
|
except StageFileFormatError:
|
||||||
|
raise LockfileCorruptedError(
|
||||||
|
f"Lockfile '{self.relpath}' is corrupted."
|
||||||
|
)
|
||||||
|
return data
|
||||||
|
|
||||||
|
def dump(self, stage, **kwargs):
|
||||||
|
stage_data = serialize.to_lockfile(stage)
|
||||||
|
if not self.exists():
|
||||||
|
modified = True
|
||||||
|
logger.info("Generating lock file '%s'", self.relpath)
|
||||||
|
data = stage_data
|
||||||
|
open(self.path, "w+").close()
|
||||||
|
else:
|
||||||
|
with self.repo.tree.open(self.path, "r") as fd:
|
||||||
|
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)
|
||||||
|
dump_yaml(self.path, data)
|
||||||
|
if modified:
|
||||||
|
self.repo.scm.track_file(self.relpath)
|
||||||
|
|
||||||
|
def remove_stage(self, stage):
|
||||||
|
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:
|
||||||
|
def __new__(cls, repo, path, **kwargs):
|
||||||
|
assert path
|
||||||
|
assert repo
|
||||||
|
|
||||||
|
_, ext = os.path.splitext(path)
|
||||||
|
if ext in [".yaml", ".yml"]:
|
||||||
|
return PipelineFile(repo, path, **kwargs)
|
||||||
|
# fallback to single stage file for better error messages
|
||||||
|
return SingleStageFile(repo, path, **kwargs)
|
||||||
+51
-47
@@ -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,12 +28,17 @@ 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"
|
output, first(stages)
|
||||||
"This is not allowed. Consider using a different output name."
|
)
|
||||||
).format(output, "\n ".join(s.relpath for s in stages))
|
else:
|
||||||
|
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.output = output
|
||||||
|
|
||||||
|
|
||||||
class OutputNotFoundError(DvcException):
|
class OutputNotFoundError(DvcException):
|
||||||
@@ -60,8 +70,8 @@ class StagePathAsOutputError(DvcException):
|
|||||||
def __init__(self, stage, output):
|
def __init__(self, stage, output):
|
||||||
assert isinstance(output, str)
|
assert isinstance(output, str)
|
||||||
super().__init__(
|
super().__init__(
|
||||||
"'{stage}' is within an output '{output}' of another stage".format(
|
"{stage} is within an output '{output}' of another stage".format(
|
||||||
stage=stage.relpath, output=output
|
stage=stage, output=output
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -77,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))
|
||||||
|
|
||||||
|
|
||||||
@@ -94,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):
|
||||||
@@ -129,12 +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("\t- {}".format(stage.relpath) for stage in stages)
|
msg = "Pipeline has a cycle involving: {}.".format(
|
||||||
msg = (
|
", ".join(s.addressing for s in stages)
|
||||||
"you've introduced a cycle in your pipeline that involves "
|
|
||||||
"the following stages:"
|
|
||||||
"\n"
|
|
||||||
"{stages}".format(stages=stages)
|
|
||||||
)
|
)
|
||||||
super().__init__(msg)
|
super().__init__(msg)
|
||||||
|
|
||||||
@@ -142,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)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -154,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):
|
||||||
@@ -162,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)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -170,17 +173,16 @@ 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 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)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -200,7 +202,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):
|
||||||
@@ -214,9 +216,7 @@ class ETagMismatchError(DvcException):
|
|||||||
class FileMissingError(DvcException):
|
class FileMissingError(DvcException):
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
self.path = path
|
self.path = path
|
||||||
super().__init__(
|
super().__init__(f"Can't find '{path}' neither locally nor on remote")
|
||||||
"Can't find '{}' neither locally nor on remote".format(path)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class DvcIgnoreInCollectedDirError(DvcException):
|
class DvcIgnoreInCollectedDirError(DvcException):
|
||||||
@@ -241,18 +241,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):
|
||||||
@@ -274,7 +270,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}'."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -289,7 +285,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):
|
||||||
@@ -297,19 +293,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):
|
||||||
@@ -329,3 +321,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}'"
|
||||||
|
)
|
||||||
|
|||||||
+136
-90
@@ -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,99 @@ 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,
|
||||||
|
None,
|
||||||
|
tree=self.repo_tree,
|
||||||
|
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,14 +168,23 @@ 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):
|
||||||
return
|
return
|
||||||
|
|
||||||
remote_name = self.config["core"].get("remote")
|
|
||||||
src_repo = Repo(self.url)
|
|
||||||
try:
|
try:
|
||||||
|
src_repo = Repo(self.url)
|
||||||
|
except NotDvcRepoError:
|
||||||
|
# If ExternalRepo does not throw NotDvcRepoError and Repo does,
|
||||||
|
# the self.url might be a bare git repo.
|
||||||
|
# NOTE: This will fail to resolve remote with relative path,
|
||||||
|
# same as if it was a remote DVC repo.
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
remote_name = self.config["core"].get("remote")
|
||||||
if remote_name:
|
if remote_name:
|
||||||
self._fix_local_remote(src_repo, remote_name)
|
self._fix_local_remote(src_repo, remote_name)
|
||||||
else:
|
else:
|
||||||
@@ -154,10 +209,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):
|
||||||
@@ -170,22 +226,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."""
|
||||||
|
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)
|
||||||
|
|
||||||
@@ -197,14 +246,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")
|
||||||
@@ -212,11 +259,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
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+103
-22
@@ -5,13 +5,14 @@ from funcy import cached_property
|
|||||||
from pathspec import PathSpec
|
from pathspec import PathSpec
|
||||||
from pathspec.patterns import GitWildMatchPattern
|
from pathspec.patterns import GitWildMatchPattern
|
||||||
|
|
||||||
|
from dvc.path_info import PathInfo
|
||||||
from dvc.scm.tree import BaseTree
|
from dvc.scm.tree import BaseTree
|
||||||
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):
|
||||||
@@ -35,12 +36,19 @@ 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)
|
|
||||||
|
return self.ignore_spec.match_file(path)
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash(self.ignore_file_path)
|
return hash(self.ignore_file_path)
|
||||||
@@ -76,21 +84,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,36 +116,108 @@ 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):
|
||||||
|
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
|
||||||
|
|
||||||
|
# if path is outside of tree, assume this is a local remote/local cache
|
||||||
|
# link/move operation where we do not need to filter ignores
|
||||||
|
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 True
|
||||||
|
|
||||||
|
# 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")
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
|
|||||||
+51
-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):
|
||||||
@@ -143,6 +172,7 @@ def _stack_trace(exc_info):
|
|||||||
|
|
||||||
|
|
||||||
def disable_other_loggers():
|
def disable_other_loggers():
|
||||||
|
logging.captureWarnings(True)
|
||||||
root = logging.root
|
root = logging.root
|
||||||
for (logger_name, logger) in root.manager.loggerDict.items():
|
for (logger_name, logger) in root.manager.loggerDict.items():
|
||||||
if logger_name != "dvc" and not logger_name.startswith("dvc."):
|
if logger_name != "dvc" and not logger_name.startswith("dvc."):
|
||||||
@@ -152,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": {
|
||||||
@@ -175,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",
|
||||||
@@ -188,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
-11
@@ -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")
|
||||||
|
|
||||||
|
|
||||||
@@ -33,18 +31,23 @@ def main(argv=None):
|
|||||||
int: command's return code.
|
int: command's return code.
|
||||||
"""
|
"""
|
||||||
args = None
|
args = None
|
||||||
cmd = None
|
|
||||||
disable_other_loggers()
|
disable_other_loggers()
|
||||||
|
|
||||||
outerLogLevel = logger.level
|
outerLogLevel = logger.level
|
||||||
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()
|
||||||
@@ -59,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(
|
||||||
|
|||||||
+54
-54
@@ -1,32 +1,33 @@
|
|||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from voluptuous import Any, Required, Lower, Length, Coerce, And, SetTo
|
|
||||||
|
|
||||||
from dvc.output.base import OutputBase
|
from voluptuous import And, Any, Coerce, Length, Lower, Required, SetTo
|
||||||
from dvc.output.gs import OutputGS
|
|
||||||
from dvc.output.hdfs import OutputHDFS
|
from dvc.output.base import BaseOutput
|
||||||
from dvc.output.local import OutputLOCAL
|
from dvc.output.gs import GSOutput
|
||||||
from dvc.output.s3 import OutputS3
|
from dvc.output.hdfs import HDFSOutput
|
||||||
from dvc.output.ssh import OutputSSH
|
from dvc.output.local import LocalOutput
|
||||||
|
from dvc.output.s3 import S3Output
|
||||||
|
from dvc.output.ssh import SSHOutput
|
||||||
from dvc.remote import Remote
|
from dvc.remote import Remote
|
||||||
from dvc.remote.hdfs import RemoteHDFS
|
from dvc.remote.hdfs import HDFSRemote
|
||||||
from dvc.remote.local import RemoteLOCAL
|
from dvc.remote.local import LocalRemote
|
||||||
from dvc.remote.s3 import RemoteS3
|
from dvc.remote.s3 import S3Remote
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
|
|
||||||
OUTS = [
|
OUTS = [
|
||||||
OutputHDFS,
|
HDFSOutput,
|
||||||
OutputS3,
|
S3Output,
|
||||||
OutputGS,
|
GSOutput,
|
||||||
OutputSSH,
|
SSHOutput,
|
||||||
# NOTE: OutputLOCAL is the default choice
|
# NOTE: LocalOutput is the default choice
|
||||||
]
|
]
|
||||||
|
|
||||||
OUTS_MAP = {
|
OUTS_MAP = {
|
||||||
Schemes.HDFS: OutputHDFS,
|
Schemes.HDFS: HDFSOutput,
|
||||||
Schemes.S3: OutputS3,
|
Schemes.S3: S3Output,
|
||||||
Schemes.GS: OutputGS,
|
Schemes.GS: GSOutput,
|
||||||
Schemes.SSH: OutputSSH,
|
Schemes.SSH: SSHOutput,
|
||||||
Schemes.LOCAL: OutputLOCAL,
|
Schemes.LOCAL: LocalOutput,
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECKSUM_SCHEMA = Any(
|
CHECKSUM_SCHEMA = Any(
|
||||||
@@ -44,22 +45,20 @@ 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 = {
|
||||||
RemoteLOCAL.PARAM_CHECKSUM: CHECKSUM_SCHEMA,
|
LocalRemote.PARAM_CHECKSUM: CHECKSUM_SCHEMA,
|
||||||
RemoteS3.PARAM_CHECKSUM: CHECKSUM_SCHEMA,
|
S3Remote.PARAM_CHECKSUM: CHECKSUM_SCHEMA,
|
||||||
RemoteHDFS.PARAM_CHECKSUM: CHECKSUM_SCHEMA,
|
HDFSRemote.PARAM_CHECKSUM: CHECKSUM_SCHEMA,
|
||||||
}
|
}
|
||||||
|
|
||||||
TAGS_SCHEMA = {str: CHECKSUMS_SCHEMA}
|
|
||||||
|
|
||||||
SCHEMA = CHECKSUMS_SCHEMA.copy()
|
SCHEMA = CHECKSUMS_SCHEMA.copy()
|
||||||
SCHEMA[Required(OutputBase.PARAM_PATH)] = str
|
SCHEMA[Required(BaseOutput.PARAM_PATH)] = str
|
||||||
SCHEMA[OutputBase.PARAM_CACHE] = bool
|
SCHEMA[BaseOutput.PARAM_CACHE] = bool
|
||||||
SCHEMA[OutputBase.PARAM_METRIC] = OutputBase.METRIC_SCHEMA
|
SCHEMA[BaseOutput.PARAM_METRIC] = BaseOutput.METRIC_SCHEMA
|
||||||
SCHEMA[OutputBase.PARAM_TAGS] = TAGS_SCHEMA
|
SCHEMA[BaseOutput.PARAM_PLOT] = bool
|
||||||
SCHEMA[OutputBase.PARAM_PERSIST] = bool
|
SCHEMA[BaseOutput.PARAM_PERSIST] = bool
|
||||||
|
|
||||||
|
|
||||||
def _get(stage, p, info, cache, metric, persist=False, tags=None):
|
def _get(stage, p, info, cache, metric, plot=False, persist=False):
|
||||||
parsed = urlparse(p)
|
parsed = urlparse(p)
|
||||||
|
|
||||||
if parsed.scheme == "remote":
|
if parsed.scheme == "remote":
|
||||||
@@ -71,8 +70,8 @@ def _get(stage, p, info, cache, metric, persist=False, tags=None):
|
|||||||
cache=cache,
|
cache=cache,
|
||||||
remote=remote,
|
remote=remote,
|
||||||
metric=metric,
|
metric=metric,
|
||||||
|
plot=plot,
|
||||||
persist=persist,
|
persist=persist,
|
||||||
tags=tags,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
for o in OUTS:
|
for o in OUTS:
|
||||||
@@ -84,29 +83,29 @@ def _get(stage, p, info, cache, metric, persist=False, tags=None):
|
|||||||
cache=cache,
|
cache=cache,
|
||||||
remote=None,
|
remote=None,
|
||||||
metric=metric,
|
metric=metric,
|
||||||
|
plot=plot,
|
||||||
persist=persist,
|
persist=persist,
|
||||||
tags=tags,
|
|
||||||
)
|
)
|
||||||
return OutputLOCAL(
|
return LocalOutput(
|
||||||
stage,
|
stage,
|
||||||
p,
|
p,
|
||||||
info,
|
info,
|
||||||
cache=cache,
|
cache=cache,
|
||||||
remote=None,
|
remote=None,
|
||||||
metric=metric,
|
metric=metric,
|
||||||
|
plot=plot,
|
||||||
persist=persist,
|
persist=persist,
|
||||||
tags=tags,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def loadd_from(stage, d_list):
|
def loadd_from(stage, d_list):
|
||||||
ret = []
|
ret = []
|
||||||
for d in d_list:
|
for d in d_list:
|
||||||
p = d.pop(OutputBase.PARAM_PATH)
|
p = d.pop(BaseOutput.PARAM_PATH)
|
||||||
cache = d.pop(OutputBase.PARAM_CACHE, True)
|
cache = d.pop(BaseOutput.PARAM_CACHE, True)
|
||||||
metric = d.pop(OutputBase.PARAM_METRIC, False)
|
metric = d.pop(BaseOutput.PARAM_METRIC, False)
|
||||||
persist = d.pop(OutputBase.PARAM_PERSIST, False)
|
plot = d.pop(BaseOutput.PARAM_PLOT, False)
|
||||||
tags = d.pop(OutputBase.PARAM_TAGS, None)
|
persist = d.pop(BaseOutput.PARAM_PERSIST, False)
|
||||||
ret.append(
|
ret.append(
|
||||||
_get(
|
_get(
|
||||||
stage,
|
stage,
|
||||||
@@ -114,24 +113,25 @@ def loadd_from(stage, d_list):
|
|||||||
info=d,
|
info=d,
|
||||||
cache=cache,
|
cache=cache,
|
||||||
metric=metric,
|
metric=metric,
|
||||||
|
plot=plot,
|
||||||
persist=persist,
|
persist=persist,
|
||||||
tags=tags,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def loads_from(stage, s_list, use_cache=True, metric=False, persist=False):
|
def loads_from(
|
||||||
ret = []
|
stage, s_list, use_cache=True, metric=False, plot=False, persist=False
|
||||||
for s in s_list:
|
):
|
||||||
ret.append(
|
return [
|
||||||
_get(
|
_get(
|
||||||
stage,
|
stage,
|
||||||
s,
|
s,
|
||||||
info={},
|
info={},
|
||||||
cache=use_cache,
|
cache=use_cache,
|
||||||
metric=metric,
|
metric=metric,
|
||||||
persist=persist,
|
plot=plot,
|
||||||
)
|
persist=persist,
|
||||||
)
|
)
|
||||||
return ret
|
for s in s_list
|
||||||
|
]
|
||||||
|
|||||||
+108
-67
@@ -1,52 +1,67 @@
|
|||||||
import logging
|
import logging
|
||||||
from urllib.parse import urlparse
|
import os
|
||||||
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 RemoteBASE
|
DvcException,
|
||||||
|
RemoteCacheRequiredError,
|
||||||
|
)
|
||||||
|
from dvc.remote.base import BaseRemote
|
||||||
|
|
||||||
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 OutputBase(object):
|
class BaseOutput:
|
||||||
IS_DEPENDENCY = False
|
IS_DEPENDENCY = False
|
||||||
|
|
||||||
REMOTE = RemoteBASE
|
REMOTE = BaseRemote
|
||||||
|
|
||||||
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_XLAB = "xlab"
|
||||||
|
PARAM_PLOT_YLAB = "ylab"
|
||||||
|
PARAM_PLOT_TITLE = "title"
|
||||||
|
PARAM_PLOT_CSV_HEADER = "csv_header"
|
||||||
PARAM_PERSIST = "persist"
|
PARAM_PERSIST = "persist"
|
||||||
|
|
||||||
METRIC_SCHEMA = Any(
|
METRIC_SCHEMA = Any(
|
||||||
@@ -58,8 +73,6 @@ class OutputBase(object):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
PARAM_TAGS = "tags"
|
|
||||||
|
|
||||||
DoesNotExistError = OutputDoesNotExistError
|
DoesNotExistError = OutputDoesNotExistError
|
||||||
IsNotFileOrDirError = OutputIsNotFileOrDirError
|
IsNotFileOrDirError = OutputIsNotFileOrDirError
|
||||||
IsStageFileError = OutputIsStageFileError
|
IsStageFileError = OutputIsStageFileError
|
||||||
@@ -74,8 +87,8 @@ class OutputBase(object):
|
|||||||
remote=None,
|
remote=None,
|
||||||
cache=True,
|
cache=True,
|
||||||
metric=False,
|
metric=False,
|
||||||
|
plot=False,
|
||||||
persist=False,
|
persist=False,
|
||||||
tags=None,
|
|
||||||
):
|
):
|
||||||
self._validate_output_path(path)
|
self._validate_output_path(path)
|
||||||
# This output (and dependency) objects have too many paths/urls
|
# This output (and dependency) objects have too many paths/urls
|
||||||
@@ -95,8 +108,8 @@ class OutputBase(object):
|
|||||||
self.remote = remote or self.REMOTE(self.repo, {})
|
self.remote = remote or self.REMOTE(self.repo, {})
|
||||||
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.tags = None if self.IS_DEPENDENCY else (tags or {})
|
|
||||||
|
|
||||||
self.path_info = self._parse_path(remote, path)
|
self.path_info = self._parse_path(remote, path)
|
||||||
if self.use_cache and self.cache is None:
|
if self.use_cache and self.cache is None:
|
||||||
@@ -147,10 +160,21 @@ class OutputBase(object):
|
|||||||
def cache_path(self):
|
def cache_path(self):
|
||||||
return self.cache.checksum_to_path_info(self.checksum).url
|
return self.cache.checksum_to_path_info(self.checksum).url
|
||||||
|
|
||||||
|
@property
|
||||||
|
def checksum_type(self):
|
||||||
|
return self.remote.PARAM_CHECKSUM
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def checksum(self):
|
def checksum(self):
|
||||||
return self.info.get(self.remote.PARAM_CHECKSUM)
|
return self.info.get(self.remote.PARAM_CHECKSUM)
|
||||||
|
|
||||||
|
@checksum.setter
|
||||||
|
def checksum(self, checksum):
|
||||||
|
self.info[self.remote.PARAM_CHECKSUM] = checksum
|
||||||
|
|
||||||
|
def get_checksum(self):
|
||||||
|
return self.remote.get_checksum(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_checksum(self.checksum)
|
||||||
@@ -159,8 +183,11 @@ class OutputBase(object):
|
|||||||
def exists(self):
|
def exists(self):
|
||||||
return self.remote.exists(self.path_info)
|
return self.remote.exists(self.path_info)
|
||||||
|
|
||||||
|
def save_info(self):
|
||||||
|
return self.remote.save_info(self.path_info)
|
||||||
|
|
||||||
def changed_checksum(self):
|
def changed_checksum(self):
|
||||||
return self.checksum != self.remote.get_checksum(self.path_info)
|
return self.checksum != self.get_checksum()
|
||||||
|
|
||||||
def changed_cache(self, filter_info=None):
|
def changed_cache(self, filter_info=None):
|
||||||
if not self.use_cache or not self.checksum:
|
if not self.use_cache or not self.checksum:
|
||||||
@@ -198,6 +225,15 @@ class OutputBase(object):
|
|||||||
def isfile(self):
|
def isfile(self):
|
||||||
return self.remote.isfile(self.path_info)
|
return self.remote.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:
|
||||||
raise self.DoesNotExistError(self)
|
raise self.DoesNotExistError(self)
|
||||||
@@ -206,35 +242,27 @@ class OutputBase(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 not self.use_cache:
|
if not self.use_cache:
|
||||||
self.info = self.remote.save_info(self.path_info)
|
self.info = self.save_info()
|
||||||
if self.metric:
|
if self.metric or self.plot:
|
||||||
self.verify_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.remote.save_info(self.path_info)
|
self.info = self.save_info()
|
||||||
|
|
||||||
def commit(self):
|
def commit(self):
|
||||||
if self.use_cache:
|
if self.use_cache:
|
||||||
@@ -247,7 +275,8 @@ class OutputBase(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 (
|
||||||
@@ -256,18 +285,19 @@ class OutputBase(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.tags:
|
if self.plot:
|
||||||
ret[self.PARAM_TAGS] = self.tags
|
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.download(self.path_info, to.path_info)
|
||||||
@@ -276,7 +306,6 @@ class OutputBase(object):
|
|||||||
self,
|
self,
|
||||||
force=False,
|
force=False,
|
||||||
progress_callback=None,
|
progress_callback=None,
|
||||||
tag=None,
|
|
||||||
relink=False,
|
relink=False,
|
||||||
filter_info=None,
|
filter_info=None,
|
||||||
):
|
):
|
||||||
@@ -287,14 +316,9 @@ class OutputBase(object):
|
|||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if tag:
|
|
||||||
info = self.tags[tag]
|
|
||||||
else:
|
|
||||||
info = self.info
|
|
||||||
|
|
||||||
return self.cache.checkout(
|
return self.cache.checkout(
|
||||||
self.path_info,
|
self.path_info,
|
||||||
info,
|
self.info,
|
||||||
force=force,
|
force=force,
|
||||||
progress_callback=progress_callback,
|
progress_callback=progress_callback,
|
||||||
relink=relink,
|
relink=relink,
|
||||||
@@ -334,7 +358,18 @@ class OutputBase(object):
|
|||||||
if self.exists:
|
if self.exists:
|
||||||
self.remote.unprotect(self.path_info)
|
self.remote.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.
|
||||||
@@ -358,16 +393,10 @@ class OutputBase(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 = (
|
||||||
@@ -383,11 +412,21 @@ class OutputBase(object):
|
|||||||
else:
|
else:
|
||||||
return cache
|
return cache
|
||||||
|
|
||||||
|
path = str(self.path_info)
|
||||||
|
filter_path = str(filter_info) if filter_info else None
|
||||||
|
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.PARAM_CHECKSUM]
|
||||||
info = self.path_info / entry[self.remote.PARAM_RELPATH]
|
entry_relpath = entry[self.remote.PARAM_RELPATH]
|
||||||
if not filter_info or info.isin_or_eq(filter_info):
|
if is_win:
|
||||||
cache.add(self.scheme, checksum, str(info))
|
entry_relpath = entry_relpath.replace("/", os.sep)
|
||||||
|
entry_path = os.path.join(path, entry_relpath)
|
||||||
|
if (
|
||||||
|
not filter_path
|
||||||
|
or entry_path == filter_path
|
||||||
|
or entry_path.startswith(filter_path + os.sep)
|
||||||
|
):
|
||||||
|
cache.add(self.scheme, checksum, entry_path)
|
||||||
|
|
||||||
return cache
|
return cache
|
||||||
|
|
||||||
@@ -420,9 +459,9 @@ class OutputBase(object):
|
|||||||
if self.exists:
|
if self.exists:
|
||||||
msg += (
|
msg += (
|
||||||
"\n"
|
"\n"
|
||||||
"You can also use `dvc commit {stage}` to associate "
|
"You can also use `dvc commit {stage.addressing}` "
|
||||||
"existing '{out}' with '{stage}'.".format(
|
"to associate existing '{out}' with {stage}.".format(
|
||||||
out=self, stage=self.stage.relpath
|
out=self, stage=self.stage
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
logger.warning(msg)
|
logger.warning(msg)
|
||||||
@@ -433,13 +472,15 @@ class OutputBase(object):
|
|||||||
if not self.is_dir_checksum:
|
if not self.is_dir_checksum:
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
ret.update(self._collect_used_dir_cache(**kwargs))
|
ret.add_child_cache(
|
||||||
|
self.checksum, self.collect_used_dir_cache(**kwargs),
|
||||||
|
)
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _validate_output_path(cls, path):
|
def _validate_output_path(cls, path):
|
||||||
from dvc.stage import Stage
|
from dvc.dvcfile import is_valid_filename
|
||||||
|
|
||||||
if Stage.is_valid_filename(path):
|
if is_valid_filename(path):
|
||||||
raise cls.IsStageFileError(path)
|
raise cls.IsStageFileError(path)
|
||||||
|
|||||||
+4
-4
@@ -1,6 +1,6 @@
|
|||||||
from dvc.output.s3 import OutputS3
|
from dvc.output.s3 import S3Output
|
||||||
from dvc.remote.gs import RemoteGS
|
from dvc.remote.gs import GSRemote
|
||||||
|
|
||||||
|
|
||||||
class OutputGS(OutputS3):
|
class GSOutput(S3Output):
|
||||||
REMOTE = RemoteGS
|
REMOTE = GSRemote
|
||||||
|
|||||||
+4
-4
@@ -1,6 +1,6 @@
|
|||||||
from dvc.output.base import OutputBase
|
from dvc.output.base import BaseOutput
|
||||||
from dvc.remote.hdfs import RemoteHDFS
|
from dvc.remote.hdfs import HDFSRemote
|
||||||
|
|
||||||
|
|
||||||
class OutputHDFS(OutputBase):
|
class HDFSOutput(BaseOutput):
|
||||||
REMOTE = RemoteHDFS
|
REMOTE = HDFSRemote
|
||||||
|
|||||||
+12
-13
@@ -4,18 +4,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 OutputBase
|
from dvc.output.base import BaseOutput
|
||||||
from dvc.remote.local import RemoteLOCAL
|
from dvc.remote.local import LocalRemote
|
||||||
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 OutputLOCAL(OutputBase):
|
class LocalOutput(BaseOutput):
|
||||||
REMOTE = RemoteLOCAL
|
REMOTE = LocalRemote
|
||||||
sep = os.sep
|
sep = os.sep
|
||||||
|
|
||||||
def __init__(self, stage, path, *args, **kwargs):
|
def __init__(self, stage, path, *args, **kwargs):
|
||||||
@@ -39,7 +37,7 @@ class OutputLOCAL(OutputBase):
|
|||||||
if not p.is_absolute():
|
if 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.REMOTE.path_cls(abs_p)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@@ -73,17 +71,18 @@ class OutputLOCAL(OutputBase):
|
|||||||
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 DvcException(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))
|
||||||
|
|||||||
+4
-4
@@ -1,6 +1,6 @@
|
|||||||
from dvc.output.base import OutputBase
|
from dvc.output.base import BaseOutput
|
||||||
from dvc.remote.s3 import RemoteS3
|
from dvc.remote.s3 import S3Remote
|
||||||
|
|
||||||
|
|
||||||
class OutputS3(OutputBase):
|
class S3Output(BaseOutput):
|
||||||
REMOTE = RemoteS3
|
REMOTE = S3Remote
|
||||||
|
|||||||
+4
-4
@@ -1,6 +1,6 @@
|
|||||||
from dvc.output.base import OutputBase
|
from dvc.output.base import BaseOutput
|
||||||
from dvc.remote.ssh import RemoteSSH
|
from dvc.remote.ssh import SSHRemote
|
||||||
|
|
||||||
|
|
||||||
class OutputSSH(OutputBase):
|
class SSHOutput(BaseOutput):
|
||||||
REMOTE = RemoteSSH
|
REMOTE = SSHRemote
|
||||||
|
|||||||
+14
-20
@@ -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)
|
||||||
@@ -33,10 +33,6 @@ class PathInfo(pathlib.PurePath, _BasePath):
|
|||||||
cls = WindowsPathInfo if os.name == "nt" else PosixPathInfo
|
cls = WindowsPathInfo if os.name == "nt" else PosixPathInfo
|
||||||
return cls._from_parts(args)
|
return cls._from_parts(args)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_posix(cls, s):
|
|
||||||
return cls(PosixPathInfo(s))
|
|
||||||
|
|
||||||
def as_posix(self):
|
def as_posix(self):
|
||||||
f = self._flavour
|
f = self._flavour
|
||||||
# Unlike original implementation [1] that uses `str()` we actually need
|
# Unlike original implementation [1] that uses `str()` we actually need
|
||||||
@@ -54,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)
|
||||||
|
|
||||||
@@ -92,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
|
||||||
@@ -104,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):
|
||||||
@@ -115,7 +110,7 @@ class URLInfo(_BasePath):
|
|||||||
assert not p.query and not p.params and not p.fragment
|
assert not p.query and not p.params and not p.fragment
|
||||||
assert p.password is None
|
assert p.password is None
|
||||||
|
|
||||||
self.fill_parts(p.scheme, p.hostname, p.username, p.port, p.path)
|
self._fill_parts(p.scheme, p.hostname, p.username, p.port, p.path)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_parts(
|
def from_parts(
|
||||||
@@ -124,13 +119,13 @@ 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)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def fill_parts(self, scheme, host, user, port, path):
|
def _fill_parts(self, scheme, host, user, port, path):
|
||||||
assert scheme != "remote"
|
assert scheme != "remote"
|
||||||
assert isinstance(path, (str, bytes, _URLPathInfo))
|
assert isinstance(path, (str, bytes, _URLPathInfo))
|
||||||
|
|
||||||
@@ -158,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
|
||||||
@@ -220,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)
|
||||||
|
|
||||||
@@ -244,6 +239,8 @@ class CloudURLInfo(URLInfo):
|
|||||||
|
|
||||||
|
|
||||||
class HTTPURLInfo(URLInfo):
|
class HTTPURLInfo(URLInfo):
|
||||||
|
__hash__ = URLInfo.__hash__
|
||||||
|
|
||||||
def __init__(self, url):
|
def __init__(self, url):
|
||||||
p = urlparse(url)
|
p = urlparse(url)
|
||||||
stripped = p._replace(params=None, query=None, fragment=None)
|
stripped = p._replace(params=None, query=None, fragment=None)
|
||||||
@@ -280,7 +277,7 @@ class HTTPURLInfo(URLInfo):
|
|||||||
)
|
)
|
||||||
|
|
||||||
obj = cls.__new__(cls)
|
obj = cls.__new__(cls)
|
||||||
obj.fill_parts(scheme, host, user, port, path)
|
obj._fill_parts(scheme, host, user, port, path)
|
||||||
obj.params = params
|
obj.params = params
|
||||||
obj.query = query
|
obj.query = query
|
||||||
obj.fragment = fragment
|
obj.fragment = fragment
|
||||||
@@ -314,6 +311,3 @@ class HTTPURLInfo(URLInfo):
|
|||||||
and self._path == other._path
|
and self._path == other._path
|
||||||
and self._extra_parts == other._extra_parts
|
and self._extra_parts == other._extra_parts
|
||||||
)
|
)
|
||||||
|
|
||||||
def __hash__(self):
|
|
||||||
return hash(self.parts)
|
|
||||||
|
|||||||
+38
-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):
|
||||||
@@ -114,13 +114,27 @@ class Tqdm(tqdm):
|
|||||||
self.total = total # pylint: disable=W0613,W0201
|
self.total = total # pylint: disable=W0613,W0201
|
||||||
self.update(current - self.n)
|
self.update(current - self.n)
|
||||||
|
|
||||||
|
def wrap_fn(self, fn, callback=None):
|
||||||
|
"""
|
||||||
|
Returns a wrapped `fn` which calls `callback()` on each call.
|
||||||
|
`callback` is `self.update` by default.
|
||||||
|
"""
|
||||||
|
if callback is None:
|
||||||
|
callback = self.update
|
||||||
|
|
||||||
|
def wrapped(*args, **kwargs):
|
||||||
|
res = fn(*args, **kwargs)
|
||||||
|
callback()
|
||||||
|
return res
|
||||||
|
|
||||||
|
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
|
||||||
@@ -128,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("")
|
||||||
|
|||||||
+21
-22
@@ -1,29 +1,28 @@
|
|||||||
import posixpath
|
import posixpath
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from dvc.remote.azure import RemoteAZURE
|
from dvc.remote.azure import AzureRemote
|
||||||
from dvc.remote.gdrive import RemoteGDrive
|
from dvc.remote.gdrive import GDriveRemote
|
||||||
from dvc.remote.gs import RemoteGS
|
from dvc.remote.gs import GSRemote
|
||||||
from dvc.remote.hdfs import RemoteHDFS
|
from dvc.remote.hdfs import HDFSRemote
|
||||||
from dvc.remote.http import RemoteHTTP
|
from dvc.remote.http import HTTPRemote
|
||||||
from dvc.remote.https import RemoteHTTPS
|
from dvc.remote.https import HTTPSRemote
|
||||||
from dvc.remote.local import RemoteLOCAL
|
from dvc.remote.local import LocalRemote
|
||||||
from dvc.remote.oss import RemoteOSS
|
from dvc.remote.oss import OSSRemote
|
||||||
from dvc.remote.s3 import RemoteS3
|
from dvc.remote.s3 import S3Remote
|
||||||
from dvc.remote.ssh import RemoteSSH
|
from dvc.remote.ssh import SSHRemote
|
||||||
|
|
||||||
|
|
||||||
REMOTES = [
|
REMOTES = [
|
||||||
RemoteAZURE,
|
AzureRemote,
|
||||||
RemoteGDrive,
|
GDriveRemote,
|
||||||
RemoteGS,
|
GSRemote,
|
||||||
RemoteHDFS,
|
HDFSRemote,
|
||||||
RemoteHTTP,
|
HTTPRemote,
|
||||||
RemoteHTTPS,
|
HTTPSRemote,
|
||||||
RemoteS3,
|
S3Remote,
|
||||||
RemoteSSH,
|
SSHRemote,
|
||||||
RemoteOSS,
|
OSSRemote,
|
||||||
# NOTE: RemoteLOCAL is the default
|
# NOTE: LocalRemote is the default
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -31,7 +30,7 @@ def _get(remote_conf):
|
|||||||
for remote in REMOTES:
|
for remote in REMOTES:
|
||||||
if remote.supported(remote_conf):
|
if remote.supported(remote_conf):
|
||||||
return remote
|
return remote
|
||||||
return RemoteLOCAL
|
return LocalRemote
|
||||||
|
|
||||||
|
|
||||||
def Remote(repo, **kwargs):
|
def Remote(repo, **kwargs):
|
||||||
|
|||||||
+37
-42
@@ -1,63 +1,39 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import posixpath
|
||||||
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 RemoteBASE
|
from dvc.remote.base import BaseRemote
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class RemoteAZURE(RemoteBASE):
|
class AzureRemote(BaseRemote):
|
||||||
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
|
||||||
|
LIST_OBJECT_PAGE_SIZE = 5000
|
||||||
|
|
||||||
def __init__(self, repo, config):
|
def __init__(self, repo, config):
|
||||||
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())
|
||||||
@@ -66,12 +42,12 @@ class RemoteAZURE(RemoteBASE):
|
|||||||
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
|
||||||
@@ -80,14 +56,23 @@ class RemoteAZURE(RemoteBASE):
|
|||||||
blob_service.create_container(self.path_info.bucket)
|
blob_service.create_container(self.path_info.bucket)
|
||||||
return blob_service
|
return blob_service
|
||||||
|
|
||||||
|
def get_etag(self, path_info):
|
||||||
|
etag = self.blob_service.get_blob_properties(
|
||||||
|
path_info.bucket, path_info.path
|
||||||
|
).properties.etag
|
||||||
|
return etag.strip('"')
|
||||||
|
|
||||||
|
def get_file_checksum(self, path_info):
|
||||||
|
return self.get_etag(path_info)
|
||||||
|
|
||||||
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 {}".format(path_info))
|
logger.debug(f"Removing {path_info}")
|
||||||
self.blob_service.delete_blob(path_info.bucket, path_info.path)
|
self.blob_service.delete_blob(path_info.bucket, path_info.path)
|
||||||
|
|
||||||
def _list_paths(self, bucket, prefix):
|
def _list_paths(self, bucket, prefix, progress_callback=None):
|
||||||
blob_service = self.blob_service
|
blob_service = self.blob_service
|
||||||
next_marker = None
|
next_marker = None
|
||||||
while True:
|
while True:
|
||||||
@@ -96,6 +81,8 @@ class RemoteAZURE(RemoteBASE):
|
|||||||
)
|
)
|
||||||
|
|
||||||
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:
|
||||||
@@ -103,8 +90,16 @@ class RemoteAZURE(RemoteBASE):
|
|||||||
|
|
||||||
next_marker = blobs.next_marker
|
next_marker = blobs.next_marker
|
||||||
|
|
||||||
def list_cache_paths(self):
|
def list_cache_paths(self, prefix=None, progress_callback=None):
|
||||||
return self._list_paths(self.path_info.bucket, self.path_info.path)
|
if prefix:
|
||||||
|
prefix = posixpath.join(
|
||||||
|
self.path_info.path, prefix[:2], prefix[2:]
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
prefix = self.path_info.path
|
||||||
|
return self._list_paths(
|
||||||
|
self.path_info.bucket, 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
|
||||||
|
|||||||
+431
-134
@@ -1,32 +1,35 @@
|
|||||||
import errno
|
import errno
|
||||||
|
import hashlib
|
||||||
import itertools
|
import itertools
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import tempfile
|
import tempfile
|
||||||
from urllib.parse import urlparse
|
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from copy import copy
|
from copy import copy
|
||||||
from functools import partial
|
from functools import partial, wraps
|
||||||
from multiprocessing import cpu_count
|
from multiprocessing import cpu_count
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from shortuuid import uuid
|
from shortuuid import uuid
|
||||||
|
|
||||||
import dvc.prompt as prompt
|
import dvc.prompt as prompt
|
||||||
from dvc.exceptions import (
|
from dvc.exceptions import (
|
||||||
CheckoutError,
|
CheckoutError,
|
||||||
DvcException,
|
|
||||||
ConfirmRemoveError,
|
ConfirmRemoveError,
|
||||||
|
DvcException,
|
||||||
DvcIgnoreInCollectedDirError,
|
DvcIgnoreInCollectedDirError,
|
||||||
RemoteCacheRequiredError,
|
RemoteCacheRequiredError,
|
||||||
)
|
)
|
||||||
from dvc.ignore import DvcIgnore
|
from dvc.ignore import DvcIgnore
|
||||||
from dvc.path_info import PathInfo, URLInfo
|
from dvc.path_info import PathInfo, URLInfo, WindowsPathInfo
|
||||||
from dvc.progress import Tqdm
|
from dvc.progress import Tqdm
|
||||||
|
from dvc.remote.index import RemoteIndex, RemoteIndexNoop
|
||||||
from dvc.remote.slow_link_detection import slow_link_guard
|
from dvc.remote.slow_link_detection import slow_link_guard
|
||||||
|
from dvc.scm.tree import is_working_tree
|
||||||
from dvc.state import StateNoop
|
from dvc.state import StateNoop
|
||||||
from dvc.utils import tmp_fname
|
from dvc.utils import tmp_fname
|
||||||
from dvc.utils.fs import move, makedirs
|
from dvc.utils.fs import makedirs, move
|
||||||
from dvc.utils.http import open_url
|
from dvc.utils.http import open_url
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -55,7 +58,7 @@ class RemoteCmdError(DvcException):
|
|||||||
|
|
||||||
class RemoteActionNotImplemented(DvcException):
|
class RemoteActionNotImplemented(DvcException):
|
||||||
def __init__(self, action, scheme):
|
def __init__(self, action, scheme):
|
||||||
m = "{} is not supported for {} remotes".format(action, scheme)
|
m = f"{action} is not supported for {scheme} remotes"
|
||||||
super().__init__(m)
|
super().__init__(m)
|
||||||
|
|
||||||
|
|
||||||
@@ -66,22 +69,37 @@ class RemoteMissingDepsError(DvcException):
|
|||||||
class DirCacheError(DvcException):
|
class DirCacheError(DvcException):
|
||||||
def __init__(self, checksum):
|
def __init__(self, checksum):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
"Failed to load dir cache for hash value: '{}'.".format(checksum)
|
f"Failed to load dir cache for hash value: '{checksum}'."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class RemoteBASE(object):
|
def index_locked(f):
|
||||||
|
@wraps(f)
|
||||||
|
def wrapper(remote_obj, *args, **kwargs):
|
||||||
|
remote = kwargs.get("remote", remote_obj)
|
||||||
|
with remote.index:
|
||||||
|
return f(remote_obj, *args, **kwargs)
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
class BaseRemote:
|
||||||
scheme = "base"
|
scheme = "base"
|
||||||
path_cls = URLInfo
|
path_cls = URLInfo
|
||||||
REQUIRES = {}
|
REQUIRES = {}
|
||||||
JOBS = 4 * cpu_count()
|
JOBS = 4 * cpu_count()
|
||||||
|
INDEX_CLS = RemoteIndex
|
||||||
|
|
||||||
PARAM_RELPATH = "relpath"
|
PARAM_RELPATH = "relpath"
|
||||||
CHECKSUM_DIR_SUFFIX = ".dir"
|
CHECKSUM_DIR_SUFFIX = ".dir"
|
||||||
CHECKSUM_JOBS = max(1, min(4, cpu_count() // 2))
|
CHECKSUM_JOBS = max(1, min(4, cpu_count() // 2))
|
||||||
DEFAULT_CACHE_TYPES = ["copy"]
|
DEFAULT_CACHE_TYPES = ["copy"]
|
||||||
DEFAULT_NO_TRAVERSE = True
|
|
||||||
DEFAULT_VERIFY = False
|
DEFAULT_VERIFY = False
|
||||||
|
LIST_OBJECT_PAGE_SIZE = 1000
|
||||||
|
TRAVERSE_WEIGHT_MULTIPLIER = 5
|
||||||
|
TRAVERSE_PREFIX_LEN = 3
|
||||||
|
TRAVERSE_THRESHOLD_SIZE = 500000
|
||||||
|
CAN_TRAVERSE = True
|
||||||
|
|
||||||
CACHE_MODE = None
|
CACHE_MODE = None
|
||||||
SHARED_MODE_MAP = {None: (None, None), "group": (None, None)}
|
SHARED_MODE_MAP = {None: (None, None), "group": (None, None)}
|
||||||
@@ -101,13 +119,21 @@ class RemoteBASE(object):
|
|||||||
or (self.repo and self.repo.config["core"].get("checksum_jobs"))
|
or (self.repo and self.repo.config["core"].get("checksum_jobs"))
|
||||||
or self.CHECKSUM_JOBS
|
or self.CHECKSUM_JOBS
|
||||||
)
|
)
|
||||||
self.no_traverse = config.get("no_traverse", self.DEFAULT_NO_TRAVERSE)
|
|
||||||
self.verify = config.get("verify", self.DEFAULT_VERIFY)
|
self.verify = config.get("verify", self.DEFAULT_VERIFY)
|
||||||
self._dir_info = {}
|
self._dir_info = {}
|
||||||
|
|
||||||
self.cache_types = config.get("type") or copy(self.DEFAULT_CACHE_TYPES)
|
self.cache_types = config.get("type") or copy(self.DEFAULT_CACHE_TYPES)
|
||||||
self.cache_type_confirmed = False
|
self.cache_type_confirmed = False
|
||||||
|
|
||||||
|
url = config.get("url")
|
||||||
|
if url:
|
||||||
|
index_name = hashlib.sha256(url.encode("utf-8")).hexdigest()
|
||||||
|
self.index = self.INDEX_CLS(
|
||||||
|
self.repo, index_name, dir_suffix=self.CHECKSUM_DIR_SUFFIX
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.index = RemoteIndexNoop()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_missing_deps(cls):
|
def get_missing_deps(cls):
|
||||||
import importlib
|
import importlib
|
||||||
@@ -126,7 +152,7 @@ class RemoteBASE(object):
|
|||||||
if not missing:
|
if not missing:
|
||||||
return
|
return
|
||||||
|
|
||||||
url = config.get("url", "{}://".format(self.scheme))
|
url = config.get("url", f"{self.scheme}://")
|
||||||
msg = (
|
msg = (
|
||||||
"URL '{}' is supported but requires these missing "
|
"URL '{}' is supported but requires these missing "
|
||||||
"dependencies: {}. If you have installed dvc using pip, "
|
"dependencies: {}. If you have installed dvc using pip, "
|
||||||
@@ -173,34 +199,46 @@ class RemoteBASE(object):
|
|||||||
|
|
||||||
def _calculate_checksums(self, file_infos):
|
def _calculate_checksums(self, file_infos):
|
||||||
file_infos = list(file_infos)
|
file_infos = list(file_infos)
|
||||||
with ThreadPoolExecutor(max_workers=self.checksum_jobs) as executor:
|
with Tqdm(
|
||||||
tasks = executor.map(self.get_file_checksum, file_infos)
|
total=len(file_infos),
|
||||||
with Tqdm(
|
unit="md5",
|
||||||
tasks,
|
desc="Computing file/dir hashes (only done once)",
|
||||||
total=len(file_infos),
|
) as pbar:
|
||||||
unit="md5",
|
worker = pbar.wrap_fn(self.get_file_checksum)
|
||||||
desc="Computing file/dir hashes (only done once)",
|
with ThreadPoolExecutor(
|
||||||
) as tasks:
|
max_workers=self.checksum_jobs
|
||||||
|
) as executor:
|
||||||
|
tasks = executor.map(worker, file_infos)
|
||||||
checksums = dict(zip(file_infos, tasks))
|
checksums = dict(zip(file_infos, tasks))
|
||||||
return checksums
|
return checksums
|
||||||
|
|
||||||
def _collect_dir(self, path_info):
|
def _collect_dir(self, path_info, tree=None, save_tree=False, **kwargs):
|
||||||
file_infos = set()
|
file_infos = set()
|
||||||
|
|
||||||
for fname in self.walk_files(path_info):
|
if tree:
|
||||||
|
walk_files = tree.walk_files
|
||||||
|
else:
|
||||||
|
walk_files = self.walk_files
|
||||||
|
|
||||||
|
for fname in walk_files(path_info, **kwargs):
|
||||||
if DvcIgnore.DVCIGNORE_FILE == fname.name:
|
if DvcIgnore.DVCIGNORE_FILE == fname.name:
|
||||||
raise DvcIgnoreInCollectedDirError(fname.parent)
|
raise DvcIgnoreInCollectedDirError(fname.parent)
|
||||||
|
|
||||||
file_infos.add(fname)
|
file_infos.add(fname)
|
||||||
|
|
||||||
checksums = {fi: self.state.get(fi) for fi in file_infos}
|
if tree:
|
||||||
not_in_state = {
|
checksums = {fi: tree.get_file_checksum(fi) for fi in file_infos}
|
||||||
fi for fi, checksum in checksums.items() if checksum is None
|
if save_tree:
|
||||||
}
|
for fi, checksum in checksums.items():
|
||||||
|
self._save_file(fi, checksum, tree=tree, **kwargs)
|
||||||
|
else:
|
||||||
|
checksums = {fi: self.state.get(fi) for fi in file_infos}
|
||||||
|
not_in_state = {
|
||||||
|
fi for fi, checksum in checksums.items() if checksum is None
|
||||||
|
}
|
||||||
|
|
||||||
new_checksums = self._calculate_checksums(not_in_state)
|
new_checksums = self._calculate_checksums(not_in_state)
|
||||||
|
checksums.update(new_checksums)
|
||||||
checksums.update(new_checksums)
|
|
||||||
|
|
||||||
result = [
|
result = [
|
||||||
{
|
{
|
||||||
@@ -221,18 +259,25 @@ class RemoteBASE(object):
|
|||||||
# Sorting the list by path to ensure reproducibility
|
# Sorting the list by path to ensure reproducibility
|
||||||
return sorted(result, key=itemgetter(self.PARAM_RELPATH))
|
return sorted(result, key=itemgetter(self.PARAM_RELPATH))
|
||||||
|
|
||||||
def get_dir_checksum(self, path_info):
|
def get_dir_checksum(self, path_info, tree=None):
|
||||||
if not self.cache:
|
if not self.cache:
|
||||||
raise RemoteCacheRequiredError(path_info)
|
raise RemoteCacheRequiredError(path_info)
|
||||||
|
|
||||||
dir_info = self._collect_dir(path_info)
|
dir_info = self._collect_dir(path_info, tree=None)
|
||||||
|
if tree:
|
||||||
|
# don't save state entry for path_info if it is a tree path
|
||||||
|
path_info = None
|
||||||
|
return self._save_dir_info(dir_info, path_info)
|
||||||
|
|
||||||
|
def _save_dir_info(self, dir_info, path_info=None):
|
||||||
checksum, tmp_info = self._get_dir_info_checksum(dir_info)
|
checksum, tmp_info = self._get_dir_info_checksum(dir_info)
|
||||||
new_info = self.cache.checksum_to_path_info(checksum)
|
new_info = self.cache.checksum_to_path_info(checksum)
|
||||||
if self.cache.changed_cache_file(checksum):
|
if self.cache.changed_cache_file(checksum):
|
||||||
self.cache.makedirs(new_info.parent)
|
self.cache.makedirs(new_info.parent)
|
||||||
self.cache.move(tmp_info, new_info, mode=self.CACHE_MODE)
|
self.cache.move(tmp_info, new_info, mode=self.CACHE_MODE)
|
||||||
|
|
||||||
self.state.save(path_info, checksum)
|
if path_info:
|
||||||
|
self.state.save(path_info, checksum)
|
||||||
self.state.save(new_info, checksum)
|
self.state.save(new_info, checksum)
|
||||||
|
|
||||||
return checksum
|
return checksum
|
||||||
@@ -280,19 +325,24 @@ class RemoteBASE(object):
|
|||||||
)
|
)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
for info in d:
|
if self.path_cls == WindowsPathInfo:
|
||||||
# NOTE: here is a BUG, see comment to .as_posix() below
|
# only need to convert it for Windows
|
||||||
relative_path = PathInfo.from_posix(info[self.PARAM_RELPATH])
|
for info in d:
|
||||||
info[self.PARAM_RELPATH] = relative_path.fspath
|
# NOTE: here is a BUG, see comment to .as_posix() below
|
||||||
|
info[self.PARAM_RELPATH] = info[self.PARAM_RELPATH].replace(
|
||||||
|
"/", self.path_cls.sep
|
||||||
|
)
|
||||||
|
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_dir_checksum(cls, checksum):
|
def is_dir_checksum(cls, checksum):
|
||||||
|
if not checksum:
|
||||||
|
return False
|
||||||
return checksum.endswith(cls.CHECKSUM_DIR_SUFFIX)
|
return checksum.endswith(cls.CHECKSUM_DIR_SUFFIX)
|
||||||
|
|
||||||
def get_checksum(self, path_info):
|
def get_checksum(self, path_info):
|
||||||
assert path_info.scheme == self.scheme
|
assert isinstance(path_info, str) or path_info.scheme == self.scheme
|
||||||
|
|
||||||
if not self.exists(path_info):
|
if not self.exists(path_info):
|
||||||
return None
|
return None
|
||||||
@@ -388,10 +438,10 @@ class RemoteBASE(object):
|
|||||||
if self.cache_type_confirmed:
|
if self.cache_type_confirmed:
|
||||||
return
|
return
|
||||||
|
|
||||||
is_link = getattr(self, "is_{}".format(link_type), None)
|
is_link = getattr(self, f"is_{link_type}", None)
|
||||||
if is_link and not is_link(path_info):
|
if is_link and not is_link(path_info):
|
||||||
self.remove(path_info)
|
self.remove(path_info)
|
||||||
raise DvcException("failed to verify {}".format(link_type))
|
raise DvcException(f"failed to verify {link_type}")
|
||||||
|
|
||||||
self.cache_type_confirmed = True
|
self.cache_type_confirmed = True
|
||||||
|
|
||||||
@@ -414,7 +464,7 @@ class RemoteBASE(object):
|
|||||||
|
|
||||||
def _do_link(self, from_info, to_info, link_method):
|
def _do_link(self, from_info, to_info, link_method):
|
||||||
if self.exists(to_info):
|
if self.exists(to_info):
|
||||||
raise DvcException("Link '{}' already exists!".format(to_info))
|
raise DvcException(f"Link '{to_info}' already exists!")
|
||||||
|
|
||||||
link_method(from_info, to_info)
|
link_method(from_info, to_info)
|
||||||
|
|
||||||
@@ -422,28 +472,45 @@ class RemoteBASE(object):
|
|||||||
"Created '%s': %s -> %s", self.cache_types[0], from_info, to_info,
|
"Created '%s': %s -> %s", self.cache_types[0], from_info, to_info,
|
||||||
)
|
)
|
||||||
|
|
||||||
def _save_file(self, path_info, checksum, save_link=True):
|
def _save_file(
|
||||||
|
self, path_info, checksum, save_link=True, tree=None, **kwargs
|
||||||
|
):
|
||||||
assert checksum
|
assert checksum
|
||||||
|
|
||||||
cache_info = self.checksum_to_path_info(checksum)
|
cache_info = self.checksum_to_path_info(checksum)
|
||||||
if self.changed_cache(checksum):
|
if tree:
|
||||||
self.move(path_info, cache_info, mode=self.CACHE_MODE)
|
if self.changed_cache(checksum):
|
||||||
self.link(cache_info, path_info)
|
with tree.open(path_info, mode="rb") as fobj:
|
||||||
elif self.iscopy(path_info) and self._cache_is_copy(path_info):
|
# if tree has fetch enabled, DVC out will be fetched on
|
||||||
# Default relink procedure involves unneeded copy
|
# open and we do not need to read/copy any data
|
||||||
self.unprotect(path_info)
|
if not (
|
||||||
|
tree.isdvc(path_info, strict=False) and tree.fetch
|
||||||
|
):
|
||||||
|
self.copy_fobj(fobj, cache_info)
|
||||||
|
callback = kwargs.get("download_callback")
|
||||||
|
if callback:
|
||||||
|
callback(1)
|
||||||
else:
|
else:
|
||||||
self.remove(path_info)
|
if self.changed_cache(checksum):
|
||||||
self.link(cache_info, path_info)
|
self.move(path_info, cache_info, mode=self.CACHE_MODE)
|
||||||
|
self.link(cache_info, path_info)
|
||||||
|
elif self.iscopy(path_info) and self._cache_is_copy(path_info):
|
||||||
|
# Default relink procedure involves unneeded copy
|
||||||
|
self.unprotect(path_info)
|
||||||
|
else:
|
||||||
|
self.remove(path_info)
|
||||||
|
self.link(cache_info, path_info)
|
||||||
|
|
||||||
if save_link:
|
if save_link:
|
||||||
self.state.save_link(path_info)
|
self.state.save_link(path_info)
|
||||||
|
|
||||||
# we need to update path and cache, since in case of reflink,
|
# we need to update path and cache, since in case of reflink,
|
||||||
# or copy cache type moving original file results in updates on
|
# or copy cache type moving original file results in updates on
|
||||||
# next executed command, which causes md5 recalculation
|
# next executed command, which causes md5 recalculation
|
||||||
self.state.save(path_info, checksum)
|
if not tree or is_working_tree(tree):
|
||||||
|
self.state.save(path_info, checksum)
|
||||||
self.state.save(cache_info, checksum)
|
self.state.save(cache_info, checksum)
|
||||||
|
return {self.PARAM_CHECKSUM: checksum}
|
||||||
|
|
||||||
def _cache_is_copy(self, path_info):
|
def _cache_is_copy(self, path_info):
|
||||||
"""Checks whether cache uses copies."""
|
"""Checks whether cache uses copies."""
|
||||||
@@ -467,20 +534,32 @@ class RemoteBASE(object):
|
|||||||
self.cache_type_confirmed = True
|
self.cache_type_confirmed = True
|
||||||
return self.cache_types[0] == "copy"
|
return self.cache_types[0] == "copy"
|
||||||
|
|
||||||
def _save_dir(self, path_info, checksum):
|
def _save_dir(
|
||||||
|
self, path_info, checksum, save_link=True, tree=None, **kwargs
|
||||||
|
):
|
||||||
|
if tree:
|
||||||
|
dir_info = self._collect_dir(
|
||||||
|
path_info, tree=tree, save_tree=True, **kwargs
|
||||||
|
)
|
||||||
|
checksum = self._save_dir_info(dir_info)
|
||||||
|
else:
|
||||||
|
dir_info = self.get_dir_cache(checksum)
|
||||||
|
|
||||||
|
for entry in Tqdm(
|
||||||
|
dir_info, desc="Saving " + path_info.name, unit="file"
|
||||||
|
):
|
||||||
|
entry_info = path_info / entry[self.PARAM_RELPATH]
|
||||||
|
entry_checksum = entry[self.PARAM_CHECKSUM]
|
||||||
|
self._save_file(entry_info, entry_checksum, save_link=False)
|
||||||
|
|
||||||
|
if save_link:
|
||||||
|
self.state.save_link(path_info)
|
||||||
|
|
||||||
cache_info = self.checksum_to_path_info(checksum)
|
cache_info = self.checksum_to_path_info(checksum)
|
||||||
dir_info = self.get_dir_cache(checksum)
|
|
||||||
|
|
||||||
for entry in Tqdm(
|
|
||||||
dir_info, desc="Saving " + path_info.name, unit="file"
|
|
||||||
):
|
|
||||||
entry_info = path_info / entry[self.PARAM_RELPATH]
|
|
||||||
entry_checksum = entry[self.PARAM_CHECKSUM]
|
|
||||||
self._save_file(entry_info, entry_checksum, save_link=False)
|
|
||||||
|
|
||||||
self.state.save_link(path_info)
|
|
||||||
self.state.save(cache_info, checksum)
|
self.state.save(cache_info, checksum)
|
||||||
self.state.save(path_info, checksum)
|
if not tree or is_working_tree(tree):
|
||||||
|
self.state.save(path_info, checksum)
|
||||||
|
return {self.PARAM_CHECKSUM: checksum}
|
||||||
|
|
||||||
def is_empty(self, path_info):
|
def is_empty(self, path_info):
|
||||||
return False
|
return False
|
||||||
@@ -509,23 +588,42 @@ class RemoteBASE(object):
|
|||||||
def protect(path_info):
|
def protect(path_info):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def save(self, path_info, checksum_info):
|
def save(
|
||||||
|
self, path_info, checksum_info, save_link=True, tree=None, **kwargs
|
||||||
|
):
|
||||||
if path_info.scheme != self.scheme:
|
if path_info.scheme != self.scheme:
|
||||||
raise RemoteActionNotImplemented(
|
raise RemoteActionNotImplemented(
|
||||||
"save {} -> {}".format(path_info.scheme, self.scheme),
|
f"save {path_info.scheme} -> {self.scheme}", self.scheme,
|
||||||
self.scheme,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
checksum = checksum_info[self.PARAM_CHECKSUM]
|
if tree:
|
||||||
self._save(path_info, checksum)
|
if tree.isdir(path_info):
|
||||||
|
# save checksum will be computed during tree walk
|
||||||
|
checksum = None
|
||||||
|
else:
|
||||||
|
checksum = tree.get_file_checksum(path_info)
|
||||||
|
else:
|
||||||
|
checksum = checksum_info[self.PARAM_CHECKSUM]
|
||||||
|
return self._save(path_info, checksum, save_link, tree, **kwargs)
|
||||||
|
|
||||||
def _save(self, path_info, checksum):
|
def _save(self, path_info, checksum, save_link=True, tree=None, **kwargs):
|
||||||
to_info = self.checksum_to_path_info(checksum)
|
if tree:
|
||||||
logger.debug("Saving '%s' to '%s'.", path_info, to_info)
|
logger.debug("Saving tree path '%s' to cache.", path_info)
|
||||||
if self.isdir(path_info):
|
else:
|
||||||
self._save_dir(path_info, checksum)
|
to_info = self.checksum_to_path_info(checksum)
|
||||||
return
|
logger.debug("Saving '%s' to '%s'.", path_info, to_info)
|
||||||
self._save_file(path_info, checksum)
|
|
||||||
|
if tree:
|
||||||
|
isdir = tree.isdir
|
||||||
|
save_link = False
|
||||||
|
else:
|
||||||
|
isdir = self.isdir
|
||||||
|
|
||||||
|
if isdir(path_info):
|
||||||
|
return self._save_dir(
|
||||||
|
path_info, checksum, save_link, tree, **kwargs
|
||||||
|
)
|
||||||
|
return self._save_file(path_info, checksum, save_link, tree, **kwargs)
|
||||||
|
|
||||||
def _handle_transfer_exception(
|
def _handle_transfer_exception(
|
||||||
self, from_info, to_info, exception, operation
|
self, from_info, to_info, exception, operation
|
||||||
@@ -604,22 +702,23 @@ class RemoteBASE(object):
|
|||||||
to_info / info.relative_to(from_info) for info in from_infos
|
to_info / info.relative_to(from_info) for info in from_infos
|
||||||
)
|
)
|
||||||
|
|
||||||
with ThreadPoolExecutor(max_workers=self.JOBS) as executor:
|
with Tqdm(
|
||||||
download_files = partial(
|
total=len(from_infos),
|
||||||
self._download_file,
|
desc="Downloading directory",
|
||||||
name=name,
|
unit="Files",
|
||||||
no_progress_bar=True,
|
disable=no_progress_bar,
|
||||||
file_mode=file_mode,
|
) as pbar:
|
||||||
dir_mode=dir_mode,
|
download_files = pbar.wrap_fn(
|
||||||
|
partial(
|
||||||
|
self._download_file,
|
||||||
|
name=name,
|
||||||
|
no_progress_bar=True,
|
||||||
|
file_mode=file_mode,
|
||||||
|
dir_mode=dir_mode,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
futures = executor.map(download_files, from_infos, to_infos)
|
with ThreadPoolExecutor(max_workers=self.JOBS) as executor:
|
||||||
with Tqdm(
|
futures = executor.map(download_files, from_infos, to_infos)
|
||||||
futures,
|
|
||||||
total=len(from_infos),
|
|
||||||
desc="Downloading directory",
|
|
||||||
unit="Files",
|
|
||||||
disable=no_progress_bar,
|
|
||||||
) as futures:
|
|
||||||
return sum(futures)
|
return sum(futures)
|
||||||
|
|
||||||
def _download_file(
|
def _download_file(
|
||||||
@@ -663,6 +762,9 @@ class RemoteBASE(object):
|
|||||||
def copy(self, from_info, to_info):
|
def copy(self, from_info, to_info):
|
||||||
raise RemoteActionNotImplemented("copy", self.scheme)
|
raise RemoteActionNotImplemented("copy", self.scheme)
|
||||||
|
|
||||||
|
def copy_fobj(self, fobj, to_info):
|
||||||
|
raise RemoteActionNotImplemented("copy_fobj", self.scheme)
|
||||||
|
|
||||||
def symlink(self, from_info, to_info):
|
def symlink(self, from_info, to_info):
|
||||||
raise RemoteActionNotImplemented("symlink", self.scheme)
|
raise RemoteActionNotImplemented("symlink", self.scheme)
|
||||||
|
|
||||||
@@ -679,43 +781,78 @@ class RemoteBASE(object):
|
|||||||
parts = self.path_cls(path).parts[-2:]
|
parts = self.path_cls(path).parts[-2:]
|
||||||
|
|
||||||
if not (len(parts) == 2 and parts[0] and len(parts[0]) == 2):
|
if not (len(parts) == 2 and parts[0] and len(parts[0]) == 2):
|
||||||
raise ValueError("Bad cache file path")
|
raise ValueError(f"Bad cache file path '{path}'")
|
||||||
|
|
||||||
return "".join(parts)
|
return "".join(parts)
|
||||||
|
|
||||||
def checksum_to_path_info(self, checksum):
|
def checksum_to_path_info(self, checksum):
|
||||||
return self.path_info / checksum[0:2] / checksum[2:]
|
return self.path_info / checksum[0:2] / checksum[2:]
|
||||||
|
|
||||||
def list_cache_paths(self):
|
# Return path as a string instead of PathInfo for remotes which support
|
||||||
|
# string paths (see local)
|
||||||
|
checksum_to_path = checksum_to_path_info
|
||||||
|
|
||||||
|
def list_cache_paths(self, prefix=None, progress_callback=None):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def all(self):
|
def cache_checksums(self, prefix=None, progress_callback=None):
|
||||||
# NOTE: The list might be way too big(e.g. 100M entries, md5 for each
|
"""Iterate over remote cache checksums.
|
||||||
# is 32 bytes, so ~3200Mb list) and we don't really need all of it at
|
|
||||||
# the same time, so it makes sense to use a generator to gradually
|
If `prefix` is specified, only checksums which begin with `prefix`
|
||||||
# iterate over it, without keeping all of it in memory.
|
will be returned.
|
||||||
for path in self.list_cache_paths():
|
"""
|
||||||
|
for path in self.list_cache_paths(prefix, progress_callback):
|
||||||
try:
|
try:
|
||||||
yield self.path_to_checksum(path)
|
yield self.path_to_checksum(path)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# We ignore all the non-cache looking files
|
logger.debug(
|
||||||
pass
|
"'%s' doesn't look like a cache file, skipping", path
|
||||||
|
)
|
||||||
|
|
||||||
def gc(self, named_cache):
|
def all(self, jobs=None, name=None):
|
||||||
used = self.extract_used_local_checksums(named_cache)
|
"""Iterate over all checksums in the remote cache.
|
||||||
|
|
||||||
|
Checksums will be fetched in parallel threads according to prefix
|
||||||
|
(except for small remotes) and a progress bar will be displayed.
|
||||||
|
"""
|
||||||
|
logger.debug(
|
||||||
|
"Fetching all checksums from '{}'".format(
|
||||||
|
name if name else "remote cache"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if not self.CAN_TRAVERSE:
|
||||||
|
return self.cache_checksums()
|
||||||
|
|
||||||
|
remote_size, remote_checksums = self._estimate_cache_size(name=name)
|
||||||
|
return self._cache_checksums_traverse(
|
||||||
|
remote_size, remote_checksums, jobs, name
|
||||||
|
)
|
||||||
|
|
||||||
|
@index_locked
|
||||||
|
def gc(self, named_cache, jobs=None):
|
||||||
|
used = set(named_cache.scheme_keys("local"))
|
||||||
|
|
||||||
if self.scheme != "":
|
if self.scheme != "":
|
||||||
used.update(named_cache[self.scheme])
|
used.update(named_cache.scheme_keys(self.scheme))
|
||||||
|
|
||||||
removed = False
|
removed = False
|
||||||
for checksum in self.all():
|
# checksums must be sorted to ensure we always remove .dir files first
|
||||||
|
for checksum in sorted(
|
||||||
|
self.all(jobs, str(self.path_info)),
|
||||||
|
key=self.is_dir_checksum,
|
||||||
|
reverse=True,
|
||||||
|
):
|
||||||
if checksum in used:
|
if checksum in used:
|
||||||
continue
|
continue
|
||||||
path_info = self.checksum_to_path_info(checksum)
|
path_info = self.checksum_to_path_info(checksum)
|
||||||
if self.is_dir_checksum(checksum):
|
if self.is_dir_checksum(checksum):
|
||||||
|
# backward compatibility
|
||||||
self._remove_unpacked_dir(checksum)
|
self._remove_unpacked_dir(checksum)
|
||||||
self.remove(path_info)
|
self.remove(path_info)
|
||||||
removed = True
|
removed = True
|
||||||
|
if removed:
|
||||||
|
self.index.clear()
|
||||||
return removed
|
return removed
|
||||||
|
|
||||||
def is_protected(self, path_info):
|
def is_protected(self, path_info):
|
||||||
@@ -733,8 +870,8 @@ class RemoteBASE(object):
|
|||||||
|
|
||||||
- Remove the file from cache if it doesn't match the actual checksum
|
- Remove the file from cache if it doesn't match the actual checksum
|
||||||
"""
|
"""
|
||||||
|
# Prefer string path over PathInfo when possible due to performance
|
||||||
cache_info = self.checksum_to_path_info(checksum)
|
cache_info = self.checksum_to_path(checksum)
|
||||||
if self.is_protected(cache_info):
|
if self.is_protected(cache_info):
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Assuming '%s' is unchanged since it is read-only", cache_info
|
"Assuming '%s' is unchanged since it is read-only", cache_info
|
||||||
@@ -769,11 +906,6 @@ class RemoteBASE(object):
|
|||||||
if self.changed_cache_file(checksum):
|
if self.changed_cache_file(checksum):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if not (path_info and filter_info) and not self._changed_unpacked_dir(
|
|
||||||
checksum
|
|
||||||
):
|
|
||||||
return False
|
|
||||||
|
|
||||||
for entry in self.get_dir_cache(checksum):
|
for entry in self.get_dir_cache(checksum):
|
||||||
entry_checksum = entry[self.PARAM_CHECKSUM]
|
entry_checksum = entry[self.PARAM_CHECKSUM]
|
||||||
|
|
||||||
@@ -785,9 +917,6 @@ class RemoteBASE(object):
|
|||||||
if self.changed_cache_file(entry_checksum):
|
if self.changed_cache_file(entry_checksum):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if not (path_info and filter_info):
|
|
||||||
self._update_unpacked_dir(checksum)
|
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def changed_cache(self, checksum, path_info=None, filter_info=None):
|
def changed_cache(self, checksum, path_info=None, filter_info=None):
|
||||||
@@ -802,11 +931,13 @@ class RemoteBASE(object):
|
|||||||
|
|
||||||
There are two ways of performing this check:
|
There are two ways of performing this check:
|
||||||
|
|
||||||
- Traverse: Get a list of all the files in the remote
|
- Traverse method: Get a list of all the files in the remote
|
||||||
(traversing the cache directory) and compare it with
|
(traversing the cache directory) and compare it with
|
||||||
the given checksums.
|
the given checksums. Cache entries will be retrieved in parallel
|
||||||
|
threads according to prefix (i.e. entries starting with, "00...",
|
||||||
|
"01...", and so on) and a progress bar will be displayed.
|
||||||
|
|
||||||
- No traverse: For each given checksum, run the `exists`
|
- Exists method: For each given checksum, run the `exists`
|
||||||
method and filter the checksums that aren't on the remote.
|
method and filter the checksums that aren't on the remote.
|
||||||
This is done in parallel threads.
|
This is done in parallel threads.
|
||||||
It also shows a progress bar when performing the check.
|
It also shows a progress bar when performing the check.
|
||||||
@@ -817,12 +948,192 @@ class RemoteBASE(object):
|
|||||||
check if particular file exists much quicker, use their own
|
check if particular file exists much quicker, use their own
|
||||||
implementation of cache_exists (see ssh, local).
|
implementation of cache_exists (see ssh, local).
|
||||||
|
|
||||||
|
Which method to use will be automatically determined after estimating
|
||||||
|
the size of the remote cache, and comparing the estimated size with
|
||||||
|
len(checksums). To estimate the size of the remote cache, we fetch
|
||||||
|
a small subset of cache entries (i.e. entries starting with "00...").
|
||||||
|
Based on the number of entries in that subset, the size of the full
|
||||||
|
cache can be estimated, since the cache is evenly distributed according
|
||||||
|
to checksum.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A list with checksums that were found in the remote
|
A list with checksums that were found in the remote
|
||||||
"""
|
"""
|
||||||
if not self.no_traverse:
|
# Remotes which do not use traverse prefix should override
|
||||||
return list(set(checksums) & set(self.all()))
|
# cache_exists() (see ssh, local)
|
||||||
|
assert self.TRAVERSE_PREFIX_LEN >= 2
|
||||||
|
|
||||||
|
checksums = set(checksums)
|
||||||
|
indexed_checksums = set(self.index.intersection(checksums))
|
||||||
|
checksums -= indexed_checksums
|
||||||
|
logger.debug(
|
||||||
|
"Matched '{}' indexed checksums".format(len(indexed_checksums))
|
||||||
|
)
|
||||||
|
if not checksums:
|
||||||
|
return indexed_checksums
|
||||||
|
|
||||||
|
if len(checksums) == 1 or not self.CAN_TRAVERSE:
|
||||||
|
remote_checksums = self._cache_object_exists(checksums, jobs, name)
|
||||||
|
return list(indexed_checksums) + remote_checksums
|
||||||
|
|
||||||
|
# Max remote size allowed for us to use traverse method
|
||||||
|
remote_size, remote_checksums = self._estimate_cache_size(
|
||||||
|
checksums, name
|
||||||
|
)
|
||||||
|
|
||||||
|
traverse_pages = remote_size / self.LIST_OBJECT_PAGE_SIZE
|
||||||
|
# For sufficiently large remotes, traverse must be weighted to account
|
||||||
|
# for performance overhead from large lists/sets.
|
||||||
|
# From testing with S3, for remotes with 1M+ files, object_exists is
|
||||||
|
# faster until len(checksums) is at least 10k~100k
|
||||||
|
if remote_size > self.TRAVERSE_THRESHOLD_SIZE:
|
||||||
|
traverse_weight = traverse_pages * self.TRAVERSE_WEIGHT_MULTIPLIER
|
||||||
|
else:
|
||||||
|
traverse_weight = traverse_pages
|
||||||
|
if len(checksums) < traverse_weight:
|
||||||
|
logger.debug(
|
||||||
|
"Large remote ('{}' checksums < '{}' traverse weight), "
|
||||||
|
"using object_exists for remaining checksums".format(
|
||||||
|
len(checksums), traverse_weight
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return (
|
||||||
|
list(indexed_checksums)
|
||||||
|
+ list(checksums & remote_checksums)
|
||||||
|
+ self._cache_object_exists(
|
||||||
|
checksums - remote_checksums, jobs, name
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
logger.debug(
|
||||||
|
"Querying '{}' checksums via traverse".format(len(checksums))
|
||||||
|
)
|
||||||
|
remote_checksums = set(
|
||||||
|
self._cache_checksums_traverse(
|
||||||
|
remote_size, remote_checksums, jobs, name
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return list(indexed_checksums) + list(
|
||||||
|
checksums & set(remote_checksums)
|
||||||
|
)
|
||||||
|
|
||||||
|
def _checksums_with_limit(
|
||||||
|
self, limit, prefix=None, progress_callback=None
|
||||||
|
):
|
||||||
|
count = 0
|
||||||
|
for checksum in self.cache_checksums(prefix, progress_callback):
|
||||||
|
yield checksum
|
||||||
|
count += 1
|
||||||
|
if count > limit:
|
||||||
|
logger.debug(
|
||||||
|
"`cache_checksums()` returned max '{}' checksums, "
|
||||||
|
"skipping remaining results".format(limit)
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
def _max_estimation_size(self, checksums):
|
||||||
|
# Max remote size allowed for us to use traverse method
|
||||||
|
return max(
|
||||||
|
self.TRAVERSE_THRESHOLD_SIZE,
|
||||||
|
len(checksums)
|
||||||
|
/ self.TRAVERSE_WEIGHT_MULTIPLIER
|
||||||
|
* self.LIST_OBJECT_PAGE_SIZE,
|
||||||
|
)
|
||||||
|
|
||||||
|
def _estimate_cache_size(self, checksums=None, name=None):
|
||||||
|
"""Estimate remote cache size based on number of entries beginning with
|
||||||
|
"00..." prefix.
|
||||||
|
"""
|
||||||
|
prefix = "0" * self.TRAVERSE_PREFIX_LEN
|
||||||
|
total_prefixes = pow(16, self.TRAVERSE_PREFIX_LEN)
|
||||||
|
if checksums:
|
||||||
|
max_checksums = self._max_estimation_size(checksums)
|
||||||
|
else:
|
||||||
|
max_checksums = None
|
||||||
|
|
||||||
|
with Tqdm(
|
||||||
|
desc="Estimating size of "
|
||||||
|
+ (f"cache in '{name}'" if name else "remote cache"),
|
||||||
|
unit="file",
|
||||||
|
) as pbar:
|
||||||
|
|
||||||
|
def update(n=1):
|
||||||
|
pbar.update(n * total_prefixes)
|
||||||
|
|
||||||
|
if max_checksums:
|
||||||
|
checksums = self._checksums_with_limit(
|
||||||
|
max_checksums / total_prefixes, prefix, update
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
checksums = self.cache_checksums(prefix, update)
|
||||||
|
|
||||||
|
remote_checksums = set(checksums)
|
||||||
|
if remote_checksums:
|
||||||
|
remote_size = total_prefixes * len(remote_checksums)
|
||||||
|
else:
|
||||||
|
remote_size = total_prefixes
|
||||||
|
logger.debug(f"Estimated remote size: {remote_size} files")
|
||||||
|
return remote_size, remote_checksums
|
||||||
|
|
||||||
|
def _cache_checksums_traverse(
|
||||||
|
self, remote_size, remote_checksums, jobs=None, name=None
|
||||||
|
):
|
||||||
|
"""Iterate over all checksums in the remote cache.
|
||||||
|
Checksums are fetched in parallel according to prefix, except in
|
||||||
|
cases where the remote size is very small.
|
||||||
|
|
||||||
|
All checksums from the remote (including any from the size
|
||||||
|
estimation step passed via the `remote_checksums` argument) will be
|
||||||
|
returned.
|
||||||
|
|
||||||
|
NOTE: For large remotes the list of checksums will be very
|
||||||
|
big(e.g. 100M entries, md5 for each is 32 bytes, so ~3200Mb list)
|
||||||
|
and we don't really need all of it at the same time, so it makes
|
||||||
|
sense to use a generator to gradually iterate over it, without
|
||||||
|
keeping all of it in memory.
|
||||||
|
"""
|
||||||
|
num_pages = remote_size / self.LIST_OBJECT_PAGE_SIZE
|
||||||
|
if num_pages < 256 / self.JOBS:
|
||||||
|
# Fetching prefixes in parallel requires at least 255 more
|
||||||
|
# requests, for small enough remotes it will be faster to fetch
|
||||||
|
# entire cache without splitting it into prefixes.
|
||||||
|
#
|
||||||
|
# NOTE: this ends up re-fetching checksums that were already
|
||||||
|
# fetched during remote size estimation
|
||||||
|
traverse_prefixes = [None]
|
||||||
|
initial = 0
|
||||||
|
else:
|
||||||
|
yield from remote_checksums
|
||||||
|
initial = len(remote_checksums)
|
||||||
|
traverse_prefixes = [f"{i:02x}" for i in range(1, 256)]
|
||||||
|
if self.TRAVERSE_PREFIX_LEN > 2:
|
||||||
|
traverse_prefixes += [
|
||||||
|
"{0:0{1}x}".format(i, self.TRAVERSE_PREFIX_LEN)
|
||||||
|
for i in range(1, pow(16, self.TRAVERSE_PREFIX_LEN - 2))
|
||||||
|
]
|
||||||
|
with Tqdm(
|
||||||
|
desc="Querying "
|
||||||
|
+ (f"cache in '{name}'" if name else "remote cache"),
|
||||||
|
total=remote_size,
|
||||||
|
initial=initial,
|
||||||
|
unit="file",
|
||||||
|
) as pbar:
|
||||||
|
|
||||||
|
def list_with_update(prefix):
|
||||||
|
return list(
|
||||||
|
self.cache_checksums(
|
||||||
|
prefix=prefix, progress_callback=pbar.update
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
with ThreadPoolExecutor(max_workers=jobs or self.JOBS) as executor:
|
||||||
|
in_remote = executor.map(list_with_update, traverse_prefixes,)
|
||||||
|
yield from itertools.chain.from_iterable(in_remote)
|
||||||
|
|
||||||
|
def _cache_object_exists(self, checksums, jobs=None, name=None):
|
||||||
|
logger.debug(
|
||||||
|
"Querying {} checksums via object_exists".format(len(checksums))
|
||||||
|
)
|
||||||
with Tqdm(
|
with Tqdm(
|
||||||
desc="Querying "
|
desc="Querying "
|
||||||
+ ("cache in " + name if name else "remote cache"),
|
+ ("cache in " + name if name else "remote cache"),
|
||||||
@@ -832,7 +1143,7 @@ class RemoteBASE(object):
|
|||||||
|
|
||||||
def exists_with_progress(path_info):
|
def exists_with_progress(path_info):
|
||||||
ret = self.exists(path_info)
|
ret = self.exists(path_info)
|
||||||
pbar.update_desc(str(path_info))
|
pbar.update_msg(str(path_info))
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
with ThreadPoolExecutor(max_workers=jobs or self.JOBS) as executor:
|
with ThreadPoolExecutor(max_workers=jobs or self.JOBS) as executor:
|
||||||
@@ -1044,19 +1355,5 @@ class RemoteBASE(object):
|
|||||||
def unprotect(path_info):
|
def unprotect(path_info):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _get_unpacked_dir_names(self, checksums):
|
|
||||||
return set()
|
|
||||||
|
|
||||||
def extract_used_local_checksums(self, named_cache):
|
|
||||||
used = set(named_cache["local"])
|
|
||||||
unpacked = self._get_unpacked_dir_names(used)
|
|
||||||
return used | unpacked
|
|
||||||
|
|
||||||
def _changed_unpacked_dir(self, checksum):
|
|
||||||
return True
|
|
||||||
|
|
||||||
def _update_unpacked_dir(self, checksum):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _remove_unpacked_dir(self, checksum):
|
def _remove_unpacked_dir(self, checksum):
|
||||||
pass
|
pass
|
||||||
|
|||||||
+333
-202
@@ -1,54 +1,72 @@
|
|||||||
from collections import defaultdict
|
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 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.scheme import Schemes
|
|
||||||
from dvc.path_info import CloudURLInfo
|
|
||||||
from dvc.remote.base import RemoteBASE
|
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
from dvc.utils import tmp_fname, format_link
|
from dvc.path_info import CloudURLInfo
|
||||||
|
from dvc.progress import Tqdm
|
||||||
|
from dvc.remote.base import BaseRemote
|
||||||
|
from dvc.scheme import Schemes
|
||||||
|
from dvc.utils import format_link, tmp_fname
|
||||||
|
|
||||||
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):
|
class GDrivePathNotFound(DvcException):
|
||||||
def __init__(self, path_info):
|
def __init__(self, path_info, hint):
|
||||||
super().__init__("Google Drive path '{}' not found.".format(path_info))
|
hint = "" if hint is None else f" {hint}"
|
||||||
|
super().__init__(f"GDrive path '{path_info}' not found.{hint}")
|
||||||
|
|
||||||
|
|
||||||
class GDriveAccessTokenRefreshError(DvcException):
|
class GDriveAuthError(DvcException):
|
||||||
def __init__(self):
|
def __init__(self, cred_location):
|
||||||
super().__init__("Google Drive access token refreshment is failed.")
|
|
||||||
|
if cred_location:
|
||||||
|
message = (
|
||||||
|
"GDrive remote auth failed with credentials in '{}'.\n"
|
||||||
|
"Backup first, remove of fix them, and run DVC again.\n"
|
||||||
|
"It should do auth again and refresh the credentials.\n\n"
|
||||||
|
"Details:".format(cred_location)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
message = "Failed to authenticate GDrive remote"
|
||||||
|
|
||||||
|
super().__init__(message)
|
||||||
|
|
||||||
|
|
||||||
class GDriveMissedCredentialKeyError(DvcException):
|
def _gdrive_retry(func):
|
||||||
def __init__(self, path):
|
|
||||||
super().__init__(
|
|
||||||
"Google Drive user credentials file '{}' "
|
|
||||||
"misses value for key.".format(path)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def gdrive_retry(func):
|
|
||||||
retry_re = re.compile(r"HttpError (403|500|502|503|504)")
|
|
||||||
|
|
||||||
def should_retry(exc):
|
def should_retry(exc):
|
||||||
from pydrive2.files import ApiRequestError
|
from pydrive2.files import ApiRequestError
|
||||||
|
|
||||||
return isinstance(exc, ApiRequestError) and retry_re.search(str(exc))
|
if not isinstance(exc, ApiRequestError):
|
||||||
|
return False
|
||||||
|
|
||||||
# 15 tries, start at 0.5s, multiply by golden ratio, cap at 20s
|
error_code = exc.error.get("code", 0)
|
||||||
|
result = False
|
||||||
|
if 500 <= error_code < 600:
|
||||||
|
result = True
|
||||||
|
|
||||||
|
if error_code == 403:
|
||||||
|
result = exc.GetField("reason") in [
|
||||||
|
"userRateLimitExceeded",
|
||||||
|
"rateLimitExceeded",
|
||||||
|
]
|
||||||
|
if result:
|
||||||
|
logger.debug(f"Retrying GDrive API call, error: {exc}.")
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
# 16 tries, start at 0.5s, multiply by golden ratio, cap at 20s
|
||||||
return retry(
|
return retry(
|
||||||
15,
|
16,
|
||||||
timeout=lambda a: min(0.5 * 1.618 ** a, 20),
|
timeout=lambda a: min(0.5 * 1.618 ** a, 20),
|
||||||
filter_errors=should_retry,
|
filter_errors=should_retry,
|
||||||
)(func)
|
)(func)
|
||||||
@@ -69,30 +87,35 @@ class GDriveURLInfo(CloudURLInfo):
|
|||||||
self._spath = re.sub("/{2,}", "/", self._spath.rstrip("/"))
|
self._spath = re.sub("/{2,}", "/", self._spath.rstrip("/"))
|
||||||
|
|
||||||
|
|
||||||
class RemoteGDrive(RemoteBASE):
|
class GDriveRemote(BaseRemote):
|
||||||
scheme = Schemes.GDRIVE
|
scheme = Schemes.GDRIVE
|
||||||
path_cls = GDriveURLInfo
|
path_cls = GDriveURLInfo
|
||||||
REQUIRES = {"pydrive2": "pydrive2"}
|
REQUIRES = {"pydrive2": "pydrive2"}
|
||||||
DEFAULT_NO_TRAVERSE = False
|
|
||||||
DEFAULT_VERIFY = True
|
DEFAULT_VERIFY = True
|
||||||
|
# Always prefer traverse for GDrive since API usage quotas are a concern.
|
||||||
|
TRAVERSE_WEIGHT_MULTIPLIER = 1
|
||||||
|
TRAVERSE_PREFIX_LEN = 2
|
||||||
|
|
||||||
GDRIVE_CREDENTIALS_DATA = "GDRIVE_CREDENTIALS_DATA"
|
GDRIVE_CREDENTIALS_DATA = "GDRIVE_CREDENTIALS_DATA"
|
||||||
DEFAULT_USER_CREDENTIALS_FILE = "gdrive-user-credentials.json"
|
DEFAULT_USER_CREDENTIALS_FILE = "gdrive-user-credentials.json"
|
||||||
|
|
||||||
|
DEFAULT_GDRIVE_CLIENT_ID = "710796635688-iivsgbgsb6uv1fap6635dhvuei09o66c.apps.googleusercontent.com" # noqa: E501
|
||||||
|
DEFAULT_GDRIVE_CLIENT_SECRET = "a1Fz59uTpVNeG_VGuSKDLJXv"
|
||||||
|
|
||||||
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(
|
||||||
"Empty Google Drive URL '{}'. Learn more at "
|
"Empty GDrive URL '{}'. Learn more at {}".format(
|
||||||
"{}.".format(
|
|
||||||
config["url"],
|
config["url"],
|
||||||
format_link("https://man.dvc.org/remote/add"),
|
format_link("https://man.dvc.org/remote/add"),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self._bucket = self.path_info.bucket
|
self._bucket = self.path_info.bucket
|
||||||
|
self._trash_only = config.get("gdrive_trash_only")
|
||||||
self._use_service_account = config.get("gdrive_use_service_account")
|
self._use_service_account = config.get("gdrive_use_service_account")
|
||||||
self._service_account_email = config.get(
|
self._service_account_email = config.get(
|
||||||
"gdrive_service_account_email"
|
"gdrive_service_account_email"
|
||||||
@@ -108,7 +131,7 @@ class RemoteGDrive(RemoteBASE):
|
|||||||
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(RemoteGDrive.GDRIVE_CREDENTIALS_DATA)
|
if os.getenv(GDriveRemote.GDRIVE_CREDENTIALS_DATA)
|
||||||
else config.get(
|
else config.get(
|
||||||
"gdrive_user_credentials_file",
|
"gdrive_user_credentials_file",
|
||||||
os.path.join(
|
os.path.join(
|
||||||
@@ -117,8 +140,6 @@ class RemoteGDrive(RemoteBASE):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self._list_params = None
|
|
||||||
|
|
||||||
def _validate_config(self):
|
def _validate_config(self):
|
||||||
# Validate Service Account configuration
|
# Validate Service Account configuration
|
||||||
if self._use_service_account and (
|
if self._use_service_account and (
|
||||||
@@ -126,125 +147,208 @@ class RemoteGDrive(RemoteBASE):
|
|||||||
or not self._service_account_p12_file_path
|
or not self._service_account_p12_file_path
|
||||||
):
|
):
|
||||||
raise DvcException(
|
raise DvcException(
|
||||||
"To use service account please specify {}, {} and "
|
"To use service account, set `gdrive_service_account_email`,\n"
|
||||||
"{} in DVC config. Learn more at "
|
"`gdrive_service_account_p12_file_path`, and optionally "
|
||||||
"{}.".format(
|
"`gdrive_service_account_user_email`\nin DVC config. "
|
||||||
"gdrive_service_account_email",
|
"Learn more at {}".format(
|
||||||
"gdrive_service_account_p12_file_path",
|
format_link("https://man.dvc.org/remote/modify")
|
||||||
"gdrive_service_account_user_email (optional)",
|
|
||||||
format_link("https://man.dvc.org/remote/modify"),
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Validate OAuth 2.0 Client ID configuration
|
# Validate OAuth 2.0 Client ID configuration
|
||||||
if not self._use_service_account and (
|
if not self._use_service_account:
|
||||||
not self._client_id or not self._client_secret
|
if bool(self._client_id) != bool(self._client_secret):
|
||||||
):
|
raise DvcException(
|
||||||
raise DvcException(
|
"Please specify GDrive's client ID and secret in "
|
||||||
"Please specify Google Drive's client id and "
|
"DVC config or omit both to use the defaults.\n"
|
||||||
"secret in DVC config. Learn more at "
|
"Learn more at {}".format(
|
||||||
"{}.".format(format_link("https://man.dvc.org/remote/modify"))
|
format_link("https://man.dvc.org/remote/modify")
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def credentials_location(self):
|
||||||
|
"""
|
||||||
|
Helper to determine where will GDrive remote read credentials from.
|
||||||
|
Useful for tests, exception messages, etc. Returns either env variable
|
||||||
|
name if it's set or actual path to the credentials file.
|
||||||
|
"""
|
||||||
|
if os.getenv(GDriveRemote.GDRIVE_CREDENTIALS_DATA):
|
||||||
|
return GDriveRemote.GDRIVE_CREDENTIALS_DATA
|
||||||
|
if os.path.exists(self._gdrive_user_credentials_path):
|
||||||
|
return self._gdrive_user_credentials_path
|
||||||
|
return None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _validate_credentials(auth, settings):
|
||||||
|
"""
|
||||||
|
Detects discrepancy in DVC config and cached credentials file.
|
||||||
|
Usually happens when a second remote is added and it is using
|
||||||
|
the same credentials default file. Or when someones decides to change
|
||||||
|
DVC config client id or secret but forgets to remove the cached
|
||||||
|
credentials file.
|
||||||
|
"""
|
||||||
|
if not os.getenv(GDriveRemote.GDRIVE_CREDENTIALS_DATA):
|
||||||
|
if (
|
||||||
|
settings["client_config"]["client_id"]
|
||||||
|
!= auth.credentials.client_id
|
||||||
|
or settings["client_config"]["client_secret"]
|
||||||
|
!= auth.credentials.client_secret
|
||||||
|
):
|
||||||
|
logger.warning(
|
||||||
|
"Client ID and secret configured do not match the "
|
||||||
|
"actual ones used\nto access the remote. Do you "
|
||||||
|
"use multiple GDrive remotes and forgot to\nset "
|
||||||
|
"`gdrive_user_credentials_file` for one or more of them? "
|
||||||
|
"Learn more at\n{}.\n".format(
|
||||||
|
format_link("https://man.dvc.org/remote/modify")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
@wrap_prop(threading.RLock())
|
@wrap_prop(threading.RLock())
|
||||||
@cached_property
|
@cached_property
|
||||||
def drive(self):
|
def _drive(self):
|
||||||
from pydrive2.auth import RefreshError
|
|
||||||
from pydrive2.auth import GoogleAuth
|
from pydrive2.auth import GoogleAuth
|
||||||
from pydrive2.drive import GoogleDrive
|
from pydrive2.drive import GoogleDrive
|
||||||
|
|
||||||
if os.getenv(RemoteGDrive.GDRIVE_CREDENTIALS_DATA):
|
if os.getenv(GDriveRemote.GDRIVE_CREDENTIALS_DATA):
|
||||||
with open(
|
with open(self._gdrive_user_credentials_path, "w") as cred_file:
|
||||||
self._gdrive_user_credentials_path, "w"
|
cred_file.write(
|
||||||
) as credentials_file:
|
os.getenv(GDriveRemote.GDRIVE_CREDENTIALS_DATA)
|
||||||
credentials_file.write(
|
|
||||||
os.getenv(RemoteGDrive.GDRIVE_CREDENTIALS_DATA)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
GoogleAuth.DEFAULT_SETTINGS["client_config_backend"] = "settings"
|
auth_settings = {
|
||||||
|
"client_config_backend": "settings",
|
||||||
|
"save_credentials": True,
|
||||||
|
"save_credentials_backend": "file",
|
||||||
|
"save_credentials_file": self._gdrive_user_credentials_path,
|
||||||
|
"get_refresh_token": True,
|
||||||
|
"oauth_scope": [
|
||||||
|
"https://www.googleapis.com/auth/drive",
|
||||||
|
"https://www.googleapis.com/auth/drive.appdata",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
if self._use_service_account:
|
if self._use_service_account:
|
||||||
GoogleAuth.DEFAULT_SETTINGS["service_config"] = {
|
auth_settings["service_config"] = {
|
||||||
"client_service_email": self._service_account_email,
|
"client_service_email": self._service_account_email,
|
||||||
"client_user_email": self._service_account_user_email,
|
"client_user_email": self._service_account_user_email,
|
||||||
"client_pkcs12_file_path": self._service_account_p12_file_path,
|
"client_pkcs12_file_path": self._service_account_p12_file_path,
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
GoogleAuth.DEFAULT_SETTINGS["client_config"] = {
|
auth_settings["client_config"] = {
|
||||||
"client_id": self._client_id,
|
"client_id": self._client_id or self.DEFAULT_GDRIVE_CLIENT_ID,
|
||||||
"client_secret": self._client_secret,
|
"client_secret": self._client_secret
|
||||||
|
or self.DEFAULT_GDRIVE_CLIENT_SECRET,
|
||||||
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
||||||
"token_uri": "https://oauth2.googleapis.com/token",
|
"token_uri": "https://oauth2.googleapis.com/token",
|
||||||
"revoke_uri": "https://oauth2.googleapis.com/revoke",
|
"revoke_uri": "https://oauth2.googleapis.com/revoke",
|
||||||
"redirect_uri": "",
|
"redirect_uri": "",
|
||||||
}
|
}
|
||||||
GoogleAuth.DEFAULT_SETTINGS["save_credentials"] = True
|
|
||||||
GoogleAuth.DEFAULT_SETTINGS["save_credentials_backend"] = "file"
|
|
||||||
GoogleAuth.DEFAULT_SETTINGS[
|
|
||||||
"save_credentials_file"
|
|
||||||
] = self._gdrive_user_credentials_path
|
|
||||||
GoogleAuth.DEFAULT_SETTINGS["get_refresh_token"] = True
|
|
||||||
GoogleAuth.DEFAULT_SETTINGS["oauth_scope"] = [
|
|
||||||
"https://www.googleapis.com/auth/drive",
|
|
||||||
"https://www.googleapis.com/auth/drive.appdata",
|
|
||||||
]
|
|
||||||
|
|
||||||
# Pass non existent settings path to force DEFAULT_SETTINGS loading
|
GoogleAuth.DEFAULT_SETTINGS.update(auth_settings)
|
||||||
|
|
||||||
|
# Pass non existent settings path to force DEFAULT_SETTINGS loadings
|
||||||
gauth = GoogleAuth(settings_file="")
|
gauth = GoogleAuth(settings_file="")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
logger.debug(
|
||||||
|
"GDrive remote auth with config '{}'.".format(
|
||||||
|
GoogleAuth.DEFAULT_SETTINGS
|
||||||
|
)
|
||||||
|
)
|
||||||
if self._use_service_account:
|
if self._use_service_account:
|
||||||
gauth.ServiceAuth()
|
gauth.ServiceAuth()
|
||||||
else:
|
else:
|
||||||
gauth.CommandLineAuth()
|
gauth.CommandLineAuth()
|
||||||
except RefreshError as exc:
|
GDriveRemote._validate_credentials(gauth, auth_settings)
|
||||||
raise GDriveAccessTokenRefreshError from exc
|
|
||||||
except KeyError as exc:
|
# Handle AuthenticationError, RefreshError and other auth failures
|
||||||
raise GDriveMissedCredentialKeyError(
|
# It's hard to come up with a narrow exception, since PyDrive throws
|
||||||
self._gdrive_user_credentials_path
|
# a lot of different errors - broken credentials file, refresh token
|
||||||
) from exc
|
# expired, flow failed, etc.
|
||||||
# Handle pydrive2.auth.AuthenticationError and other auth failures
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise DvcException("Google Drive authentication failed") from exc
|
raise GDriveAuthError(self.credentials_location) from exc
|
||||||
finally:
|
finally:
|
||||||
if os.getenv(RemoteGDrive.GDRIVE_CREDENTIALS_DATA):
|
if os.getenv(GDriveRemote.GDRIVE_CREDENTIALS_DATA):
|
||||||
os.remove(self._gdrive_user_credentials_path)
|
os.remove(self._gdrive_user_credentials_path)
|
||||||
|
|
||||||
return GoogleDrive(gauth)
|
return GoogleDrive(gauth)
|
||||||
|
|
||||||
@wrap_prop(threading.RLock())
|
@wrap_prop(threading.RLock())
|
||||||
@cached_property
|
@cached_property
|
||||||
def cache(self):
|
def _ids_cache(self):
|
||||||
cache = {"dirs": defaultdict(list), "ids": {}}
|
cache = {
|
||||||
|
"dirs": defaultdict(list),
|
||||||
|
"ids": {},
|
||||||
|
"root_id": self._get_item_id(
|
||||||
|
self.path_info,
|
||||||
|
use_cache=False,
|
||||||
|
hint="Confirm the directory exists and you can access it.",
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
cache["root_id"] = self._get_remote_id(self.path_info)
|
self._cache_path_id(self.path_info.path, cache["root_id"], cache)
|
||||||
cache["dirs"][self.path_info.path] = [cache["root_id"]]
|
|
||||||
self._cache_path(self.path_info.path, cache["root_id"], cache)
|
|
||||||
|
|
||||||
for item in self.gdrive_list_item(
|
for item in self._gdrive_list(
|
||||||
"'{}' in parents and trashed=false".format(cache["root_id"])
|
"'{}' in parents and trashed=false".format(cache["root_id"])
|
||||||
):
|
):
|
||||||
remote_path = (self.path_info / item["title"]).path
|
item_path = (self.path_info / item["title"]).path
|
||||||
self._cache_path(remote_path, item["id"], cache)
|
self._cache_path_id(item_path, item["id"], cache)
|
||||||
|
|
||||||
return cache
|
return cache
|
||||||
|
|
||||||
def _cache_path(self, remote_path, remote_id, cache=None):
|
def _cache_path_id(self, path, item_id, cache=None):
|
||||||
cache = cache or self.cache
|
cache = cache or self._ids_cache
|
||||||
cache["dirs"][remote_path].append(remote_id)
|
cache["dirs"][path].append(item_id)
|
||||||
cache["ids"][remote_id] = remote_path
|
cache["ids"][item_id] = path
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def list_params(self):
|
def _list_params(self):
|
||||||
params = {"corpora": "default"}
|
params = {"corpora": "default"}
|
||||||
if self._bucket != "root" and self._bucket != "appDataFolder":
|
if self._bucket != "root" and self._bucket != "appDataFolder":
|
||||||
drive_id = self._get_remote_drive_id(self._bucket)
|
drive_id = self._gdrive_shared_drive_id(self._bucket)
|
||||||
if drive_id:
|
if drive_id:
|
||||||
|
logger.debug(
|
||||||
|
"GDrive remote '{}' is using shared drive id '{}'.".format(
|
||||||
|
self.path_info, drive_id
|
||||||
|
)
|
||||||
|
)
|
||||||
params["driveId"] = drive_id
|
params["driveId"] = drive_id
|
||||||
params["corpora"] = "drive"
|
params["corpora"] = "drive"
|
||||||
return params
|
return params
|
||||||
|
|
||||||
@gdrive_retry
|
@_gdrive_retry
|
||||||
def gdrive_upload_file(
|
def _gdrive_shared_drive_id(self, item_id):
|
||||||
|
from pydrive2.files import ApiRequestError
|
||||||
|
|
||||||
|
param = {"id": item_id}
|
||||||
|
# it does not create a file on the remote
|
||||||
|
item = self._drive.CreateFile(param)
|
||||||
|
# ID of the shared drive the item resides in.
|
||||||
|
# Only populated for items in shared drives.
|
||||||
|
try:
|
||||||
|
item.FetchMetadata("driveId")
|
||||||
|
except ApiRequestError as exc:
|
||||||
|
error_code = exc.error.get("code", 0)
|
||||||
|
if error_code == 404:
|
||||||
|
raise DvcException(
|
||||||
|
"'{}' for '{}':\n\n"
|
||||||
|
"1. Confirm the directory exists and you can access it.\n"
|
||||||
|
"2. Make sure that credentials in '{}'\n"
|
||||||
|
" are correct for this remote e.g. "
|
||||||
|
"use the `gdrive_user_credentials_file` config\n"
|
||||||
|
" option if you use multiple GDrive remotes with "
|
||||||
|
"different email accounts.\n\nDetails".format(
|
||||||
|
item_id, self.path_info, self.credentials_location
|
||||||
|
)
|
||||||
|
) from exc
|
||||||
|
raise
|
||||||
|
|
||||||
|
return item.get("driveId", None)
|
||||||
|
|
||||||
|
@_gdrive_retry
|
||||||
|
def _gdrive_upload_file(
|
||||||
self,
|
self,
|
||||||
parent_id,
|
parent_id,
|
||||||
title,
|
title,
|
||||||
@@ -252,7 +356,7 @@ class RemoteGDrive(RemoteBASE):
|
|||||||
from_file="",
|
from_file="",
|
||||||
progress_name="",
|
progress_name="",
|
||||||
):
|
):
|
||||||
item = self.drive.CreateFile(
|
item = self._drive.CreateFile(
|
||||||
{"title": title, "parents": [{"id": parent_id}]}
|
{"title": title, "parents": [{"id": parent_id}]}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -272,161 +376,188 @@ class RemoteGDrive(RemoteBASE):
|
|||||||
item.Upload()
|
item.Upload()
|
||||||
return item
|
return item
|
||||||
|
|
||||||
@gdrive_retry
|
@_gdrive_retry
|
||||||
def gdrive_download_file(
|
def _gdrive_download_file(
|
||||||
self, file_id, to_file, progress_name, no_progress_bar
|
self, item_id, to_file, progress_desc, no_progress_bar
|
||||||
):
|
):
|
||||||
param = {"id": file_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_name, 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)
|
||||||
|
|
||||||
def gdrive_list_item(self, query):
|
@_gdrive_retry
|
||||||
|
def _gdrive_delete_file(self, item_id):
|
||||||
|
from pydrive2.files import ApiRequestError
|
||||||
|
|
||||||
|
param = {"id": item_id}
|
||||||
|
# it does not create a file on the remote
|
||||||
|
item = self._drive.CreateFile(param)
|
||||||
|
|
||||||
|
try:
|
||||||
|
item.Trash() if self._trash_only else item.Delete()
|
||||||
|
except ApiRequestError as exc:
|
||||||
|
http_error_code = exc.error.get("code", 0)
|
||||||
|
if (
|
||||||
|
http_error_code == 403
|
||||||
|
and self._list_params["corpora"] == "drive"
|
||||||
|
and exc.GetField("location") == "file.permissions"
|
||||||
|
):
|
||||||
|
raise DvcException(
|
||||||
|
"Insufficient permissions to {}. You should have {} "
|
||||||
|
"access level for the used shared drive. More details "
|
||||||
|
"at {}.".format(
|
||||||
|
"move the file into Trash"
|
||||||
|
if self._trash_only
|
||||||
|
else "permanently delete the file",
|
||||||
|
"Manager or Content Manager"
|
||||||
|
if self._trash_only
|
||||||
|
else "Manager",
|
||||||
|
"https://support.google.com/a/answer/7337554",
|
||||||
|
)
|
||||||
|
) from exc
|
||||||
|
raise
|
||||||
|
|
||||||
|
def _gdrive_list(self, query):
|
||||||
param = {"q": query, "maxResults": 1000}
|
param = {"q": query, "maxResults": 1000}
|
||||||
param.update(self.list_params)
|
param.update(self._list_params)
|
||||||
|
file_list = self._drive.ListFile(param)
|
||||||
|
|
||||||
file_list = self.drive.ListFile(param)
|
# Isolate and decorate fetching of remote drive items in pages.
|
||||||
|
get_list = _gdrive_retry(lambda: next(file_list, None))
|
||||||
|
|
||||||
# Isolate and decorate fetching of remote drive items in pages
|
# Fetch pages until None is received, lazily flatten the thing.
|
||||||
get_list = gdrive_retry(lambda: next(file_list, None))
|
|
||||||
|
|
||||||
# Fetch pages until None is received, lazily flatten the thing
|
|
||||||
return cat(iter(get_list, None))
|
return cat(iter(get_list, None))
|
||||||
|
|
||||||
@wrap_with(threading.RLock())
|
@_gdrive_retry
|
||||||
def gdrive_create_dir(self, parent_id, title, remote_path):
|
def _gdrive_create_dir(self, parent_id, title):
|
||||||
cached = self.cache["dirs"].get(remote_path)
|
|
||||||
if cached:
|
|
||||||
return cached[0]
|
|
||||||
|
|
||||||
item = self._create_remote_dir(parent_id, title)
|
|
||||||
|
|
||||||
if parent_id == self.cache["root_id"]:
|
|
||||||
self._cache_path(remote_path, item["id"])
|
|
||||||
|
|
||||||
return item["id"]
|
|
||||||
|
|
||||||
@gdrive_retry
|
|
||||||
def _create_remote_dir(self, parent_id, title):
|
|
||||||
parent = {"id": parent_id}
|
parent = {"id": parent_id}
|
||||||
item = self.drive.CreateFile(
|
item = self._drive.CreateFile(
|
||||||
{"title": title, "parents": [parent], "mimeType": FOLDER_MIME_TYPE}
|
{"title": title, "parents": [parent], "mimeType": FOLDER_MIME_TYPE}
|
||||||
)
|
)
|
||||||
item.Upload()
|
item.Upload()
|
||||||
return item
|
return item
|
||||||
|
|
||||||
@gdrive_retry
|
@wrap_with(threading.RLock())
|
||||||
def _delete_remote_file(self, remote_id):
|
def _create_dir(self, parent_id, title, remote_path):
|
||||||
param = {"id": remote_id}
|
cached = self._ids_cache["dirs"].get(remote_path)
|
||||||
# it does not create a file on the remote
|
if cached:
|
||||||
item = self.drive.CreateFile(param)
|
return cached[0]
|
||||||
item.Delete()
|
|
||||||
|
|
||||||
@gdrive_retry
|
item = self._gdrive_create_dir(parent_id, title)
|
||||||
def _get_remote_item(self, name, parents_ids):
|
|
||||||
if not parents_ids:
|
if parent_id == self._ids_cache["root_id"]:
|
||||||
|
self._cache_path_id(remote_path, item["id"])
|
||||||
|
|
||||||
|
return item["id"]
|
||||||
|
|
||||||
|
def _get_remote_item_ids(self, parent_ids, title):
|
||||||
|
if not parent_ids:
|
||||||
return None
|
return None
|
||||||
query = "({})".format(
|
query = "trashed=false and ({})".format(
|
||||||
" or ".join(
|
" or ".join(
|
||||||
"'{}' in parents".format(parent_id)
|
f"'{parent_id}' in parents" for parent_id in parent_ids
|
||||||
for parent_id in parents_ids
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
query += " and title='{}'".format(title.replace("'", "\\'"))
|
||||||
|
|
||||||
query += " and trashed=false and title='{}'".format(name)
|
# GDrive list API is case insensitive, we need to compare
|
||||||
|
# all results and pick the ones with the right title
|
||||||
|
return [
|
||||||
|
item["id"]
|
||||||
|
for item in self._gdrive_list(query)
|
||||||
|
if item["title"] == title
|
||||||
|
]
|
||||||
|
|
||||||
# Remote might contain items with duplicated path (titles).
|
def _get_cached_item_ids(self, path, use_cache):
|
||||||
# We thus limit number of items.
|
|
||||||
param = {"q": query, "maxResults": 1}
|
|
||||||
param.update(self.list_params)
|
|
||||||
|
|
||||||
# Limit found remote items count to 1 in response
|
|
||||||
item_list = self.drive.ListFile(param).GetList()
|
|
||||||
return next(iter(item_list), None)
|
|
||||||
|
|
||||||
@gdrive_retry
|
|
||||||
def _get_remote_drive_id(self, remote_id):
|
|
||||||
param = {"id": remote_id}
|
|
||||||
# it does not create a file on the remote
|
|
||||||
item = self.drive.CreateFile(param)
|
|
||||||
item.FetchMetadata("driveId")
|
|
||||||
return item.get("driveId", None)
|
|
||||||
|
|
||||||
def _get_cached_remote_ids(self, path):
|
|
||||||
if not path:
|
if not path:
|
||||||
return [self._bucket]
|
return [self._bucket]
|
||||||
if "cache" in self.__dict__:
|
if use_cache:
|
||||||
return self.cache["dirs"].get(path, [])
|
return self._ids_cache["dirs"].get(path, [])
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def _path_to_remote_ids(self, path, create):
|
def _path_to_item_ids(self, path, create, use_cache):
|
||||||
remote_ids = self._get_cached_remote_ids(path)
|
item_ids = self._get_cached_item_ids(path, use_cache)
|
||||||
if remote_ids:
|
if item_ids:
|
||||||
return remote_ids
|
return item_ids
|
||||||
|
|
||||||
parent_path, part = posixpath.split(path)
|
parent_path, title = posixpath.split(path)
|
||||||
parent_ids = self._path_to_remote_ids(parent_path, create)
|
parent_ids = self._path_to_item_ids(parent_path, create, use_cache)
|
||||||
item = self._get_remote_item(part, parent_ids)
|
item_ids = self._get_remote_item_ids(parent_ids, title)
|
||||||
|
if item_ids:
|
||||||
|
return item_ids
|
||||||
|
|
||||||
if not item:
|
return (
|
||||||
return (
|
[self._create_dir(min(parent_ids), title, path)] if create else []
|
||||||
[self.gdrive_create_dir(parent_ids[0], part, path)]
|
)
|
||||||
if create
|
|
||||||
else []
|
|
||||||
)
|
|
||||||
|
|
||||||
return [item["id"]]
|
def _get_item_id(self, path_info, create=False, use_cache=True, hint=None):
|
||||||
|
|
||||||
def _get_remote_id(self, path_info, create=False):
|
|
||||||
assert path_info.bucket == self._bucket
|
assert path_info.bucket == self._bucket
|
||||||
|
|
||||||
remote_ids = self._path_to_remote_ids(path_info.path, create)
|
item_ids = self._path_to_item_ids(path_info.path, create, use_cache)
|
||||||
if not remote_ids:
|
if item_ids:
|
||||||
raise GDrivePathNotFound(path_info)
|
return min(item_ids)
|
||||||
|
|
||||||
return remote_ids[0]
|
assert not create
|
||||||
|
raise GDrivePathNotFound(path_info, hint)
|
||||||
|
|
||||||
def exists(self, path_info):
|
def exists(self, path_info):
|
||||||
try:
|
try:
|
||||||
self._get_remote_id(path_info)
|
self._get_item_id(path_info)
|
||||||
except GDrivePathNotFound:
|
except GDrivePathNotFound:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _upload(self, from_file, to_info, name, no_progress_bar):
|
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
|
||||||
parent_id = self._get_remote_id(dirname, True)
|
parent_id = self._get_item_id(dirname, True)
|
||||||
|
|
||||||
self.gdrive_upload_file(
|
self._gdrive_upload_file(
|
||||||
parent_id, to_info.name, no_progress_bar, from_file, name
|
parent_id, to_info.name, no_progress_bar, from_file, name
|
||||||
)
|
)
|
||||||
|
|
||||||
def _download(self, from_info, to_file, name, no_progress_bar):
|
def _download(self, from_info, to_file, name=None, no_progress_bar=False):
|
||||||
file_id = self._get_remote_id(from_info)
|
item_id = self._get_item_id(from_info)
|
||||||
self.gdrive_download_file(file_id, to_file, name, no_progress_bar)
|
self._gdrive_download_file(item_id, to_file, name, no_progress_bar)
|
||||||
|
|
||||||
def list_cache_paths(self):
|
def list_cache_paths(self, prefix=None, progress_callback=None):
|
||||||
if not self.cache["ids"]:
|
if not self._ids_cache["ids"]:
|
||||||
return
|
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(
|
parents_query = " or ".join(
|
||||||
"'{}' in parents".format(dir_id) for dir_id in self.cache["ids"]
|
f"'{dir_id}' in parents" for dir_id in dir_ids
|
||||||
)
|
)
|
||||||
query = "({}) and trashed=false".format(parents_query)
|
query = f"({parents_query}) and trashed=false"
|
||||||
|
|
||||||
for item in self.gdrive_list_item(query):
|
for item in self._gdrive_list(query):
|
||||||
|
if progress_callback:
|
||||||
|
progress_callback()
|
||||||
parent_id = item["parents"][0]["id"]
|
parent_id = item["parents"][0]["id"]
|
||||||
yield posixpath.join(self.cache["ids"][parent_id], item["title"])
|
yield posixpath.join(
|
||||||
|
self._ids_cache["ids"][parent_id], item["title"]
|
||||||
|
)
|
||||||
|
|
||||||
def remove(self, path_info):
|
def remove(self, path_info):
|
||||||
remote_id = self._get_remote_id(path_info)
|
item_id = self._get_item_id(path_info)
|
||||||
self._delete_remote_file(remote_id)
|
self._gdrive_delete_file(item_id)
|
||||||
|
|
||||||
|
def get_file_checksum(self, path_info):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def walk_files(self, path_info):
|
||||||
|
raise NotImplementedError
|
||||||
|
|||||||
+25
-12
@@ -1,16 +1,16 @@
|
|||||||
import logging
|
import logging
|
||||||
|
import os.path
|
||||||
|
import posixpath
|
||||||
|
import threading
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
import io
|
|
||||||
import os.path
|
|
||||||
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 RemoteBASE
|
from dvc.remote.base import BaseRemote
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -54,7 +54,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",
|
||||||
@@ -65,7 +65,7 @@ def _upload_to_bucket(
|
|||||||
blob.upload_from_file(wrapped)
|
blob.upload_from_file(wrapped)
|
||||||
|
|
||||||
|
|
||||||
class RemoteGS(RemoteBASE):
|
class GSRemote(BaseRemote):
|
||||||
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"}
|
||||||
@@ -109,7 +109,7 @@ class RemoteGS(RemoteBASE):
|
|||||||
from_bucket = self.gs.bucket(from_info.bucket)
|
from_bucket = self.gs.bucket(from_info.bucket)
|
||||||
blob = from_bucket.get_blob(from_info.path)
|
blob = from_bucket.get_blob(from_info.path)
|
||||||
if not blob:
|
if not blob:
|
||||||
msg = "'{}' doesn't exist in the cloud".format(from_info.path)
|
msg = f"'{from_info.path}' doesn't exist in the cloud"
|
||||||
raise DvcException(msg)
|
raise DvcException(msg)
|
||||||
|
|
||||||
to_bucket = self.gs.bucket(to_info.bucket)
|
to_bucket = self.gs.bucket(to_info.bucket)
|
||||||
@@ -119,21 +119,31 @@ class RemoteGS(RemoteBASE):
|
|||||||
if path_info.scheme != "gs":
|
if path_info.scheme != "gs":
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
logger.debug("Removing gs://{}".format(path_info))
|
logger.debug(f"Removing gs://{path_info}")
|
||||||
blob = self.gs.bucket(path_info.bucket).get_blob(path_info.path)
|
blob = self.gs.bucket(path_info.bucket).get_blob(path_info.path)
|
||||||
if not blob:
|
if not blob:
|
||||||
return
|
return
|
||||||
|
|
||||||
blob.delete()
|
blob.delete()
|
||||||
|
|
||||||
def _list_paths(self, path_info, max_items=None):
|
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(
|
for blob in self.gs.bucket(path_info.bucket).list_blobs(
|
||||||
prefix=path_info.path, max_results=max_items
|
prefix=path_info.path, max_results=max_items
|
||||||
):
|
):
|
||||||
|
if progress_callback:
|
||||||
|
progress_callback()
|
||||||
yield blob.name
|
yield blob.name
|
||||||
|
|
||||||
def list_cache_paths(self):
|
def list_cache_paths(self, prefix=None, progress_callback=None):
|
||||||
return self._list_paths(self.path_info)
|
return self._list_paths(
|
||||||
|
self.path_info, prefix=prefix, progress_callback=progress_callback
|
||||||
|
)
|
||||||
|
|
||||||
def walk_files(self, path_info):
|
def walk_files(self, path_info):
|
||||||
for fname in self._list_paths(path_info / ""):
|
for fname in self._list_paths(path_info / ""):
|
||||||
@@ -143,6 +153,9 @@ class RemoteGS(RemoteBASE):
|
|||||||
yield path_info.replace(fname)
|
yield path_info.replace(fname)
|
||||||
|
|
||||||
def makedirs(self, path_info):
|
def makedirs(self, path_info):
|
||||||
|
if not path_info.path:
|
||||||
|
return
|
||||||
|
|
||||||
self.gs.bucket(path_info.bucket).blob(
|
self.gs.bucket(path_info.bucket).blob(
|
||||||
(path_info / "").path
|
(path_info / "").path
|
||||||
).upload_from_string("")
|
).upload_from_string("")
|
||||||
@@ -179,7 +192,7 @@ class RemoteGS(RemoteBASE):
|
|||||||
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",
|
||||||
|
|||||||
+31
-14
@@ -8,19 +8,21 @@ 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 RemoteBASE, 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 BaseRemote, RemoteCmdError
|
||||||
|
from .pool import get_connection
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class RemoteHDFS(RemoteBASE):
|
class HDFSRemote(BaseRemote):
|
||||||
scheme = Schemes.HDFS
|
scheme = Schemes.HDFS
|
||||||
REGEX = r"^hdfs://((?P<user>.*)@)?.*$"
|
REGEX = r"^hdfs://((?P<user>.*)@)?.*$"
|
||||||
PARAM_CHECKSUM = "checksum"
|
PARAM_CHECKSUM = "checksum"
|
||||||
REQUIRES = {"pyarrow": "pyarrow"}
|
REQUIRES = {"pyarrow": "pyarrow"}
|
||||||
|
TRAVERSE_PREFIX_LEN = 2
|
||||||
|
|
||||||
def __init__(self, repo, config):
|
def __init__(self, repo, config):
|
||||||
super().__init__(repo, config)
|
super().__init__(repo, config)
|
||||||
@@ -53,7 +55,7 @@ class RemoteHDFS(RemoteBASE):
|
|||||||
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.
|
||||||
@@ -85,7 +87,7 @@ class RemoteHDFS(RemoteBASE):
|
|||||||
# 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")
|
||||||
|
|
||||||
@@ -110,7 +112,7 @@ class RemoteHDFS(RemoteBASE):
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
if self.exists(path_info):
|
if self.exists(path_info):
|
||||||
logger.debug("Removing {}".format(path_info.path))
|
logger.debug(f"Removing {path_info.path}")
|
||||||
with self.hdfs(path_info) as hdfs:
|
with self.hdfs(path_info) as hdfs:
|
||||||
hdfs.rm(path_info.path)
|
hdfs.rm(path_info.path)
|
||||||
|
|
||||||
@@ -145,23 +147,38 @@ class RemoteHDFS(RemoteBASE):
|
|||||||
yield fd
|
yield fd
|
||||||
else:
|
else:
|
||||||
yield io.TextIOWrapper(fd, encoding=encoding)
|
yield io.TextIOWrapper(fd, encoding=encoding)
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
# Empty .errno and not specific enough error class in pyarrow,
|
# Empty .errno and not specific enough error class in pyarrow,
|
||||||
# see https://issues.apache.org/jira/browse/ARROW-6248
|
# see https://issues.apache.org/jira/browse/ARROW-6248
|
||||||
if "file does not exist" in str(e):
|
if "file does not exist" in str(e):
|
||||||
raise FileNotFoundError(*e.args)
|
raise FileNotFoundError(*e.args)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def list_cache_paths(self):
|
def list_cache_paths(self, prefix=None, progress_callback=None):
|
||||||
if not self.exists(self.path_info):
|
if not self.exists(self.path_info):
|
||||||
return
|
return
|
||||||
|
|
||||||
dirs = deque([self.path_info.path])
|
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:
|
with self.hdfs(self.path_info) as hdfs:
|
||||||
|
if prefix and not hdfs.exists(root):
|
||||||
|
return
|
||||||
while dirs:
|
while dirs:
|
||||||
for entry in hdfs.ls(dirs.pop(), detail=True):
|
try:
|
||||||
if entry["kind"] == "directory":
|
entries = hdfs.ls(dirs.pop(), detail=True)
|
||||||
dirs.append(urlparse(entry["name"]).path)
|
for entry in entries:
|
||||||
elif entry["kind"] == "file":
|
if entry["kind"] == "directory":
|
||||||
yield urlparse(entry["name"]).path
|
dirs.append(urlparse(entry["name"]).path)
|
||||||
|
elif entry["kind"] == "file":
|
||||||
|
if progress_callback:
|
||||||
|
progress_callback()
|
||||||
|
yield urlparse(entry["name"]).path
|
||||||
|
except OSError 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
|
||||||
|
|||||||
+33
-36
@@ -4,12 +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.config import ConfigError
|
|
||||||
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 RemoteBASE
|
from dvc.remote.base import BaseRemote
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -24,7 +23,7 @@ def ask_password(host, user):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class RemoteHTTP(RemoteBASE):
|
class HTTPRemote(BaseRemote):
|
||||||
scheme = Schemes.HTTP
|
scheme = Schemes.HTTP
|
||||||
path_cls = HTTPURLInfo
|
path_cls = HTTPURLInfo
|
||||||
SESSION_RETRIES = 5
|
SESSION_RETRIES = 5
|
||||||
@@ -32,6 +31,7 @@ class RemoteHTTP(RemoteBASE):
|
|||||||
REQUEST_TIMEOUT = 10
|
REQUEST_TIMEOUT = 10
|
||||||
CHUNK_SIZE = 2 ** 16
|
CHUNK_SIZE = 2 ** 16
|
||||||
PARAM_CHECKSUM = "etag"
|
PARAM_CHECKSUM = "etag"
|
||||||
|
CAN_TRAVERSE = False
|
||||||
|
|
||||||
def __init__(self, repo, config):
|
def __init__(self, repo, config):
|
||||||
super().__init__(repo, config)
|
super().__init__(repo, config)
|
||||||
@@ -45,12 +45,6 @@ class RemoteHTTP(RemoteBASE):
|
|||||||
else:
|
else:
|
||||||
self.path_info = None
|
self.path_info = None
|
||||||
|
|
||||||
if not self.no_traverse:
|
|
||||||
raise ConfigError(
|
|
||||||
"HTTP doesn't support traversing the remote to list existing "
|
|
||||||
"files. Use: `dvc remote modify <name> no_traverse true`"
|
|
||||||
)
|
|
||||||
|
|
||||||
self.auth = config.get("auth", None)
|
self.auth = config.get("auth", None)
|
||||||
self.custom_auth_header = config.get("custom_auth_header", None)
|
self.custom_auth_header = config.get("custom_auth_header", None)
|
||||||
self.password = config.get("password", None)
|
self.password = config.get("password", None)
|
||||||
@@ -61,39 +55,42 @@ class RemoteHTTP(RemoteBASE):
|
|||||||
response = self._request("GET", from_info.url, stream=True)
|
response = self._request("GET", from_info.url, stream=True)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
raise HTTPError(response.status_code, response.reason)
|
raise HTTPError(response.status_code, response.reason)
|
||||||
with Tqdm(
|
with open(to_file, "wb") as fd:
|
||||||
total=None if no_progress_bar else self._content_length(response),
|
with Tqdm.wrapattr(
|
||||||
leave=False,
|
fd,
|
||||||
bytes=True,
|
"write",
|
||||||
desc=from_info.url if name is None else name,
|
total=None
|
||||||
disable=no_progress_bar,
|
if no_progress_bar
|
||||||
) as pbar:
|
else self._content_length(response),
|
||||||
with open(to_file, "wb") as fd:
|
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):
|
for chunk in response.iter_content(chunk_size=self.CHUNK_SIZE):
|
||||||
fd.write(chunk)
|
fd_wrapped.write(chunk)
|
||||||
pbar.update(len(chunk))
|
|
||||||
|
|
||||||
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):
|
||||||
with Tqdm(
|
def chunks():
|
||||||
total=None if no_progress_bar else os.path.getsize(from_file),
|
with open(from_file, "rb") as fd:
|
||||||
leave=False,
|
with Tqdm.wrapattr(
|
||||||
bytes=True,
|
fd,
|
||||||
desc=to_info.url if name is None else name,
|
"read",
|
||||||
disable=no_progress_bar,
|
total=None
|
||||||
) as pbar:
|
if no_progress_bar
|
||||||
|
else os.path.getsize(from_file),
|
||||||
def chunks():
|
leave=False,
|
||||||
with open(from_file, "rb") as fd:
|
desc=to_info.url if name is None else name,
|
||||||
|
disable=no_progress_bar,
|
||||||
|
) as fd_wrapped:
|
||||||
while True:
|
while True:
|
||||||
chunk = fd.read(self.CHUNK_SIZE)
|
chunk = fd_wrapped.read(self.CHUNK_SIZE)
|
||||||
if not chunk:
|
if not chunk:
|
||||||
break
|
break
|
||||||
pbar.update(len(chunk))
|
|
||||||
yield chunk
|
yield chunk
|
||||||
|
|
||||||
response = self._request("POST", to_info.url, data=chunks())
|
response = self._request("POST", to_info.url, data=chunks())
|
||||||
if response.status_code not in (200, 201):
|
if response.status_code not in (200, 201):
|
||||||
raise HTTPError(response.status_code, response.reason)
|
raise HTTPError(response.status_code, response.reason)
|
||||||
|
|
||||||
def exists(self, path_info):
|
def exists(self, path_info):
|
||||||
return bool(self._request("HEAD", path_info.url))
|
return bool(self._request("HEAD", path_info.url))
|
||||||
@@ -188,7 +185,7 @@ class RemoteHTTP(RemoteBASE):
|
|||||||
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 gc(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|||||||
+3
-2
@@ -1,6 +1,7 @@
|
|||||||
from .http import RemoteHTTP
|
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
|
|
||||||
|
from .http import HTTPRemote
|
||||||
|
|
||||||
class RemoteHTTPS(RemoteHTTP):
|
|
||||||
|
class HTTPSRemote(HTTPRemote):
|
||||||
scheme = Schemes.HTTPS
|
scheme = Schemes.HTTPS
|
||||||
|
|||||||
@@ -0,0 +1,212 @@
|
|||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import sqlite3
|
||||||
|
import threading
|
||||||
|
|
||||||
|
from funcy import lchunks
|
||||||
|
|
||||||
|
from dvc.state import _connect_sqlite
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class RemoteIndexNoop:
|
||||||
|
"""No-op class for remotes which are not indexed (i.e. local)."""
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def __exit__(self, typ, value, tbck):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
return iter([])
|
||||||
|
|
||||||
|
def __contains__(self, checksum):
|
||||||
|
return False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def checksums():
|
||||||
|
return []
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def dir_checksums():
|
||||||
|
return []
|
||||||
|
|
||||||
|
def load(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def dump(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def update(self, *args):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def intersection(*args):
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
class RemoteIndex:
|
||||||
|
"""Class for indexing remote checksums in a sqlite3 database.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
repo: repo for this remote index.
|
||||||
|
name: name for this index. Index db will be loaded from and saved to
|
||||||
|
``.dvc/tmp/index/{name}.idx``.
|
||||||
|
dir_suffix: suffix used for naming directory checksums
|
||||||
|
"""
|
||||||
|
|
||||||
|
INDEX_SUFFIX = ".idx"
|
||||||
|
VERSION = 1
|
||||||
|
INDEX_TABLE = "remote_index"
|
||||||
|
INDEX_TABLE_LAYOUT = "checksum TEXT PRIMARY KEY, " "dir INTEGER NOT NULL"
|
||||||
|
|
||||||
|
def __init__(self, repo, name, dir_suffix=".dir"):
|
||||||
|
self.path = os.path.join(repo.index_dir, f"{name}{self.INDEX_SUFFIX}")
|
||||||
|
|
||||||
|
self.dir_suffix = dir_suffix
|
||||||
|
self.database = None
|
||||||
|
self.cursor = None
|
||||||
|
self.modified = False
|
||||||
|
self.lock = threading.Lock()
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
cmd = f"SELECT checksum FROM {self.INDEX_TABLE}"
|
||||||
|
for (checksum,) in self._execute(cmd):
|
||||||
|
yield checksum
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
self.lock.acquire()
|
||||||
|
self.load()
|
||||||
|
|
||||||
|
def __exit__(self, typ, value, tbck):
|
||||||
|
self.dump()
|
||||||
|
self.lock.release()
|
||||||
|
|
||||||
|
def __contains__(self, checksum):
|
||||||
|
cmd = "SELECT checksum FROM {} WHERE checksum = (?)".format(
|
||||||
|
self.INDEX_TABLE
|
||||||
|
)
|
||||||
|
self._execute(cmd, (checksum,))
|
||||||
|
return self.cursor.fetchone() is not None
|
||||||
|
|
||||||
|
def checksums(self):
|
||||||
|
"""Iterate over checksums stored in the index."""
|
||||||
|
return iter(self)
|
||||||
|
|
||||||
|
def dir_checksums(self):
|
||||||
|
"""Iterate over .dir checksums stored in the index."""
|
||||||
|
cmd = f"SELECT checksum FROM {self.INDEX_TABLE} WHERE dir = 1"
|
||||||
|
for (checksum,) in self._execute(cmd):
|
||||||
|
yield checksum
|
||||||
|
|
||||||
|
def is_dir_checksum(self, checksum):
|
||||||
|
return checksum.endswith(self.dir_suffix)
|
||||||
|
|
||||||
|
def _execute(self, cmd, parameters=()):
|
||||||
|
return self.cursor.execute(cmd, parameters)
|
||||||
|
|
||||||
|
def _executemany(self, cmd, seq_of_parameters):
|
||||||
|
return self.cursor.executemany(cmd, seq_of_parameters)
|
||||||
|
|
||||||
|
def _prepare_db(self, empty=False):
|
||||||
|
if not empty:
|
||||||
|
cmd = "PRAGMA user_version;"
|
||||||
|
self._execute(cmd)
|
||||||
|
ret = self.cursor.fetchall()
|
||||||
|
assert len(ret) == 1
|
||||||
|
assert len(ret[0]) == 1
|
||||||
|
assert isinstance(ret[0][0], int)
|
||||||
|
version = ret[0][0]
|
||||||
|
|
||||||
|
if version != self.VERSION:
|
||||||
|
logger.error(
|
||||||
|
"Index file version '{}' will be reformatted "
|
||||||
|
"to the current version '{}'.".format(
|
||||||
|
version, self.VERSION,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
cmd = "DROP TABLE IF EXISTS {};"
|
||||||
|
self._execute(cmd.format(self.INDEX_TABLE))
|
||||||
|
|
||||||
|
cmd = "CREATE TABLE IF NOT EXISTS {} ({})"
|
||||||
|
self._execute(cmd.format(self.INDEX_TABLE, self.INDEX_TABLE_LAYOUT))
|
||||||
|
|
||||||
|
cmd = "PRAGMA user_version = {};"
|
||||||
|
self._execute(cmd.format(self.VERSION))
|
||||||
|
|
||||||
|
def load(self):
|
||||||
|
"""(Re)load this index database."""
|
||||||
|
retries = 1
|
||||||
|
while True:
|
||||||
|
assert self.database is None
|
||||||
|
assert self.cursor is None
|
||||||
|
|
||||||
|
empty = not os.path.isfile(self.path)
|
||||||
|
self.database = _connect_sqlite(self.path, {"nolock": 1})
|
||||||
|
self.cursor = self.database.cursor()
|
||||||
|
|
||||||
|
try:
|
||||||
|
self._prepare_db(empty=empty)
|
||||||
|
return
|
||||||
|
except sqlite3.DatabaseError:
|
||||||
|
self.cursor.close()
|
||||||
|
self.database.close()
|
||||||
|
self.database = None
|
||||||
|
self.cursor = None
|
||||||
|
if retries > 0:
|
||||||
|
os.unlink(self.path)
|
||||||
|
retries -= 1
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
|
def dump(self):
|
||||||
|
"""Save this index database."""
|
||||||
|
assert self.database is not None
|
||||||
|
|
||||||
|
self.database.commit()
|
||||||
|
self.cursor.close()
|
||||||
|
self.database.close()
|
||||||
|
self.database = None
|
||||||
|
self.cursor = None
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
"""Clear this index (to force re-indexing later).
|
||||||
|
|
||||||
|
Changes to the index will not committed until dump() is called.
|
||||||
|
"""
|
||||||
|
cmd = f"DELETE FROM {self.INDEX_TABLE}"
|
||||||
|
self._execute(cmd)
|
||||||
|
|
||||||
|
def update(self, dir_checksums, file_checksums):
|
||||||
|
"""Update this index, adding the specified checksums.
|
||||||
|
|
||||||
|
Changes to the index will not committed until dump() is called.
|
||||||
|
"""
|
||||||
|
cmd = "INSERT OR IGNORE INTO {} (checksum, dir) VALUES (?, ?)".format(
|
||||||
|
self.INDEX_TABLE
|
||||||
|
)
|
||||||
|
self._executemany(
|
||||||
|
cmd, ((checksum, True) for checksum in dir_checksums)
|
||||||
|
)
|
||||||
|
self._executemany(
|
||||||
|
cmd, ((checksum, False) for checksum in file_checksums)
|
||||||
|
)
|
||||||
|
|
||||||
|
def intersection(self, checksums):
|
||||||
|
"""Iterate over values from `checksums` which exist in the index."""
|
||||||
|
# sqlite has a compile time limit of 999, see:
|
||||||
|
# https://www.sqlite.org/c3ref/c_limit_attached.html#sqlitelimitvariablenumber
|
||||||
|
for chunk in lchunks(999, checksums):
|
||||||
|
cmd = "SELECT checksum FROM {} WHERE checksum IN ({})".format(
|
||||||
|
self.INDEX_TABLE, ",".join("?" for checksum in chunk)
|
||||||
|
)
|
||||||
|
for (checksum,) in self._execute(cmd, chunk):
|
||||||
|
yield checksum
|
||||||
+316
-127
@@ -2,31 +2,47 @@ import errno
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import stat
|
import stat
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
|
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 RemoteBASE, STATUS_MAP
|
from dvc.remote.base import (
|
||||||
from dvc.remote.base import STATUS_DELETED, STATUS_MISSING, STATUS_NEW
|
STATUS_DELETED,
|
||||||
|
STATUS_MAP,
|
||||||
|
STATUS_MISSING,
|
||||||
|
STATUS_NEW,
|
||||||
|
BaseRemote,
|
||||||
|
index_locked,
|
||||||
|
)
|
||||||
|
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 RemoteLOCAL(RemoteBASE):
|
class LocalRemote(BaseRemote):
|
||||||
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
|
||||||
|
INDEX_CLS = RemoteIndexNoop
|
||||||
|
|
||||||
UNPACKED_DIR_SUFFIX = ".unpacked"
|
UNPACKED_DIR_SUFFIX = ".unpacked"
|
||||||
|
|
||||||
@@ -52,13 +68,51 @@ class RemoteLOCAL(RemoteBASE):
|
|||||||
def cache_dir(self, value):
|
def cache_dir(self, value):
|
||||||
self.path_info = PathInfo(value) if value else None
|
self.path_info = PathInfo(value) if value else None
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def _work_tree(self):
|
||||||
|
if self.repo:
|
||||||
|
return WorkingTree(self.repo.root_dir)
|
||||||
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def work_tree(self):
|
||||||
|
# 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 and not is_working_tree(self.repo.tree):
|
||||||
|
return self._work_tree
|
||||||
|
return None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def supported(cls, config):
|
def supported(cls, config):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def list_cache_paths(self):
|
@cached_property
|
||||||
|
def cache_path(self):
|
||||||
|
return os.path.abspath(self.cache_dir)
|
||||||
|
|
||||||
|
def checksum_to_path(self, checksum):
|
||||||
|
# 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}{checksum[0:2]}{os.sep}{checksum[2:]}"
|
||||||
|
)
|
||||||
|
|
||||||
|
def list_cache_paths(self, prefix=None, progress_callback=None):
|
||||||
assert self.path_info is not None
|
assert self.path_info is not None
|
||||||
return walk_files(self.path_info)
|
if prefix:
|
||||||
|
path_info = self.path_info / prefix[:2]
|
||||||
|
if not self.exists(path_info):
|
||||||
|
return
|
||||||
|
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):
|
def get(self, md5):
|
||||||
if not md5:
|
if not md5:
|
||||||
@@ -66,10 +120,13 @@ class RemoteLOCAL(RemoteBASE):
|
|||||||
|
|
||||||
return self.checksum_to_path_info(md5).url
|
return self.checksum_to_path_info(md5).url
|
||||||
|
|
||||||
@staticmethod
|
def exists(self, path_info):
|
||||||
def exists(path_info):
|
assert isinstance(path_info, str) or path_info.scheme == "local"
|
||||||
assert path_info.scheme == "local"
|
if not self.repo:
|
||||||
return os.path.lexists(fspath_py35(path_info))
|
return os.path.exists(path_info)
|
||||||
|
if self.work_tree and self.work_tree.exists(path_info):
|
||||||
|
return True
|
||||||
|
return self.repo.tree.exists(path_info)
|
||||||
|
|
||||||
def makedirs(self, path_info):
|
def makedirs(self, path_info):
|
||||||
makedirs(path_info, exist_ok=True, mode=self._dir_mode)
|
makedirs(path_info, exist_ok=True, mode=self._dir_mode)
|
||||||
@@ -101,13 +158,19 @@ class RemoteLOCAL(RemoteBASE):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@staticmethod
|
def isfile(self, path_info):
|
||||||
def isfile(path_info):
|
if not self.repo:
|
||||||
return os.path.isfile(fspath_py35(path_info))
|
return os.path.isfile(path_info)
|
||||||
|
if self.work_tree and self.work_tree.isfile(path_info):
|
||||||
|
return True
|
||||||
|
return self.repo.tree.isfile(path_info)
|
||||||
|
|
||||||
@staticmethod
|
def isdir(self, path_info):
|
||||||
def isdir(path_info):
|
if not self.repo:
|
||||||
return os.path.isdir(fspath_py35(path_info))
|
return os.path.isdir(path_info)
|
||||||
|
if self.work_tree and self.work_tree.isdir(path_info):
|
||||||
|
return True
|
||||||
|
return self.repo.tree.isdir(path_info)
|
||||||
|
|
||||||
def iscopy(self, path_info):
|
def iscopy(self, path_info):
|
||||||
return not (
|
return not (
|
||||||
@@ -116,23 +179,29 @@ class RemoteLOCAL(RemoteBASE):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getsize(path_info):
|
def getsize(path_info):
|
||||||
return os.path.getsize(fspath_py35(path_info))
|
return os.path.getsize(path_info)
|
||||||
|
|
||||||
def walk_files(self, path_info):
|
def walk_files(self, path_info):
|
||||||
assert is_working_tree(self.repo.tree)
|
if self.work_tree:
|
||||||
|
tree = self.work_tree
|
||||||
for fname in self.repo.tree.walk_files(path_info):
|
else:
|
||||||
|
tree = self.repo.tree
|
||||||
|
for fname in tree.walk_files(path_info):
|
||||||
yield PathInfo(fname)
|
yield PathInfo(fname)
|
||||||
|
|
||||||
def get_file_checksum(self, path_info):
|
def get_file_checksum(self, path_info):
|
||||||
return file_md5(path_info)[0]
|
return file_md5(path_info)[0]
|
||||||
|
|
||||||
def remove(self, path_info):
|
def remove(self, path_info):
|
||||||
if path_info.scheme != "local":
|
if isinstance(path_info, PathInfo):
|
||||||
raise NotImplementedError
|
if path_info.scheme != "local":
|
||||||
|
raise NotImplementedError
|
||||||
|
path = path_info.fspath
|
||||||
|
else:
|
||||||
|
path = path_info
|
||||||
|
|
||||||
if self.exists(path_info):
|
if self.exists(path):
|
||||||
remove(path_info.fspath)
|
remove(path)
|
||||||
|
|
||||||
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":
|
||||||
@@ -152,8 +221,19 @@ class RemoteLOCAL(RemoteBASE):
|
|||||||
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
|
||||||
@@ -201,8 +281,8 @@ class RemoteLOCAL(RemoteBASE):
|
|||||||
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 cache_exists(self, checksums, jobs=None, name=None):
|
||||||
return [
|
return [
|
||||||
@@ -225,7 +305,9 @@ class RemoteLOCAL(RemoteBASE):
|
|||||||
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)
|
||||||
|
|
||||||
def _download(
|
def _download(
|
||||||
self, from_info, to_file, name=None, no_progress_bar=False, **_kwargs
|
self, from_info, to_file, name=None, no_progress_bar=False, **_kwargs
|
||||||
@@ -236,8 +318,9 @@ class RemoteLOCAL(RemoteBASE):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def open(path_info, mode="r", encoding=None):
|
def open(path_info, mode="r", encoding=None):
|
||||||
return open(fspath_py35(path_info), mode=mode, encoding=encoding)
|
return open(path_info, mode=mode, encoding=encoding)
|
||||||
|
|
||||||
|
@index_locked
|
||||||
def status(
|
def status(
|
||||||
self,
|
self,
|
||||||
named_cache,
|
named_cache,
|
||||||
@@ -246,37 +329,128 @@ class RemoteLOCAL(RemoteBASE):
|
|||||||
show_checksums=False,
|
show_checksums=False,
|
||||||
download=False,
|
download=False,
|
||||||
):
|
):
|
||||||
logger.debug(
|
# Return flattened dict containing all status info
|
||||||
"Preparing to collect status from {}".format(remote.path_info)
|
dir_status, file_status, _ = self._status(
|
||||||
|
named_cache,
|
||||||
|
remote,
|
||||||
|
jobs=jobs,
|
||||||
|
show_checksums=show_checksums,
|
||||||
|
download=download,
|
||||||
)
|
)
|
||||||
md5s = list(named_cache[self.scheme])
|
return dict(dir_status, **file_status)
|
||||||
|
|
||||||
|
def _status(
|
||||||
|
self,
|
||||||
|
named_cache,
|
||||||
|
remote,
|
||||||
|
jobs=None,
|
||||||
|
show_checksums=False,
|
||||||
|
download=False,
|
||||||
|
):
|
||||||
|
"""Return a tuple of (dir_status_info, file_status_info, dir_contents).
|
||||||
|
|
||||||
|
dir_status_info contains status for .dir files, file_status_info
|
||||||
|
contains status for all other files, and dir_contents is a dict of
|
||||||
|
{dir_checksum: set(file_checksum, ...)} which can be used to map
|
||||||
|
a .dir file to its file contents.
|
||||||
|
"""
|
||||||
|
logger.debug(f"Preparing to collect status from {remote.path_info}")
|
||||||
|
md5s = set(named_cache.scheme_keys(self.scheme))
|
||||||
|
|
||||||
logger.debug("Collecting information from local cache...")
|
logger.debug("Collecting information from local cache...")
|
||||||
local_exists = self.cache_exists(md5s, jobs=jobs, name=self.cache_dir)
|
local_exists = frozenset(
|
||||||
|
self.cache_exists(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,
|
||||||
# if the resources that we want to fetch are already cached,
|
# if the resources that we want to fetch are already cached,
|
||||||
# there's no need to check the remote storage for the existence of
|
# there's no need to check the remote storage for the existence of
|
||||||
# those files.
|
# those files.
|
||||||
if download and sorted(local_exists) == sorted(md5s):
|
if download and local_exists == md5s:
|
||||||
remote_exists = local_exists
|
remote_exists = local_exists
|
||||||
else:
|
else:
|
||||||
logger.debug("Collecting information from remote cache...")
|
logger.debug("Collecting information from remote cache...")
|
||||||
remote_exists = list(
|
remote_exists = set()
|
||||||
remote.cache_exists(
|
dir_md5s = set(named_cache.dir_keys(self.scheme))
|
||||||
md5s, jobs=jobs, name=str(remote.path_info)
|
if dir_md5s:
|
||||||
|
remote_exists.update(
|
||||||
|
self._indexed_dir_checksums(named_cache, remote, dir_md5s)
|
||||||
)
|
)
|
||||||
|
md5s.difference_update(remote_exists)
|
||||||
|
if md5s:
|
||||||
|
remote_exists.update(
|
||||||
|
remote.cache_exists(
|
||||||
|
md5s, jobs=jobs, name=str(remote.path_info)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return self._make_status(
|
||||||
|
named_cache, show_checksums, local_exists, remote_exists
|
||||||
|
)
|
||||||
|
|
||||||
|
def _make_status(
|
||||||
|
self, named_cache, show_checksums, local_exists, remote_exists
|
||||||
|
):
|
||||||
|
def make_names(checksum, names):
|
||||||
|
return {"name": checksum if show_checksums else " ".join(names)}
|
||||||
|
|
||||||
|
dir_status = {}
|
||||||
|
file_status = {}
|
||||||
|
dir_contents = {}
|
||||||
|
for checksum, item in named_cache[self.scheme].items():
|
||||||
|
if item.children:
|
||||||
|
dir_status[checksum] = make_names(checksum, item.names)
|
||||||
|
dir_contents[checksum] = set()
|
||||||
|
for child_checksum, child in item.children.items():
|
||||||
|
file_status[child_checksum] = make_names(
|
||||||
|
child_checksum, child.names
|
||||||
|
)
|
||||||
|
dir_contents[checksum].add(child_checksum)
|
||||||
|
else:
|
||||||
|
file_status[checksum] = make_names(checksum, item.names)
|
||||||
|
|
||||||
|
self._fill_statuses(dir_status, local_exists, remote_exists)
|
||||||
|
self._fill_statuses(file_status, local_exists, remote_exists)
|
||||||
|
|
||||||
|
self._log_missing_caches(dict(dir_status, **file_status))
|
||||||
|
|
||||||
|
return dir_status, file_status, dir_contents
|
||||||
|
|
||||||
|
def _indexed_dir_checksums(self, named_cache, remote, dir_md5s):
|
||||||
|
# Validate our index by verifying all indexed .dir checksums
|
||||||
|
# still exist on the remote
|
||||||
|
indexed_dirs = set(remote.index.dir_checksums())
|
||||||
|
indexed_dir_exists = set()
|
||||||
|
if indexed_dirs:
|
||||||
|
indexed_dir_exists.update(
|
||||||
|
remote._cache_object_exists(indexed_dirs)
|
||||||
)
|
)
|
||||||
|
missing_dirs = indexed_dirs.difference(indexed_dir_exists)
|
||||||
|
if missing_dirs:
|
||||||
|
logger.debug(
|
||||||
|
"Remote cache missing indexed .dir checksums '{}', "
|
||||||
|
"clearing remote index".format(", ".join(missing_dirs))
|
||||||
|
)
|
||||||
|
remote.index.clear()
|
||||||
|
|
||||||
ret = {
|
# Check if non-indexed (new) dir checksums exist on remote
|
||||||
checksum: {"name": checksum if show_checksums else " ".join(names)}
|
dir_exists = dir_md5s.intersection(indexed_dir_exists)
|
||||||
for checksum, names in named_cache[self.scheme].items()
|
dir_exists.update(remote._cache_object_exists(dir_md5s - dir_exists))
|
||||||
}
|
|
||||||
self._fill_statuses(ret, local_exists, remote_exists)
|
|
||||||
|
|
||||||
self._log_missing_caches(ret)
|
# If .dir checksum exists on the remote, assume directory contents
|
||||||
|
# still exists on the remote
|
||||||
return ret
|
for dir_checksum in dir_exists:
|
||||||
|
file_checksums = list(
|
||||||
|
named_cache.child_keys(self.scheme, dir_checksum)
|
||||||
|
)
|
||||||
|
if dir_checksum not in remote.index:
|
||||||
|
logger.debug(
|
||||||
|
"Indexing new .dir '{}' with '{}' nested files".format(
|
||||||
|
dir_checksum, len(file_checksums)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
remote.index.update([dir_checksum], file_checksums)
|
||||||
|
yield dir_checksum
|
||||||
|
yield from file_checksums
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _fill_statuses(checksum_info_dir, local_exists, remote_exists):
|
def _fill_statuses(checksum_info_dir, local_exists, remote_exists):
|
||||||
@@ -292,6 +466,7 @@ class RemoteLOCAL(RemoteBASE):
|
|||||||
cache = []
|
cache = []
|
||||||
path_infos = []
|
path_infos = []
|
||||||
names = []
|
names = []
|
||||||
|
checksums = []
|
||||||
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"
|
||||||
):
|
):
|
||||||
@@ -299,6 +474,7 @@ class RemoteLOCAL(RemoteBASE):
|
|||||||
cache.append(self.checksum_to_path_info(md5))
|
cache.append(self.checksum_to_path_info(md5))
|
||||||
path_infos.append(remote.checksum_to_path_info(md5))
|
path_infos.append(remote.checksum_to_path_info(md5))
|
||||||
names.append(info["name"])
|
names.append(info["name"])
|
||||||
|
checksums.append(md5)
|
||||||
|
|
||||||
if download:
|
if download:
|
||||||
to_infos = cache
|
to_infos = cache
|
||||||
@@ -307,7 +483,7 @@ class RemoteLOCAL(RemoteBASE):
|
|||||||
to_infos = path_infos
|
to_infos = path_infos
|
||||||
from_infos = cache
|
from_infos = cache
|
||||||
|
|
||||||
return from_infos, to_infos, names
|
return from_infos, to_infos, names, checksums
|
||||||
|
|
||||||
def _process(
|
def _process(
|
||||||
self,
|
self,
|
||||||
@@ -331,14 +507,16 @@ class RemoteLOCAL(RemoteBASE):
|
|||||||
file_mode=self._file_mode,
|
file_mode=self._file_mode,
|
||||||
)
|
)
|
||||||
status = STATUS_DELETED
|
status = STATUS_DELETED
|
||||||
|
desc = "Downloading"
|
||||||
else:
|
else:
|
||||||
func = remote.upload
|
func = remote.upload
|
||||||
status = STATUS_NEW
|
status = STATUS_NEW
|
||||||
|
desc = "Uploading"
|
||||||
|
|
||||||
if jobs is None:
|
if jobs is None:
|
||||||
jobs = remote.JOBS
|
jobs = remote.JOBS
|
||||||
|
|
||||||
status_info = self.status(
|
dir_status, file_status, dir_contents = self._status(
|
||||||
named_cache,
|
named_cache,
|
||||||
remote,
|
remote,
|
||||||
jobs=jobs,
|
jobs=jobs,
|
||||||
@@ -346,24 +524,87 @@ class RemoteLOCAL(RemoteBASE):
|
|||||||
download=download,
|
download=download,
|
||||||
)
|
)
|
||||||
|
|
||||||
plans = self._get_plans(download, remote, status_info, status)
|
dir_plans = self._get_plans(download, remote, dir_status, status)
|
||||||
|
file_plans = self._get_plans(download, remote, file_status, status)
|
||||||
|
|
||||||
if len(plans[0]) == 0:
|
total = len(dir_plans[0]) + len(file_plans[0])
|
||||||
|
if total == 0:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if jobs > 1:
|
with Tqdm(total=total, unit="file", desc=desc) as pbar:
|
||||||
|
func = pbar.wrap_fn(func)
|
||||||
with ThreadPoolExecutor(max_workers=jobs) as executor:
|
with ThreadPoolExecutor(max_workers=jobs) as executor:
|
||||||
fails = sum(executor.map(func, *plans))
|
if download:
|
||||||
else:
|
fails = sum(executor.map(func, *dir_plans))
|
||||||
fails = sum(map(func, *plans))
|
fails += sum(executor.map(func, *file_plans))
|
||||||
|
else:
|
||||||
|
# for uploads, push files first, and any .dir files last
|
||||||
|
|
||||||
|
file_futures = {}
|
||||||
|
for from_info, to_info, name, checksum in zip(*file_plans):
|
||||||
|
file_futures[checksum] = executor.submit(
|
||||||
|
func, from_info, to_info, name
|
||||||
|
)
|
||||||
|
dir_futures = {}
|
||||||
|
for from_info, to_info, name, dir_checksum in zip(
|
||||||
|
*dir_plans
|
||||||
|
):
|
||||||
|
wait_futures = {
|
||||||
|
future
|
||||||
|
for file_checksum, future in file_futures.items()
|
||||||
|
if file_checksum in dir_contents[dir_checksum]
|
||||||
|
}
|
||||||
|
dir_futures[dir_checksum] = executor.submit(
|
||||||
|
self._dir_upload,
|
||||||
|
func,
|
||||||
|
wait_futures,
|
||||||
|
from_info,
|
||||||
|
to_info,
|
||||||
|
name,
|
||||||
|
)
|
||||||
|
fails = sum(
|
||||||
|
future.result()
|
||||||
|
for future in concat(
|
||||||
|
file_futures.values(), dir_futures.values()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if fails:
|
if fails:
|
||||||
if download:
|
if download:
|
||||||
|
remote.index.clear()
|
||||||
raise DownloadError(fails)
|
raise DownloadError(fails)
|
||||||
raise UploadError(fails)
|
raise UploadError(fails)
|
||||||
|
|
||||||
return len(plans[0])
|
if not download:
|
||||||
|
# index successfully pushed dirs
|
||||||
|
for dir_checksum, future in dir_futures.items():
|
||||||
|
if future.result() == 0:
|
||||||
|
file_checksums = dir_contents[dir_checksum]
|
||||||
|
logger.debug(
|
||||||
|
"Indexing pushed dir '{}' with "
|
||||||
|
"'{}' nested files".format(
|
||||||
|
dir_checksum, len(file_checksums)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
remote.index.update([dir_checksum], file_checksums)
|
||||||
|
|
||||||
|
return len(dir_plans[0]) + len(file_plans[0])
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _dir_upload(func, futures, from_info, to_info, name):
|
||||||
|
for future in as_completed(futures):
|
||||||
|
if future.result():
|
||||||
|
# do not upload this .dir file if any file in this
|
||||||
|
# directory failed to upload
|
||||||
|
logger.debug(
|
||||||
|
"failed to upload full contents of '{}', "
|
||||||
|
"aborting .dir file upload".format(name)
|
||||||
|
)
|
||||||
|
logger.error(f"failed to upload '{from_info}' to '{to_info}'")
|
||||||
|
return 1
|
||||||
|
return func(from_info, to_info, name)
|
||||||
|
|
||||||
|
@index_locked
|
||||||
def push(self, named_cache, remote, jobs=None, show_checksums=False):
|
def push(self, named_cache, remote, jobs=None, show_checksums=False):
|
||||||
return self._process(
|
return self._process(
|
||||||
named_cache,
|
named_cache,
|
||||||
@@ -373,6 +614,7 @@ class RemoteLOCAL(RemoteBASE):
|
|||||||
download=False,
|
download=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@index_locked
|
||||||
def pull(self, named_cache, remote, jobs=None, show_checksums=False):
|
def pull(self, named_cache, remote, jobs=None, show_checksums=False):
|
||||||
return self._process(
|
return self._process(
|
||||||
named_cache,
|
named_cache,
|
||||||
@@ -402,7 +644,7 @@ class RemoteLOCAL(RemoteBASE):
|
|||||||
|
|
||||||
def _unprotect_file(self, path):
|
def _unprotect_file(self, path):
|
||||||
if System.is_symlink(path) or System.is_hardlink(path):
|
if System.is_symlink(path) or System.is_hardlink(path):
|
||||||
logger.debug("Unprotecting '{}'".format(path))
|
logger.debug(f"Unprotecting '{path}'")
|
||||||
tmp = os.path.join(os.path.dirname(path), "." + uuid())
|
tmp = os.path.join(os.path.dirname(path), "." + uuid())
|
||||||
|
|
||||||
# The operations order is important here - if some application
|
# The operations order is important here - if some application
|
||||||
@@ -431,9 +673,7 @@ class RemoteLOCAL(RemoteBASE):
|
|||||||
def unprotect(self, path_info):
|
def unprotect(self, path_info):
|
||||||
path = path_info.fspath
|
path = path_info.fspath
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
raise DvcException(
|
raise DvcException(f"can't unprotect non-existing data '{path}'")
|
||||||
"can't unprotect non-existing data '{}'".format(path)
|
|
||||||
)
|
|
||||||
|
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
self._unprotect_dir(path)
|
self._unprotect_dir(path)
|
||||||
@@ -441,85 +681,34 @@ class RemoteLOCAL(RemoteBASE):
|
|||||||
self._unprotect_file(path)
|
self._unprotect_file(path)
|
||||||
|
|
||||||
def protect(self, path_info):
|
def protect(self, path_info):
|
||||||
path = fspath_py35(path_info)
|
path = os.fspath(path_info)
|
||||||
mode = self.CACHE_MODE
|
mode = self.CACHE_MODE
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.chmod(path, mode)
|
os.chmod(path, mode)
|
||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
# In share cache scenario, we might not own the cache file, so we
|
# 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.
|
# need to check if cache file is already protected.
|
||||||
if exc.errno not in [errno.EPERM, errno.EACCES]:
|
if exc.errno not in [errno.EPERM, errno.EACCES]:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
actual = os.stat(path).st_mode
|
actual = stat.S_IMODE(os.stat(path).st_mode)
|
||||||
if actual & mode != mode:
|
if actual != mode:
|
||||||
raise
|
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):
|
def _remove_unpacked_dir(self, checksum):
|
||||||
path_info = self._get_unpacked_dir_path_info(checksum)
|
info = self.checksum_to_path_info(checksum)
|
||||||
|
path_info = info.with_name(info.name + self.UNPACKED_DIR_SUFFIX)
|
||||||
self.remove(path_info)
|
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):
|
def is_protected(self, path_info):
|
||||||
if not self.exists(path_info):
|
try:
|
||||||
|
mode = os.stat(path_info).st_mode
|
||||||
|
except FileNotFoundError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
mode = os.stat(fspath_py35(path_info)).st_mode
|
|
||||||
|
|
||||||
return stat.S_IMODE(mode) == self.CACHE_MODE
|
return stat.S_IMODE(mode) == self.CACHE_MODE
|
||||||
|
|||||||
+19
-10
@@ -1,19 +1,19 @@
|
|||||||
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 RemoteBASE
|
from dvc.remote.base import BaseRemote
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class RemoteOSS(RemoteBASE):
|
class OSSRemote(BaseRemote):
|
||||||
"""
|
"""
|
||||||
oss2 document:
|
oss2 document:
|
||||||
https://www.alibabacloud.com/help/doc-detail/32026.htm
|
https://www.alibabacloud.com/help/doc-detail/32026.htm
|
||||||
@@ -37,6 +37,7 @@ class RemoteOSS(RemoteBASE):
|
|||||||
REQUIRES = {"oss2": "oss2"}
|
REQUIRES = {"oss2": "oss2"}
|
||||||
PARAM_CHECKSUM = "etag"
|
PARAM_CHECKSUM = "etag"
|
||||||
COPY_POLL_SECONDS = 5
|
COPY_POLL_SECONDS = 5
|
||||||
|
LIST_OBJECT_PAGE_SIZE = 100
|
||||||
|
|
||||||
def __init__(self, repo, config):
|
def __init__(self, repo, config):
|
||||||
super().__init__(repo, config)
|
super().__init__(repo, config)
|
||||||
@@ -63,9 +64,9 @@ class RemoteOSS(RemoteBASE):
|
|||||||
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)
|
||||||
@@ -86,17 +87,25 @@ class RemoteOSS(RemoteBASE):
|
|||||||
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):
|
def _list_paths(self, prefix, progress_callback=None):
|
||||||
import oss2
|
import oss2
|
||||||
|
|
||||||
for blob in oss2.ObjectIterator(self.oss_service, prefix=prefix):
|
for blob in oss2.ObjectIterator(self.oss_service, prefix=prefix):
|
||||||
|
if progress_callback:
|
||||||
|
progress_callback()
|
||||||
yield blob.key
|
yield blob.key
|
||||||
|
|
||||||
def list_cache_paths(self):
|
def list_cache_paths(self, prefix=None, progress_callback=None):
|
||||||
return self._list_paths(self.path_info.path)
|
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
|
||||||
|
|||||||
+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
|
||||||
|
|||||||
+37
-17
@@ -1,23 +1,21 @@
|
|||||||
# -*- 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 RemoteBASE
|
from dvc.remote.base import BaseRemote
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class RemoteS3(RemoteBASE):
|
class S3Remote(BaseRemote):
|
||||||
scheme = Schemes.S3
|
scheme = Schemes.S3
|
||||||
path_cls = CloudURLInfo
|
path_cls = CloudURLInfo
|
||||||
REQUIRES = {"boto3": "boto3"}
|
REQUIRES = {"boto3": "boto3"}
|
||||||
@@ -46,6 +44,10 @@ class RemoteS3(RemoteBASE):
|
|||||||
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
|
||||||
@@ -84,9 +86,7 @@ class RemoteS3(RemoteBASE):
|
|||||||
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
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -109,7 +109,7 @@ class RemoteS3(RemoteBASE):
|
|||||||
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,
|
||||||
@@ -187,27 +187,44 @@ class RemoteS3(RemoteBASE):
|
|||||||
if path_info.scheme != "s3":
|
if path_info.scheme != "s3":
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
logger.debug("Removing {}".format(path_info))
|
logger.debug(f"Removing {path_info}")
|
||||||
self.s3.delete_object(Bucket=path_info.bucket, Key=path_info.path)
|
self.s3.delete_object(Bucket=path_info.bucket, Key=path_info.path)
|
||||||
|
|
||||||
def _list_objects(self, path_info, max_items=None):
|
def _list_objects(
|
||||||
|
self, path_info, max_items=None, prefix=None, progress_callback=None
|
||||||
|
):
|
||||||
""" Read config for list object api, paginate through list objects."""
|
""" Read config for list object api, paginate through list objects."""
|
||||||
kwargs = {
|
kwargs = {
|
||||||
"Bucket": path_info.bucket,
|
"Bucket": path_info.bucket,
|
||||||
"Prefix": path_info.path,
|
"Prefix": path_info.path,
|
||||||
"PaginationConfig": {"MaxItems": max_items},
|
"PaginationConfig": {"MaxItems": max_items},
|
||||||
}
|
}
|
||||||
|
if prefix:
|
||||||
|
kwargs["Prefix"] = posixpath.join(path_info.path, prefix[:2])
|
||||||
paginator = self.s3.get_paginator(self.list_objects_api)
|
paginator = self.s3.get_paginator(self.list_objects_api)
|
||||||
for page in paginator.paginate(**kwargs):
|
for page in paginator.paginate(**kwargs):
|
||||||
yield from page.get("Contents", ())
|
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):
|
def _list_paths(
|
||||||
|
self, path_info, max_items=None, prefix=None, progress_callback=None
|
||||||
|
):
|
||||||
return (
|
return (
|
||||||
item["Key"] for item in self._list_objects(path_info, max_items)
|
item["Key"]
|
||||||
|
for item in self._list_objects(
|
||||||
|
path_info, max_items, prefix, progress_callback
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def list_cache_paths(self):
|
def list_cache_paths(self, prefix=None, progress_callback=None):
|
||||||
return self._list_paths(self.path_info)
|
return self._list_paths(
|
||||||
|
self.path_info, prefix=prefix, progress_callback=progress_callback
|
||||||
|
)
|
||||||
|
|
||||||
def isfile(self, path_info):
|
def isfile(self, path_info):
|
||||||
from botocore.exceptions import ClientError
|
from botocore.exceptions import ClientError
|
||||||
@@ -238,6 +255,9 @@ class RemoteS3(RemoteBASE):
|
|||||||
#
|
#
|
||||||
# We are not creating directory objects for every parent prefix,
|
# We are not creating directory objects for every parent prefix,
|
||||||
# as it is not required.
|
# as it is not required.
|
||||||
|
if not path_info.path:
|
||||||
|
return
|
||||||
|
|
||||||
dir_path = path_info / ""
|
dir_path = path_info / ""
|
||||||
self.s3.put_object(Bucket=path_info.bucket, Key=dir_path.path, Body="")
|
self.s3.put_object(Bucket=path_info.bucket, Key=dir_path.path, Body="")
|
||||||
|
|
||||||
|
|||||||
@@ -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__]
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user