mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-26 15:28:28 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2e01ce1974 | ||
|
|
d587d41d6c | ||
|
|
27c2401f59 | ||
|
|
174621696d | ||
|
|
e1a193f00b | ||
|
|
cccead3441 | ||
|
|
8102ede5cc | ||
|
|
14944dd9e0 | ||
|
|
63f32936b2 | ||
|
|
7d13d24a1f | ||
|
|
9cb8187cb3 | ||
|
|
98590779eb | ||
|
|
9ae8bcdf52 | ||
|
|
14958ff85f | ||
|
|
9909ee85a1 | ||
|
|
45477a2a81 | ||
|
|
282e83c481 | ||
|
|
51988475a4 | ||
|
|
52ee995f5e | ||
|
|
e0842ce01e | ||
|
|
a814a49181 | ||
|
|
d28f5675b4 | ||
|
|
66f24b8708 | ||
|
|
ae8efdeb0f | ||
|
|
53ba51b5fe | ||
|
|
e90c5fdd19 | ||
|
|
a72cea67f1 | ||
|
|
242d346f15 | ||
|
|
bb24131530 | ||
|
|
b0fd40f12c | ||
|
|
9ce6bce9b6 | ||
|
|
f4b14c2d4a | ||
|
|
273b02fc54 | ||
|
|
7c5e0f2949 | ||
|
|
ac9819eb02 | ||
|
|
02cfe33cf9 | ||
|
|
c635493104 | ||
|
|
039c2421d9 | ||
|
|
e3ee960e8e | ||
|
|
9d82739b3a | ||
|
|
fa550f91c3 | ||
|
|
384a4113ca | ||
|
|
b370465209 | ||
|
|
748bda8950 | ||
|
|
47bdf523d7 | ||
|
|
0fdb119ed5 | ||
|
|
226c68f8ff | ||
|
|
02a0d1af52 | ||
|
|
eeeaa9d324 | ||
|
|
a7da6c2a80 | ||
|
|
b75aab4d85 | ||
|
|
f30d51ca42 | ||
|
|
4b938c5104 | ||
|
|
550cbb5e11 | ||
|
|
5900151ebd | ||
|
|
e7686f90a6 | ||
|
|
e97f8fe19c | ||
|
|
320715a5f8 | ||
|
|
8676617ae0 | ||
|
|
e7cc7765ac | ||
|
|
21200c14df | ||
|
|
ce554b6ae7 | ||
|
|
79dafe8310 | ||
|
|
982802effc | ||
|
|
b87e76aa84 | ||
|
|
2c81bf1748 | ||
|
|
adedd19c52 | ||
|
|
985aef883e | ||
|
|
ffaac0f088 | ||
|
|
fc77618ad1 | ||
|
|
b2c2929869 | ||
|
|
a92bfd272d | ||
|
|
31e4a3325d | ||
|
|
67980de44d | ||
|
|
8932e0be84 | ||
|
|
9ad1e0e159 | ||
|
|
4348832b44 | ||
|
|
d05be36694 | ||
|
|
2ea5ef07dd | ||
|
|
8205c84077 | ||
|
|
b020918f5d | ||
|
|
c84833bab1 | ||
|
|
13db267a5d | ||
|
|
b337396144 | ||
|
|
3feaa86696 | ||
|
|
131eb7b3a1 | ||
|
|
b771b06b25 | ||
|
|
08300d3bcf | ||
|
|
bb46043689 | ||
|
|
fe2d913821 | ||
|
|
969a85efb6 | ||
|
|
b1d6918c5a | ||
|
|
a5e19ecd6a | ||
|
|
434cd305e9 | ||
|
|
8112ce36d1 | ||
|
|
6a1f3659f5 | ||
|
|
ec82c3fff5 | ||
|
|
d4757120c9 | ||
|
|
9f0b86f221 | ||
|
|
48dbcf9163 | ||
|
|
3741f730e0 | ||
|
|
58c97b963c | ||
|
|
6a9c0c5ce5 | ||
|
|
1d8761e0c9 | ||
|
|
2277a1a655 | ||
|
|
cbd7472079 | ||
|
|
7b59108379 | ||
|
|
c4888cbd7d | ||
|
|
9203d33a3c | ||
|
|
60d83a74d7 | ||
|
|
689ae22fb4 | ||
|
|
b5068a9200 | ||
|
|
c6ce69dd30 | ||
|
|
7cbcd4a7be | ||
|
|
03fc531a5c | ||
|
|
d038bca05e | ||
|
|
d8982c6db7 | ||
|
|
372d6f045b | ||
|
|
51ada6d272 | ||
|
|
55df6b8a6a | ||
|
|
8b0e0b995e | ||
|
|
407f5607a2 | ||
|
|
78e12327bc | ||
|
|
4f2de7a3ef | ||
|
|
f8c9797f2a | ||
|
|
28f6beaf78 | ||
|
|
628f87845c | ||
|
|
273518afab | ||
|
|
b027760e12 | ||
|
|
a2cac8b423 | ||
|
|
3e42e015d6 | ||
|
|
257f58450a | ||
|
|
c840cecc91 | ||
|
|
e5f91f5c7f | ||
|
|
2ee68b01b0 | ||
|
|
f8200ca2b8 | ||
|
|
228b3b16e5 | ||
|
|
1ab1abf62a | ||
|
|
49974c075c | ||
|
|
a2c91d2058 | ||
|
|
7fd191126e | ||
|
|
5374880220 | ||
|
|
c83a4ea406 | ||
|
|
6b05cc5e24 | ||
|
|
388eccad13 | ||
|
|
ccc17917cf | ||
|
|
386d0c463a | ||
|
|
c04cdaf70f | ||
|
|
fa5487ebfe | ||
|
|
9331ad23e4 | ||
|
|
66fc988ebf | ||
|
|
40122cefa5 | ||
|
|
a9ccf70439 | ||
|
|
a9d620beda | ||
|
|
af2a12a188 | ||
|
|
00461bb5df | ||
|
|
0db41b94fc | ||
|
|
2646c0d6bc | ||
|
|
1cc646614f | ||
|
|
84e9c1b0de | ||
|
|
4f692b0b69 | ||
|
|
6fb84f641c | ||
|
|
9b73a745b4 | ||
|
|
4c53e636bc | ||
|
|
40bd838c11 | ||
|
|
709e121b31 | ||
|
|
0cc5227f47 | ||
|
|
4f89db8e0d | ||
|
|
37f890444a | ||
|
|
b779a117ab | ||
|
|
c0fbdb3531 | ||
|
|
a017b87db5 | ||
|
|
c4970a016f | ||
|
|
cffc019e1f | ||
|
|
8010005364 | ||
|
|
261ddc947b | ||
|
|
862ab8de62 | ||
|
|
19606ba211 | ||
|
|
7df53e5e26 | ||
|
|
764960fbfc | ||
|
|
948633782e | ||
|
|
ceaba68f62 | ||
|
|
8162bb159c | ||
|
|
c28e671f47 | ||
|
|
34ed545d64 | ||
|
|
23811e028c | ||
|
|
6fcafc9121 | ||
|
|
db555ec66b | ||
|
|
c64b4ce78f | ||
|
|
01a4473c20 | ||
|
|
77ff24260e | ||
|
|
7a92ff5e5d | ||
|
|
fa4bf40eb4 | ||
|
|
11382cc891 | ||
|
|
eb8e03a465 | ||
|
|
0bb3f40be8 | ||
|
|
afe96974c3 | ||
|
|
a6151eaf9e | ||
|
|
76cc70a86b | ||
|
|
4d36bc4de8 | ||
|
|
af26d54524 | ||
|
|
4b30b8bea6 | ||
|
|
5db7a4cab6 | ||
|
|
dcea83e75b | ||
|
|
f51bef040a | ||
|
|
2ce617c642 | ||
|
|
f5d46c2fdf | ||
|
|
7e2520c02a | ||
|
|
723477ed5a | ||
|
|
76c6c54278 | ||
|
|
dcce3a31a9 | ||
|
|
64dfaffd7c | ||
|
|
aec8d65791 | ||
|
|
8a38611e26 | ||
|
|
6b9d842b26 | ||
|
|
84a3a59bc7 | ||
|
|
31502aee0a | ||
|
|
2512df7ca1 | ||
|
|
11c94b10f2 | ||
|
|
6cad3c95dd | ||
|
|
aa4ec8acd5 | ||
|
|
b0b04d44b1 | ||
|
|
fa76c79ee9 | ||
|
|
78e0434dd3 | ||
|
|
6e92352001 | ||
|
|
89c7f984ad | ||
|
|
620d082b0b | ||
|
|
62afee1e2d | ||
|
|
c5496870e5 | ||
|
|
a217e4a18b | ||
|
|
526f615647 | ||
|
|
1dafbd8361 | ||
|
|
d3acbfe2b1 | ||
|
|
96a97ec0e4 | ||
|
|
7f52170465 | ||
|
|
1331651fe1 | ||
|
|
189e88f1db | ||
|
|
9967d52885 | ||
|
|
e0884df99c | ||
|
|
09cec69429 | ||
|
|
3b23dfebae | ||
|
|
13bb56aa8e | ||
|
|
7bf9a0e805 | ||
|
|
a7d665157c | ||
|
|
475fe544f0 | ||
|
|
995287bbba | ||
|
|
51fa0f5c38 | ||
|
|
a41e23a453 | ||
|
|
821ec0a934 | ||
|
|
6c7eccf5fd | ||
|
|
b072370efb | ||
|
|
c4f92314db | ||
|
|
f09c27e74c | ||
|
|
529073967e | ||
|
|
69eb86a06f | ||
|
|
9a9f46b2b8 | ||
|
|
5152866634 | ||
|
|
f49feddb7f | ||
|
|
94f2a1d3be | ||
|
|
8252ae5f3c | ||
|
|
bb84f5d9e2 | ||
|
|
f50f12ad61 | ||
|
|
7e4966fbe5 | ||
|
|
2e9fac5fb3 | ||
|
|
2d70bc5ec4 | ||
|
|
176a23e291 | ||
|
|
c884c94d61 | ||
|
|
f6f18bc201 | ||
|
|
3a3fa7cdde | ||
|
|
1e1a0999f6 | ||
|
|
7f0537038c | ||
|
|
7c45711e34 | ||
|
|
1e52bc94a3 | ||
|
|
38cbd998e1 | ||
|
|
09a88b8ea6 | ||
|
|
bc1d10532a | ||
|
|
56322d0a53 | ||
|
|
f4f0554884 | ||
|
|
011bd18e9f | ||
|
|
6d745eb4f0 | ||
|
|
788d840e7d | ||
|
|
7586c32d95 | ||
|
|
dcba0e8da4 | ||
|
|
1294450a46 | ||
|
|
c989b28eae | ||
|
|
abb78ce19d | ||
|
|
bc4c9fe9ea | ||
|
|
d138bdd72a | ||
|
|
7c3c2e8123 | ||
|
|
04c53601c0 | ||
|
|
3ba70d375e | ||
|
|
85ad7358d9 | ||
|
|
cb56f57908 | ||
|
|
a7a007e4f9 | ||
|
|
e33274723d | ||
|
|
f1efc8f409 | ||
|
|
1a2c91eb5a | ||
|
|
806f8032d9 | ||
|
|
8cb4202292 | ||
|
|
5faae2a6e9 | ||
|
|
6237a665c3 | ||
|
|
011bd35a6c | ||
|
|
133018af78 | ||
|
|
c65fdcabae | ||
|
|
e1692a6be0 | ||
|
|
c8f37fdb88 | ||
|
|
7f66db7039 | ||
|
|
470f411cd6 | ||
|
|
d721e919e4 | ||
|
|
c03fbb0056 | ||
|
|
cb3e52829b | ||
|
|
4b7d130003 | ||
|
|
d5312e56a1 | ||
|
|
2a6c4291ce | ||
|
|
40c3bbd1ba | ||
|
|
92b17e3a89 | ||
|
|
153c374c02 | ||
|
|
4cf2f8139b | ||
|
|
c2ec8b27ca | ||
|
|
6324bd8a69 | ||
|
|
251a3269c2 | ||
|
|
b340254556 | ||
|
|
7501302baa | ||
|
|
d7564e9965 | ||
|
|
d06dd3caa9 | ||
|
|
9741f6d706 | ||
|
|
ca2e6a004c | ||
|
|
40bdf613f0 | ||
|
|
379ed8e6fc | ||
|
|
2f6a8a7349 | ||
|
|
d5b7f7cf2c | ||
|
|
1788fe95dd | ||
|
|
96ead9425a | ||
|
|
f4349aa09b | ||
|
|
2f620e9226 | ||
|
|
d3931def53 | ||
|
|
3ec64301b9 | ||
|
|
8e738262ad | ||
|
|
3daeeaffdb | ||
|
|
eeba567774 | ||
|
|
72eb4a5737 | ||
|
|
72ec2a8541 | ||
|
|
07676b2531 | ||
|
|
556143fd7e | ||
|
|
b8cd02457a | ||
|
|
de01b11483 | ||
|
|
38d811035c | ||
|
|
389efd7ae6 | ||
|
|
f0ad1b4f93 | ||
|
|
f6d40948d6 | ||
|
|
4b27fd7c23 | ||
|
|
4220baa602 | ||
|
|
2e9fa0607e | ||
|
|
685e76cfbe | ||
|
|
dca48fe8d7 | ||
|
|
9f1330a387 | ||
|
|
f4ee0e16b4 | ||
|
|
4531aa34ca | ||
|
|
80e181f2fc | ||
|
|
c85a46cdda | ||
|
|
89bf7fce13 | ||
|
|
42d50f084f | ||
|
|
edd8344659 | ||
|
|
4b17685351 | ||
|
|
e1b82c5222 | ||
|
|
e9a9415fbf | ||
|
|
6494bd0151 | ||
|
|
d1441ee16a | ||
|
|
7da3de451f | ||
|
|
4a3f06df3a | ||
|
|
2225764438 | ||
|
|
644444b5a7 | ||
|
|
60b69b93cb | ||
|
|
fec1499c67 | ||
|
|
a38941b47e | ||
|
|
6a9ab9cdfb | ||
|
|
e211423398 | ||
|
|
96cdd073bd | ||
|
|
59d5c73c5e | ||
|
|
58bed0e9ba | ||
|
|
92752e0392 | ||
|
|
4a7bb49bb0 | ||
|
|
3d58f4b8ce | ||
|
|
f827d641d5 | ||
|
|
9940540917 | ||
|
|
32fa8e33c4 | ||
|
|
911534116e | ||
|
|
9b136f0c3f | ||
|
|
411b388960 | ||
|
|
e6016ca202 | ||
|
|
b2495aa230 | ||
|
|
f4522760ba | ||
|
|
0736c64188 | ||
|
|
6cf194f85f | ||
|
|
5038fd225b | ||
|
|
bfecd7d8e8 | ||
|
|
a5bdfa90f0 | ||
|
|
4d75e75631 | ||
|
|
f8ba5daae2 | ||
|
|
831e85682e | ||
|
|
ec05e6026f | ||
|
|
0669d8d885 | ||
|
|
2c7d89939c | ||
|
|
e8c4924997 | ||
|
|
2747e77012 | ||
|
|
87f1c42acf | ||
|
|
8a5dc6a781 | ||
|
|
33ece011fb | ||
|
|
79232dfedf | ||
|
|
aa7b4c6340 | ||
|
|
668002cb01 | ||
|
|
25efd0efe8 | ||
|
|
b0ae5e2251 | ||
|
|
e48055077d | ||
|
|
7527a220f6 | ||
|
|
feaa5cfcb2 | ||
|
|
10ae13132d | ||
|
|
924323f54f | ||
|
|
235d4c9a94 | ||
|
|
4b6ebc7527 | ||
|
|
699602f4d0 | ||
|
|
10a2eeb2b8 | ||
|
|
b9f547637c | ||
|
|
052b15a2a8 | ||
|
|
68220cbea0 | ||
|
|
21a6be7c58 | ||
|
|
2b90d7dfaf | ||
|
|
9d7e483599 | ||
|
|
8f8c561d1b | ||
|
|
32cef509b7 | ||
|
|
6a79111047 | ||
|
|
09e51e655d | ||
|
|
4aa8fd0fbb | ||
|
|
3cebd98c54 | ||
|
|
b11fe83828 | ||
|
|
cc8d0ef43f | ||
|
|
3e011d70d5 | ||
|
|
0649242578 | ||
|
|
549f342db9 | ||
|
|
4e53491f5c | ||
|
|
0da1664f3f | ||
|
|
3b6a1c441e | ||
|
|
ca490f699e | ||
|
|
59105ec639 | ||
|
|
1d550f35af | ||
|
|
fba94a4569 | ||
|
|
0e257adc63 | ||
|
|
8b28a268e8 | ||
|
|
09f9506ca0 | ||
|
|
f20adf5e0f | ||
|
|
9f90c806d5 | ||
|
|
c16d3fa43d | ||
|
|
3ceef7dbf1 | ||
|
|
34804b5636 | ||
|
|
060fc4fbb7 | ||
|
|
4496dbf5b5 | ||
|
|
334afebd31 | ||
|
|
775e1e8374 | ||
|
|
548c2dcc1f | ||
|
|
15b1e7072b | ||
|
|
f0a729df4d | ||
|
|
7424f22e2a | ||
|
|
9ee5018c63 | ||
|
|
026047aa80 | ||
|
|
3878c50ea8 | ||
|
|
3ffb6320ac | ||
|
|
52fe76cefc | ||
|
|
d0e1c88792 | ||
|
|
fcdb503b4e | ||
|
|
3d2493a391 | ||
|
|
fc6999ad17 | ||
|
|
e0b3e98039 | ||
|
|
04bd460136 | ||
|
|
d7a35b9852 | ||
|
|
ab22118cd4 | ||
|
|
b0dbcdcdb6 | ||
|
|
fb756c0538 | ||
|
|
00267706b7 | ||
|
|
1fcb94dee8 | ||
|
|
dc6abba679 | ||
|
|
fdc455a08f | ||
|
|
7b590e7c5d | ||
|
|
e3a7857b13 | ||
|
|
644c2df5e8 | ||
|
|
de24794cd5 | ||
|
|
1ea8cc9e54 | ||
|
|
738dfd49cf | ||
|
|
a5ab01390f | ||
|
|
a664059eff | ||
|
|
c94ab359b6 | ||
|
|
9643ff7229 | ||
|
|
8da40af3e4 | ||
|
|
36935bdce2 | ||
|
|
2f030e870b | ||
|
|
a2adc956b9 | ||
|
|
deaa27dde2 | ||
|
|
b784216f68 | ||
|
|
32bb46f34f | ||
|
|
2cbd46ba75 | ||
|
|
954e4784ab | ||
|
|
62edbaf07c | ||
|
|
e928034fac | ||
|
|
749fec381f | ||
|
|
21de21fe37 | ||
|
|
0756af5012 | ||
|
|
2457633990 | ||
|
|
46bc89319a | ||
|
|
4a82974da4 | ||
|
|
688da04d4a | ||
|
|
e1b34442aa | ||
|
|
38dd1c9fe7 | ||
|
|
b31bd1cb30 | ||
|
|
2b3c30cb0c | ||
|
|
ebaffd728e | ||
|
|
ece7d6ba67 | ||
|
|
cf5d461f4d | ||
|
|
ff3b686058 | ||
|
|
0b9cd4c93c | ||
|
|
15488ebefd | ||
|
|
6a3c516b71 | ||
|
|
de768375ed | ||
|
|
2f88fa88c4 | ||
|
|
01abf7c19c | ||
|
|
4ebacf1e0a | ||
|
|
5e69e29b2f | ||
|
|
bc5611968f | ||
|
|
8c19492ba6 | ||
|
|
61be19b9b5 | ||
|
|
424396b068 | ||
|
|
8b16af965c | ||
|
|
cf7e534e2d | ||
|
|
2931d30ca5 | ||
|
|
7fa90e425d | ||
|
|
54a48e3256 | ||
|
|
1ca2dc19c2 | ||
|
|
67ddb7b41f | ||
|
|
61bf1194c3 | ||
|
|
ccdcb1f4c1 | ||
|
|
226322d312 | ||
|
|
e1f43965a2 | ||
|
|
18e80b25ac | ||
|
|
131099750e | ||
|
|
d1cc143ef2 | ||
|
|
93a298343f | ||
|
|
636a019289 | ||
|
|
79e8e4edaf | ||
|
|
1f495d66dd | ||
|
|
4564e8be30 | ||
|
|
d460d18942 | ||
|
|
4901765cd4 | ||
|
|
24be96fce9 | ||
|
|
981dd401fa | ||
|
|
9887de6a65 | ||
|
|
8a270329ed | ||
|
|
747cb649f7 | ||
|
|
fc321683d8 | ||
|
|
56500601bd | ||
|
|
4f8432886d | ||
|
|
54402f3de5 | ||
|
|
1633245769 | ||
|
|
f52763a0b3 | ||
|
|
4ee3d0d602 | ||
|
|
777a23afac | ||
|
|
e2b5ab996f | ||
|
|
fcbbfac7f8 | ||
|
|
1a35128457 | ||
|
|
69c63a8374 | ||
|
|
4013256c91 | ||
|
|
d6bb4341dd | ||
|
|
be2e0778b4 | ||
|
|
a61291039e | ||
|
|
d5fcf7377d | ||
|
|
b9d685a650 | ||
|
|
334556f07d | ||
|
|
2e47674a46 | ||
|
|
c31ec3038a | ||
|
|
54deca73d3 | ||
|
|
1d9acdc8f3 | ||
|
|
bc7d952e88 | ||
|
|
718c9c98ce | ||
|
|
fcca6361ed | ||
|
|
714503a9e8 | ||
|
|
01a6580b3d | ||
|
|
026c4fa47d | ||
|
|
6c352eeaf0 | ||
|
|
f789cdff89 | ||
|
|
bfb98e9288 | ||
|
|
a82d6e4173 | ||
|
|
05c1e76091 | ||
|
|
adce620621 | ||
|
|
1c14a7e202 | ||
|
|
dac17e247d | ||
|
|
d89c16dfe8 | ||
|
|
a2a6f8bd58 | ||
|
|
1d196b4df6 | ||
|
|
2f2e7121eb | ||
|
|
de0fe94cd0 | ||
|
|
5d1ad03fe9 | ||
|
|
9f1bd98fcc | ||
|
|
41e6c22e7d | ||
|
|
b82104a608 | ||
|
|
14745039a4 | ||
|
|
958aa265e7 | ||
|
|
ac24b5c6f0 | ||
|
|
5b352491d4 | ||
|
|
32b5b33329 | ||
|
|
4aecb12988 | ||
|
|
ef944e6509 | ||
|
|
e31364979b | ||
|
|
8cd4eeac18 | ||
|
|
6ae0be2179 | ||
|
|
70ddb7c931 | ||
|
|
c4bc4c83e8 | ||
|
|
31e9cc2e40 | ||
|
|
b8e40f5091 | ||
|
|
1cfccef22e | ||
|
|
44392941af | ||
|
|
023dec4aa6 | ||
|
|
b773ba73cf | ||
|
|
0b1d4f10d6 | ||
|
|
8b41655894 | ||
|
|
35f125f3df | ||
|
|
00925029b4 | ||
|
|
9c772f5f6c | ||
|
|
e3cfa7348c | ||
|
|
9b5740555c | ||
|
|
ce9205a3cc | ||
|
|
5cb36fc983 | ||
|
|
64f038fda8 | ||
|
|
a8f0c5241c | ||
|
|
12c7013062 | ||
|
|
9cb32b5d29 | ||
|
|
765d2ed61b | ||
|
|
78458ee5a1 | ||
|
|
07dcf6953c | ||
|
|
172032d3b3 | ||
|
|
4e5a81402d | ||
|
|
fef635c6f0 | ||
|
|
8d1934d494 | ||
|
|
dea1950ba0 | ||
|
|
e2a5741374 | ||
|
|
ab23bcd2e8 | ||
|
|
4759517c8d | ||
|
|
7afff1ef29 | ||
|
|
d128d51a2b | ||
|
|
afa0a30a73 | ||
|
|
6bb654750a | ||
|
|
35dd1fda9c | ||
|
|
d8b03737ee | ||
|
|
73750df73f | ||
|
|
11d906ee51 | ||
|
|
b823ce48e1 | ||
|
|
4061b74cf3 | ||
|
|
baa9a5701f | ||
|
|
00de04c82d | ||
|
|
ed1c3a7a15 | ||
|
|
fcf2e3522c | ||
|
|
dfdb24d89d | ||
|
|
99ffa7c6fd | ||
|
|
9592246746 | ||
|
|
815444ffdc | ||
|
|
2f48bb4089 | ||
|
|
c8d2f4f1fb | ||
|
|
9ca3c05f6d | ||
|
|
31efaac4f3 | ||
|
|
5d1c1c418c | ||
|
|
f4595a02b2 | ||
|
|
f4b820aa4c | ||
|
|
0b111d2a10 | ||
|
|
b14ad4f8cc | ||
|
|
864bc999d1 | ||
|
|
2bf6eef53b | ||
|
|
fe9ae2c5d1 | ||
|
|
e2b1fb1f64 | ||
|
|
39c0bdbe79 | ||
|
|
1fd8b47936 | ||
|
|
fe4f1f4eb7 | ||
|
|
0c99fd3277 | ||
|
|
5ed832077d | ||
|
|
f44727a4d0 | ||
|
|
f799e1e3d9 | ||
|
|
d346b8e3f7 | ||
|
|
102187be58 | ||
|
|
71e98cda5c | ||
|
|
22e54a037b | ||
|
|
67896aa45d | ||
|
|
a4b3c6d872 | ||
|
|
b77ce02f6b | ||
|
|
9bdbe279dd | ||
|
|
a077135d76 | ||
|
|
7b1823e324 | ||
|
|
681fb82123 | ||
|
|
488e0d86cd | ||
|
|
5825e95d6f | ||
|
|
a56c8bbab6 | ||
|
|
4edf368d68 | ||
|
|
ef82cedd00 | ||
|
|
91f3036cf1 | ||
|
|
e4dafb8552 | ||
|
|
625b20833e | ||
|
|
332d2198f4 | ||
|
|
33abc407a1 | ||
|
|
424ee7f1b7 | ||
|
|
1c4a8cf2ca | ||
|
|
76228a2118 | ||
|
|
bbb1c59df2 | ||
|
|
58f65345ff | ||
|
|
66def035bf | ||
|
|
c1b04b88fa | ||
|
|
4c9245a3b3 | ||
|
|
c4b2f682f6 | ||
|
|
1c9588e8d5 | ||
|
|
048e34a6a1 | ||
|
|
59409be7ab | ||
|
|
71c4787553 | ||
|
|
b8a42939ad | ||
|
|
375998c664 | ||
|
|
39989ad233 | ||
|
|
fe1d7e9f1d | ||
|
|
0899b277c0 | ||
|
|
253a0eae13 | ||
|
|
8964967af0 | ||
|
|
520e01f113 | ||
|
|
30212f886b | ||
|
|
8dd264c025 | ||
|
|
ec88fa8dec | ||
|
|
fb99f2e332 | ||
|
|
bb2cf74328 | ||
|
|
bd9eb8faba | ||
|
|
fa16b56cba | ||
|
|
07da9f1e5c | ||
|
|
5d2ac9fca2 | ||
|
|
27af048d3e | ||
|
|
5d85692719 | ||
|
|
6e66ddfcb9 | ||
|
|
00c135f7d5 | ||
|
|
8cbefaaa88 | ||
|
|
0275a0d8d8 | ||
|
|
b51ee18fc0 | ||
|
|
c6a024f83b | ||
|
|
1c0f5cdf4b | ||
|
|
a7e825a038 | ||
|
|
7b97d7249d | ||
|
|
83a2afc7b0 | ||
|
|
0a83027536 | ||
|
|
d809723bc9 | ||
|
|
35e0dd9206 | ||
|
|
047352027f | ||
|
|
81a4cea71a | ||
|
|
ad306d7bf3 | ||
|
|
d3457fb8f9 | ||
|
|
59a143eb08 | ||
|
|
64c1321c9d | ||
|
|
a6ff46ce81 | ||
|
|
b81ace54df | ||
|
|
8495b0521b | ||
|
|
9fa5fb0baf | ||
|
|
efcf4e3312 | ||
|
|
b3d72e11fe | ||
|
|
7d45a55072 | ||
|
|
4181c0ec4a | ||
|
|
5cb775308d | ||
|
|
2b7731e4f9 | ||
|
|
8f190a90ee |
@@ -1,19 +0,0 @@
|
|||||||
version: "2"
|
|
||||||
checks:
|
|
||||||
argument-count:
|
|
||||||
config:
|
|
||||||
threshold: 8
|
|
||||||
complex-logic:
|
|
||||||
config:
|
|
||||||
threshold: 6
|
|
||||||
file-lines:
|
|
||||||
config:
|
|
||||||
threshold: 350
|
|
||||||
method-complexity:
|
|
||||||
config:
|
|
||||||
threshold: 15
|
|
||||||
method-count:
|
|
||||||
config:
|
|
||||||
threshold: 30
|
|
||||||
exclude_patterns:
|
|
||||||
- tests
|
|
||||||
+10
-1
@@ -1 +1,10 @@
|
|||||||
|
comment: false
|
||||||
|
coverage:
|
||||||
|
status:
|
||||||
|
project:
|
||||||
|
default:
|
||||||
|
target: 85
|
||||||
|
threshold: 10%
|
||||||
|
patch:
|
||||||
|
default:
|
||||||
|
threshold: 25%
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
[run]
|
[run]
|
||||||
|
branch = True
|
||||||
|
source = dvc
|
||||||
omit =
|
omit =
|
||||||
*__main__.py
|
*__main__.py
|
||||||
|
|
||||||
[report]
|
[report]
|
||||||
exclude_lines =
|
exclude_lines =
|
||||||
if __name__ == .__main__.:
|
if __name__ == .__main__.:
|
||||||
|
if typing.TYPE_CHECKING:
|
||||||
|
if TYPE_CHECKING:
|
||||||
pass
|
pass
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
# pragma: no cover
|
# pragma: no cover
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
version = 1
|
|
||||||
|
|
||||||
test_patterns = [
|
|
||||||
'tests/**'
|
|
||||||
]
|
|
||||||
|
|
||||||
[[analyzers]]
|
|
||||||
name = 'python'
|
|
||||||
enabled = true
|
|
||||||
runtime_version = '3.x.x'
|
|
||||||
|
|
||||||
@@ -9,3 +9,4 @@
|
|||||||
/pkg
|
/pkg
|
||||||
/repos
|
/repos
|
||||||
/tmp
|
/tmp
|
||||||
|
/experiments
|
||||||
|
|||||||
@@ -3,9 +3,50 @@ name: "\U0001F41B Bug Report"
|
|||||||
about: Create a bug report to help us improve DVC
|
about: Create a bug report to help us improve DVC
|
||||||
---
|
---
|
||||||
|
|
||||||
## Bug Report
|
# Bug Report
|
||||||
|
|
||||||
### Please provide information about your setup
|
<!--
|
||||||
|
## Issue name
|
||||||
|
|
||||||
|
Issue names must follow the pattern `command: description` where the command is the dvc command that you are trying to run. The description should describe the consequence of the bug.
|
||||||
|
|
||||||
|
Example: `repro: doesn't detect input changes`
|
||||||
|
-->
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
<!--
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
-->
|
||||||
|
|
||||||
|
### Reproduce
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Step list of how to reproduce the bug
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Example:
|
||||||
|
|
||||||
|
1. dvc init
|
||||||
|
2. Copy dataset.zip to the directory
|
||||||
|
3. dvc add dataset.zip
|
||||||
|
4. dvc run -d dataset.zip -o model ./train.sh
|
||||||
|
5. modify dataset.zip
|
||||||
|
6. dvc repro
|
||||||
|
-->
|
||||||
|
|
||||||
|
### Expected
|
||||||
|
|
||||||
|
<!--
|
||||||
|
A clear and concise description of what you expect to happen.
|
||||||
|
-->
|
||||||
|
|
||||||
|
### Environment information
|
||||||
|
|
||||||
|
<!--
|
||||||
|
This is required to ensure that we can reproduce the bug.
|
||||||
|
-->
|
||||||
|
|
||||||
**Output of `dvc version`:**
|
**Output of `dvc version`:**
|
||||||
|
|
||||||
@@ -15,4 +56,6 @@ $ dvc version
|
|||||||
|
|
||||||
**Additional Information (if any):**
|
**Additional Information (if any):**
|
||||||
|
|
||||||
|
<!--
|
||||||
If applicable, please also provide a `--verbose` output of the command, eg: `dvc add --verbose`.
|
If applicable, please also provide a `--verbose` output of the command, eg: `dvc add --verbose`.
|
||||||
|
-->
|
||||||
@@ -2,6 +2,4 @@
|
|||||||
|
|
||||||
* [ ] 📖 If this PR requires [documentation](https://dvc.org/doc) updates, I have created a separate PR (or issue, at least) in [dvc.org](https://github.com/iterative/dvc.org) and linked it here.
|
* [ ] 📖 If this PR requires [documentation](https://dvc.org/doc) updates, I have created a separate PR (or issue, at least) in [dvc.org](https://github.com/iterative/dvc.org) and linked it here.
|
||||||
|
|
||||||
* [ ] ❌ I will check DeepSource, CodeClimate, and other sanity checks below. (We consider them recommendatory and don't expect everything to be addressed. Please fix things that actually improve code or fix bugs.)
|
|
||||||
|
|
||||||
Thank you for the contribution - we'll try to review it as soon as possible. 🙏
|
Thank you for the contribution - we'll try to review it as soon as possible. 🙏
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
pull_request_rules:
|
||||||
|
- name: backport patches to 1.11
|
||||||
|
conditions:
|
||||||
|
- base=master
|
||||||
|
- label=backport-1.11
|
||||||
|
actions:
|
||||||
|
backport:
|
||||||
|
branches:
|
||||||
|
- "1.11"
|
||||||
@@ -1,5 +1,49 @@
|
|||||||
# Config for https://github.com/apps/release-drafter
|
# Config for https://github.com/apps/release-drafter
|
||||||
branches:
|
name-template: "$RESOLVED_VERSION 🦉 "
|
||||||
- master
|
tag-template: "$RESOLVED_VERSION"
|
||||||
|
categories:
|
||||||
|
- title: "🚀 New Features and Enhancements "
|
||||||
|
labels:
|
||||||
|
- "feature"
|
||||||
|
- "enhancement"
|
||||||
|
- "ui"
|
||||||
|
- title: "💣 Breaking Changes "
|
||||||
|
labels:
|
||||||
|
- "breaking-change"
|
||||||
|
- title: "🏇 Optimizations "
|
||||||
|
labels:
|
||||||
|
- "optimize"
|
||||||
|
- "performance"
|
||||||
|
- title: "🐛 Bug Fixes "
|
||||||
|
labels:
|
||||||
|
- "bugfix"
|
||||||
|
- "bug"
|
||||||
|
- title: "🔨 Maintenance "
|
||||||
|
labels:
|
||||||
|
- "maintenance"
|
||||||
|
- "refactoring"
|
||||||
|
- "chore"
|
||||||
|
- "build"
|
||||||
|
- "ci"
|
||||||
|
change-template: "- $TITLE (#$NUMBER) @$AUTHOR"
|
||||||
|
version-resolver:
|
||||||
|
major:
|
||||||
|
labels:
|
||||||
|
- "major"
|
||||||
|
minor:
|
||||||
|
labels:
|
||||||
|
- "minor"
|
||||||
|
patch:
|
||||||
|
labels:
|
||||||
|
- "patch"
|
||||||
|
default: patch
|
||||||
|
exclude-labels:
|
||||||
|
- "skip-changelog"
|
||||||
template: |
|
template: |
|
||||||
|
> Refer to https://dvc.org/doc/install for installation instructions.
|
||||||
|
|
||||||
|
## Changes
|
||||||
|
|
||||||
$CHANGES
|
$CHANGES
|
||||||
|
|
||||||
|
Thanks again to $CONTRIBUTORS for the contributions! 🎉
|
||||||
|
|||||||
@@ -0,0 +1,131 @@
|
|||||||
|
name: Build packages
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
release:
|
||||||
|
types: [released, prereleased]
|
||||||
|
jobs:
|
||||||
|
linux:
|
||||||
|
runs-on: ubuntu-16.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/[email protected]
|
||||||
|
- name: Set up Python 3.7
|
||||||
|
uses: actions/[email protected]
|
||||||
|
with:
|
||||||
|
python-version: 3.7
|
||||||
|
- name: Set up Ruby 2.4
|
||||||
|
uses: actions/setup-ruby@v1
|
||||||
|
with:
|
||||||
|
ruby-version: 2.4
|
||||||
|
- name: Build
|
||||||
|
run: ./scripts/build_posix.sh
|
||||||
|
- name: Publish deb
|
||||||
|
if: github.event_name == 'release'
|
||||||
|
uses: actions/[email protected]
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ github.event.release.upload_url }}
|
||||||
|
asset_path: dvc_${{ github.event.release.tag_name }}_amd64.deb
|
||||||
|
asset_name: dvc_${{ github.event.release.tag_name }}_amd64.deb
|
||||||
|
asset_content_type: binary/octet-stream
|
||||||
|
- name: Publish rpm
|
||||||
|
if: github.event_name == 'release'
|
||||||
|
uses: actions/[email protected]
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ github.event.release.upload_url }}
|
||||||
|
asset_path: dvc-${{ github.event.release.tag_name }}-1.x86_64.rpm
|
||||||
|
asset_name: dvc-${{ github.event.release.tag_name }}-1.x86_64.rpm
|
||||||
|
asset_content_type: binary/octet-stream
|
||||||
|
mac:
|
||||||
|
runs-on: macos-10.15
|
||||||
|
steps:
|
||||||
|
- uses: actions/[email protected]
|
||||||
|
- name: Set up Python 3.7
|
||||||
|
uses: actions/[email protected]
|
||||||
|
with:
|
||||||
|
python-version: 3.7
|
||||||
|
- name: Set up Ruby 2.4
|
||||||
|
uses: actions/setup-ruby@v1
|
||||||
|
with:
|
||||||
|
ruby-version: 2.4
|
||||||
|
- name: Build
|
||||||
|
run: ./scripts/build_posix.sh
|
||||||
|
- name: Publish
|
||||||
|
if: github.event_name == 'release'
|
||||||
|
uses: actions/[email protected]
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ github.event.release.upload_url }}
|
||||||
|
asset_path: dvc-${{ github.event.release.tag_name }}.pkg
|
||||||
|
asset_name: dvc-${{ github.event.release.tag_name }}.pkg
|
||||||
|
asset_content_type: binary/octet-stream
|
||||||
|
windows:
|
||||||
|
runs-on: windows-2019
|
||||||
|
steps:
|
||||||
|
- uses: actions/[email protected]
|
||||||
|
- name: Set up Python 3.7
|
||||||
|
uses: actions/[email protected]
|
||||||
|
with:
|
||||||
|
python-version: 3.7
|
||||||
|
- name: Build
|
||||||
|
run: scripts\build_windows.cmd
|
||||||
|
shell: cmd
|
||||||
|
- name: Publish
|
||||||
|
if: github.event_name == 'release'
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
uses: actions/[email protected]
|
||||||
|
with:
|
||||||
|
upload_url: ${{ github.event.release.upload_url }}
|
||||||
|
asset_path: dvc-${{ github.event.release.tag_name }}.exe
|
||||||
|
asset_name: dvc-${{ github.event.release.tag_name }}.exe
|
||||||
|
asset_content_type: binary/octet-stream
|
||||||
|
python:
|
||||||
|
runs-on: ubuntu-16.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/[email protected]
|
||||||
|
- name: Set up Python 3.7
|
||||||
|
uses: actions/[email protected]
|
||||||
|
with:
|
||||||
|
python-version: 3.7
|
||||||
|
- name: Install
|
||||||
|
run: pip install ".[all,tests]"
|
||||||
|
- name: Build packages
|
||||||
|
run: ./scripts/build_package.sh
|
||||||
|
- name: Publish packages to PyPI
|
||||||
|
if: github.event_name == 'release'
|
||||||
|
uses: pypa/gh-action-pypi-publish@master
|
||||||
|
with:
|
||||||
|
user: __token__
|
||||||
|
password: ${{ secrets.PYPI_TOKEN }}
|
||||||
|
snap:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/[email protected]
|
||||||
|
- name: Build the package
|
||||||
|
uses: snapcore/action-build@v1
|
||||||
|
id: snapcraft
|
||||||
|
- name: Test the package
|
||||||
|
run: |
|
||||||
|
sudo snap install --dangerous --classic ${{ steps.snapcraft.outputs.snap }}
|
||||||
|
dvc version
|
||||||
|
sudo snap remove dvc
|
||||||
|
- name: Publish to the edge channel
|
||||||
|
uses: snapcore/action-publish@v1
|
||||||
|
if: github.event_name == 'push'
|
||||||
|
with:
|
||||||
|
store_login: ${{ secrets.STORE_LOGIN }}
|
||||||
|
snap: ${{ steps.snapcraft.outputs.snap }}
|
||||||
|
release: edge,v2/edge
|
||||||
|
- name: Publish to the stable channel
|
||||||
|
uses: snapcore/action-publish@v1
|
||||||
|
if: ${{ github.event_name == 'release' && github.event.release.released }}
|
||||||
|
with:
|
||||||
|
store_login: ${{ secrets.STORE_LOGIN }}
|
||||||
|
snap: ${{ steps.snapcraft.outputs.snap }}
|
||||||
|
release: stable,v2/stable
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
name: Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
env:
|
||||||
|
DVC_TEST: "true"
|
||||||
|
HOMEBREW_NO_AUTO_UPDATE: 1
|
||||||
|
SHELL: /bin/bash
|
||||||
|
GDRIVE_CREDENTIALS_DATA: ${{ secrets.GDRIVE_CREDENTIALS_DATA }}
|
||||||
|
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||||
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||||
|
GS_CREDS_JSON: ${{ secrets.GS_CREDS_JSON }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/[email protected]
|
||||||
|
- name: Set up Python 3.8
|
||||||
|
uses: actions/[email protected]
|
||||||
|
with:
|
||||||
|
python-version: 3.8
|
||||||
|
- name: Install requirements
|
||||||
|
run: pip install ".[all,tests]" Pygments collective.checkdocs pre-commit
|
||||||
|
- name: install temporary dependencies
|
||||||
|
run: |
|
||||||
|
pip install git+https://github.com/isidentical/gdrivefs@service-account
|
||||||
|
pip install git+https://github.com/isidentical/pydata-google-auth@service-account
|
||||||
|
- name: Check README
|
||||||
|
run: python setup.py checkdocs
|
||||||
|
- uses: pre-commit/[email protected]
|
||||||
|
tests:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-18.04, windows-2019, macos-10.15]
|
||||||
|
pyv: ["3.6", "3.7", "3.8", "3.9"]
|
||||||
|
# macos 11.0 workers take too long to start up
|
||||||
|
# include:
|
||||||
|
# - os: "macos-11.0"
|
||||||
|
# pyv: "3.9"
|
||||||
|
exclude:
|
||||||
|
- os: macos-10.15
|
||||||
|
pyv: "3.9"
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/[email protected]
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/[email protected]
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.pyv }}
|
||||||
|
- name: get pip cache dir
|
||||||
|
id: pip-cache-dir
|
||||||
|
run: |
|
||||||
|
echo "::set-output name=dir::$(pip cache dir)"
|
||||||
|
- name: set pip cache
|
||||||
|
id: pip-cache
|
||||||
|
uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: ${{ steps.pip-cache-dir.outputs.dir }}
|
||||||
|
key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-pip-
|
||||||
|
- name: install
|
||||||
|
if: steps.cache.pip-cache-dir.cache-hit != 'true'
|
||||||
|
run: |
|
||||||
|
pip install wheel
|
||||||
|
pip install -e ".[all,tests]"
|
||||||
|
- name: install temporary dependencies
|
||||||
|
run: |
|
||||||
|
pip install git+https://github.com/isidentical/gdrivefs@service-account
|
||||||
|
pip install git+https://github.com/isidentical/pydata-google-auth@service-account
|
||||||
|
- name: setup git
|
||||||
|
run: |
|
||||||
|
git config --global user.email "[email protected]"
|
||||||
|
git config --global user.name "DVC Tester"
|
||||||
|
- name: setup gs creds
|
||||||
|
shell: bash
|
||||||
|
if: env.GS_CREDS_JSON != ''
|
||||||
|
run: |
|
||||||
|
mkdir -p scripts/ci
|
||||||
|
echo "$GS_CREDS_JSON" > scripts/ci/gcp-creds.json
|
||||||
|
- name: run tests
|
||||||
|
run: python -m tests --all --cov-report=xml --cov-report=term --tap-combined -n=4
|
||||||
|
- name: upload coverage report
|
||||||
|
uses: codecov/[email protected]
|
||||||
|
with:
|
||||||
|
file: ./coverage.xml
|
||||||
|
fail_ci_if_error: false
|
||||||
|
- name: Post TAP
|
||||||
|
# Running custom fork with an option, that does not fail CI on error
|
||||||
|
uses: skshetry/flaky-service/packages/action@master
|
||||||
|
if: always() && github.ref == 'refs/heads/master'
|
||||||
|
with:
|
||||||
|
file-path: ${{github.workspace}}/testresults.tap
|
||||||
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
os: ${{runner.os}}
|
||||||
|
matrix: ${{toJson(matrix)}}
|
||||||
|
repo-description: ${{github.event.repository.description}}
|
||||||
|
fail_ci_if_error: false
|
||||||
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
neatlynx.conf
|
neatlynx.conf
|
||||||
neatlynx/__pycache__
|
neatlynx/__pycache__
|
||||||
.idea
|
.idea
|
||||||
cache
|
/cache
|
||||||
*.pyc
|
*.pyc
|
||||||
.env/
|
.env/
|
||||||
.env2.7/
|
.env2.7/
|
||||||
|
.python-version
|
||||||
|
|
||||||
cache
|
|
||||||
.dvc.conf.lock
|
.dvc.conf.lock
|
||||||
.DS_Store
|
.DS_Store
|
||||||
build/
|
build/
|
||||||
|
|||||||
+16
-7
@@ -4,15 +4,11 @@ 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:
|
- hooks:
|
||||||
- id: isort
|
- id: isort
|
||||||
language_version: python3
|
language_version: python3
|
||||||
repo: https://github.com/timothycrosley/isort
|
repo: https://github.com/timothycrosley/isort
|
||||||
rev: 4.3.21
|
rev: 5.6.4
|
||||||
- hooks:
|
- hooks:
|
||||||
- id: flake8
|
- id: flake8
|
||||||
language_version: python3
|
language_version: python3
|
||||||
@@ -22,7 +18,20 @@ repos:
|
|||||||
- flake8-debugger
|
- flake8-debugger
|
||||||
- flake8-string-format
|
- flake8-string-format
|
||||||
repo: https://gitlab.com/pycqa/flake8
|
repo: https://gitlab.com/pycqa/flake8
|
||||||
rev: 3.7.9
|
rev: 3.8.4
|
||||||
|
- hooks:
|
||||||
|
- id: mypy
|
||||||
|
language_version: python3
|
||||||
|
files: ^dvc/
|
||||||
|
repo: https://github.com/pre-commit/mirrors-mypy
|
||||||
|
rev: 'v0.790'
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: pylint
|
||||||
|
name: pylint
|
||||||
|
entry: pylint
|
||||||
|
language: system
|
||||||
|
types: [python]
|
||||||
- hooks:
|
- hooks:
|
||||||
- args:
|
- args:
|
||||||
- -i
|
- -i
|
||||||
@@ -30,7 +39,7 @@ repos:
|
|||||||
id: beautysh
|
id: beautysh
|
||||||
language_version: python3
|
language_version: python3
|
||||||
repo: https://github.com/lovesegfault/beautysh
|
repo: https://github.com/lovesegfault/beautysh
|
||||||
rev: master
|
rev: 6.0.1
|
||||||
- hooks:
|
- hooks:
|
||||||
- args:
|
- args:
|
||||||
- git-hook
|
- git-hook
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
# A comma-separated list of package or module names from where C extensions may
|
# A comma-separated list of package or module names from where C extensions may
|
||||||
# be loaded. Extensions are loading into the active Python interpreter and may
|
# be loaded. Extensions are loading into the active Python interpreter and may
|
||||||
# run arbitrary code.
|
# run arbitrary code.
|
||||||
extension-pkg-whitelist=
|
extension-pkg-whitelist=pygit2
|
||||||
|
|
||||||
# Add files or directories to the blacklist. They should be base names, not
|
# Add files or directories to the blacklist. They should be base names, not
|
||||||
# paths.
|
# paths.
|
||||||
@@ -15,7 +15,11 @@ ignore-patterns=
|
|||||||
|
|
||||||
# Python code to execute, usually for sys.path manipulation such as
|
# Python code to execute, usually for sys.path manipulation such as
|
||||||
# pygtk.require().
|
# pygtk.require().
|
||||||
#init-hook=
|
init-hook="import sys; \
|
||||||
|
from pathlib import Path; \
|
||||||
|
from pylint.config import find_pylintrc; \
|
||||||
|
sys.path.append(Path(find_pylintrc()).parent / 'tests');"
|
||||||
|
|
||||||
|
|
||||||
# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the
|
# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the
|
||||||
# number of processors available to use.
|
# number of processors available to use.
|
||||||
@@ -28,7 +32,7 @@ limit-inference-results=100
|
|||||||
|
|
||||||
# List of plugins (as comma separated values of python modules names) to load,
|
# List of plugins (as comma separated values of python modules names) to load,
|
||||||
# usually to register additional checkers.
|
# usually to register additional checkers.
|
||||||
load-plugins=
|
load-plugins=pylint_pytest,pylint_plugin_disable
|
||||||
|
|
||||||
# Pickle collected data for later comparisons.
|
# Pickle collected data for later comparisons.
|
||||||
persistent=yes
|
persistent=yes
|
||||||
@@ -60,7 +64,16 @@ confidence=
|
|||||||
# --enable=similarities". If you want to run only the classes checker, but have
|
# --enable=similarities". If you want to run only the classes checker, but have
|
||||||
# no Warning level messages displayed, use "--disable=all --enable=classes
|
# no Warning level messages displayed, use "--disable=all --enable=classes
|
||||||
# --disable=W".
|
# --disable=W".
|
||||||
disable=print-statement,
|
disable=format,
|
||||||
|
# ^ most of them are covered by flake8,
|
||||||
|
# and are conventions rather than warnings or errors
|
||||||
|
refactoring, # will be noisy if it starts giving suggestions
|
||||||
|
spelling,
|
||||||
|
# design is too-few-* and too-many-* checks, too-much-* for us right now
|
||||||
|
design,
|
||||||
|
# following were generated by default
|
||||||
|
# most of them are redundant Py3 checks for Py2+3 codebase
|
||||||
|
print-statement,
|
||||||
parameter-unpacking,
|
parameter-unpacking,
|
||||||
unpacking-in-except,
|
unpacking-in-except,
|
||||||
old-raise-syntax,
|
old-raise-syntax,
|
||||||
@@ -139,15 +152,40 @@ disable=print-statement,
|
|||||||
deprecated-sys-function,
|
deprecated-sys-function,
|
||||||
exception-escape,
|
exception-escape,
|
||||||
comprehension-escape,
|
comprehension-escape,
|
||||||
useless-object-inheritance,
|
# custom disables start here
|
||||||
missing-docstring,
|
no-self-use,
|
||||||
bad-continuation
|
invalid-name,
|
||||||
|
# already a check enabled for `wildcard-import`
|
||||||
|
unused-wildcard-import,
|
||||||
|
misplaced-comparison-constant,
|
||||||
|
# probably soon: https://github.com/iterative/dvc/issues/1843
|
||||||
|
logging-format-interpolation,
|
||||||
|
logging-fstring-interpolation,
|
||||||
|
# we don't have proper docstrings yet
|
||||||
|
# even if we do, we'll be doing it gradually
|
||||||
|
missing-function-docstring,
|
||||||
|
missing-module-docstring,
|
||||||
|
missing-class-docstring,
|
||||||
|
duplicate-code,
|
||||||
|
# too noisy, and detects issues even when import is inside a function
|
||||||
|
# see: https://github.com/PyCQA/pylint/issues/850
|
||||||
|
cyclic-import,
|
||||||
|
# isort should cover these:
|
||||||
|
wrong-import-order,
|
||||||
|
wrong-import-position,
|
||||||
|
ungrouped-imports,
|
||||||
|
multiple-imports,
|
||||||
|
# we use it to speedup/optimize
|
||||||
|
import-outside-toplevel,
|
||||||
|
fixme,
|
||||||
|
|
||||||
|
|
||||||
# Enable the message, report, category or checker with the given id(s). You can
|
# Enable the message, report, category or checker with the given id(s). You can
|
||||||
# either give multiple identifier separated by comma (,) or put this option
|
# either give multiple identifier separated by comma (,) or put this option
|
||||||
# multiple time (only on the command line, not in the configuration file where
|
# multiple time (only on the command line, not in the configuration file where
|
||||||
# it should appear only once). See also the "--disable" option for examples.
|
# it should appear only once). See also the "--disable" option for examples.
|
||||||
enable=c-extension-no-member
|
enable=c-extension-no-member,
|
||||||
|
no-else-return,
|
||||||
|
|
||||||
|
|
||||||
[REPORTS]
|
[REPORTS]
|
||||||
@@ -228,7 +266,7 @@ contextmanager-decorators=contextlib.contextmanager
|
|||||||
# List of members which are set dynamically and missed by pylint inference
|
# List of members which are set dynamically and missed by pylint inference
|
||||||
# system, and so shouldn't trigger E1101 when accessed. Python regular
|
# system, and so shouldn't trigger E1101 when accessed. Python regular
|
||||||
# expressions are accepted.
|
# expressions are accepted.
|
||||||
generated-members=
|
generated-members=hdfs.*,pytest.lazy_fixture,logging.TRACE,logger.trace,sys.getwindowsversion
|
||||||
|
|
||||||
# Tells whether missing members accessed in mixin class should be ignored. A
|
# Tells whether missing members accessed in mixin class should be ignored. A
|
||||||
# mixin class is detected if its name ends with "mixin" (case insensitive).
|
# mixin class is detected if its name ends with "mixin" (case insensitive).
|
||||||
@@ -249,13 +287,13 @@ ignore-on-opaque-inference=yes
|
|||||||
# List of class names for which member attributes should not be checked (useful
|
# List of class names for which member attributes should not be checked (useful
|
||||||
# for classes with dynamically set attributes). This supports the use of
|
# for classes with dynamically set attributes). This supports the use of
|
||||||
# qualified names.
|
# qualified names.
|
||||||
ignored-classes=optparse.Values,thread._local,_thread._local
|
ignored-classes=optparse.Values,thread._local,_thread._local,Dvcfile
|
||||||
|
|
||||||
# List of module names for which member attributes should not be checked
|
# List of module names for which member attributes should not be checked
|
||||||
# (useful for modules/projects where namespaces are manipulated during runtime
|
# (useful for modules/projects where namespaces are manipulated during runtime
|
||||||
# and thus existing member attributes cannot be deduced by static analysis. It
|
# and thus existing member attributes cannot be deduced by static analysis. It
|
||||||
# supports qualified module names, as well as Unix pattern matching.
|
# supports qualified module names, as well as Unix pattern matching.
|
||||||
ignored-modules=
|
ignored-modules=azure
|
||||||
|
|
||||||
# Show a hint with possible names when a member name was not found. The aspect
|
# Show a hint with possible names when a member name was not found. The aspect
|
||||||
# of finding the hint is based on edit distance.
|
# of finding the hint is based on edit distance.
|
||||||
@@ -290,7 +328,7 @@ dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_
|
|||||||
|
|
||||||
# Argument names that match this expression will be ignored. Default to name
|
# Argument names that match this expression will be ignored. Default to name
|
||||||
# with leading underscore.
|
# with leading underscore.
|
||||||
ignored-argument-names=_.*|^ignored_|^unused_
|
ignored-argument-names=_.*|^ignored_|^unused_|args|kwargs
|
||||||
|
|
||||||
# Tells whether we should check for unused import in __init__ files.
|
# Tells whether we should check for unused import in __init__ files.
|
||||||
init-import=no
|
init-import=no
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
---
|
|
||||||
restylers:
|
|
||||||
- name: black
|
|
||||||
image: restyled/restyler-black:v19.10b0
|
|
||||||
command:
|
|
||||||
- black
|
|
||||||
arguments: []
|
|
||||||
include:
|
|
||||||
- "**/*.py"
|
|
||||||
interpreters:
|
|
||||||
- python
|
|
||||||
- name: isort
|
|
||||||
image: restyled/restyler-isort:v4.3.21
|
|
||||||
command:
|
|
||||||
- isort
|
|
||||||
arguments: []
|
|
||||||
include:
|
|
||||||
- "**/*.py"
|
|
||||||
interpreters:
|
|
||||||
- python
|
|
||||||
-170
@@ -1,170 +0,0 @@
|
|||||||
cache:
|
|
||||||
directories:
|
|
||||||
- $HOME/.cache/pip
|
|
||||||
- $HOME/.pyenv
|
|
||||||
dist: xenial
|
|
||||||
env:
|
|
||||||
global:
|
|
||||||
- HOMEBREW_NO_AUTO_UPDATE=1
|
|
||||||
- PYENV_ROOT="$HOME/.pyenv"
|
|
||||||
- PATH="$PYENV_ROOT/bin:$PATH"
|
|
||||||
- PIP_CACHE_DIR="$HOME/.cache/pip" # unify pip cache location for all platforms
|
|
||||||
stages:
|
|
||||||
- check
|
|
||||||
- test
|
|
||||||
- build
|
|
||||||
# Travis doesn't support testing python on Mac yet, so we need
|
|
||||||
# to workaround it by installing it directly with brew.
|
|
||||||
#
|
|
||||||
# Note that we specify language as ruby-2.4.3 to help us satisfy
|
|
||||||
# fpm dependencies, as travis runs el capitan with an old ruby
|
|
||||||
# version, that causes fpm to crash.
|
|
||||||
#
|
|
||||||
# Each job will use the previous job's `stage` tag if not specified.
|
|
||||||
jobs:
|
|
||||||
include:
|
|
||||||
# patch formatting checks
|
|
||||||
- name: "Check patch formatting"
|
|
||||||
stage: check
|
|
||||||
os: linux
|
|
||||||
language: python
|
|
||||||
python: 3.7
|
|
||||||
before_install:
|
|
||||||
install:
|
|
||||||
script: ./scripts/ci/check_patch.sh
|
|
||||||
# test jobs
|
|
||||||
- name: "3.7 on Windows"
|
|
||||||
stage: test
|
|
||||||
os: windows # Windows 10.0.17134 N/A Build 17134
|
|
||||||
language: shell # 'language: python' is an error on Travis CI Windows
|
|
||||||
env:
|
|
||||||
- PYTHON_VERSION=3.7.5
|
|
||||||
- PATH=/c/Python37:/c/Python37/Scripts:$PATH
|
|
||||||
- name: "3.8 on Windows"
|
|
||||||
os: windows # Windows 10.0.17134 N/A Build 17134
|
|
||||||
language: shell # 'language: python' is an error on Travis CI Windows
|
|
||||||
env:
|
|
||||||
- PYTHON_VERSION=3.8.0
|
|
||||||
- PATH=/c/Python38:/c/Python38/Scripts:$PATH
|
|
||||||
- name: "3.6 on Linux"
|
|
||||||
language: python
|
|
||||||
python: 3.6
|
|
||||||
- name: "3.7 on Linux"
|
|
||||||
language: python
|
|
||||||
python: 3.7
|
|
||||||
- name: "3.8 on Linux"
|
|
||||||
language: python
|
|
||||||
python: 3.8
|
|
||||||
- name: "3.7 on Mac"
|
|
||||||
os: osx
|
|
||||||
osx_image: xcode11.3
|
|
||||||
# build jobs
|
|
||||||
- name: "Mac pkg"
|
|
||||||
stage: build
|
|
||||||
os: osx
|
|
||||||
osx_image: xcode9.4
|
|
||||||
language: ruby
|
|
||||||
rvm: 2.4.3
|
|
||||||
install:
|
|
||||||
script: ./scripts/build_posix.sh
|
|
||||||
- name: "Windows pkg"
|
|
||||||
os: windows
|
|
||||||
language: shell
|
|
||||||
install:
|
|
||||||
script: ./scripts/build_windows.cmd
|
|
||||||
env:
|
|
||||||
- PYTHON_VERSION=3.7.5
|
|
||||||
- PATH=/c/Python37:/c/Python37/Scripts:$PATH
|
|
||||||
- name: "Linux pkgs"
|
|
||||||
language: python
|
|
||||||
python: 3.7
|
|
||||||
before_install:
|
|
||||||
install:
|
|
||||||
script: ./scripts/build_posix.sh
|
|
||||||
- name: "PyPI pkgs"
|
|
||||||
language: python
|
|
||||||
python: 3.8
|
|
||||||
script: ./scripts/build_package.sh
|
|
||||||
- name: Snapcraft snap
|
|
||||||
language: python
|
|
||||||
python: 3.8
|
|
||||||
addons:
|
|
||||||
snaps:
|
|
||||||
- name: snapcraft
|
|
||||||
channel: stable
|
|
||||||
confinement: classic
|
|
||||||
- name: review-tools
|
|
||||||
channel: stable
|
|
||||||
- name: lxd
|
|
||||||
channel: stable
|
|
||||||
env:
|
|
||||||
- SNAPCRAFT_IMAGE_INFO: |
|
|
||||||
'{"build_url": "$TRAVIS_JOB_WEB_URL"}'
|
|
||||||
- SNAPCRAFT_BUILD_ENVIRONMENT: lxd
|
|
||||||
- SNAPCRAFT_BUILD_INFO: 1 # https://snapcraft.io/blog/introducing-developer-notifications-for-snap-security-updates
|
|
||||||
install:
|
|
||||||
- sudo usermod --append --groups lxd $USER
|
|
||||||
- sudo /snap/bin/lxd.migrate -yes
|
|
||||||
- sudo /snap/bin/lxd waitready
|
|
||||||
- sudo /snap/bin/lxd init --auto
|
|
||||||
script:
|
|
||||||
- ./scripts/build_snap.sh
|
|
||||||
after_failure:
|
|
||||||
- sudo journalctl -u snapd
|
|
||||||
|
|
||||||
before_install:
|
|
||||||
- bash ./scripts/ci/before_install.sh
|
|
||||||
- source env.sh
|
|
||||||
- bash ./scripts/ci/check_python.sh
|
|
||||||
install:
|
|
||||||
- bash ./scripts/ci/install.sh
|
|
||||||
script:
|
|
||||||
- bash ./scripts/ci/script.sh
|
|
||||||
deploy:
|
|
||||||
- provider: releases
|
|
||||||
api_key:
|
|
||||||
secure: nyo17gF4Xl6DFL/KVkMewC805Cv+eK99L7SiYCU+WUAYDIzzFL3YJm7fm8bznPeor7DmpO7uSLSveMnJETBtdurW6JWhCTUss4yD66yFzpk6Z5cvHf/1UA5pdMHkkMM54fRaTRt6L2Yal7RPwGEQTBECLXW1Xmf78Y6+0l8lTvXQ9jXOQSRO/63VDKI5Zww2+XytVicUFlr0hLMGKUuaCjjXcQlAPzBgQz3/5Iz6EtzeTf2o+gTPjocbRbSFPikfiBXUn8XlJ8jBj7i114XJRJffw59KxYGDzxp+enfLBULGNoW0Np2hZqkKkPUIdB08C8XVbRXlFYX8cEYBczjqhv8A05p5F5CnltnqQ0KazcoUP2awPVqn68dWNRF+kqrnMBus8euYKIZ4dy/6bVEKJRa84ESJXZVDcwXTAXRqyovSxOlXqg9ZgAImMKBfKn/fpDX2xIvQPaXcnJxKbmcePfdbC1d0HYJ5jkbNaxKE/T15VvhzIho7mJ2WAv1r8QouQUuzqtpzIGbRn/KXHRUzCtyP0k4+eMKMLFOPzg848WsDarP3v8VYiSy4nFY7ZP7DRd3KttvW5bgVbSeO4jPmTgS6TnnpRwual9BJXSG7bjbfpIMii3bNZ7jWL4zpKT9Jfm8w9RGKLcX9HqkZ3+y60+LtYdhEfBvqsIlWQoIJBXg=
|
|
||||||
file_glob: true
|
|
||||||
file:
|
|
||||||
- dvc*.rpm
|
|
||||||
- dvc*.deb
|
|
||||||
- dvc*.pkg
|
|
||||||
- dvc*.exe
|
|
||||||
skip_cleanup: true
|
|
||||||
on:
|
|
||||||
condition: "$(./scripts/ci/deploy_condition.sh dvc*.rpm dvc*.deb dvc*.pkg dvc*.exe)"
|
|
||||||
tags: true
|
|
||||||
repo: iterative/dvc
|
|
||||||
stage: build
|
|
||||||
- provider: pypi
|
|
||||||
user:
|
|
||||||
secure: "IOzNfgPoG3ICg3+s4AuZCCnawgd/KqMzeiAB9R0B9Xb6ProPQJp9O3GBZrtg5OJMHdWQQtwULeOh/LWk4sFdXMcX1iNEgm5Tb7DwO7TDtltW14jUgN9AqfY2twj4UIsW/ON8w0P8v36ZoQq1kO6Pfgjijdm3w+9h6rpps8rJ6jXYpVZVO+SSzzijWddanMkEz4GgctZ2r7U5MWlmm1UogF60kEZIZCQykz0yJnhTpP9nMFDKw6Maki/mcfVwTQ/v3RqjzttHei/aaEMGQXYr3TOX8NPYJXerBpjShDZqcgcCfqPzhi7uCwVYaPvRsMMYH5jgtMz/SO3J6ToeGKT0f1F1ihRyCdusg325TMK7Vv8yHJzL4ngeUbb/oqxWtxhLY7f77Lkx6hBwe6ROpTqiQHIfZad5qyIHihKcDcIHo4FwLHVzxR4y+Ds2js5dXwBkUBaEAx0Dmc6ZdgXqxd815GDwv+VVpzXJhtO6qXmKE36F/Oe6eCNG3dk5MdOK4C2DrM9M8MXllqeQtX6JrM2stWlBalAc9Jn4b0xxAoghX3x3G3hNsLc9Uist1VinY2+IcPozusqj66c+Vbi5YngWSbICOjlIcq2GaOlBi3xioGts396442ztf1eLjMVuvykCI3b4Yz/vJYZOZjUvG/6nLfaFQTJLSXkTvI4do3foeY4="
|
|
||||||
password:
|
|
||||||
secure: "ts/3FSPL+w4euXryip9wCJWUqUwuJ2CqHi0nEpYVM10KL0cp9aMkQXN/7C8ih+j/JZ25kaO+tis1nx0JERVnKrg/1F/fJhxHTpakCP4OSIlhKRXDt7yUUHcKKt5QdM2XCKhApptP6RTpWL1vlc36CMrhdvTcMYp7hlDOiWjdhhim24FGQzabL42Ko59ttyyCROqgcnjHqj+WlhJl7iYO+lv2PLOtslpkIYY5EMjgBLuGyOvxTqZsAXtworsASdB2CrsTE6iMRcrM1afgkyBlUqDezoiv9TwfZrZ85oRoAxPB7su4QWK7lEP0wGQV/SDz/RL7c+cNfRaauxUKVcC8I2LfaEpudv8vi205+v/08wzPbS4xSOnf89irUJnyGxUy+bYLoXPPVPMyzcQRAUnrQl+ENCmN62HU+/2pkIyiUJvt0wYYP0vp+3pIbXbYQGmAIMq7nZJd7K3rikfnQIGKI03xZsFe3PEdjzhDI9Ej/tRUbJx4pgg084QuYYca6MSYn/zJ5pqIG4A7ngCSxoxoWZT0duo8PrUWQeT17L73Q86HeEv3OzZhWfEF2fNDN3Qbsu4CllSZnbE7DXgAuysTwTYHS/na6lp7wejOqdRUXrHbidVla9Mwxyc9JdWNWzUDxALvNxAdNbV6l85mO8izy8wjQF6M1O7idqTfjQeR4pc="
|
|
||||||
skip_existing: true
|
|
||||||
file_glob: true
|
|
||||||
file:
|
|
||||||
- dist/dvc*.whl
|
|
||||||
- dist/dvc*.tar.gz
|
|
||||||
skip_cleanup: true
|
|
||||||
on:
|
|
||||||
condition: "$(./scripts/ci/deploy_condition.sh dist/dvc*.whl dist/dvc*.tar.gz)"
|
|
||||||
tags: true
|
|
||||||
repo: iterative/dvc
|
|
||||||
stage: build
|
|
||||||
- provider: script
|
|
||||||
skip_cleanup: true
|
|
||||||
script: "(echo $SNAP_TOKEN | snapcraft login --with -) && timeout 600 snapcraft push dvc_*.snap --release $SNAP_CHANNEL || echo timed out"
|
|
||||||
on:
|
|
||||||
all_branches: true
|
|
||||||
condition: "$(./scripts/ci/deploy_condition.sh dvc_*.snap) && ($TRAVIS_BRANCH = master || -n $TRAVIS_TAG) && -n $SNAP_CHANNEL"
|
|
||||||
repo: iterative/dvc
|
|
||||||
stage: build
|
|
||||||
- provider: script
|
|
||||||
skip_cleanup: true
|
|
||||||
script: "(echo $SNAP_TOKEN | snapcraft login --with -) && timeout 600 snapcraft push dvc_*.snap --release $SNAP_CHANNEL_MAJOR || echo timed out"
|
|
||||||
on:
|
|
||||||
all_branches: true
|
|
||||||
condition: "$(./scripts/ci/deploy_condition.sh dvc_*.snap) && ($TRAVIS_BRANCH = master || -n $TRAVIS_TAG) && -n $SNAP_CHANNEL_MAJOR"
|
|
||||||
repo: iterative/dvc
|
|
||||||
stage: build
|
|
||||||
+4
-38
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
|Release| |CI| |Maintainability| |Coverage| |Donate| |DOI|
|
|Release| |CI| |Maintainability| |Coverage| |Donate| |DOI|
|
||||||
|
|
||||||
|Snap| |Choco| |Brew| |Conda| |PyPI| |Packages|
|
|PyPI| |Packages| |Brew| |Conda| |Choco| |Snap|
|
||||||
|
|
||||||
|
|
|
|
||||||
|
|
||||||
@@ -131,8 +131,6 @@ Conda (Anaconda)
|
|||||||
|
|
||||||
conda install -c conda-forge dvc
|
conda install -c conda-forge dvc
|
||||||
|
|
||||||
Currently, this includes support for Python versions 2.7, 3.6 and 3.7.
|
|
||||||
|
|
||||||
pip (PyPI)
|
pip (PyPI)
|
||||||
----------
|
----------
|
||||||
|
|
||||||
@@ -203,38 +201,6 @@ Contributing
|
|||||||
Contributions are welcome! Please see our `Contributing Guide <https://dvc.org/doc/user-guide/contributing/core>`_ for more
|
Contributions are welcome! Please see our `Contributing Guide <https://dvc.org/doc/user-guide/contributing/core>`_ for more
|
||||||
details.
|
details.
|
||||||
|
|
||||||
.. image:: https://sourcerer.io/fame/efiop/iterative/dvc/images/0
|
|
||||||
:target: https://sourcerer.io/fame/efiop/iterative/dvc/links/0
|
|
||||||
:alt: 0
|
|
||||||
|
|
||||||
.. image:: https://sourcerer.io/fame/efiop/iterative/dvc/images/1
|
|
||||||
:target: https://sourcerer.io/fame/efiop/iterative/dvc/links/1
|
|
||||||
:alt: 1
|
|
||||||
|
|
||||||
.. image:: https://sourcerer.io/fame/efiop/iterative/dvc/images/2
|
|
||||||
:target: https://sourcerer.io/fame/efiop/iterative/dvc/links/2
|
|
||||||
:alt: 2
|
|
||||||
|
|
||||||
.. image:: https://sourcerer.io/fame/efiop/iterative/dvc/images/3
|
|
||||||
:target: https://sourcerer.io/fame/efiop/iterative/dvc/links/3
|
|
||||||
:alt: 3
|
|
||||||
|
|
||||||
.. image:: https://sourcerer.io/fame/efiop/iterative/dvc/images/4
|
|
||||||
:target: https://sourcerer.io/fame/efiop/iterative/dvc/links/4
|
|
||||||
:alt: 4
|
|
||||||
|
|
||||||
.. image:: https://sourcerer.io/fame/efiop/iterative/dvc/images/5
|
|
||||||
:target: https://sourcerer.io/fame/efiop/iterative/dvc/links/5
|
|
||||||
:alt: 5
|
|
||||||
|
|
||||||
.. image:: https://sourcerer.io/fame/efiop/iterative/dvc/images/6
|
|
||||||
:target: https://sourcerer.io/fame/efiop/iterative/dvc/links/6
|
|
||||||
:alt: 6
|
|
||||||
|
|
||||||
.. image:: https://sourcerer.io/fame/efiop/iterative/dvc/images/7
|
|
||||||
:target: https://sourcerer.io/fame/efiop/iterative/dvc/links/7
|
|
||||||
:alt: 7
|
|
||||||
|
|
||||||
Mailing List
|
Mailing List
|
||||||
============
|
============
|
||||||
|
|
||||||
@@ -264,9 +230,9 @@ Iterative, *DVC: Data Version Control - Git for Data & Models* (2020)
|
|||||||
:target: https://travis-ci.com/iterative/dvc/branches
|
:target: https://travis-ci.com/iterative/dvc/branches
|
||||||
:alt: Release
|
:alt: Release
|
||||||
|
|
||||||
.. |CI| image:: https://img.shields.io/travis/com/iterative/dvc/master?label=dev&logo=travis
|
.. |CI| image:: https://github.com/iterative/dvc/workflows/Tests/badge.svg?branch=master
|
||||||
:target: https://travis-ci.com/iterative/dvc/builds
|
:target: https://github.com/iterative/dvc/actions
|
||||||
:alt: Travis dev branch
|
:alt: GHA Tests
|
||||||
|
|
||||||
.. |Maintainability| image:: https://codeclimate.com/github/iterative/dvc/badges/gpa.svg
|
.. |Maintainability| image:: https://codeclimate.com/github/iterative/dvc/badges/gpa.svg
|
||||||
:target: https://codeclimate.com/github/iterative/dvc
|
:target: https://codeclimate.com/github/iterative/dvc
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
from contextlib import ExitStack, contextmanager
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from argparse import Namespace
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def instrument(html_output=False):
|
||||||
|
"""Run a statistical profiler"""
|
||||||
|
try:
|
||||||
|
from pyinstrument import Profiler # pylint: disable=import-error
|
||||||
|
except ImportError:
|
||||||
|
print("Failed to run profiler, pyinstrument is not installed")
|
||||||
|
yield
|
||||||
|
return
|
||||||
|
|
||||||
|
profiler = Profiler()
|
||||||
|
|
||||||
|
profiler.start()
|
||||||
|
yield
|
||||||
|
profiler.stop()
|
||||||
|
|
||||||
|
if html_output:
|
||||||
|
profiler.open_in_browser()
|
||||||
|
return
|
||||||
|
print(profiler.output_text(unicode=True, color=True))
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def profile(dump_path: str = None):
|
||||||
|
"""Run a cprofile"""
|
||||||
|
import cProfile
|
||||||
|
|
||||||
|
prof = cProfile.Profile()
|
||||||
|
prof.enable()
|
||||||
|
|
||||||
|
yield
|
||||||
|
|
||||||
|
prof.disable()
|
||||||
|
if not dump_path:
|
||||||
|
prof.print_stats(sort="cumtime")
|
||||||
|
return
|
||||||
|
prof.dump_stats(dump_path)
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def debug():
|
||||||
|
try:
|
||||||
|
yield
|
||||||
|
except Exception: # pylint: disable=broad-except
|
||||||
|
try:
|
||||||
|
import ipdb as pdb # noqa: T100, pylint: disable=import-error
|
||||||
|
except ImportError:
|
||||||
|
import pdb # noqa: T100
|
||||||
|
pdb.post_mortem()
|
||||||
|
|
||||||
|
raise # prevent from jumping ahead
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def debugtools(args: "Namespace" = None, **kwargs):
|
||||||
|
kw = vars(args) if args else {}
|
||||||
|
kw.update(kwargs)
|
||||||
|
|
||||||
|
with ExitStack() as stack:
|
||||||
|
if kw.get("pdb"):
|
||||||
|
stack.enter_context(debug())
|
||||||
|
if kw.get("cprofile") or kw.get("cprofile_dump"):
|
||||||
|
stack.enter_context(profile(kw.get("cprofile_dump")))
|
||||||
|
if kw.get("instrument") or kw.get("instrument_open"):
|
||||||
|
stack.enter_context(instrument(kw.get("instrument_open", False)))
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
def add_debugging_flags(parser):
|
||||||
|
from argparse import SUPPRESS
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"--cprofile", action="store_true", default=False, help=SUPPRESS,
|
||||||
|
)
|
||||||
|
parser.add_argument("--cprofile-dump", help=SUPPRESS)
|
||||||
|
parser.add_argument(
|
||||||
|
"--pdb", action="store_true", default=False, help=SUPPRESS,
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--instrument", action="store_true", default=False, help=SUPPRESS,
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--instrument-open", action="store_true", default=False, help=SUPPRESS,
|
||||||
|
)
|
||||||
+28
-18
@@ -1,24 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import platform
|
|
||||||
import sys
|
|
||||||
import tempfile
|
|
||||||
import uuid
|
|
||||||
|
|
||||||
import distro
|
|
||||||
import requests
|
|
||||||
|
|
||||||
from dvc import __version__
|
|
||||||
from dvc.config import Config, to_bool
|
|
||||||
from dvc.daemon import daemon
|
|
||||||
from dvc.exceptions import NotDvcRepoError
|
|
||||||
from dvc.lock import Lock, LockError
|
|
||||||
from dvc.repo import Repo
|
|
||||||
from dvc.scm import SCM, NoSCM
|
|
||||||
from dvc.scm.base import SCMError
|
|
||||||
from dvc.utils import env2bool, is_binary
|
|
||||||
from dvc.utils.fs import makedirs
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -35,6 +17,10 @@ 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.
|
||||||
"""
|
"""
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
from dvc.daemon import daemon
|
||||||
|
|
||||||
report = {}
|
report = {}
|
||||||
|
|
||||||
# Include command execution information on the report only when available.
|
# Include command execution information on the report only when available.
|
||||||
@@ -50,6 +36,9 @@ def collect_and_send_report(args=None, return_code=None):
|
|||||||
|
|
||||||
|
|
||||||
def is_enabled():
|
def is_enabled():
|
||||||
|
from dvc.config import Config, to_bool
|
||||||
|
from dvc.utils import env2bool
|
||||||
|
|
||||||
if env2bool("DVC_TEST"):
|
if env2bool("DVC_TEST"):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -69,6 +58,8 @@ def send(path):
|
|||||||
`collect_and_send_report`. Sending happens on another process,
|
`collect_and_send_report`. Sending happens on another process,
|
||||||
thus, the need of removing such file afterwards.
|
thus, the need of removing such file afterwards.
|
||||||
"""
|
"""
|
||||||
|
import requests
|
||||||
|
|
||||||
url = "https://analytics.dvc.org"
|
url = "https://analytics.dvc.org"
|
||||||
headers = {"content-type": "application/json"}
|
headers = {"content-type": "application/json"}
|
||||||
|
|
||||||
@@ -86,6 +77,11 @@ def send(path):
|
|||||||
|
|
||||||
|
|
||||||
def _scm_in_use():
|
def _scm_in_use():
|
||||||
|
from dvc.exceptions import NotDvcRepoError
|
||||||
|
from dvc.repo import Repo
|
||||||
|
from dvc.scm import SCM, NoSCM
|
||||||
|
from dvc.scm.base import SCMError
|
||||||
|
|
||||||
try:
|
try:
|
||||||
scm = SCM(root_dir=Repo.find_root())
|
scm = SCM(root_dir=Repo.find_root())
|
||||||
return type(scm).__name__
|
return type(scm).__name__
|
||||||
@@ -99,6 +95,9 @@ def _runtime_info():
|
|||||||
"""
|
"""
|
||||||
Gather information from the environment where DVC runs to fill a report.
|
Gather information from the environment where DVC runs to fill a report.
|
||||||
"""
|
"""
|
||||||
|
from dvc import __version__
|
||||||
|
from dvc.utils import is_binary
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"dvc_version": __version__,
|
"dvc_version": __version__,
|
||||||
"is_binary": is_binary(),
|
"is_binary": is_binary(),
|
||||||
@@ -109,6 +108,11 @@ def _runtime_info():
|
|||||||
|
|
||||||
|
|
||||||
def _system_info():
|
def _system_info():
|
||||||
|
import platform
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import distro
|
||||||
|
|
||||||
system = platform.system()
|
system = platform.system()
|
||||||
|
|
||||||
if system == "Windows":
|
if system == "Windows":
|
||||||
@@ -147,6 +151,12 @@ def _find_or_create_user_id():
|
|||||||
|
|
||||||
IDs are generated randomly with UUID.
|
IDs are generated randomly with UUID.
|
||||||
"""
|
"""
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
from dvc.config import Config
|
||||||
|
from dvc.lock import Lock, LockError
|
||||||
|
from dvc.utils.fs import makedirs
|
||||||
|
|
||||||
config_dir = Config.get_dir("global")
|
config_dir = Config.get_dir("global")
|
||||||
fname = os.path.join(config_dir, "user_id")
|
fname = os.path.join(config_dir, "user_id")
|
||||||
lockfile = os.path.join(config_dir, "user_id.lock")
|
lockfile = os.path.join(config_dir, "user_id.lock")
|
||||||
|
|||||||
@@ -1,39 +1,41 @@
|
|||||||
import os
|
import os
|
||||||
from contextlib import _GeneratorContextManager as GCM
|
from contextlib import _GeneratorContextManager as GCM
|
||||||
from contextlib import contextmanager
|
|
||||||
|
|
||||||
from dvc.exceptions import DvcException, NotDvcRepoError
|
from funcy import reraise
|
||||||
from dvc.external_repo import external_repo
|
|
||||||
|
from dvc.exceptions import OutputNotFoundError, PathMissingError
|
||||||
|
from dvc.objects.stage import get_hash
|
||||||
|
from dvc.path_info import PathInfo
|
||||||
from dvc.repo import Repo
|
from dvc.repo import Repo
|
||||||
|
|
||||||
|
|
||||||
class UrlNotDvcRepoError(DvcException):
|
|
||||||
"""Thrown if the given URL is not a DVC repository."""
|
|
||||||
|
|
||||||
def __init__(self, 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):
|
||||||
"""
|
"""
|
||||||
Returns the URL to the storage location of a data file or directory tracked
|
Returns the URL to the storage location of a data file or directory tracked
|
||||||
in a DVC repo. For Git repos, HEAD is used unless a rev argument is
|
in a DVC repo. For Git repos, HEAD is used unless a rev argument is
|
||||||
supplied. The default remote is tried unless a remote argument is supplied.
|
supplied. The default remote is tried unless a remote argument is supplied.
|
||||||
|
|
||||||
Raises UrlNotDvcRepoError if repo is not a DVC project.
|
Raises OutputNotFoundError if the file is not tracked by DVC.
|
||||||
|
|
||||||
NOTE: This function does not check for the actual existence of the file or
|
NOTE: This function does not check for the actual existence of the file or
|
||||||
directory in the remote storage.
|
directory in the remote storage.
|
||||||
"""
|
"""
|
||||||
with _make_repo(repo, rev=rev) as _repo:
|
with Repo.open(repo, rev=rev, subrepos=True, uninitialized=True) as _repo:
|
||||||
if not isinstance(_repo, Repo):
|
path_info = PathInfo(_repo.root_dir) / path
|
||||||
raise UrlNotDvcRepoError(_repo.url)
|
with reraise(FileNotFoundError, PathMissingError(path, repo)):
|
||||||
out = _repo.find_out_by_relpath(path)
|
metadata = _repo.repo_fs.metadata(path_info)
|
||||||
remote_obj = _repo.cloud.get_remote(remote)
|
|
||||||
return str(remote_obj.hash_to_path_info(out.checksum))
|
if not metadata.is_dvc:
|
||||||
|
raise OutputNotFoundError(path, repo)
|
||||||
|
|
||||||
|
cloud = metadata.repo.cloud
|
||||||
|
hash_info = get_hash(path_info, _repo.repo_fs, "md5")
|
||||||
|
return cloud.get_url_for(remote, checksum=hash_info.value)
|
||||||
|
|
||||||
|
|
||||||
def open(path, repo=None, rev=None, remote=None, mode="r", encoding=None):
|
def open( # noqa, pylint: disable=redefined-builtin
|
||||||
|
path, repo=None, rev=None, remote=None, mode="r", encoding=None
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Open file in the supplied path tracked in a repo (both DVC projects and
|
Open file in the supplied path tracked in a repo (both DVC projects and
|
||||||
plain Git repos are supported). For Git repos, HEAD is used unless a rev
|
plain Git repos are supported). For Git repos, HEAD is used unless a rev
|
||||||
@@ -58,7 +60,9 @@ def open(path, repo=None, rev=None, remote=None, mode="r", encoding=None):
|
|||||||
|
|
||||||
|
|
||||||
class _OpenContextManager(GCM):
|
class _OpenContextManager(GCM):
|
||||||
def __init__(self, func, args, kwds):
|
def __init__(
|
||||||
|
self, func, args, kwds
|
||||||
|
): # pylint: disable=super-init-not-called
|
||||||
self.gen = func(*args, **kwds)
|
self.gen = func(*args, **kwds)
|
||||||
self.func, self.args, self.kwds = func, args, kwds
|
self.func, self.args, self.kwds = func, args, kwds
|
||||||
|
|
||||||
@@ -69,7 +73,7 @@ class _OpenContextManager(GCM):
|
|||||||
|
|
||||||
|
|
||||||
def _open(path, repo=None, rev=None, remote=None, mode="r", encoding=None):
|
def _open(path, repo=None, rev=None, remote=None, mode="r", encoding=None):
|
||||||
with _make_repo(repo, rev=rev) as _repo:
|
with Repo.open(repo, rev=rev, subrepos=True, uninitialized=True) as _repo:
|
||||||
with _repo.open_by_relpath(
|
with _repo.open_by_relpath(
|
||||||
path, remote=remote, mode=mode, encoding=encoding
|
path, remote=remote, mode=mode, encoding=encoding
|
||||||
) as fd:
|
) as fd:
|
||||||
@@ -88,14 +92,33 @@ def read(path, repo=None, rev=None, remote=None, mode="r", encoding=None):
|
|||||||
return fd.read()
|
return fd.read()
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
def make_checkpoint():
|
||||||
def _make_repo(repo_url=None, rev=None):
|
"""
|
||||||
repo_url = repo_url or os.getcwd()
|
Signal DVC to create a checkpoint experiment.
|
||||||
if rev is None and os.path.exists(repo_url):
|
|
||||||
try:
|
If the current process is being run from DVC, this function will block
|
||||||
yield Repo(repo_url)
|
until DVC has finished creating the checkpoint. Otherwise, this function
|
||||||
return
|
will return immediately.
|
||||||
except NotDvcRepoError:
|
"""
|
||||||
pass # fallthrough to external_repo
|
import builtins
|
||||||
with external_repo(url=repo_url, rev=rev) as repo:
|
from time import sleep
|
||||||
yield repo
|
|
||||||
|
from dvc.env import DVC_CHECKPOINT, DVC_ROOT
|
||||||
|
from dvc.stage.run import CHECKPOINT_SIGNAL_FILE
|
||||||
|
|
||||||
|
if os.getenv(DVC_CHECKPOINT) is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
root_dir = os.getenv(DVC_ROOT, Repo.find_root())
|
||||||
|
signal_file = os.path.join(
|
||||||
|
root_dir, Repo.DVC_DIR, "tmp", CHECKPOINT_SIGNAL_FILE
|
||||||
|
)
|
||||||
|
|
||||||
|
with builtins.open(signal_file, "w") as fobj:
|
||||||
|
# NOTE: force flushing/writing empty file to disk, otherwise when
|
||||||
|
# run in certain contexts (pytest) file may not actually be written
|
||||||
|
fobj.write("")
|
||||||
|
fobj.flush()
|
||||||
|
os.fsync(fobj.fileno())
|
||||||
|
while os.path.exists(signal_file):
|
||||||
|
sleep(0.1)
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import logging
|
||||||
|
import os
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
from dvc.exceptions import NotDvcRepoError
|
||||||
|
from dvc.repo import Repo
|
||||||
|
from dvc.utils.html import write
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def summary(path: str, revs: List[str] = None):
|
||||||
|
try:
|
||||||
|
root = Repo.find_root()
|
||||||
|
except NotDvcRepoError:
|
||||||
|
root = os.getcwd()
|
||||||
|
|
||||||
|
metrics, plots = Repo(root_dir=root, uninitialized=True).live.show(
|
||||||
|
path, revs
|
||||||
|
)
|
||||||
|
|
||||||
|
html_path = path + ".html"
|
||||||
|
write(html_path, plots, metrics)
|
||||||
|
logger.info(f"\nfile://{os.path.abspath(html_path)}")
|
||||||
+302
@@ -0,0 +1,302 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
from shortuuid import uuid
|
||||||
|
|
||||||
|
import dvc.prompt as prompt
|
||||||
|
from dvc.exceptions import (
|
||||||
|
CacheLinkError,
|
||||||
|
CheckoutError,
|
||||||
|
ConfirmRemoveError,
|
||||||
|
DvcException,
|
||||||
|
)
|
||||||
|
from dvc.objects import ObjectFormatError, check, load
|
||||||
|
from dvc.objects.stage import get_hash
|
||||||
|
from dvc.remote.slow_link_detection import ( # type: ignore[attr-defined]
|
||||||
|
slow_link_guard,
|
||||||
|
)
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def _changed(path_info, fs, obj, cache):
|
||||||
|
logger.trace("checking if '%s'('%s') has changed.", path_info, obj)
|
||||||
|
|
||||||
|
try:
|
||||||
|
check(cache, obj)
|
||||||
|
except (FileNotFoundError, ObjectFormatError):
|
||||||
|
logger.debug(
|
||||||
|
"cache for '%s'('%s') has changed.", path_info, obj.hash_info
|
||||||
|
)
|
||||||
|
return True
|
||||||
|
|
||||||
|
try:
|
||||||
|
actual = get_hash(path_info, fs, obj.hash_info.name)
|
||||||
|
except FileNotFoundError:
|
||||||
|
logger.debug("'%s' doesn't exist.", path_info)
|
||||||
|
return True
|
||||||
|
|
||||||
|
if obj.hash_info != actual:
|
||||||
|
logger.debug(
|
||||||
|
"hash value '%s' for '%s' has changed (actual '%s').",
|
||||||
|
obj.hash_info,
|
||||||
|
actual,
|
||||||
|
path_info,
|
||||||
|
)
|
||||||
|
return True
|
||||||
|
|
||||||
|
logger.trace("'%s' hasn't changed.", path_info)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def _remove(path_info, fs, cache, force=False):
|
||||||
|
if not fs.exists(path_info):
|
||||||
|
return
|
||||||
|
|
||||||
|
if force:
|
||||||
|
fs.remove(path_info)
|
||||||
|
return
|
||||||
|
|
||||||
|
current = get_hash(path_info, fs, fs.PARAM_CHECKSUM)
|
||||||
|
try:
|
||||||
|
obj = load(cache, current)
|
||||||
|
check(cache, obj)
|
||||||
|
except (FileNotFoundError, ObjectFormatError):
|
||||||
|
msg = (
|
||||||
|
f"file/directory '{path_info}' is going to be removed. "
|
||||||
|
"Are you sure you want to proceed?"
|
||||||
|
)
|
||||||
|
|
||||||
|
if not prompt.confirm(msg):
|
||||||
|
raise ConfirmRemoveError(str(path_info))
|
||||||
|
|
||||||
|
fs.remove(path_info)
|
||||||
|
|
||||||
|
|
||||||
|
def _verify_link(cache, path_info, link_type):
|
||||||
|
if link_type == "hardlink" and cache.fs.getsize(path_info) == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
if cache.cache_type_confirmed:
|
||||||
|
return
|
||||||
|
|
||||||
|
is_link = getattr(cache.fs, f"is_{link_type}", None)
|
||||||
|
if is_link and not is_link(path_info):
|
||||||
|
cache.fs.remove(path_info)
|
||||||
|
raise DvcException(f"failed to verify {link_type}")
|
||||||
|
|
||||||
|
cache.cache_type_confirmed = True
|
||||||
|
|
||||||
|
|
||||||
|
def _do_link(cache, from_info, to_info, link_method):
|
||||||
|
if cache.fs.exists(to_info):
|
||||||
|
raise DvcException(f"Link '{to_info}' already exists!")
|
||||||
|
|
||||||
|
link_method(from_info, to_info)
|
||||||
|
|
||||||
|
logger.debug(
|
||||||
|
"Created '%s': %s -> %s", cache.cache_types[0], from_info, to_info,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@slow_link_guard
|
||||||
|
def _try_links(cache, from_info, to_info, link_types):
|
||||||
|
while link_types:
|
||||||
|
link_method = getattr(cache.fs, link_types[0])
|
||||||
|
try:
|
||||||
|
_do_link(cache, from_info, to_info, link_method)
|
||||||
|
_verify_link(cache, to_info, link_types[0])
|
||||||
|
return
|
||||||
|
|
||||||
|
except DvcException as exc:
|
||||||
|
logger.debug(
|
||||||
|
"Cache type '%s' is not supported: %s", link_types[0], exc
|
||||||
|
)
|
||||||
|
del link_types[0]
|
||||||
|
|
||||||
|
raise CacheLinkError([to_info])
|
||||||
|
|
||||||
|
|
||||||
|
def _link(cache, from_info, to_info):
|
||||||
|
assert cache.fs.isfile(from_info)
|
||||||
|
cache.makedirs(to_info.parent)
|
||||||
|
_try_links(cache, from_info, to_info, cache.cache_types)
|
||||||
|
|
||||||
|
|
||||||
|
def _cache_is_copy(cache, path_info):
|
||||||
|
"""Checks whether cache uses copies."""
|
||||||
|
if cache.cache_type_confirmed:
|
||||||
|
return cache.cache_types[0] == "copy"
|
||||||
|
|
||||||
|
if set(cache.cache_types) <= {"copy"}:
|
||||||
|
return True
|
||||||
|
|
||||||
|
workspace_file = path_info.with_name("." + uuid())
|
||||||
|
test_cache_file = cache.fs.path_info / ".cache_type_test_file"
|
||||||
|
if not cache.fs.exists(test_cache_file):
|
||||||
|
cache.makedirs(test_cache_file.parent)
|
||||||
|
with cache.fs.open(test_cache_file, "wb") as fobj:
|
||||||
|
fobj.write(bytes(1))
|
||||||
|
try:
|
||||||
|
_link(cache, test_cache_file, workspace_file)
|
||||||
|
finally:
|
||||||
|
cache.fs.remove(workspace_file)
|
||||||
|
cache.fs.remove(test_cache_file)
|
||||||
|
|
||||||
|
cache.cache_type_confirmed = True
|
||||||
|
return cache.cache_types[0] == "copy"
|
||||||
|
|
||||||
|
|
||||||
|
def _checkout_file(
|
||||||
|
path_info, fs, obj, cache, force, progress_callback=None, relink=False,
|
||||||
|
):
|
||||||
|
"""The file is changed we need to checkout a new copy"""
|
||||||
|
modified = False
|
||||||
|
cache_info = cache.hash_to_path_info(obj.hash_info.value)
|
||||||
|
if fs.exists(path_info):
|
||||||
|
if not relink and _changed(path_info, fs, obj, cache):
|
||||||
|
modified = True
|
||||||
|
_remove(path_info, fs, cache, force=force)
|
||||||
|
_link(cache, cache_info, path_info)
|
||||||
|
else:
|
||||||
|
if fs.iscopy(path_info) and _cache_is_copy(cache, path_info):
|
||||||
|
cache.unprotect(path_info)
|
||||||
|
else:
|
||||||
|
_remove(path_info, fs, cache, force=force)
|
||||||
|
_link(cache, cache_info, path_info)
|
||||||
|
else:
|
||||||
|
_link(cache, cache_info, path_info)
|
||||||
|
modified = True
|
||||||
|
|
||||||
|
fs.repo.state.save(path_info, fs, obj.hash_info)
|
||||||
|
if progress_callback:
|
||||||
|
progress_callback(str(path_info))
|
||||||
|
|
||||||
|
return modified
|
||||||
|
|
||||||
|
|
||||||
|
def _remove_redundant_files(path_info, fs, dir_info, cache, force):
|
||||||
|
existing_files = set(fs.walk_files(path_info))
|
||||||
|
|
||||||
|
needed_files = {info for info, _ in dir_info.items(path_info)}
|
||||||
|
redundant_files = existing_files - needed_files
|
||||||
|
for path in redundant_files:
|
||||||
|
_remove(path, fs, cache, force)
|
||||||
|
|
||||||
|
return bool(redundant_files)
|
||||||
|
|
||||||
|
|
||||||
|
def _checkout_dir(
|
||||||
|
path_info, fs, obj, cache, force, progress_callback=None, relink=False,
|
||||||
|
):
|
||||||
|
modified = False, False
|
||||||
|
# Create dir separately so that dir is created
|
||||||
|
# even if there are no files in it
|
||||||
|
if not fs.exists(path_info):
|
||||||
|
modified = True
|
||||||
|
fs.makedirs(path_info)
|
||||||
|
|
||||||
|
logger.debug("Linking directory '%s'.", path_info)
|
||||||
|
|
||||||
|
for entry_info, entry_hash_info in obj.hash_info.dir_info.items(path_info):
|
||||||
|
entry_modified = _checkout_file(
|
||||||
|
entry_info,
|
||||||
|
fs,
|
||||||
|
cache.get(entry_hash_info),
|
||||||
|
cache,
|
||||||
|
force,
|
||||||
|
progress_callback,
|
||||||
|
relink,
|
||||||
|
)
|
||||||
|
if entry_modified:
|
||||||
|
modified = True
|
||||||
|
|
||||||
|
modified = (
|
||||||
|
_remove_redundant_files(
|
||||||
|
path_info, fs, obj.hash_info.dir_info, cache, force
|
||||||
|
)
|
||||||
|
or modified
|
||||||
|
)
|
||||||
|
|
||||||
|
fs.repo.state.save(path_info, fs, obj.hash_info)
|
||||||
|
|
||||||
|
# relink is not modified, assume it as nochange
|
||||||
|
return modified and not relink
|
||||||
|
|
||||||
|
|
||||||
|
def _checkout(
|
||||||
|
path_info,
|
||||||
|
fs,
|
||||||
|
obj,
|
||||||
|
cache,
|
||||||
|
force=False,
|
||||||
|
progress_callback=None,
|
||||||
|
relink=False,
|
||||||
|
):
|
||||||
|
if not obj.hash_info.isdir:
|
||||||
|
ret = _checkout_file(
|
||||||
|
path_info, fs, obj, cache, force, progress_callback, relink
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
ret = _checkout_dir(
|
||||||
|
path_info, fs, obj, cache, force, progress_callback, relink,
|
||||||
|
)
|
||||||
|
|
||||||
|
fs.repo.state.save_link(path_info, fs)
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
def checkout(
|
||||||
|
path_info,
|
||||||
|
fs,
|
||||||
|
obj,
|
||||||
|
cache,
|
||||||
|
force=False,
|
||||||
|
progress_callback=None,
|
||||||
|
relink=False,
|
||||||
|
quiet=False,
|
||||||
|
):
|
||||||
|
if path_info.scheme not in ["local", cache.fs.scheme]:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
failed = None
|
||||||
|
skip = False
|
||||||
|
if not obj:
|
||||||
|
if not quiet:
|
||||||
|
logger.warning(
|
||||||
|
"No file hash info found for '%s'. It won't be created.",
|
||||||
|
path_info,
|
||||||
|
)
|
||||||
|
_remove(path_info, fs, cache, force=force)
|
||||||
|
failed = path_info
|
||||||
|
|
||||||
|
elif not relink and not _changed(path_info, fs, obj, cache):
|
||||||
|
logger.trace("Data '%s' didn't change.", path_info)
|
||||||
|
skip = True
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
check(cache, obj)
|
||||||
|
except (FileNotFoundError, ObjectFormatError):
|
||||||
|
if not quiet:
|
||||||
|
logger.warning(
|
||||||
|
"Cache '%s' not found. File '%s' won't be created.",
|
||||||
|
obj.hash_info,
|
||||||
|
path_info,
|
||||||
|
)
|
||||||
|
_remove(path_info, fs, cache, force=force)
|
||||||
|
failed = path_info
|
||||||
|
|
||||||
|
if failed or skip:
|
||||||
|
if progress_callback and obj:
|
||||||
|
progress_callback(
|
||||||
|
str(path_info), len(obj),
|
||||||
|
)
|
||||||
|
if failed:
|
||||||
|
raise CheckoutError([failed])
|
||||||
|
return
|
||||||
|
|
||||||
|
logger.debug("Checking out '%s' with cache '%s'.", path_info, obj)
|
||||||
|
|
||||||
|
return _checkout(
|
||||||
|
path_info, fs, obj, cache, force, progress_callback, relink,
|
||||||
|
)
|
||||||
+40
-20
@@ -1,11 +1,14 @@
|
|||||||
"""DVC command line interface"""
|
"""DVC command line interface"""
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from ._debug import add_debugging_flags
|
||||||
from .command import (
|
from .command import (
|
||||||
add,
|
add,
|
||||||
cache,
|
cache,
|
||||||
|
check_ignore,
|
||||||
checkout,
|
checkout,
|
||||||
commit,
|
commit,
|
||||||
completion,
|
completion,
|
||||||
@@ -15,6 +18,7 @@ from .command import (
|
|||||||
data_sync,
|
data_sync,
|
||||||
destroy,
|
destroy,
|
||||||
diff,
|
diff,
|
||||||
|
experiments,
|
||||||
freeze,
|
freeze,
|
||||||
gc,
|
gc,
|
||||||
get,
|
get,
|
||||||
@@ -24,6 +28,7 @@ from .command import (
|
|||||||
imp_url,
|
imp_url,
|
||||||
init,
|
init,
|
||||||
install,
|
install,
|
||||||
|
live,
|
||||||
ls,
|
ls,
|
||||||
metrics,
|
metrics,
|
||||||
move,
|
move,
|
||||||
@@ -34,6 +39,7 @@ from .command import (
|
|||||||
repro,
|
repro,
|
||||||
root,
|
root,
|
||||||
run,
|
run,
|
||||||
|
stage,
|
||||||
unprotect,
|
unprotect,
|
||||||
update,
|
update,
|
||||||
version,
|
version,
|
||||||
@@ -77,37 +83,43 @@ COMMANDS = [
|
|||||||
update,
|
update,
|
||||||
git_hook,
|
git_hook,
|
||||||
plots,
|
plots,
|
||||||
|
stage,
|
||||||
|
experiments,
|
||||||
|
check_ignore,
|
||||||
|
live,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def _find_parser(parser, cmd_cls):
|
||||||
|
defaults = parser._defaults # pylint: disable=protected-access
|
||||||
|
if not cmd_cls or cmd_cls == defaults.get("func"):
|
||||||
|
parser.print_help()
|
||||||
|
raise DvcParserError()
|
||||||
|
|
||||||
|
actions = parser._actions # pylint: disable=protected-access
|
||||||
|
for action in actions:
|
||||||
|
if not isinstance(action.choices, dict):
|
||||||
|
# NOTE: we are only interested in subparsers
|
||||||
|
continue
|
||||||
|
for subparser in action.choices.values():
|
||||||
|
_find_parser(subparser, cmd_cls)
|
||||||
|
|
||||||
|
|
||||||
class DvcParser(argparse.ArgumentParser):
|
class DvcParser(argparse.ArgumentParser):
|
||||||
"""Custom parser class for dvc CLI."""
|
"""Custom parser class for dvc CLI."""
|
||||||
|
|
||||||
def error(self, message, command=None):
|
def error(self, message, cmd_cls=None): # pylint: disable=arguments-differ
|
||||||
"""Custom error method.
|
|
||||||
Args:
|
|
||||||
message (str): error message.
|
|
||||||
command (str): subcommand name for help message
|
|
||||||
Raises:
|
|
||||||
dvc.exceptions.DvcParser: dvc parser exception.
|
|
||||||
|
|
||||||
"""
|
|
||||||
logger.error(message)
|
logger.error(message)
|
||||||
if command is not None:
|
_find_parser(self, cmd_cls)
|
||||||
for action in self._actions:
|
|
||||||
if action.dest == "cmd" and command in action.choices:
|
|
||||||
subparser = action.choices[command]
|
|
||||||
subparser.print_help()
|
|
||||||
raise DvcParserError()
|
|
||||||
self.print_help()
|
|
||||||
raise DvcParserError()
|
|
||||||
|
|
||||||
# override this to send subcommand name to error method
|
|
||||||
def parse_args(self, args=None, namespace=None):
|
def parse_args(self, args=None, namespace=None):
|
||||||
|
# NOTE: overriding to provide a more granular help message.
|
||||||
|
# E.g. `dvc plots diff --bad-flag` would result in a `dvc plots diff`
|
||||||
|
# help message instead of generic `dvc` usage.
|
||||||
args, argv = self.parse_known_args(args, namespace)
|
args, argv = self.parse_known_args(args, namespace)
|
||||||
if argv:
|
if argv:
|
||||||
msg = "unrecognized arguments: %s"
|
msg = "unrecognized arguments: %s"
|
||||||
self.error(msg % " ".join(argv), args.cmd)
|
self.error(msg % " ".join(argv), getattr(args, "func", None))
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
@@ -130,7 +142,7 @@ def get_parent_parser():
|
|||||||
in order to prevent some weird behavior.
|
in order to prevent some weird behavior.
|
||||||
"""
|
"""
|
||||||
parent_parser = argparse.ArgumentParser(add_help=False)
|
parent_parser = argparse.ArgumentParser(add_help=False)
|
||||||
|
add_debugging_flags(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="count", default=0, help="Be quiet."
|
"-q", "--quiet", action="count", default=0, help="Be quiet."
|
||||||
@@ -177,6 +189,14 @@ def get_main_parser():
|
|||||||
help="Show program's version.",
|
help="Show program's version.",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"--cd",
|
||||||
|
default=os.path.curdir,
|
||||||
|
metavar="<path>",
|
||||||
|
help="Change to directory before executing.",
|
||||||
|
type=str,
|
||||||
|
)
|
||||||
|
|
||||||
# Sub commands
|
# Sub commands
|
||||||
subparsers = parser.add_subparsers(
|
subparsers = parser.add_subparsers(
|
||||||
title="Available Commands",
|
title="Available Commands",
|
||||||
|
|||||||
+57
-7
@@ -3,13 +3,17 @@ import logging
|
|||||||
|
|
||||||
from dvc.command import completion
|
from dvc.command import completion
|
||||||
from dvc.command.base import CmdBase, append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
from dvc.exceptions import DvcException, RecursiveAddingWhileUsingFilename
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CmdAdd(CmdBase):
|
class CmdAdd(CmdBase):
|
||||||
def run(self):
|
def run(self):
|
||||||
|
from dvc.exceptions import (
|
||||||
|
DvcException,
|
||||||
|
RecursiveAddingWhileUsingFilename,
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if len(self.args.targets) > 1 and self.args.file:
|
if len(self.args.targets) > 1 and self.args.file:
|
||||||
raise RecursiveAddingWhileUsingFilename()
|
raise RecursiveAddingWhileUsingFilename()
|
||||||
@@ -20,6 +24,12 @@ class CmdAdd(CmdBase):
|
|||||||
no_commit=self.args.no_commit,
|
no_commit=self.args.no_commit,
|
||||||
fname=self.args.file,
|
fname=self.args.file,
|
||||||
external=self.args.external,
|
external=self.args.external,
|
||||||
|
glob=self.args.glob,
|
||||||
|
desc=self.args.desc,
|
||||||
|
out=self.args.out,
|
||||||
|
remote=self.args.remote,
|
||||||
|
to_remote=self.args.to_remote,
|
||||||
|
jobs=self.args.jobs,
|
||||||
)
|
)
|
||||||
|
|
||||||
except DvcException:
|
except DvcException:
|
||||||
@@ -57,16 +67,56 @@ def add_parser(subparsers, parent_parser):
|
|||||||
default=False,
|
default=False,
|
||||||
help="Allow targets that are outside of the DVC repository.",
|
help="Allow targets that are outside of the DVC repository.",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--glob",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Allows targets containing shell-style wildcards.",
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--file",
|
"--file",
|
||||||
help="Specify name of the DVC-file this command will generate.",
|
help="Specify name of the .dvc file this command will generate.",
|
||||||
metavar="<filename>",
|
metavar="<filename>",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"targets",
|
"-o",
|
||||||
nargs="+",
|
"--out",
|
||||||
help="Input files/directories to add.",
|
help="Destination path to put files to.",
|
||||||
metavar="targets",
|
metavar="<path>",
|
||||||
choices=completion.Required.FILE,
|
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--to-remote",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Download it directly to the remote",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-r",
|
||||||
|
"--remote",
|
||||||
|
help="Remote storage to download to",
|
||||||
|
metavar="<name>",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-j",
|
||||||
|
"--jobs",
|
||||||
|
type=int,
|
||||||
|
help=(
|
||||||
|
"Number of jobs to run simultaneously. "
|
||||||
|
"The default value is 4 * cpu_count(). "
|
||||||
|
"For SSH remotes, the default is 4. "
|
||||||
|
),
|
||||||
|
metavar="<number>",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--desc",
|
||||||
|
type=str,
|
||||||
|
metavar="<text>",
|
||||||
|
help=(
|
||||||
|
"User description of the data (optional). "
|
||||||
|
"This doesn't affect any DVC operations."
|
||||||
|
),
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"targets", nargs="+", help="Input files/directories to add.",
|
||||||
|
).complete = completion.FILE
|
||||||
parser.set_defaults(func=CmdAdd)
|
parser.set_defaults(func=CmdAdd)
|
||||||
|
|||||||
+17
-16
@@ -1,4 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -26,31 +28,30 @@ def append_doc_link(help_message, path):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class CmdBase:
|
class CmdBase(ABC):
|
||||||
|
UNINITIALIZED = False
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
self.repo = Repo()
|
os.chdir(args.cd)
|
||||||
|
|
||||||
|
self.repo = Repo(uninitialized=self.UNINITIALIZED)
|
||||||
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)
|
if self.repo.tmp_dir:
|
||||||
updater = Updater(self.repo.tmp_dir, hardlink_lock=hardlink_lock)
|
hardlink_lock = self.config["core"].get("hardlink_lock", False)
|
||||||
updater.check()
|
updater = Updater(self.repo.tmp_dir, hardlink_lock=hardlink_lock)
|
||||||
|
updater.check()
|
||||||
|
|
||||||
@property
|
@abstractmethod
|
||||||
def default_targets(self):
|
|
||||||
"""Default targets for `dvc repro`."""
|
|
||||||
from dvc.dvcfile import PIPELINE_FILE
|
|
||||||
|
|
||||||
logger.debug(f"assuming default target '{PIPELINE_FILE}'.")
|
|
||||||
return [PIPELINE_FILE]
|
|
||||||
|
|
||||||
# Abstract methods that have to be implemented by any inheritance class
|
|
||||||
def run(self):
|
def run(self):
|
||||||
raise NotImplementedError
|
pass
|
||||||
|
|
||||||
|
|
||||||
class CmdBaseNoRepo(CmdBase):
|
class CmdBaseNoRepo(CmdBase):
|
||||||
def __init__(self, args):
|
def __init__(self, args): # pylint: disable=super-init-not-called
|
||||||
self.args = args
|
self.args = args
|
||||||
|
|
||||||
|
os.chdir(args.cd)
|
||||||
|
|||||||
+23
-6
@@ -1,14 +1,31 @@
|
|||||||
import argparse
|
import argparse
|
||||||
|
import logging
|
||||||
|
|
||||||
from dvc.command import completion
|
from dvc.command import completion
|
||||||
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
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CmdCacheDir(CmdConfig):
|
class CmdCacheDir(CmdConfig):
|
||||||
def run(self):
|
def run(self):
|
||||||
with self.config.edit(level=self.args.level) as edit:
|
if self.args.value is None and not self.args.unset:
|
||||||
edit["cache"]["dir"] = self.args.value
|
if self.args.level:
|
||||||
|
conf = self.config.read(level=self.args.level)
|
||||||
|
else:
|
||||||
|
# Use merged config with default values
|
||||||
|
conf = self.config
|
||||||
|
self._check(conf, False, "cache", "dir")
|
||||||
|
logger.info(conf["cache"]["dir"])
|
||||||
|
return 0
|
||||||
|
with self.config.edit(level=self.args.level) as conf:
|
||||||
|
if self.args.unset:
|
||||||
|
self._check(conf, False, "cache", "dir")
|
||||||
|
del conf["cache"]["dir"]
|
||||||
|
else:
|
||||||
|
self._check(conf, False, "cache")
|
||||||
|
conf["cache"]["dir"] = self.args.value
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
@@ -55,8 +72,8 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"value",
|
"value",
|
||||||
help="Path to cache directory. Relative paths are resolved relative "
|
help="Path to cache directory. Relative paths are resolved relative "
|
||||||
"to the current directory and saved to config relative to the "
|
"to the current directory and saved to config relative to the "
|
||||||
"config file location.",
|
"config file location. If no path is provided, it returns the "
|
||||||
metavar="value",
|
"current cache directory.",
|
||||||
choices=completion.Required.DIR,
|
nargs="?",
|
||||||
)
|
).complete = completion.DIR
|
||||||
cache_dir_parser.set_defaults(func=CmdCacheDir)
|
cache_dir_parser.set_defaults(func=CmdCacheDir)
|
||||||
|
|||||||
@@ -0,0 +1,127 @@
|
|||||||
|
import argparse
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from dvc.command import completion
|
||||||
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class CmdCheckIgnore(CmdBase):
|
||||||
|
def __init__(self, args):
|
||||||
|
super().__init__(args)
|
||||||
|
self.ignore_filter = self.repo.fs.dvcignore
|
||||||
|
|
||||||
|
def _show_results(self, result):
|
||||||
|
if not result.match and not self.args.non_matching:
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.args.details:
|
||||||
|
patterns = result.patterns
|
||||||
|
if not self.args.all:
|
||||||
|
patterns = patterns[-1:]
|
||||||
|
|
||||||
|
for pattern in patterns:
|
||||||
|
logger.info("{}\t{}".format(pattern, result.file))
|
||||||
|
else:
|
||||||
|
logger.info(result.file)
|
||||||
|
|
||||||
|
def _check_one_file(self, target):
|
||||||
|
result = self.ignore_filter.check_ignore(target)
|
||||||
|
self._show_results(result)
|
||||||
|
if result.match:
|
||||||
|
return 0
|
||||||
|
return 1
|
||||||
|
|
||||||
|
def _interactive_mode(self):
|
||||||
|
ret = 1
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
target = input()
|
||||||
|
except (KeyboardInterrupt, EOFError):
|
||||||
|
break
|
||||||
|
if target == "":
|
||||||
|
break
|
||||||
|
if not self._check_one_file(target):
|
||||||
|
ret = 0
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def _normal_mode(self):
|
||||||
|
ret = 1
|
||||||
|
for target in self.args.targets:
|
||||||
|
if not self._check_one_file(target):
|
||||||
|
ret = 0
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def _check_args(self):
|
||||||
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
|
if not self.args.stdin and not self.args.targets:
|
||||||
|
raise DvcException("`targets` or `--stdin` needed")
|
||||||
|
|
||||||
|
if self.args.stdin and self.args.targets:
|
||||||
|
raise DvcException("cannot have both `targets` and `--stdin`")
|
||||||
|
|
||||||
|
if self.args.non_matching and not self.args.details:
|
||||||
|
raise DvcException(
|
||||||
|
"`--non-matching` is only valid with `--details`"
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.args.all and not self.args.details:
|
||||||
|
raise DvcException("`--all` is only valid with `--details`")
|
||||||
|
|
||||||
|
if self.args.quiet and self.args.details:
|
||||||
|
raise DvcException("cannot use both `--details` and `--quiet`")
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
self._check_args()
|
||||||
|
if self.args.stdin:
|
||||||
|
return self._interactive_mode()
|
||||||
|
return self._normal_mode()
|
||||||
|
|
||||||
|
|
||||||
|
def add_parser(subparsers, parent_parser):
|
||||||
|
ADD_HELP = (
|
||||||
|
"Check whether files or directories are excluded due to `.dvcignore`."
|
||||||
|
)
|
||||||
|
|
||||||
|
parser = subparsers.add_parser(
|
||||||
|
"check-ignore",
|
||||||
|
parents=[parent_parser],
|
||||||
|
description=append_doc_link(ADD_HELP, "check-ignore"),
|
||||||
|
help=ADD_HELP,
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-d",
|
||||||
|
"--details",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Show the exclude patterns along with each target path.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-a",
|
||||||
|
"--all",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Include the target paths which don’t match any pattern "
|
||||||
|
"in the `--details` list.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-n",
|
||||||
|
"--non-matching",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Include the target paths which don’t match any pattern "
|
||||||
|
"in the `--details` list.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--stdin",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Read paths from standard input instead of providing `targets`.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"targets", nargs="*", help="File or directory paths to check",
|
||||||
|
).complete = completion.FILE
|
||||||
|
parser.set_defaults(func=CmdCheckIgnore)
|
||||||
@@ -7,7 +7,6 @@ import colorama
|
|||||||
from dvc.command import completion
|
from dvc.command import completion
|
||||||
from dvc.command.base import CmdBase, append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
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__)
|
||||||
|
|
||||||
@@ -39,6 +38,8 @@ def log_changes(stats):
|
|||||||
|
|
||||||
class CmdCheckout(CmdBase):
|
class CmdCheckout(CmdBase):
|
||||||
def run(self):
|
def run(self):
|
||||||
|
from dvc.utils.humanize import get_summary
|
||||||
|
|
||||||
stats, exc = None, None
|
stats, exc = None, None
|
||||||
try:
|
try:
|
||||||
stats = self.repo.checkout(
|
stats = self.repo.checkout(
|
||||||
@@ -112,9 +113,9 @@ def add_parser(subparsers, parent_parser):
|
|||||||
checkout_parser.add_argument(
|
checkout_parser.add_argument(
|
||||||
"targets",
|
"targets",
|
||||||
nargs="*",
|
nargs="*",
|
||||||
help="DVC-files to checkout. Optional. "
|
help=(
|
||||||
"(Finds all DVC-files in the workspace by default.)",
|
"Limit command scope to these tracked files/directories, "
|
||||||
metavar="targets",
|
".dvc files, or stage names."
|
||||||
choices=completion.Optional.DVC_FILE,
|
),
|
||||||
)
|
).complete = completion.DVC_FILE
|
||||||
checkout_parser.set_defaults(func=CmdCheckout)
|
checkout_parser.set_defaults(func=CmdCheckout)
|
||||||
|
|||||||
@@ -3,13 +3,14 @@ import logging
|
|||||||
|
|
||||||
from dvc.command import completion
|
from dvc.command import completion
|
||||||
from dvc.command.base import CmdBase, append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
from dvc.exceptions import DvcException
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CmdCommit(CmdBase):
|
class CmdCommit(CmdBase):
|
||||||
def run(self):
|
def run(self):
|
||||||
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
if not self.args.targets:
|
if not self.args.targets:
|
||||||
self.args.targets = [None]
|
self.args.targets = [None]
|
||||||
|
|
||||||
@@ -32,7 +33,10 @@ class CmdCommit(CmdBase):
|
|||||||
|
|
||||||
|
|
||||||
def add_parser(subparsers, parent_parser):
|
def add_parser(subparsers, parent_parser):
|
||||||
COMMIT_HELP = "Save changed data to cache and update DVC-files."
|
COMMIT_HELP = (
|
||||||
|
"Record changes to files or directories tracked by DVC"
|
||||||
|
" by storing the current versions in the cache."
|
||||||
|
)
|
||||||
|
|
||||||
commit_parser = subparsers.add_parser(
|
commit_parser = subparsers.add_parser(
|
||||||
"commit",
|
"commit",
|
||||||
@@ -65,9 +69,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
commit_parser.add_argument(
|
commit_parser.add_argument(
|
||||||
"targets",
|
"targets",
|
||||||
nargs="*",
|
nargs="*",
|
||||||
help="DVC-files to commit. Optional. "
|
help="stages or .dvc files to commit. Optional. "
|
||||||
"(Finds all DVC-files in the workspace by default.)",
|
"(Finds all DVC files in the workspace by default.)",
|
||||||
metavar="targets",
|
).complete = completion.DVC_FILE
|
||||||
choices=completion.Optional.DVC_FILE,
|
|
||||||
)
|
|
||||||
commit_parser.set_defaults(func=CmdCommit)
|
commit_parser.set_defaults(func=CmdCommit)
|
||||||
|
|||||||
+53
-16
@@ -6,10 +6,9 @@ import shtab
|
|||||||
from dvc.command.base import CmdBaseNoRepo, append_doc_link
|
from dvc.command.base import CmdBaseNoRepo, append_doc_link
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
CHOICE_FUNCTIONS = {
|
FILE = shtab.FILE
|
||||||
"bash": {"DVCFile": "_dvc_compgen_DVCFiles"},
|
DIR = shtab.DIRECTORY
|
||||||
"zsh": {"DVCFile": "_files -g '(*?.dvc|Dvcfile|dvc.yaml)'"},
|
|
||||||
}
|
|
||||||
PREAMBLE = {
|
PREAMBLE = {
|
||||||
"bash": """
|
"bash": """
|
||||||
# $1=COMP_WORDS[1]
|
# $1=COMP_WORDS[1]
|
||||||
@@ -19,17 +18,60 @@ _dvc_compgen_DVCFiles() {
|
|||||||
compgen -f -X '!*Dvcfile' -- $1
|
compgen -f -X '!*Dvcfile' -- $1
|
||||||
compgen -f -X '!*dvc.yaml' -- $1
|
compgen -f -X '!*dvc.yaml' -- $1
|
||||||
}
|
}
|
||||||
""",
|
|
||||||
"zsh": "",
|
_dvc_compgen_stages() {
|
||||||
|
local _dvc_stages=($(dvc stage list -q --names-only))
|
||||||
|
compgen -W "${_dvc_stages[*]}" -- $1
|
||||||
|
}
|
||||||
|
_dvc_compgen_stages_and_files() {
|
||||||
|
_dvc_compgen_DVCFiles $1
|
||||||
|
_dvc_compgen_stages $1
|
||||||
|
}
|
||||||
|
""",
|
||||||
|
"zsh": """
|
||||||
|
_dvc_compadd_DVCFiles() {
|
||||||
|
_files -g '(*?.dvc|Dvcfile|dvc.yaml)'
|
||||||
|
}
|
||||||
|
_dvc_compadd_stages() {
|
||||||
|
# this will also show up the description of the stages
|
||||||
|
_describe 'stages' "($(_dvc_stages_output))"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_dvc_stages_output() {
|
||||||
|
dvc stage list -q | awk '{
|
||||||
|
# escape possible `:` on the stage name
|
||||||
|
sub(/:/, "\\\\\\\\:", $1);
|
||||||
|
# read all of the columns except the first
|
||||||
|
# reading `out` from $2, so as not to have a leading whitespace
|
||||||
|
out=$2; for(i=3;i<=NF;i++){out=out" "$i};
|
||||||
|
# print key, ":" and then single-quote the description
|
||||||
|
# colon is a delimiter used by `_describe` to separate field/description
|
||||||
|
print $1":""\\047"out"\\047"
|
||||||
|
# single quote -> \\047
|
||||||
|
}'
|
||||||
|
}
|
||||||
|
|
||||||
class Optional(shtab.Optional):
|
_dvc_compadd_stages_and_files() {
|
||||||
DVC_FILE = [shtab.Choice("DVCFile", required=False)]
|
_dvc_compadd_DVCFiles
|
||||||
|
_dvc_compadd_stages
|
||||||
|
}
|
||||||
|
""",
|
||||||
|
}
|
||||||
|
|
||||||
|
DVC_FILE = {
|
||||||
|
"bash": "_dvc_compgen_DVCFiles",
|
||||||
|
"zsh": "_dvc_compadd_DVCFiles",
|
||||||
|
}
|
||||||
|
|
||||||
class Required(shtab.Required):
|
STAGE = {
|
||||||
DVC_FILE = [shtab.Choice("DVCFile", required=True)]
|
"bash": "_dvc_compgen_stages",
|
||||||
|
"zsh": "_dvc_compadd_stages",
|
||||||
|
}
|
||||||
|
|
||||||
|
DVCFILES_AND_STAGE = {
|
||||||
|
"bash": "_dvc_compgen_stages_and_files",
|
||||||
|
"zsh": "_dvc_compadd_stages_and_files",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class CmdCompletion(CmdBaseNoRepo):
|
class CmdCompletion(CmdBaseNoRepo):
|
||||||
@@ -38,12 +80,7 @@ class CmdCompletion(CmdBaseNoRepo):
|
|||||||
|
|
||||||
parser = get_main_parser()
|
parser = get_main_parser()
|
||||||
shell = self.args.shell
|
shell = self.args.shell
|
||||||
script = shtab.complete(
|
script = shtab.complete(parser, shell=shell, preamble=PREAMBLE)
|
||||||
parser,
|
|
||||||
shell=shell,
|
|
||||||
preamble=PREAMBLE[shell],
|
|
||||||
choice_functions=CHOICE_FUNCTIONS[shell],
|
|
||||||
)
|
|
||||||
print(script)
|
print(script)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|||||||
+148
-16
@@ -1,33 +1,115 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
from dvc.command.base import CmdBaseNoRepo, append_doc_link
|
from dvc.command.base import CmdBaseNoRepo, append_doc_link
|
||||||
from dvc.config import Config, ConfigError
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
NAME_REGEX = r"^(?P<remote>remote\.)?(?P<section>[^\.]*)\.(?P<option>[^\.]*)$"
|
||||||
|
|
||||||
|
|
||||||
|
def _name_type(value):
|
||||||
|
import re
|
||||||
|
|
||||||
|
match = re.match(NAME_REGEX, value)
|
||||||
|
if not match:
|
||||||
|
raise argparse.ArgumentTypeError(
|
||||||
|
"name argument should look like "
|
||||||
|
"remote.name.option or "
|
||||||
|
"section.option"
|
||||||
|
)
|
||||||
|
return (
|
||||||
|
bool(match.group("remote")),
|
||||||
|
match.group("section").lower(),
|
||||||
|
match.group("option").lower(),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class CmdConfig(CmdBaseNoRepo):
|
class CmdConfig(CmdBaseNoRepo):
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
|
from dvc.config import Config
|
||||||
|
|
||||||
super().__init__(args)
|
super().__init__(args)
|
||||||
|
|
||||||
self.config = Config(validate=False)
|
self.config = Config(validate=False)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
section, opt = self.args.name.lower().strip().split(".", 1)
|
if self.args.show_origin:
|
||||||
|
if any((self.args.value, self.args.unset)):
|
||||||
|
logger.error(
|
||||||
|
"--show-origin can't be used together with any of these "
|
||||||
|
"options: -u/--unset, value"
|
||||||
|
)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
if self.args.list:
|
||||||
|
return self._list()
|
||||||
|
|
||||||
|
if self.args.name is None:
|
||||||
|
logger.error("name argument is required")
|
||||||
|
return 1
|
||||||
|
|
||||||
|
remote, section, opt = self.args.name
|
||||||
|
|
||||||
if self.args.value is None and not self.args.unset:
|
if self.args.value is None and not self.args.unset:
|
||||||
conf = self.config.load_one(self.args.level)
|
return self._get(remote, section, opt)
|
||||||
self._check(conf, section, opt)
|
|
||||||
logger.info(conf[section][opt])
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
return self._set(remote, section, opt)
|
||||||
|
|
||||||
|
def _list(self):
|
||||||
|
if any((self.args.name, self.args.value, self.args.unset)):
|
||||||
|
logger.error(
|
||||||
|
"-l/--list can't be used together with any of these "
|
||||||
|
"options: -u/--unset, name, value"
|
||||||
|
)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
levels = [self.args.level] if self.args.level else self.config.LEVELS
|
||||||
|
for level in levels:
|
||||||
|
conf = self.config.read(level)
|
||||||
|
prefix = self._config_file_prefix(
|
||||||
|
self.args.show_origin, self.config, level
|
||||||
|
)
|
||||||
|
logger.info("\n".join(self._format_config(conf, prefix)))
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def _get(self, remote, section, opt):
|
||||||
|
from dvc.config import ConfigError
|
||||||
|
|
||||||
|
levels = (
|
||||||
|
[self.args.level] if self.args.level else self.config.LEVELS[::-1]
|
||||||
|
)
|
||||||
|
|
||||||
|
for level in levels:
|
||||||
|
conf = self.config.read(level)
|
||||||
|
if remote:
|
||||||
|
conf = conf["remote"]
|
||||||
|
|
||||||
|
try:
|
||||||
|
self._check(conf, remote, section, opt)
|
||||||
|
except ConfigError:
|
||||||
|
if self.args.level:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
prefix = self._config_file_prefix(
|
||||||
|
self.args.show_origin, self.config, level
|
||||||
|
)
|
||||||
|
logger.info("{}{}".format(prefix, conf[section][opt]))
|
||||||
|
break
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def _set(self, remote, section, opt):
|
||||||
with self.config.edit(self.args.level) as conf:
|
with self.config.edit(self.args.level) as conf:
|
||||||
|
if remote:
|
||||||
|
conf = conf["remote"]
|
||||||
if self.args.unset:
|
if self.args.unset:
|
||||||
self._check(conf, section, opt)
|
self._check(conf, remote, section, opt)
|
||||||
del conf[section][opt]
|
del conf[section][opt]
|
||||||
else:
|
else:
|
||||||
self._check(conf, section)
|
self._check(conf, remote, section)
|
||||||
conf[section][opt] = self.args.value
|
conf[section][opt] = self.args.value
|
||||||
|
|
||||||
if self.args.name == "cache.type":
|
if self.args.name == "cache.type":
|
||||||
@@ -39,14 +121,39 @@ class CmdConfig(CmdBaseNoRepo):
|
|||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def _check(self, conf, section, opt=None):
|
def _check(self, conf, remote, section, opt=None):
|
||||||
|
from dvc.config import ConfigError
|
||||||
|
|
||||||
|
name = "remote" if remote else "section"
|
||||||
if section not in conf:
|
if section not in conf:
|
||||||
msg = "section {} doesn't exist"
|
raise ConfigError(f"{name} '{section}' doesn't exist")
|
||||||
raise ConfigError(msg.format(self.args.name))
|
|
||||||
|
|
||||||
if opt and opt not in conf[section]:
|
if opt and opt not in conf[section]:
|
||||||
msg = "option {} doesn't exist"
|
raise ConfigError(
|
||||||
raise ConfigError(msg.format(self.args.name))
|
f"option '{opt}' doesn't exist in {name} '{section}'"
|
||||||
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _format_config(config, prefix=""):
|
||||||
|
from dvc.utils.flatten import flatten
|
||||||
|
|
||||||
|
for key, value in flatten(config).items():
|
||||||
|
yield f"{prefix}{key}={value}"
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _config_file_prefix(show_origin, config, level):
|
||||||
|
from dvc.repo import Repo
|
||||||
|
|
||||||
|
if not show_origin:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
level = level or "repo"
|
||||||
|
fname = config.files[level]
|
||||||
|
|
||||||
|
if level in ["local", "repo"]:
|
||||||
|
fname = os.path.relpath(fname, start=Repo.find_root())
|
||||||
|
|
||||||
|
return fname + "\t"
|
||||||
|
|
||||||
|
|
||||||
parent_config_parser = argparse.ArgumentParser(add_help=False)
|
parent_config_parser = argparse.ArgumentParser(add_help=False)
|
||||||
@@ -65,14 +172,21 @@ level_group.add_argument(
|
|||||||
const="system",
|
const="system",
|
||||||
help="Use system config.",
|
help="Use system config.",
|
||||||
)
|
)
|
||||||
|
level_group.add_argument(
|
||||||
|
"--project",
|
||||||
|
dest="level",
|
||||||
|
action="store_const",
|
||||||
|
const="repo",
|
||||||
|
help="Use project config (.dvc/config).",
|
||||||
|
)
|
||||||
level_group.add_argument(
|
level_group.add_argument(
|
||||||
"--local",
|
"--local",
|
||||||
dest="level",
|
dest="level",
|
||||||
action="store_const",
|
action="store_const",
|
||||||
const="local",
|
const="local",
|
||||||
help="Use local config.",
|
help="Use local config (.dvc/config.local).",
|
||||||
)
|
)
|
||||||
parent_config_parser.set_defaults(level="repo")
|
parent_config_parser.set_defaults(level=None)
|
||||||
|
|
||||||
|
|
||||||
def add_parser(subparsers, parent_parser):
|
def add_parser(subparsers, parent_parser):
|
||||||
@@ -92,6 +206,24 @@ def add_parser(subparsers, parent_parser):
|
|||||||
action="store_true",
|
action="store_true",
|
||||||
help="Unset option.",
|
help="Unset option.",
|
||||||
)
|
)
|
||||||
config_parser.add_argument("name", help="Option name.")
|
config_parser.add_argument(
|
||||||
|
"name",
|
||||||
|
nargs="?",
|
||||||
|
type=_name_type,
|
||||||
|
help="Option name (section.option or remote.name.option).",
|
||||||
|
)
|
||||||
config_parser.add_argument("value", nargs="?", help="Option value.")
|
config_parser.add_argument("value", nargs="?", help="Option value.")
|
||||||
|
config_parser.add_argument(
|
||||||
|
"-l",
|
||||||
|
"--list",
|
||||||
|
default=False,
|
||||||
|
action="store_true",
|
||||||
|
help="List all defined config values.",
|
||||||
|
)
|
||||||
|
config_parser.add_argument(
|
||||||
|
"--show-origin",
|
||||||
|
default=False,
|
||||||
|
action="store_true",
|
||||||
|
help="Show the source file containing each config value.",
|
||||||
|
)
|
||||||
config_parser.set_defaults(func=CmdConfig)
|
config_parser.set_defaults(func=CmdConfig)
|
||||||
|
|||||||
@@ -9,8 +9,9 @@ class CmdDaemonBase(CmdBaseNoRepo):
|
|||||||
class CmdDaemonUpdater(CmdDaemonBase):
|
class CmdDaemonUpdater(CmdDaemonBase):
|
||||||
def run(self):
|
def run(self):
|
||||||
import os
|
import os
|
||||||
from dvc.repo import Repo
|
|
||||||
from dvc.config import Config
|
from dvc.config import Config
|
||||||
|
from dvc.repo import Repo
|
||||||
from dvc.updater import Updater
|
from dvc.updater import Updater
|
||||||
|
|
||||||
root_dir = Repo.find_root()
|
root_dir = Repo.find_root()
|
||||||
@@ -66,9 +67,6 @@ def add_parser(subparsers, parent_parser):
|
|||||||
help=DAEMON_ANALYTICS_HELP,
|
help=DAEMON_ANALYTICS_HELP,
|
||||||
)
|
)
|
||||||
daemon_analytics_parser.add_argument(
|
daemon_analytics_parser.add_argument(
|
||||||
"target",
|
"target", help="Analytics file.",
|
||||||
help="Analytics file.",
|
).complete = completion.FILE
|
||||||
metavar="target",
|
|
||||||
choices=completion.Required.FILE,
|
|
||||||
)
|
|
||||||
daemon_analytics_parser.set_defaults(func=CmdDaemonAnalytics)
|
daemon_analytics_parser.set_defaults(func=CmdDaemonAnalytics)
|
||||||
|
|||||||
+76
-41
@@ -2,14 +2,13 @@ import argparse
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dvc.command.base import CmdBase, append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
from dvc.exceptions import DvcException
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _show_ascii(G):
|
def _show_ascii(G):
|
||||||
from dvc.repo.graph import get_pipelines
|
|
||||||
from dvc.dagascii import draw
|
from dvc.dagascii import draw
|
||||||
|
from dvc.repo.graph import get_pipelines
|
||||||
|
|
||||||
pipelines = get_pipelines(G)
|
pipelines = get_pipelines(G)
|
||||||
|
|
||||||
@@ -22,6 +21,7 @@ def _show_ascii(G):
|
|||||||
|
|
||||||
def _show_dot(G):
|
def _show_dot(G):
|
||||||
import io
|
import io
|
||||||
|
|
||||||
from networkx.drawing.nx_pydot import write_dot
|
from networkx.drawing.nx_pydot import write_dot
|
||||||
|
|
||||||
dot_file = io.StringIO()
|
dot_file = io.StringIO()
|
||||||
@@ -29,57 +29,85 @@ def _show_dot(G):
|
|||||||
return dot_file.getvalue()
|
return dot_file.getvalue()
|
||||||
|
|
||||||
|
|
||||||
def _build(G, target=None, full=False):
|
def _collect_targets(repo, target, outs):
|
||||||
|
if not target:
|
||||||
|
return []
|
||||||
|
|
||||||
|
pairs = repo.stage.collect_granular(target)
|
||||||
|
if not outs:
|
||||||
|
return [stage.addressing for stage, _ in pairs]
|
||||||
|
|
||||||
|
targets = []
|
||||||
|
for stage, info in pairs:
|
||||||
|
if not info:
|
||||||
|
targets.extend([str(out) for out in stage.outs])
|
||||||
|
continue
|
||||||
|
|
||||||
|
for out in repo.outs_trie.itervalues(prefix=info.parts): # noqa: B301
|
||||||
|
targets.extend(str(out))
|
||||||
|
|
||||||
|
return targets
|
||||||
|
|
||||||
|
|
||||||
|
def _transform(repo, outs):
|
||||||
import networkx as nx
|
import networkx as nx
|
||||||
from dvc.repo.graph import get_pipeline, get_pipelines
|
|
||||||
|
|
||||||
if target:
|
from dvc.stage import Stage
|
||||||
H = get_pipeline(get_pipelines(G), target)
|
|
||||||
if not full:
|
def _relabel(node) -> str:
|
||||||
descendants = nx.descendants(G, target)
|
return node.addressing if isinstance(node, Stage) else str(node)
|
||||||
|
|
||||||
|
G = repo.outs_graph if outs else repo.graph
|
||||||
|
return nx.relabel_nodes(G, _relabel, copy=True)
|
||||||
|
|
||||||
|
|
||||||
|
def _filter(G, targets, full):
|
||||||
|
import networkx as nx
|
||||||
|
|
||||||
|
if not targets:
|
||||||
|
return G
|
||||||
|
|
||||||
|
H = G.copy()
|
||||||
|
if not full:
|
||||||
|
descendants = set()
|
||||||
|
for target in targets:
|
||||||
|
descendants.update(nx.descendants(G, target))
|
||||||
descendants.add(target)
|
descendants.add(target)
|
||||||
H.remove_nodes_from(set(G.nodes()) - descendants)
|
H.remove_nodes_from(set(G.nodes()) - descendants)
|
||||||
else:
|
|
||||||
H = G
|
|
||||||
|
|
||||||
def _relabel(stage):
|
undirected = H.to_undirected()
|
||||||
return stage.addressing
|
connected = set()
|
||||||
|
for target in targets:
|
||||||
|
connected.update(nx.node_connected_component(undirected, target))
|
||||||
|
|
||||||
return nx.relabel_nodes(H, _relabel, copy=False)
|
H.remove_nodes_from(set(H.nodes()) - connected)
|
||||||
|
|
||||||
|
return H
|
||||||
|
|
||||||
|
|
||||||
|
def _build(repo, target=None, full=False, outs=False):
|
||||||
|
targets = _collect_targets(repo, target, outs)
|
||||||
|
G = _transform(repo, outs)
|
||||||
|
return _filter(G, targets, full)
|
||||||
|
|
||||||
|
|
||||||
class CmdDAG(CmdBase):
|
class CmdDAG(CmdBase):
|
||||||
def run(self):
|
def run(self):
|
||||||
try:
|
G = _build(
|
||||||
target = None
|
self.repo,
|
||||||
if self.args.target:
|
target=self.args.target,
|
||||||
stages = self.repo.collect(self.args.target)
|
full=self.args.full,
|
||||||
if len(stages) > 1:
|
outs=self.args.outs,
|
||||||
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
|
||||||
|
|
||||||
if self.args.dot:
|
pager(_show_ascii(G))
|
||||||
logger.info(_show_dot(G))
|
|
||||||
else:
|
|
||||||
from dvc.utils.pager import pager
|
|
||||||
|
|
||||||
pager(_show_ascii(G))
|
return 0
|
||||||
|
|
||||||
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):
|
def add_parser(subparsers, parent_parser):
|
||||||
@@ -106,6 +134,13 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"showing DAG consisting only of ancestors."
|
"showing DAG consisting only of ancestors."
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
dag_parser.add_argument(
|
||||||
|
"-o",
|
||||||
|
"--outs",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Print output files instead of stages.",
|
||||||
|
)
|
||||||
dag_parser.add_argument(
|
dag_parser.add_argument(
|
||||||
"target",
|
"target",
|
||||||
nargs="?",
|
nargs="?",
|
||||||
|
|||||||
+38
-14
@@ -3,25 +3,28 @@ import logging
|
|||||||
|
|
||||||
from dvc.command import completion
|
from dvc.command import completion
|
||||||
from dvc.command.base import CmdBase, append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
from dvc.command.checkout import log_changes
|
|
||||||
from dvc.exceptions import CheckoutError, DvcException
|
|
||||||
from dvc.utils.humanize import get_summary
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CmdDataBase(CmdBase):
|
class CmdDataBase(CmdBase):
|
||||||
def log_summary(self, stats):
|
def log_summary(self, stats):
|
||||||
|
from dvc.utils.humanize import get_summary
|
||||||
|
|
||||||
default_msg = "Everything is up to date."
|
default_msg = "Everything is up to date."
|
||||||
logger.info(get_summary(stats.items()) or default_msg)
|
logger.info(get_summary(stats.items()) or default_msg)
|
||||||
|
|
||||||
|
|
||||||
class CmdDataPull(CmdDataBase):
|
class CmdDataPull(CmdDataBase):
|
||||||
def log_summary(self, stats):
|
def log_summary(self, stats):
|
||||||
|
from dvc.command.checkout import log_changes
|
||||||
|
|
||||||
log_changes(stats)
|
log_changes(stats)
|
||||||
super().log_summary(stats)
|
super().log_summary(stats)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
from dvc.exceptions import CheckoutError, DvcException
|
||||||
|
|
||||||
try:
|
try:
|
||||||
stats = self.repo.pull(
|
stats = self.repo.pull(
|
||||||
targets=self.args.targets,
|
targets=self.args.targets,
|
||||||
@@ -34,6 +37,7 @@ class CmdDataPull(CmdDataBase):
|
|||||||
force=self.args.force,
|
force=self.args.force,
|
||||||
recursive=self.args.recursive,
|
recursive=self.args.recursive,
|
||||||
run_cache=self.args.run_cache,
|
run_cache=self.args.run_cache,
|
||||||
|
glob=self.args.glob,
|
||||||
)
|
)
|
||||||
self.log_summary(stats)
|
self.log_summary(stats)
|
||||||
except (CheckoutError, DvcException) as exc:
|
except (CheckoutError, DvcException) as exc:
|
||||||
@@ -46,6 +50,8 @@ class CmdDataPull(CmdDataBase):
|
|||||||
|
|
||||||
class CmdDataPush(CmdDataBase):
|
class CmdDataPush(CmdDataBase):
|
||||||
def run(self):
|
def run(self):
|
||||||
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
try:
|
try:
|
||||||
processed_files_count = self.repo.push(
|
processed_files_count = self.repo.push(
|
||||||
targets=self.args.targets,
|
targets=self.args.targets,
|
||||||
@@ -57,6 +63,7 @@ class CmdDataPush(CmdDataBase):
|
|||||||
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,
|
run_cache=self.args.run_cache,
|
||||||
|
glob=self.args.glob,
|
||||||
)
|
)
|
||||||
self.log_summary({"pushed": processed_files_count})
|
self.log_summary({"pushed": processed_files_count})
|
||||||
except DvcException:
|
except DvcException:
|
||||||
@@ -67,6 +74,8 @@ class CmdDataPush(CmdDataBase):
|
|||||||
|
|
||||||
class CmdDataFetch(CmdDataBase):
|
class CmdDataFetch(CmdDataBase):
|
||||||
def run(self):
|
def run(self):
|
||||||
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
try:
|
try:
|
||||||
processed_files_count = self.repo.fetch(
|
processed_files_count = self.repo.fetch(
|
||||||
targets=self.args.targets,
|
targets=self.args.targets,
|
||||||
@@ -97,17 +106,21 @@ def shared_parent_parser():
|
|||||||
"-j",
|
"-j",
|
||||||
"--jobs",
|
"--jobs",
|
||||||
type=int,
|
type=int,
|
||||||
help="Number of jobs to run simultaneously.",
|
help=(
|
||||||
|
"Number of jobs to run simultaneously. "
|
||||||
|
"The default value is 4 * cpu_count(). "
|
||||||
|
"For SSH remotes, the default is 4. "
|
||||||
|
),
|
||||||
metavar="<number>",
|
metavar="<number>",
|
||||||
)
|
)
|
||||||
parent_parser.add_argument(
|
parent_parser.add_argument(
|
||||||
"targets",
|
"targets",
|
||||||
nargs="*",
|
nargs="*",
|
||||||
help="Limit command scope to these DVC-files. "
|
help=(
|
||||||
"Using -R, directories to search DVC-files in can also be given.",
|
"Limit command scope to these tracked files/directories, "
|
||||||
metavar="targets",
|
".dvc files, or stage names."
|
||||||
choices=completion.Optional.DVC_FILE,
|
),
|
||||||
)
|
).complete = completion.DVC_FILE
|
||||||
|
|
||||||
return parent_parser
|
return parent_parser
|
||||||
|
|
||||||
@@ -173,7 +186,13 @@ def add_parser(subparsers, _parent_parser):
|
|||||||
"--run-cache",
|
"--run-cache",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
help=argparse.SUPPRESS,
|
help="Fetch run history for all stages.",
|
||||||
|
)
|
||||||
|
pull_parser.add_argument(
|
||||||
|
"--glob",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Pull cache for targets matching shell-style wildcards.",
|
||||||
)
|
)
|
||||||
pull_parser.set_defaults(func=CmdDataPull)
|
pull_parser.set_defaults(func=CmdDataPull)
|
||||||
|
|
||||||
@@ -228,14 +247,19 @@ def add_parser(subparsers, _parent_parser):
|
|||||||
"--run-cache",
|
"--run-cache",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
help=argparse.SUPPRESS,
|
help="Push run history for all stages.",
|
||||||
|
)
|
||||||
|
push_parser.add_argument(
|
||||||
|
"--glob",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Allows targets containing shell-style wildcards.",
|
||||||
)
|
)
|
||||||
push_parser.set_defaults(func=CmdDataPush)
|
push_parser.set_defaults(func=CmdDataPush)
|
||||||
|
|
||||||
# Fetch
|
# Fetch
|
||||||
FETCH_HELP = (
|
FETCH_HELP = (
|
||||||
"Get tracked files or directories from remote storage"
|
"Download files or directories from remote storage to the cache."
|
||||||
" into the cache."
|
|
||||||
)
|
)
|
||||||
|
|
||||||
fetch_parser = subparsers.add_parser(
|
fetch_parser = subparsers.add_parser(
|
||||||
@@ -289,7 +313,7 @@ def add_parser(subparsers, _parent_parser):
|
|||||||
"--run-cache",
|
"--run-cache",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
help=argparse.SUPPRESS,
|
help="Fetch run history for all stages.",
|
||||||
)
|
)
|
||||||
fetch_parser.set_defaults(func=CmdDataFetch)
|
fetch_parser.set_defaults(func=CmdDataFetch)
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,14 @@ import logging
|
|||||||
|
|
||||||
import dvc.prompt as prompt
|
import dvc.prompt as prompt
|
||||||
from dvc.command.base import CmdBase, append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
from dvc.exceptions import DvcException
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CmdDestroy(CmdBase):
|
class CmdDestroy(CmdBase):
|
||||||
def run(self):
|
def run(self):
|
||||||
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
try:
|
try:
|
||||||
statement = (
|
statement = (
|
||||||
"This will destroy all information about your pipelines,"
|
"This will destroy all information about your pipelines,"
|
||||||
@@ -25,14 +26,14 @@ class CmdDestroy(CmdBase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.repo.destroy()
|
self.repo.destroy()
|
||||||
except Exception:
|
except DvcException:
|
||||||
logger.exception("failed to destroy DVC")
|
logger.exception("failed to destroy DVC")
|
||||||
return 1
|
return 1
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def add_parser(subparsers, parent_parser):
|
def add_parser(subparsers, parent_parser):
|
||||||
DESTROY_HELP = "Remove DVC-files, local DVC config and data cache."
|
DESTROY_HELP = "Remove DVC files, local DVC config and data cache."
|
||||||
|
|
||||||
destroy_parser = subparsers.add_parser(
|
destroy_parser = subparsers.add_parser(
|
||||||
"destroy",
|
"destroy",
|
||||||
|
|||||||
+79
-25
@@ -5,36 +5,51 @@ import os
|
|||||||
|
|
||||||
import colorama
|
import colorama
|
||||||
|
|
||||||
|
from dvc.command import completion
|
||||||
from dvc.command.base import CmdBase, append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
from dvc.exceptions import DvcException
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _show_md(diff):
|
def _digest(checksum):
|
||||||
|
if isinstance(checksum, str):
|
||||||
|
return checksum[0:8]
|
||||||
|
return "{}..{}".format(checksum["old"][0:8], checksum["new"][0:8])
|
||||||
|
|
||||||
|
|
||||||
|
def _show_md(diff, show_hash=False, hide_missing=False):
|
||||||
from dvc.utils.diff import table
|
from dvc.utils.diff import table
|
||||||
|
|
||||||
|
header = ["Status", "Hash", "Path"] if show_hash else ["Status", "Path"]
|
||||||
rows = []
|
rows = []
|
||||||
for status in ["added", "deleted", "modified"]:
|
statuses = ["added", "deleted", "renamed", "modified"]
|
||||||
|
if not hide_missing:
|
||||||
|
statuses.append("not in cache")
|
||||||
|
for status in statuses:
|
||||||
entries = diff.get(status, [])
|
entries = diff.get(status, [])
|
||||||
if not entries:
|
if not entries:
|
||||||
continue
|
continue
|
||||||
paths = sorted(entry["path"] for entry in entries)
|
for entry in entries:
|
||||||
for path in paths:
|
path = entry["path"]
|
||||||
rows.append([status, path])
|
if isinstance(path, dict):
|
||||||
|
path = f"{path['old']} -> {path['new']}"
|
||||||
|
if show_hash:
|
||||||
|
check_sum = _digest(entry.get("hash", ""))
|
||||||
|
rows.append([status, check_sum, path])
|
||||||
|
else:
|
||||||
|
rows.append([status, path])
|
||||||
|
|
||||||
return table(["Status", "Path"], rows, True)
|
return table(header, rows, True)
|
||||||
|
|
||||||
|
|
||||||
class CmdDiff(CmdBase):
|
class CmdDiff(CmdBase):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _format(diff):
|
def _format(diff, hide_missing=False):
|
||||||
"""
|
"""
|
||||||
Given a diff structure, generate a string of paths separated
|
Given a diff structure, generate a string of paths separated
|
||||||
by new lines and grouped together by their state.
|
by new lines and grouped together by their state.
|
||||||
|
|
||||||
A group's header is colored and its entries are sorted to enhance
|
A group's header is colored to enhance readability, for example:
|
||||||
readability, for example:
|
|
||||||
|
|
||||||
Added:
|
Added:
|
||||||
another_file.txt
|
another_file.txt
|
||||||
@@ -55,21 +70,21 @@ class CmdDiff(CmdBase):
|
|||||||
At the bottom, include a summary with the number of files per state.
|
At the bottom, include a summary with the number of files per state.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _digest(checksum):
|
|
||||||
if type(checksum) is str:
|
|
||||||
return checksum[0:8]
|
|
||||||
return "{}..{}".format(checksum["old"][0:8], checksum["new"][0:8])
|
|
||||||
|
|
||||||
colors = {
|
colors = {
|
||||||
"added": colorama.Fore.GREEN,
|
"added": colorama.Fore.GREEN,
|
||||||
"modified": colorama.Fore.YELLOW,
|
"modified": colorama.Fore.YELLOW,
|
||||||
"deleted": colorama.Fore.RED,
|
"deleted": colorama.Fore.RED,
|
||||||
|
"renamed": colorama.Fore.GREEN,
|
||||||
|
"not in cache": colorama.Fore.YELLOW,
|
||||||
}
|
}
|
||||||
|
|
||||||
summary = {}
|
summary = {}
|
||||||
groups = []
|
groups = []
|
||||||
|
|
||||||
for state in ["added", "deleted", "modified"]:
|
states = ["added", "deleted", "renamed", "modified"]
|
||||||
|
if not hide_missing:
|
||||||
|
states.append("not in cache")
|
||||||
|
for state in states:
|
||||||
summary[state] = 0
|
summary[state] = 0
|
||||||
entries = diff[state]
|
entries = diff[state]
|
||||||
|
|
||||||
@@ -80,6 +95,8 @@ class CmdDiff(CmdBase):
|
|||||||
|
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
path = entry["path"]
|
path = entry["path"]
|
||||||
|
if isinstance(path, dict):
|
||||||
|
path = f"{path['old']} -> {path['new']}"
|
||||||
checksum = entry.get("hash")
|
checksum = entry.get("hash")
|
||||||
summary[state] += 1 if not path.endswith(os.sep) else 0
|
summary[state] += 1 if not path.endswith(os.sep) else 0
|
||||||
content.append(
|
content.append(
|
||||||
@@ -87,7 +104,7 @@ class CmdDiff(CmdBase):
|
|||||||
space=" ",
|
space=" ",
|
||||||
checksum=_digest(checksum) if checksum else "",
|
checksum=_digest(checksum) if checksum else "",
|
||||||
separator=" " if checksum else "",
|
separator=" " if checksum else "",
|
||||||
path=entry["path"],
|
path=path,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -100,28 +117,51 @@ class CmdDiff(CmdBase):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
groups.append(
|
if not sum(summary.values()):
|
||||||
|
return None
|
||||||
|
|
||||||
|
fmt = (
|
||||||
"files summary: {added} added, {deleted} deleted,"
|
"files summary: {added} added, {deleted} deleted,"
|
||||||
" {modified} modified".format_map(summary)
|
" {renamed} renamed, {modified} modified"
|
||||||
)
|
)
|
||||||
|
if not hide_missing:
|
||||||
|
fmt += ", {not in cache} not in cache"
|
||||||
|
groups.append(fmt.format_map(summary))
|
||||||
|
|
||||||
return "\n\n".join(groups)
|
return "\n\n".join(groups)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
try:
|
from dvc.exceptions import DvcException
|
||||||
diff = self.repo.diff(self.args.a_rev, self.args.b_rev)
|
|
||||||
|
|
||||||
if not self.args.show_hash:
|
try:
|
||||||
for _, entries in diff.items():
|
diff = self.repo.diff(
|
||||||
|
self.args.a_rev, self.args.b_rev, self.args.targets
|
||||||
|
)
|
||||||
|
show_hash = self.args.show_hash
|
||||||
|
hide_missing = self.args.b_rev or self.args.hide_missing
|
||||||
|
if hide_missing:
|
||||||
|
del diff["not in cache"]
|
||||||
|
|
||||||
|
for key, entries in diff.items():
|
||||||
|
entries = sorted(
|
||||||
|
entries,
|
||||||
|
key=lambda entry: entry["path"]["old"]
|
||||||
|
if isinstance(entry["path"], dict)
|
||||||
|
else entry["path"],
|
||||||
|
)
|
||||||
|
if not show_hash:
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
del entry["hash"]
|
del entry["hash"]
|
||||||
|
diff[key] = entries
|
||||||
|
|
||||||
if self.args.show_json:
|
if self.args.show_json:
|
||||||
logger.info(json.dumps(diff))
|
logger.info(json.dumps(diff))
|
||||||
elif self.args.show_md:
|
elif self.args.show_md:
|
||||||
logger.info(_show_md(diff))
|
logger.info(_show_md(diff, show_hash, hide_missing))
|
||||||
elif diff:
|
elif diff:
|
||||||
logger.info(self._format(diff))
|
output = self._format(diff, hide_missing)
|
||||||
|
if output:
|
||||||
|
logger.info(output)
|
||||||
|
|
||||||
except DvcException:
|
except DvcException:
|
||||||
logger.exception("failed to get diff")
|
logger.exception("failed to get diff")
|
||||||
@@ -141,6 +181,15 @@ def add_parser(subparsers, parent_parser):
|
|||||||
help=DIFF_DESCRIPTION,
|
help=DIFF_DESCRIPTION,
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
)
|
)
|
||||||
|
diff_parser.add_argument(
|
||||||
|
"--targets",
|
||||||
|
nargs="*",
|
||||||
|
help=(
|
||||||
|
"Specific DVC-tracked files to compare. "
|
||||||
|
"Accepts one or more file paths."
|
||||||
|
),
|
||||||
|
metavar="<paths>",
|
||||||
|
).complete = completion.FILE
|
||||||
diff_parser.add_argument(
|
diff_parser.add_argument(
|
||||||
"a_rev",
|
"a_rev",
|
||||||
help="Old Git commit to compare (defaults to HEAD)",
|
help="Old Git commit to compare (defaults to HEAD)",
|
||||||
@@ -170,4 +219,9 @@ def add_parser(subparsers, parent_parser):
|
|||||||
action="store_true",
|
action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
)
|
)
|
||||||
|
diff_parser.add_argument(
|
||||||
|
"--hide-missing",
|
||||||
|
help="Hide missing cache file status.",
|
||||||
|
action="store_true",
|
||||||
|
)
|
||||||
diff_parser.set_defaults(func=CmdDiff)
|
diff_parser.set_defaults(func=CmdDiff)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
+6
-14
@@ -31,7 +31,7 @@ class CmdUnfreeze(CmdFreezeBase):
|
|||||||
|
|
||||||
|
|
||||||
def add_parser(subparsers, parent_parser):
|
def add_parser(subparsers, parent_parser):
|
||||||
FREEZE_HELP = "Freeze DVC-files."
|
FREEZE_HELP = "Freeze stages or .dvc files."
|
||||||
freeze_parser = subparsers.add_parser(
|
freeze_parser = subparsers.add_parser(
|
||||||
"freeze",
|
"freeze",
|
||||||
parents=[parent_parser],
|
parents=[parent_parser],
|
||||||
@@ -40,15 +40,11 @@ def add_parser(subparsers, parent_parser):
|
|||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
)
|
)
|
||||||
freeze_parser.add_argument(
|
freeze_parser.add_argument(
|
||||||
"targets",
|
"targets", nargs="+", help="Stages or .dvc files to freeze",
|
||||||
nargs="+",
|
).complete = completion.DVC_FILE
|
||||||
help="DVC-files to freeze.",
|
|
||||||
metavar="targets",
|
|
||||||
choices=completion.Required.DVC_FILE,
|
|
||||||
)
|
|
||||||
freeze_parser.set_defaults(func=CmdFreeze)
|
freeze_parser.set_defaults(func=CmdFreeze)
|
||||||
|
|
||||||
UNFREEZE_HELP = "Unfreeze DVC-files."
|
UNFREEZE_HELP = "Unfreeze stages or .dvc files."
|
||||||
unfreeze_parser = subparsers.add_parser(
|
unfreeze_parser = subparsers.add_parser(
|
||||||
"unfreeze",
|
"unfreeze",
|
||||||
parents=[parent_parser],
|
parents=[parent_parser],
|
||||||
@@ -57,10 +53,6 @@ def add_parser(subparsers, parent_parser):
|
|||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
)
|
)
|
||||||
unfreeze_parser.add_argument(
|
unfreeze_parser.add_argument(
|
||||||
"targets",
|
"targets", nargs="+", help="Stages or .dvc files to unfreeze",
|
||||||
nargs="+",
|
).complete = completion.DVC_FILE
|
||||||
help="DVC-files to unfreeze.",
|
|
||||||
metavar="targets",
|
|
||||||
choices=completion.Required.DVC_FILE,
|
|
||||||
)
|
|
||||||
unfreeze_parser.set_defaults(func=CmdUnfreeze)
|
unfreeze_parser.set_defaults(func=CmdUnfreeze)
|
||||||
|
|||||||
+14
-1
@@ -30,6 +30,8 @@ class CmdGC(CmdBase):
|
|||||||
msg += " and all git branches"
|
msg += " and all git branches"
|
||||||
elif self.args.all_tags:
|
elif self.args.all_tags:
|
||||||
msg += " and all git tags"
|
msg += " and all git tags"
|
||||||
|
elif self.args.all_experiments:
|
||||||
|
msg += " and all experiments"
|
||||||
|
|
||||||
if self.args.repos:
|
if self.args.repos:
|
||||||
msg += " of the current and the following repos:"
|
msg += " of the current and the following repos:"
|
||||||
@@ -49,6 +51,7 @@ class CmdGC(CmdBase):
|
|||||||
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,
|
all_commits=self.args.all_commits,
|
||||||
|
all_experiments=self.args.all_experiments,
|
||||||
cloud=self.args.cloud,
|
cloud=self.args.cloud,
|
||||||
remote=self.args.remote,
|
remote=self.args.remote,
|
||||||
force=self.args.force,
|
force=self.args.force,
|
||||||
@@ -99,6 +102,12 @@ def add_parser(subparsers, parent_parser):
|
|||||||
default=False,
|
default=False,
|
||||||
help="Keep data files for all Git commits.",
|
help="Keep data files for all Git commits.",
|
||||||
)
|
)
|
||||||
|
gc_parser.add_argument(
|
||||||
|
"--all-experiments",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Keep data files for all experiments.",
|
||||||
|
)
|
||||||
gc_parser.add_argument(
|
gc_parser.add_argument(
|
||||||
"-c",
|
"-c",
|
||||||
"--cloud",
|
"--cloud",
|
||||||
@@ -123,7 +132,11 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"-j",
|
"-j",
|
||||||
"--jobs",
|
"--jobs",
|
||||||
type=int,
|
type=int,
|
||||||
help="Number of jobs to run simultaneously.",
|
help=(
|
||||||
|
"Number of jobs to run simultaneously. "
|
||||||
|
"The default value is 4 * cpu_count(). "
|
||||||
|
"For SSH remotes, the default is 4. "
|
||||||
|
),
|
||||||
metavar="<number>",
|
metavar="<number>",
|
||||||
)
|
)
|
||||||
gc_parser.add_argument(
|
gc_parser.add_argument(
|
||||||
|
|||||||
+15
-7
@@ -39,6 +39,7 @@ class CmdGet(CmdBaseNoRepo):
|
|||||||
path=self.args.path,
|
path=self.args.path,
|
||||||
out=self.args.out,
|
out=self.args.out,
|
||||||
rev=self.args.rev,
|
rev=self.args.rev,
|
||||||
|
jobs=self.args.jobs,
|
||||||
)
|
)
|
||||||
return 0
|
return 0
|
||||||
except DvcException:
|
except DvcException:
|
||||||
@@ -63,19 +64,15 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"url", help="Location of DVC or Git repository to download from"
|
"url", help="Location of DVC or Git repository to download from"
|
||||||
)
|
)
|
||||||
get_parser.add_argument(
|
get_parser.add_argument(
|
||||||
"path",
|
"path", help="Path to a file or directory within the repository",
|
||||||
help="Path to a file or directory within the repository",
|
).complete = completion.FILE
|
||||||
metavar="path",
|
|
||||||
choices=completion.Required.FILE,
|
|
||||||
)
|
|
||||||
get_parser.add_argument(
|
get_parser.add_argument(
|
||||||
"-o",
|
"-o",
|
||||||
"--out",
|
"--out",
|
||||||
nargs="?",
|
nargs="?",
|
||||||
help="Destination path to download files to",
|
help="Destination path to download files to",
|
||||||
metavar="<path>",
|
metavar="<path>",
|
||||||
choices=completion.Optional.DIR,
|
).complete = completion.DIR
|
||||||
)
|
|
||||||
get_parser.add_argument(
|
get_parser.add_argument(
|
||||||
"--rev",
|
"--rev",
|
||||||
nargs="?",
|
nargs="?",
|
||||||
@@ -88,4 +85,15 @@ def add_parser(subparsers, parent_parser):
|
|||||||
help="Print the storage location (URL) the target data would be "
|
help="Print the storage location (URL) the target data would be "
|
||||||
"downloaded from, and exit.",
|
"downloaded from, and exit.",
|
||||||
)
|
)
|
||||||
|
get_parser.add_argument(
|
||||||
|
"-j",
|
||||||
|
"--jobs",
|
||||||
|
type=int,
|
||||||
|
help=(
|
||||||
|
"Number of jobs to run simultaneously. "
|
||||||
|
"The default value is 4 * cpu_count(). "
|
||||||
|
"For SSH remotes, the default is 4. "
|
||||||
|
),
|
||||||
|
metavar="<number>",
|
||||||
|
)
|
||||||
get_parser.set_defaults(func=CmdGet)
|
get_parser.set_defaults(func=CmdGet)
|
||||||
|
|||||||
+13
-6
@@ -14,7 +14,7 @@ class CmdGetUrl(CmdBaseNoRepo):
|
|||||||
from dvc.repo import Repo
|
from dvc.repo import Repo
|
||||||
|
|
||||||
try:
|
try:
|
||||||
Repo.get_url(self.args.url, out=self.args.out)
|
Repo.get_url(self.args.url, out=self.args.out, jobs=self.args.jobs)
|
||||||
return 0
|
return 0
|
||||||
except DvcException:
|
except DvcException:
|
||||||
logger.exception(f"failed to get '{self.args.url}'")
|
logger.exception(f"failed to get '{self.args.url}'")
|
||||||
@@ -34,10 +34,17 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"url", help="See `dvc import-url -h` for full list of supported URLs."
|
"url", help="See `dvc import-url -h` for full list of supported URLs."
|
||||||
)
|
)
|
||||||
get_parser.add_argument(
|
get_parser.add_argument(
|
||||||
"out",
|
"out", nargs="?", help="Destination path to put data to.",
|
||||||
nargs="?",
|
).complete = completion.DIR
|
||||||
help="Destination path to put data to.",
|
get_parser.add_argument(
|
||||||
metavar="out",
|
"-j",
|
||||||
choices=completion.Optional.DIR,
|
"--jobs",
|
||||||
|
type=int,
|
||||||
|
help=(
|
||||||
|
"Number of jobs to run simultaneously. "
|
||||||
|
"The default value is 4 * cpu_count(). "
|
||||||
|
"For SSH remotes, the default is 4. "
|
||||||
|
),
|
||||||
|
metavar="<number>",
|
||||||
)
|
)
|
||||||
get_parser.set_defaults(func=CmdGetUrl)
|
get_parser.set_defaults(func=CmdGetUrl)
|
||||||
|
|||||||
+49
-2
@@ -19,6 +19,9 @@ class CmdHookBase(CmdBaseNoRepo):
|
|||||||
|
|
||||||
return self._run()
|
return self._run()
|
||||||
|
|
||||||
|
def _run(self):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class CmdPreCommit(CmdHookBase):
|
class CmdPreCommit(CmdHookBase):
|
||||||
def _run(self):
|
def _run(self):
|
||||||
@@ -28,7 +31,7 @@ class CmdPreCommit(CmdHookBase):
|
|||||||
|
|
||||||
|
|
||||||
class CmdPostCheckout(CmdHookBase):
|
class CmdPostCheckout(CmdHookBase):
|
||||||
def run(self):
|
def _run(self):
|
||||||
# when we are running from pre-commit tool, it doesn't provide CLI
|
# when we are running from pre-commit tool, it doesn't provide CLI
|
||||||
# flags, but instead provides respective env vars that we could use.
|
# flags, but instead provides respective env vars that we could use.
|
||||||
flag = os.environ.get("PRE_COMMIT_CHECKOUT_TYPE")
|
flag = os.environ.get("PRE_COMMIT_CHECKOUT_TYPE")
|
||||||
@@ -52,12 +55,32 @@ class CmdPostCheckout(CmdHookBase):
|
|||||||
|
|
||||||
|
|
||||||
class CmdPrePush(CmdHookBase):
|
class CmdPrePush(CmdHookBase):
|
||||||
def run(self):
|
def _run(self):
|
||||||
from dvc.main import main
|
from dvc.main import main
|
||||||
|
|
||||||
return main(["push"])
|
return main(["push"])
|
||||||
|
|
||||||
|
|
||||||
|
class CmdMergeDriver(CmdHookBase):
|
||||||
|
def _run(self):
|
||||||
|
from dvc.dvcfile import Dvcfile
|
||||||
|
from dvc.repo import Repo
|
||||||
|
|
||||||
|
dvc = Repo()
|
||||||
|
|
||||||
|
try:
|
||||||
|
with dvc.state:
|
||||||
|
ancestor = Dvcfile(dvc, self.args.ancestor, verify=False)
|
||||||
|
our = Dvcfile(dvc, self.args.our, verify=False)
|
||||||
|
their = Dvcfile(dvc, self.args.their, verify=False)
|
||||||
|
|
||||||
|
our.merge(ancestor, their)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
finally:
|
||||||
|
dvc.close()
|
||||||
|
|
||||||
|
|
||||||
def add_parser(subparsers, parent_parser):
|
def add_parser(subparsers, parent_parser):
|
||||||
GIT_HOOK_HELP = "Run GIT hook."
|
GIT_HOOK_HELP = "Run GIT hook."
|
||||||
|
|
||||||
@@ -110,3 +133,27 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"args", nargs="*", help="Arguments passed by GIT or pre-commit tool.",
|
"args", nargs="*", help="Arguments passed by GIT or pre-commit tool.",
|
||||||
)
|
)
|
||||||
pre_push_parser.set_defaults(func=CmdPrePush)
|
pre_push_parser.set_defaults(func=CmdPrePush)
|
||||||
|
|
||||||
|
MERGE_DRIVER_HELP = "Run GIT merge driver."
|
||||||
|
merge_driver_parser = git_hook_subparsers.add_parser(
|
||||||
|
"merge-driver",
|
||||||
|
parents=[parent_parser],
|
||||||
|
description=MERGE_DRIVER_HELP,
|
||||||
|
help=MERGE_DRIVER_HELP,
|
||||||
|
)
|
||||||
|
merge_driver_parser.add_argument(
|
||||||
|
"--ancestor",
|
||||||
|
required=True,
|
||||||
|
help="Ancestor's version of the conflicting file.",
|
||||||
|
)
|
||||||
|
merge_driver_parser.add_argument(
|
||||||
|
"--our",
|
||||||
|
required=True,
|
||||||
|
help="Current version of the conflicting file.",
|
||||||
|
)
|
||||||
|
merge_driver_parser.add_argument(
|
||||||
|
"--their",
|
||||||
|
required=True,
|
||||||
|
help="Other branch's version of the conflicting file.",
|
||||||
|
)
|
||||||
|
merge_driver_parser.set_defaults(func=CmdMergeDriver)
|
||||||
|
|||||||
+38
-7
@@ -15,7 +15,11 @@ class CmdImport(CmdBase):
|
|||||||
self.args.url,
|
self.args.url,
|
||||||
self.args.path,
|
self.args.path,
|
||||||
out=self.args.out,
|
out=self.args.out,
|
||||||
|
fname=self.args.file,
|
||||||
rev=self.args.rev,
|
rev=self.args.rev,
|
||||||
|
no_exec=self.args.no_exec,
|
||||||
|
desc=self.args.desc,
|
||||||
|
jobs=self.args.jobs,
|
||||||
)
|
)
|
||||||
except DvcException:
|
except DvcException:
|
||||||
logger.exception(
|
logger.exception(
|
||||||
@@ -44,23 +48,50 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"url", help="Location of DVC or Git repository to download from"
|
"url", help="Location of DVC or Git repository to download from"
|
||||||
)
|
)
|
||||||
import_parser.add_argument(
|
import_parser.add_argument(
|
||||||
"path",
|
"path", help="Path to a file or directory within the repository",
|
||||||
help="Path to a file or directory within the repository",
|
).complete = completion.FILE
|
||||||
metavar="path",
|
|
||||||
choices=completion.Required.FILE,
|
|
||||||
)
|
|
||||||
import_parser.add_argument(
|
import_parser.add_argument(
|
||||||
"-o",
|
"-o",
|
||||||
"--out",
|
"--out",
|
||||||
nargs="?",
|
nargs="?",
|
||||||
help="Destination path to download files to",
|
help="Destination path to download files to",
|
||||||
metavar="<path>",
|
metavar="<path>",
|
||||||
choices=completion.Optional.DIR,
|
).complete = completion.DIR
|
||||||
)
|
|
||||||
import_parser.add_argument(
|
import_parser.add_argument(
|
||||||
"--rev",
|
"--rev",
|
||||||
nargs="?",
|
nargs="?",
|
||||||
help="Git revision (e.g. SHA, branch, tag)",
|
help="Git revision (e.g. SHA, branch, tag)",
|
||||||
metavar="<commit>",
|
metavar="<commit>",
|
||||||
)
|
)
|
||||||
|
import_parser.add_argument(
|
||||||
|
"--file",
|
||||||
|
help="Specify name of the .dvc file this command will generate.",
|
||||||
|
metavar="<filename>",
|
||||||
|
)
|
||||||
|
import_parser.add_argument(
|
||||||
|
"--no-exec",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Only create .dvc file without actually downloading it.",
|
||||||
|
)
|
||||||
|
import_parser.add_argument(
|
||||||
|
"--desc",
|
||||||
|
type=str,
|
||||||
|
metavar="<text>",
|
||||||
|
help=(
|
||||||
|
"User description of the data (optional). "
|
||||||
|
"This doesn't affect any DVC operations."
|
||||||
|
),
|
||||||
|
)
|
||||||
|
import_parser.add_argument(
|
||||||
|
"-j",
|
||||||
|
"--jobs",
|
||||||
|
type=int,
|
||||||
|
help=(
|
||||||
|
"Number of jobs to run simultaneously. "
|
||||||
|
"The default value is 4 * cpu_count(). "
|
||||||
|
"For SSH remotes, the default is 4. "
|
||||||
|
),
|
||||||
|
metavar="<number>",
|
||||||
|
)
|
||||||
import_parser.set_defaults(func=CmdImport)
|
import_parser.set_defaults(func=CmdImport)
|
||||||
|
|||||||
+49
-22
@@ -16,6 +16,10 @@ class CmdImportUrl(CmdBase):
|
|||||||
out=self.args.out,
|
out=self.args.out,
|
||||||
fname=self.args.file,
|
fname=self.args.file,
|
||||||
no_exec=self.args.no_exec,
|
no_exec=self.args.no_exec,
|
||||||
|
remote=self.args.remote,
|
||||||
|
to_remote=self.args.to_remote,
|
||||||
|
desc=self.args.desc,
|
||||||
|
jobs=self.args.jobs,
|
||||||
)
|
)
|
||||||
except DvcException:
|
except DvcException:
|
||||||
logger.exception(
|
logger.exception(
|
||||||
@@ -42,38 +46,61 @@ def add_parser(subparsers, parent_parser):
|
|||||||
)
|
)
|
||||||
import_parser.add_argument(
|
import_parser.add_argument(
|
||||||
"url",
|
"url",
|
||||||
help="Supported urls:\n"
|
help="Location of the data to download. Supported URLs:\n"
|
||||||
"/path/to/file\n"
|
"/absolute/path/to/file/or/dir\n"
|
||||||
"/path/to/directory\n"
|
"relative/path/to/file/or/dir\n"
|
||||||
"C:\\\\path\\to\\file\n"
|
"C:\\\\path\\to\\file\\or\\dir\n"
|
||||||
"C:\\\\path\\to\\directory\n"
|
|
||||||
"https://example.com/path/to/file\n"
|
"https://example.com/path/to/file\n"
|
||||||
"s3://bucket/path/to/file\n"
|
"s3://bucket/key/path\n"
|
||||||
"s3://bucket/path/to/directory\n"
|
"gs://bucket/path/to/file/or/dir\n"
|
||||||
"gs://bucket/path/to/file\n"
|
|
||||||
"gs://bucket/path/to/directory\n"
|
|
||||||
"hdfs://example.com/path/to/file\n"
|
"hdfs://example.com/path/to/file\n"
|
||||||
"ssh://example.com:/path/to/file\n"
|
"ssh://example.com/absolute/path/to/file/or/dir\n"
|
||||||
"ssh://example.com:/path/to/directory\n"
|
"remote://remote_name/path/to/file/or/dir (see `dvc remote`)",
|
||||||
"remote://myremote/path/to/file (see `dvc remote`)",
|
|
||||||
)
|
)
|
||||||
import_parser.add_argument(
|
import_parser.add_argument(
|
||||||
"out",
|
"out", nargs="?", help="Destination path to put files to.",
|
||||||
nargs="?",
|
).complete = completion.DIR
|
||||||
help="Destination path to put files to.",
|
|
||||||
metavar="out",
|
|
||||||
choices=completion.Optional.DIR,
|
|
||||||
)
|
|
||||||
import_parser.add_argument(
|
import_parser.add_argument(
|
||||||
"--file",
|
"--file",
|
||||||
help="Specify name of the DVC-file this command will generate.",
|
help="Specify name of the .dvc file this command will generate.",
|
||||||
metavar="<filename>",
|
metavar="<filename>",
|
||||||
choices=completion.Optional.DIR,
|
).complete = completion.DIR
|
||||||
)
|
|
||||||
import_parser.add_argument(
|
import_parser.add_argument(
|
||||||
"--no-exec",
|
"--no-exec",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
help="Only create DVC-file without actually downloading it.",
|
help="Only create .dvc file without actually downloading it.",
|
||||||
|
)
|
||||||
|
import_parser.add_argument(
|
||||||
|
"--to-remote",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Download it directly to the remote",
|
||||||
|
)
|
||||||
|
import_parser.add_argument(
|
||||||
|
"-r",
|
||||||
|
"--remote",
|
||||||
|
help="Remote storage to download to",
|
||||||
|
metavar="<name>",
|
||||||
|
)
|
||||||
|
import_parser.add_argument(
|
||||||
|
"-j",
|
||||||
|
"--jobs",
|
||||||
|
type=int,
|
||||||
|
help=(
|
||||||
|
"Number of jobs to run simultaneously. "
|
||||||
|
"The default value is 4 * cpu_count(). "
|
||||||
|
"For SSH remotes, the default is 4. "
|
||||||
|
),
|
||||||
|
metavar="<number>",
|
||||||
|
)
|
||||||
|
import_parser.add_argument(
|
||||||
|
"--desc",
|
||||||
|
type=str,
|
||||||
|
metavar="<text>",
|
||||||
|
help=(
|
||||||
|
"User description of the data (optional). "
|
||||||
|
"This doesn't affect any DVC operations."
|
||||||
|
),
|
||||||
)
|
)
|
||||||
import_parser.set_defaults(func=CmdImportUrl)
|
import_parser.set_defaults(func=CmdImportUrl)
|
||||||
|
|||||||
+29
-1
@@ -1,15 +1,42 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import colorama
|
||||||
|
|
||||||
|
from dvc import analytics
|
||||||
from dvc.command.base import CmdBaseNoRepo, append_doc_link
|
from dvc.command.base import CmdBaseNoRepo, append_doc_link
|
||||||
|
from dvc.utils import boxify
|
||||||
|
from dvc.utils import format_link as fmt_link
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def _welcome_message():
|
||||||
|
if analytics.is_enabled():
|
||||||
|
logger.info(
|
||||||
|
boxify(
|
||||||
|
"DVC has enabled anonymous aggregate usage analytics.\n"
|
||||||
|
"Read the analytics documentation (and how to opt-out) here:\n"
|
||||||
|
+ fmt_link("https://dvc.org/doc/user-guide/analytics"),
|
||||||
|
border_color="red",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
msg = (
|
||||||
|
"{yellow}What's next?{nc}\n"
|
||||||
|
"{yellow}------------{nc}\n"
|
||||||
|
f"- Check out the documentation: {fmt_link('https://dvc.org/doc')}\n"
|
||||||
|
f"- Get help and share ideas: {fmt_link('https://dvc.org/chat')}\n"
|
||||||
|
f"- Star us on GitHub: {fmt_link('https://github.com/iterative/dvc')}"
|
||||||
|
).format(yellow=colorama.Fore.YELLOW, nc=colorama.Fore.RESET)
|
||||||
|
|
||||||
|
logger.info(msg)
|
||||||
|
|
||||||
|
|
||||||
class CmdInit(CmdBaseNoRepo):
|
class CmdInit(CmdBaseNoRepo):
|
||||||
def run(self):
|
def run(self):
|
||||||
from dvc.repo import Repo
|
|
||||||
from dvc.exceptions import InitError
|
from dvc.exceptions import InitError
|
||||||
|
from dvc.repo import Repo
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.repo = Repo.init(
|
self.repo = Repo.init(
|
||||||
@@ -19,6 +46,7 @@ class CmdInit(CmdBaseNoRepo):
|
|||||||
subdir=self.args.subdir,
|
subdir=self.args.subdir,
|
||||||
)
|
)
|
||||||
self.config = self.repo.config
|
self.config = self.repo.config
|
||||||
|
_welcome_message()
|
||||||
except InitError:
|
except InitError:
|
||||||
logger.exception("failed to initiate DVC")
|
logger.exception("failed to initiate DVC")
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import argparse
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dvc.command.base import CmdBase, append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -10,7 +11,7 @@ class CmdInstall(CmdBase):
|
|||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
self.repo.install(self.args.use_pre_commit_tool)
|
self.repo.install(self.args.use_pre_commit_tool)
|
||||||
except Exception:
|
except DvcException:
|
||||||
logger.exception("failed to install DVC Git hooks")
|
logger.exception("failed to install DVC Git hooks")
|
||||||
return 1
|
return 1
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
import argparse
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
from dvc.command import completion
|
||||||
|
from dvc.command.base import CmdBase, fix_subparsers
|
||||||
|
from dvc.utils.html import write
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class CmdLive(CmdBase):
|
||||||
|
UNINITIALIZED = True
|
||||||
|
|
||||||
|
def _run(self, target, revs=None):
|
||||||
|
metrics, plots = self.repo.live.show(target=target, revs=revs)
|
||||||
|
|
||||||
|
html_path = self.args.target + ".html"
|
||||||
|
write(html_path, plots, metrics)
|
||||||
|
|
||||||
|
logger.info(f"\nfile://{os.path.abspath(html_path)}")
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
class CmdLiveShow(CmdLive):
|
||||||
|
def run(self):
|
||||||
|
return self._run(self.args.target)
|
||||||
|
|
||||||
|
|
||||||
|
class CmdLiveDiff(CmdLive):
|
||||||
|
def run(self):
|
||||||
|
return self._run(self.args.target, self.args.revs)
|
||||||
|
|
||||||
|
|
||||||
|
def shared_parent_parser():
|
||||||
|
parent_parser = argparse.ArgumentParser(add_help=False)
|
||||||
|
parent_parser.add_argument(
|
||||||
|
"target", help="Logs dir to produce summary from",
|
||||||
|
).complete = completion.DIR
|
||||||
|
parent_parser.add_argument(
|
||||||
|
"-o",
|
||||||
|
"--out",
|
||||||
|
default=None,
|
||||||
|
help="Destination path to save plots to",
|
||||||
|
metavar="<path>",
|
||||||
|
).complete = completion.DIR
|
||||||
|
return parent_parser
|
||||||
|
|
||||||
|
|
||||||
|
def add_parser(subparsers, parent_parser):
|
||||||
|
LIVE_DESCRIPTION = (
|
||||||
|
"Commands to visualize and compare dvclive-produced logs."
|
||||||
|
)
|
||||||
|
live_parser = subparsers.add_parser(
|
||||||
|
"live",
|
||||||
|
parents=[parent_parser],
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
description=LIVE_DESCRIPTION,
|
||||||
|
)
|
||||||
|
live_subparsers = live_parser.add_subparsers(
|
||||||
|
dest="cmd",
|
||||||
|
help="Use `dvc live CMD --help` to display command-specific help.",
|
||||||
|
)
|
||||||
|
|
||||||
|
fix_subparsers(live_subparsers)
|
||||||
|
|
||||||
|
SHOW_HELP = "Visualize dvclive directory content."
|
||||||
|
live_show_parser = live_subparsers.add_parser(
|
||||||
|
"show",
|
||||||
|
parents=[parent_parser, shared_parent_parser()],
|
||||||
|
help=SHOW_HELP,
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
)
|
||||||
|
live_show_parser.set_defaults(func=CmdLiveShow)
|
||||||
|
|
||||||
|
DIFF_HELP = (
|
||||||
|
"Show multiple versions of dvclive data, "
|
||||||
|
"by plotting it in single view."
|
||||||
|
)
|
||||||
|
live_diff_parser = live_subparsers.add_parser(
|
||||||
|
"diff",
|
||||||
|
parents=[parent_parser, shared_parent_parser()],
|
||||||
|
help=DIFF_HELP,
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
)
|
||||||
|
live_diff_parser.add_argument(
|
||||||
|
"--revs",
|
||||||
|
nargs="*",
|
||||||
|
default=None,
|
||||||
|
help="Git revision (e.g. SHA, branch, tag)",
|
||||||
|
metavar="<commit>",
|
||||||
|
)
|
||||||
|
live_diff_parser.set_defaults(func=CmdLiveDiff)
|
||||||
@@ -75,7 +75,5 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"path",
|
"path",
|
||||||
nargs="?",
|
nargs="?",
|
||||||
help="Path to directory within the repository to list outputs for",
|
help="Path to directory within the repository to list outputs for",
|
||||||
metavar="path",
|
).complete = completion.DIR
|
||||||
choices=completion.Optional.DIR,
|
|
||||||
)
|
|
||||||
list_parser.set_defaults(func=CmdList)
|
list_parser.set_defaults(func=CmdList)
|
||||||
|
|||||||
+84
-42
@@ -11,34 +11,69 @@ logger = logging.getLogger(__name__)
|
|||||||
DEFAULT_PRECISION = 5
|
DEFAULT_PRECISION = 5
|
||||||
|
|
||||||
|
|
||||||
def show_metrics(
|
def _show_metrics(
|
||||||
metrics, all_branches=False, all_tags=False, all_commits=False
|
metrics,
|
||||||
|
markdown=False,
|
||||||
|
all_branches=False,
|
||||||
|
all_tags=False,
|
||||||
|
all_commits=False,
|
||||||
|
precision=None,
|
||||||
):
|
):
|
||||||
from flatten_json import flatten
|
from dvc.utils.diff import format_dict, table
|
||||||
from dvc.utils.diff import format_dict
|
from dvc.utils.flatten import flatten
|
||||||
|
|
||||||
# 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)
|
||||||
|
with_rev = any([all_branches, all_tags, all_commits])
|
||||||
|
header_set = set()
|
||||||
|
rows = []
|
||||||
|
|
||||||
for branch, val in metrics.items():
|
if precision is None:
|
||||||
if all_branches or all_tags or all_commits:
|
precision = DEFAULT_PRECISION
|
||||||
logger.info(f"{branch}:")
|
|
||||||
|
|
||||||
for fname, metric in val.items():
|
def _round(val):
|
||||||
|
if isinstance(val, float):
|
||||||
|
return round(val, precision)
|
||||||
|
return val
|
||||||
|
|
||||||
|
for _branch, val in metrics.items():
|
||||||
|
for _fname, metric in val.items():
|
||||||
if not isinstance(metric, dict):
|
if not isinstance(metric, dict):
|
||||||
logger.info("\t{}: {}".format(fname, str(metric)))
|
header_set.add("")
|
||||||
continue
|
continue
|
||||||
|
for key, _val in flatten(format_dict(metric)).items():
|
||||||
|
header_set.add(key)
|
||||||
|
header = sorted(header_set)
|
||||||
|
for branch, val in metrics.items():
|
||||||
|
for fname, metric in val.items():
|
||||||
|
row = []
|
||||||
|
if with_rev:
|
||||||
|
row.append(branch)
|
||||||
|
row.append(fname)
|
||||||
|
if not isinstance(metric, dict):
|
||||||
|
row.append(str(metric))
|
||||||
|
rows.append(row)
|
||||||
|
continue
|
||||||
|
flattened_val = flatten(format_dict(metric))
|
||||||
|
|
||||||
logger.info(f"\t{fname}:")
|
for i in header:
|
||||||
for key, value in flatten(format_dict(metric), ".").items():
|
row.append(_round(flattened_val.get(i)))
|
||||||
logger.info(f"\t\t{key}: {value}")
|
rows.append(row)
|
||||||
|
header.insert(0, "Path")
|
||||||
|
if with_rev:
|
||||||
|
header.insert(0, "Revision")
|
||||||
|
|
||||||
if missing:
|
if missing:
|
||||||
raise BadMetricError(missing)
|
raise BadMetricError(missing)
|
||||||
|
return table(header, rows, markdown)
|
||||||
|
|
||||||
|
|
||||||
class CmdMetricsShow(CmdBase):
|
class CmdMetricsBase(CmdBase):
|
||||||
|
UNINITIALIZED = True
|
||||||
|
|
||||||
|
|
||||||
|
class CmdMetricsShow(CmdMetricsBase):
|
||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
metrics = self.repo.metrics.show(
|
metrics = self.repo.metrics.show(
|
||||||
@@ -54,20 +89,23 @@ class CmdMetricsShow(CmdBase):
|
|||||||
|
|
||||||
logger.info(json.dumps(metrics))
|
logger.info(json.dumps(metrics))
|
||||||
else:
|
else:
|
||||||
show_metrics(
|
table = _show_metrics(
|
||||||
metrics,
|
metrics,
|
||||||
|
self.args.show_md,
|
||||||
self.args.all_branches,
|
self.args.all_branches,
|
||||||
self.args.all_tags,
|
self.args.all_tags,
|
||||||
self.args.all_commits,
|
self.args.all_commits,
|
||||||
)
|
)
|
||||||
|
if table:
|
||||||
|
logger.info(table)
|
||||||
except DvcException:
|
except DvcException:
|
||||||
logger.exception("failed to show metrics")
|
logger.exception("")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def _show_diff(diff, markdown=False, no_path=False, old=False, precision=None):
|
def _show_diff(diff, markdown=False, no_path=False, precision=None):
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
from dvc.utils.diff import table
|
from dvc.utils.diff import table
|
||||||
@@ -87,24 +125,20 @@ def _show_diff(diff, markdown=False, no_path=False, old=False, precision=None):
|
|||||||
for metric, change in sorted_mdiff.items():
|
for metric, change in sorted_mdiff.items():
|
||||||
row = [] if no_path else [fname]
|
row = [] if no_path else [fname]
|
||||||
row.append(metric)
|
row.append(metric)
|
||||||
if old:
|
row.append(_round(change.get("old")))
|
||||||
row.append(_round(change.get("old")))
|
|
||||||
row.append(_round(change["new"]))
|
row.append(_round(change["new"]))
|
||||||
row.append(_round(change.get("diff", "diff not supported")))
|
row.append(_round(change.get("diff")))
|
||||||
rows.append(row)
|
rows.append(row)
|
||||||
|
|
||||||
header = [] if no_path else ["Path"]
|
header = [] if no_path else ["Path"]
|
||||||
header.append("Metric")
|
header.append("Metric")
|
||||||
if old:
|
header.extend(["Old", "New"])
|
||||||
header.extend(["Old", "New"])
|
|
||||||
else:
|
|
||||||
header.append("Value")
|
|
||||||
header.append("Change")
|
header.append("Change")
|
||||||
|
|
||||||
return table(header, rows, markdown)
|
return table(header, rows, markdown)
|
||||||
|
|
||||||
|
|
||||||
class CmdMetricsDiff(CmdBase):
|
class CmdMetricsDiff(CmdMetricsBase):
|
||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
diff = self.repo.metrics.diff(
|
diff = self.repo.metrics.diff(
|
||||||
@@ -124,7 +158,6 @@ class CmdMetricsDiff(CmdBase):
|
|||||||
diff,
|
diff,
|
||||||
self.args.show_md,
|
self.args.show_md,
|
||||||
self.args.no_path,
|
self.args.no_path,
|
||||||
self.args.old,
|
|
||||||
precision=self.args.precision,
|
precision=self.args.precision,
|
||||||
)
|
)
|
||||||
if table:
|
if table:
|
||||||
@@ -167,12 +200,10 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"targets",
|
"targets",
|
||||||
nargs="*",
|
nargs="*",
|
||||||
help=(
|
help=(
|
||||||
"Limit command scope to these metric files. Using -R, "
|
"Limit command scope to these metrics files. Using -R, "
|
||||||
"directories to search metric files in can also be given."
|
"directories to search metrics files in can also be given."
|
||||||
),
|
),
|
||||||
metavar="targets",
|
).complete = completion.FILE
|
||||||
choices=completion.Optional.FILE,
|
|
||||||
)
|
|
||||||
metrics_show_parser.add_argument(
|
metrics_show_parser.add_argument(
|
||||||
"-a",
|
"-a",
|
||||||
"--all-branches",
|
"--all-branches",
|
||||||
@@ -199,6 +230,12 @@ def add_parser(subparsers, parent_parser):
|
|||||||
default=False,
|
default=False,
|
||||||
help="Show output in JSON format.",
|
help="Show output in JSON format.",
|
||||||
)
|
)
|
||||||
|
metrics_show_parser.add_argument(
|
||||||
|
"--show-md",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Show tabulated output in the Markdown format (GFM).",
|
||||||
|
)
|
||||||
metrics_show_parser.add_argument(
|
metrics_show_parser.add_argument(
|
||||||
"-R",
|
"-R",
|
||||||
"--recursive",
|
"--recursive",
|
||||||
@@ -206,9 +243,18 @@ def add_parser(subparsers, parent_parser):
|
|||||||
default=False,
|
default=False,
|
||||||
help=(
|
help=(
|
||||||
"If any target is a directory, recursively search and process "
|
"If any target is a directory, recursively search and process "
|
||||||
"metric files."
|
"metrics files."
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
metrics_show_parser.add_argument(
|
||||||
|
"--precision",
|
||||||
|
type=int,
|
||||||
|
help=(
|
||||||
|
"Round metrics to `n` digits precision after the decimal point. "
|
||||||
|
f"Rounds to {DEFAULT_PRECISION} digits by default."
|
||||||
|
),
|
||||||
|
metavar="<n>",
|
||||||
|
)
|
||||||
metrics_show_parser.set_defaults(func=CmdMetricsShow)
|
metrics_show_parser.set_defaults(func=CmdMetricsShow)
|
||||||
|
|
||||||
METRICS_DIFF_HELP = (
|
METRICS_DIFF_HELP = (
|
||||||
@@ -234,12 +280,14 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"--targets",
|
"--targets",
|
||||||
nargs="*",
|
nargs="*",
|
||||||
help=(
|
help=(
|
||||||
"Limit command scope to these metric files. Using -R, "
|
"Specific metrics file(s) to compare "
|
||||||
"directories to search metric files in can also be given."
|
"(even if not found as `metrics` in `dvc.yaml`). "
|
||||||
|
"Using -R, directories to search metrics files in "
|
||||||
|
"can also be given."
|
||||||
|
"Shows all tracked metrics by default."
|
||||||
),
|
),
|
||||||
metavar="<paths>",
|
metavar="<paths>",
|
||||||
choices=completion.Optional.FILE,
|
).complete = completion.FILE
|
||||||
)
|
|
||||||
metrics_diff_parser.add_argument(
|
metrics_diff_parser.add_argument(
|
||||||
"-R",
|
"-R",
|
||||||
"--recursive",
|
"--recursive",
|
||||||
@@ -247,7 +295,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
default=False,
|
default=False,
|
||||||
help=(
|
help=(
|
||||||
"If any target is a directory, recursively search and process "
|
"If any target is a directory, recursively search and process "
|
||||||
"metric files."
|
"metrics files."
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
metrics_diff_parser.add_argument(
|
metrics_diff_parser.add_argument(
|
||||||
@@ -268,12 +316,6 @@ def add_parser(subparsers, parent_parser):
|
|||||||
default=False,
|
default=False,
|
||||||
help="Show tabulated output in the Markdown format (GFM).",
|
help="Show tabulated output in the Markdown format (GFM).",
|
||||||
)
|
)
|
||||||
metrics_diff_parser.add_argument(
|
|
||||||
"--old",
|
|
||||||
action="store_true",
|
|
||||||
default=False,
|
|
||||||
help="Show old metric value.",
|
|
||||||
)
|
|
||||||
metrics_diff_parser.add_argument(
|
metrics_diff_parser.add_argument(
|
||||||
"--no-path",
|
"--no-path",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
|
|||||||
+5
-11
@@ -25,7 +25,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
MOVE_HELP = "Rename or move a DVC controlled data file or a directory."
|
MOVE_HELP = "Rename or move a DVC controlled data file or a directory."
|
||||||
MOVE_DESCRIPTION = (
|
MOVE_DESCRIPTION = (
|
||||||
"Rename or move a DVC controlled data file or a directory.\n"
|
"Rename or move a DVC controlled data file or a directory.\n"
|
||||||
"It renames and modifies the corresponding DVC-file to reflect the"
|
"It renames and modifies the corresponding .dvc file to reflect the"
|
||||||
" changes."
|
" changes."
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -37,15 +37,9 @@ def add_parser(subparsers, parent_parser):
|
|||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
)
|
)
|
||||||
move_parser.add_argument(
|
move_parser.add_argument(
|
||||||
"src",
|
"src", help="Source path to a data file or directory.",
|
||||||
help="Source path to a data file or directory.",
|
).complete = completion.FILE
|
||||||
metavar="src",
|
|
||||||
choices=completion.Required.FILE,
|
|
||||||
)
|
|
||||||
move_parser.add_argument(
|
move_parser.add_argument(
|
||||||
"dst",
|
"dst", help="Destination path.",
|
||||||
help="Destination path.",
|
).complete = completion.FILE
|
||||||
metavar="dst",
|
|
||||||
choices=completion.Required.FILE,
|
|
||||||
)
|
|
||||||
move_parser.set_defaults(func=CmdMove)
|
move_parser.set_defaults(func=CmdMove)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import argparse
|
|||||||
import logging
|
import logging
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
from dvc.command import completion
|
||||||
from dvc.command.base import CmdBase, append_doc_link, fix_subparsers
|
from dvc.command.base import CmdBase, append_doc_link, fix_subparsers
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
@@ -30,11 +31,14 @@ def _show_diff(diff, markdown=False, no_path=False):
|
|||||||
|
|
||||||
|
|
||||||
class CmdParamsDiff(CmdBase):
|
class CmdParamsDiff(CmdBase):
|
||||||
|
UNINITIALIZED = True
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
diff = self.repo.params.diff(
|
diff = self.repo.params.diff(
|
||||||
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,
|
||||||
all=self.args.all,
|
all=self.args.all,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -91,6 +95,16 @@ def add_parser(subparsers, parent_parser):
|
|||||||
nargs="?",
|
nargs="?",
|
||||||
help=("New Git commit to compare (defaults to the current workspace)"),
|
help=("New Git commit to compare (defaults to the current workspace)"),
|
||||||
)
|
)
|
||||||
|
params_diff_parser.add_argument(
|
||||||
|
"--targets",
|
||||||
|
nargs="*",
|
||||||
|
help=(
|
||||||
|
"Specific params file(s) to compare "
|
||||||
|
"(even if not found as `params` in `dvc.yaml`). "
|
||||||
|
"Shows all tracked params by default."
|
||||||
|
),
|
||||||
|
metavar="<paths>",
|
||||||
|
).complete = completion.FILE
|
||||||
params_diff_parser.add_argument(
|
params_diff_parser.add_argument(
|
||||||
"--all",
|
"--all",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
|
|||||||
+39
-49
@@ -5,36 +5,19 @@ import os
|
|||||||
from dvc.command import completion
|
from dvc.command import completion
|
||||||
from dvc.command.base import CmdBase, append_doc_link, fix_subparsers
|
from dvc.command.base import CmdBase, append_doc_link, fix_subparsers
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
from dvc.schema import PLOT_PROPS
|
|
||||||
from dvc.utils import format_link
|
from dvc.utils import format_link
|
||||||
|
from dvc.utils.html import write
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
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):
|
class CmdPlots(CmdBase):
|
||||||
def _func(self, *args, **kwargs):
|
def _func(self, *args, **kwargs):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def _props(self):
|
def _props(self):
|
||||||
|
from dvc.schema import PLOT_PROPS
|
||||||
|
|
||||||
# Pass only props specified by user, to not shadow ones from plot def
|
# Pass only props specified by user, to not shadow ones from plot def
|
||||||
props = {p: getattr(self.args, p) for p in PLOT_PROPS}
|
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}
|
return {k: v for k, v in props.items() if v is not None}
|
||||||
@@ -58,19 +41,12 @@ class CmdPlots(CmdBase):
|
|||||||
logger.info(plots[target])
|
logger.info(plots[target])
|
||||||
return 0
|
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"
|
path = self.args.out or "plots.html"
|
||||||
|
path = os.path.join(os.getcwd(), path)
|
||||||
|
|
||||||
with open(path, "w") as fobj:
|
write(path, plots)
|
||||||
fobj.write(html)
|
|
||||||
|
|
||||||
logger.info(
|
logger.info(f"file://{path}")
|
||||||
"file://{}".format(os.path.join(self.repo.root_dir, path))
|
|
||||||
)
|
|
||||||
|
|
||||||
except DvcException:
|
except DvcException:
|
||||||
logger.exception("")
|
logger.exception("")
|
||||||
@@ -80,13 +56,22 @@ class CmdPlots(CmdBase):
|
|||||||
|
|
||||||
|
|
||||||
class CmdPlotsShow(CmdPlots):
|
class CmdPlotsShow(CmdPlots):
|
||||||
|
UNINITIALIZED = True
|
||||||
|
|
||||||
def _func(self, *args, **kwargs):
|
def _func(self, *args, **kwargs):
|
||||||
return self.repo.plots.show(*args, **kwargs)
|
return self.repo.plots.show(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class CmdPlotsDiff(CmdPlots):
|
class CmdPlotsDiff(CmdPlots):
|
||||||
|
UNINITIALIZED = True
|
||||||
|
|
||||||
def _func(self, *args, **kwargs):
|
def _func(self, *args, **kwargs):
|
||||||
return self.repo.plots.diff(*args, revs=self.args.revisions, **kwargs)
|
return self.repo.plots.diff(
|
||||||
|
*args,
|
||||||
|
revs=self.args.revisions,
|
||||||
|
experiment=self.args.experiment,
|
||||||
|
**kwargs,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class CmdPlotsModify(CmdPlots):
|
class CmdPlotsModify(CmdPlots):
|
||||||
@@ -117,7 +102,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
|
|
||||||
fix_subparsers(plots_subparsers)
|
fix_subparsers(plots_subparsers)
|
||||||
|
|
||||||
SHOW_HELP = "Generate plots from metric files."
|
SHOW_HELP = "Generate plots from metrics files."
|
||||||
plots_show_parser = plots_subparsers.add_parser(
|
plots_show_parser = plots_subparsers.add_parser(
|
||||||
"show",
|
"show",
|
||||||
parents=[parent_parser],
|
parents=[parent_parser],
|
||||||
@@ -128,10 +113,10 @@ def add_parser(subparsers, parent_parser):
|
|||||||
plots_show_parser.add_argument(
|
plots_show_parser.add_argument(
|
||||||
"targets",
|
"targets",
|
||||||
nargs="*",
|
nargs="*",
|
||||||
help="Plots files to visualize. Shows all plots by default.",
|
help="Files to visualize (supports any file, "
|
||||||
metavar="targets",
|
"even when not found as `plots` in `dvc.yaml`). "
|
||||||
choices=completion.Optional.FILE,
|
"Shows all plots by default.",
|
||||||
)
|
).complete = completion.FILE
|
||||||
_add_props_arguments(plots_show_parser)
|
_add_props_arguments(plots_show_parser)
|
||||||
_add_output_arguments(plots_show_parser)
|
_add_output_arguments(plots_show_parser)
|
||||||
plots_show_parser.set_defaults(func=CmdPlotsShow)
|
plots_show_parser.set_defaults(func=CmdPlotsShow)
|
||||||
@@ -150,9 +135,19 @@ def add_parser(subparsers, parent_parser):
|
|||||||
plots_diff_parser.add_argument(
|
plots_diff_parser.add_argument(
|
||||||
"--targets",
|
"--targets",
|
||||||
nargs="*",
|
nargs="*",
|
||||||
help="Plots file to visualize. Shows all plots by default.",
|
help=(
|
||||||
metavar="<path>",
|
"Specific plots file(s) to visualize "
|
||||||
choices=completion.Optional.FILE,
|
"(even if not found as `plots` in `dvc.yaml`). "
|
||||||
|
"Shows all tracked plots by default."
|
||||||
|
),
|
||||||
|
metavar="<paths>",
|
||||||
|
).complete = completion.FILE
|
||||||
|
plots_diff_parser.add_argument(
|
||||||
|
"-e",
|
||||||
|
"--experiment",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help=argparse.SUPPRESS,
|
||||||
)
|
)
|
||||||
plots_diff_parser.add_argument(
|
plots_diff_parser.add_argument(
|
||||||
"revisions", nargs="*", default=None, help="Git commits to plot from",
|
"revisions", nargs="*", default=None, help="Git commits to plot from",
|
||||||
@@ -161,7 +156,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
_add_output_arguments(plots_diff_parser)
|
_add_output_arguments(plots_diff_parser)
|
||||||
plots_diff_parser.set_defaults(func=CmdPlotsDiff)
|
plots_diff_parser.set_defaults(func=CmdPlotsDiff)
|
||||||
|
|
||||||
PLOTS_MODIFY_HELP = "Modify display properties of plot metric files."
|
PLOTS_MODIFY_HELP = "Modify display properties of plot metrics files."
|
||||||
plots_modify_parser = plots_subparsers.add_parser(
|
plots_modify_parser = plots_subparsers.add_parser(
|
||||||
"modify",
|
"modify",
|
||||||
parents=[parent_parser],
|
parents=[parent_parser],
|
||||||
@@ -170,11 +165,8 @@ def add_parser(subparsers, parent_parser):
|
|||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
)
|
)
|
||||||
plots_modify_parser.add_argument(
|
plots_modify_parser.add_argument(
|
||||||
"target",
|
"target", help="Metric file to set properties to",
|
||||||
help="Metric file to set properties to",
|
).complete = completion.FILE
|
||||||
metavar="target",
|
|
||||||
choices=completion.Required.FILE,
|
|
||||||
)
|
|
||||||
_add_props_arguments(plots_modify_parser)
|
_add_props_arguments(plots_modify_parser)
|
||||||
plots_modify_parser.add_argument(
|
plots_modify_parser.add_argument(
|
||||||
"--unset",
|
"--unset",
|
||||||
@@ -198,8 +190,7 @@ def _add_props_arguments(parser):
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
metavar="<path>",
|
metavar="<path>",
|
||||||
choices=completion.Optional.FILE,
|
).complete = completion.FILE
|
||||||
)
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-x", default=None, help="Field name for X axis.", metavar="<field>"
|
"-x", default=None, help="Field name for X axis.", metavar="<field>"
|
||||||
)
|
)
|
||||||
@@ -231,8 +222,7 @@ def _add_output_arguments(parser):
|
|||||||
default=None,
|
default=None,
|
||||||
help="Destination path to save plots to",
|
help="Destination path to save plots to",
|
||||||
metavar="<path>",
|
metavar="<path>",
|
||||||
choices=completion.Optional.DIR,
|
).complete = completion.DIR
|
||||||
)
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--show-vega",
|
"--show-vega",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
|
|||||||
+25
-10
@@ -3,7 +3,6 @@ import logging
|
|||||||
|
|
||||||
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__)
|
||||||
@@ -17,12 +16,16 @@ class CmdRemote(CmdConfig):
|
|||||||
self.args.name = self.args.name.lower()
|
self.args.name = self.args.name.lower()
|
||||||
|
|
||||||
def _check_exists(self, conf):
|
def _check_exists(self, conf):
|
||||||
|
from dvc.config import ConfigError
|
||||||
|
|
||||||
if self.args.name not in conf["remote"]:
|
if self.args.name not in conf["remote"]:
|
||||||
raise ConfigError(f"remote '{self.args.name}' doesn't exists.")
|
raise ConfigError(f"remote '{self.args.name}' doesn't exist.")
|
||||||
|
|
||||||
|
|
||||||
class CmdRemoteAdd(CmdRemote):
|
class CmdRemoteAdd(CmdRemote):
|
||||||
def run(self):
|
def run(self):
|
||||||
|
from dvc.config import ConfigError
|
||||||
|
|
||||||
if self.args.default:
|
if self.args.default:
|
||||||
logger.info(f"Setting '{self.args.name}' as a default remote.")
|
logger.info(f"Setting '{self.args.name}' as a default remote.")
|
||||||
|
|
||||||
@@ -46,13 +49,14 @@ class CmdRemoteRemove(CmdRemote):
|
|||||||
self._check_exists(conf)
|
self._check_exists(conf)
|
||||||
del conf["remote"][self.args.name]
|
del conf["remote"][self.args.name]
|
||||||
|
|
||||||
|
up_to_level = self.args.level or "repo"
|
||||||
# Remove core.remote refs to this remote in any shadowing configs
|
# Remove core.remote refs to this remote in any shadowing configs
|
||||||
for level in reversed(self.config.LEVELS):
|
for level in reversed(self.config.LEVELS):
|
||||||
with self.config.edit(level) as conf:
|
with self.config.edit(level) as conf:
|
||||||
if conf["core"].get("remote") == self.args.name:
|
if conf["core"].get("remote") == self.args.name:
|
||||||
del conf["core"]["remote"]
|
del conf["core"]["remote"]
|
||||||
|
|
||||||
if level == self.args.level:
|
if level == up_to_level:
|
||||||
break
|
break
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@@ -60,8 +64,15 @@ class CmdRemoteRemove(CmdRemote):
|
|||||||
|
|
||||||
class CmdRemoteModify(CmdRemote):
|
class CmdRemoteModify(CmdRemote):
|
||||||
def run(self):
|
def run(self):
|
||||||
|
from dvc.config import merge
|
||||||
|
|
||||||
with self.config.edit(self.args.level) as conf:
|
with self.config.edit(self.args.level) as conf:
|
||||||
self._check_exists(conf)
|
merged = self.config.load_config_to_level(self.args.level)
|
||||||
|
merge(merged, conf)
|
||||||
|
self._check_exists(merged)
|
||||||
|
|
||||||
|
if self.args.name not in conf["remote"]:
|
||||||
|
conf["remote"][self.args.name] = {}
|
||||||
section = conf["remote"][self.args.name]
|
section = conf["remote"][self.args.name]
|
||||||
if self.args.unset:
|
if self.args.unset:
|
||||||
section.pop(self.args.option, None)
|
section.pop(self.args.option, None)
|
||||||
@@ -72,9 +83,10 @@ class CmdRemoteModify(CmdRemote):
|
|||||||
|
|
||||||
class CmdRemoteDefault(CmdRemote):
|
class CmdRemoteDefault(CmdRemote):
|
||||||
def run(self):
|
def run(self):
|
||||||
|
from dvc.config import ConfigError
|
||||||
|
|
||||||
if self.args.name is None and not self.args.unset:
|
if self.args.name is None and not self.args.unset:
|
||||||
conf = self.config.load_one(self.args.level)
|
conf = self.config.read(self.args.level)
|
||||||
try:
|
try:
|
||||||
print(conf["core"]["remote"])
|
print(conf["core"]["remote"])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@@ -102,7 +114,7 @@ class CmdRemoteDefault(CmdRemote):
|
|||||||
|
|
||||||
class CmdRemoteList(CmdRemote):
|
class CmdRemoteList(CmdRemote):
|
||||||
def run(self):
|
def run(self):
|
||||||
conf = self.config.load_one(self.args.level)
|
conf = self.config.read(self.args.level)
|
||||||
for name, conf in conf["remote"].items():
|
for name, conf in conf["remote"].items():
|
||||||
logger.info("{}\t{}".format(name, conf["url"]))
|
logger.info("{}\t{}".format(name, conf["url"]))
|
||||||
return 0
|
return 0
|
||||||
@@ -114,6 +126,8 @@ class CmdRemoteRename(CmdRemote):
|
|||||||
conf["core"]["remote"] = self.args.new
|
conf["core"]["remote"] = self.args.new
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
from dvc.config import ConfigError
|
||||||
|
|
||||||
all_config = self.config.load_config_to_level(None)
|
all_config = self.config.load_config_to_level(None)
|
||||||
if self.args.new in all_config.get("remote", {}):
|
if self.args.new in all_config.get("remote", {}):
|
||||||
raise ConfigError(
|
raise ConfigError(
|
||||||
@@ -128,8 +142,9 @@ class CmdRemoteRename(CmdRemote):
|
|||||||
del conf["remote"][self.args.name]
|
del conf["remote"][self.args.name]
|
||||||
self._rename_default(conf)
|
self._rename_default(conf)
|
||||||
|
|
||||||
|
up_to_level = self.args.level or "repo"
|
||||||
for level in reversed(self.config.LEVELS):
|
for level in reversed(self.config.LEVELS):
|
||||||
if level == self.args.level:
|
if level == up_to_level:
|
||||||
break
|
break
|
||||||
with self.config.edit(level) as level_conf:
|
with self.config.edit(level) as level_conf:
|
||||||
self._rename_default(level_conf)
|
self._rename_default(level_conf)
|
||||||
@@ -167,7 +182,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
remote_add_parser.add_argument("name", help="Name of the remote")
|
remote_add_parser.add_argument("name", help="Name of the remote")
|
||||||
remote_add_parser.add_argument(
|
remote_add_parser.add_argument(
|
||||||
"url",
|
"url",
|
||||||
help="URL. See full list of supported urls at {}".format(
|
help="Remote location. See full list of supported URLs at {}".format(
|
||||||
format_link("https://man.dvc.org/remote")
|
format_link("https://man.dvc.org/remote")
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -196,7 +211,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
)
|
)
|
||||||
remote_default_parser.add_argument(
|
remote_default_parser.add_argument(
|
||||||
"name", nargs="?", help="Name of the remote."
|
"name", nargs="?", help="Name of the remote"
|
||||||
)
|
)
|
||||||
remote_default_parser.add_argument(
|
remote_default_parser.add_argument(
|
||||||
"-u",
|
"-u",
|
||||||
@@ -215,7 +230,7 @@ def add_parser(subparsers, parent_parser):
|
|||||||
help=REMOTE_MODIFY_HELP,
|
help=REMOTE_MODIFY_HELP,
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
)
|
)
|
||||||
remote_modify_parser.add_argument("name", help="Name of the remote.")
|
remote_modify_parser.add_argument("name", help="Name of the remote")
|
||||||
remote_modify_parser.add_argument(
|
remote_modify_parser.add_argument(
|
||||||
"option", help="Name of the option to modify."
|
"option", help="Name of the option to modify."
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -14,13 +14,16 @@ class CmdRemove(CmdBase):
|
|||||||
try:
|
try:
|
||||||
self.repo.remove(target, outs=self.args.outs)
|
self.repo.remove(target, outs=self.args.outs)
|
||||||
except DvcException:
|
except DvcException:
|
||||||
logger.exception(f"failed to remove '{target}'")
|
logger.exception("")
|
||||||
return 1
|
return 1
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def add_parser(subparsers, parent_parser):
|
def add_parser(subparsers, parent_parser):
|
||||||
REMOVE_HELP = "Remove stage entry and unprotect outputs"
|
REMOVE_HELP = (
|
||||||
|
"Remove stages from dvc.yaml and/or"
|
||||||
|
" stop tracking files or directories."
|
||||||
|
)
|
||||||
remove_parser = subparsers.add_parser(
|
remove_parser = subparsers.add_parser(
|
||||||
"remove",
|
"remove",
|
||||||
parents=[parent_parser],
|
parents=[parent_parser],
|
||||||
@@ -37,8 +40,6 @@ def add_parser(subparsers, parent_parser):
|
|||||||
remove_parser.add_argument(
|
remove_parser.add_argument(
|
||||||
"targets",
|
"targets",
|
||||||
nargs="+",
|
nargs="+",
|
||||||
help="DVC-files to remove.",
|
help=".dvc files or stages from dvc.yaml to remove.",
|
||||||
metavar="targets",
|
).complete = completion.DVC_FILE
|
||||||
choices=completion.Required.DVC_FILE,
|
|
||||||
)
|
|
||||||
remove_parser.set_defaults(func=CmdRemove)
|
remove_parser.set_defaults(func=CmdRemove)
|
||||||
|
|||||||
+64
-66
@@ -1,80 +1,56 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
|
|
||||||
from dvc.command import completion
|
from dvc.command import completion
|
||||||
from dvc.command.base import CmdBase, append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
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
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CmdRepro(CmdBase):
|
class CmdRepro(CmdBase):
|
||||||
def run(self):
|
def run(self):
|
||||||
saved_dir = os.path.realpath(os.curdir)
|
stages = self.repo.reproduce(**self._repro_kwargs)
|
||||||
if self.args.cwd:
|
if len(stages) == 0:
|
||||||
os.chdir(self.args.cwd)
|
logger.info(CmdDataStatus.UP_TO_DATE_MSG)
|
||||||
|
else:
|
||||||
|
logger.info(
|
||||||
|
"Use `dvc push` to send your updates to " "remote storage."
|
||||||
|
)
|
||||||
|
|
||||||
# Dirty hack so the for loop below can at least enter once
|
if self.args.metrics:
|
||||||
if self.args.all_pipelines:
|
metrics = self.repo.metrics.show()
|
||||||
self.args.targets = [None]
|
logger.info(_show_metrics(metrics))
|
||||||
elif not self.args.targets:
|
|
||||||
self.args.targets = self.default_targets
|
|
||||||
|
|
||||||
ret = 0
|
return 0
|
||||||
for target in self.args.targets:
|
|
||||||
try:
|
|
||||||
stages = self.repo.reproduce(
|
|
||||||
target,
|
|
||||||
single_item=self.args.single_item,
|
|
||||||
force=self.args.force,
|
|
||||||
dry=self.args.dry,
|
|
||||||
interactive=self.args.interactive,
|
|
||||||
pipeline=self.args.pipeline,
|
|
||||||
all_pipelines=self.args.all_pipelines,
|
|
||||||
run_cache=not self.args.no_run_cache,
|
|
||||||
no_commit=self.args.no_commit,
|
|
||||||
downstream=self.args.downstream,
|
|
||||||
recursive=self.args.recursive,
|
|
||||||
force_downstream=self.args.force_downstream,
|
|
||||||
)
|
|
||||||
|
|
||||||
if len(stages) == 0:
|
@property
|
||||||
logger.info(CmdDataStatus.UP_TO_DATE_MSG)
|
def _repro_kwargs(self):
|
||||||
|
return {
|
||||||
if self.args.metrics:
|
"targets": self.args.targets,
|
||||||
metrics = self.repo.metrics.show()
|
"single_item": self.args.single_item,
|
||||||
show_metrics(metrics)
|
"force": self.args.force,
|
||||||
except DvcException:
|
"dry": self.args.dry,
|
||||||
logger.exception("")
|
"interactive": self.args.interactive,
|
||||||
ret = 1
|
"pipeline": self.args.pipeline,
|
||||||
break
|
"all_pipelines": self.args.all_pipelines,
|
||||||
|
"run_cache": not self.args.no_run_cache,
|
||||||
os.chdir(saved_dir)
|
"no_commit": self.args.no_commit,
|
||||||
return ret
|
"downstream": self.args.downstream,
|
||||||
|
"recursive": self.args.recursive,
|
||||||
|
"force_downstream": self.args.force_downstream,
|
||||||
|
"pull": self.args.pull,
|
||||||
|
"glob": self.args.glob,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def add_parser(subparsers, parent_parser):
|
def add_arguments(repro_parser):
|
||||||
REPRO_HELP = (
|
|
||||||
"Reproduce complete or partial pipelines by executing their stages."
|
|
||||||
)
|
|
||||||
repro_parser = subparsers.add_parser(
|
|
||||||
"repro",
|
|
||||||
parents=[parent_parser],
|
|
||||||
description=append_doc_link(REPRO_HELP, "repro"),
|
|
||||||
help=REPRO_HELP,
|
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
||||||
)
|
|
||||||
repro_parser.add_argument(
|
repro_parser.add_argument(
|
||||||
"targets",
|
"targets",
|
||||||
nargs="*",
|
nargs="*",
|
||||||
help=f"Stages to reproduce. '{PIPELINE_FILE}' by default.",
|
help="Stages to reproduce. 'dvc.yaml' by default.",
|
||||||
metavar="targets",
|
).complete = completion.DVCFILES_AND_STAGE
|
||||||
choices=completion.Optional.DVC_FILE,
|
|
||||||
)
|
|
||||||
repro_parser.add_argument(
|
repro_parser.add_argument(
|
||||||
"-f",
|
"-f",
|
||||||
"--force",
|
"--force",
|
||||||
@@ -90,13 +66,6 @@ def add_parser(subparsers, parent_parser):
|
|||||||
help="Reproduce only single data item without recursive dependencies "
|
help="Reproduce only single data item without recursive dependencies "
|
||||||
"check.",
|
"check.",
|
||||||
)
|
)
|
||||||
repro_parser.add_argument(
|
|
||||||
"-c",
|
|
||||||
"--cwd",
|
|
||||||
default=os.path.curdir,
|
|
||||||
help="Directory within your repo to reproduce from.",
|
|
||||||
metavar="<path>",
|
|
||||||
)
|
|
||||||
repro_parser.add_argument(
|
repro_parser.add_argument(
|
||||||
"-m",
|
"-m",
|
||||||
"--metrics",
|
"--metrics",
|
||||||
@@ -123,8 +92,8 @@ def add_parser(subparsers, parent_parser):
|
|||||||
"--pipeline",
|
"--pipeline",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
help="Reproduce the whole pipeline that the specified stage file "
|
help="Reproduce the whole pipeline that the specified targets "
|
||||||
"belongs to.",
|
"belong to.",
|
||||||
)
|
)
|
||||||
repro_parser.add_argument(
|
repro_parser.add_argument(
|
||||||
"-P",
|
"-P",
|
||||||
@@ -168,4 +137,33 @@ def add_parser(subparsers, parent_parser):
|
|||||||
default=False,
|
default=False,
|
||||||
help="Start from the specified stages when reproducing pipelines.",
|
help="Start from the specified stages when reproducing pipelines.",
|
||||||
)
|
)
|
||||||
|
repro_parser.add_argument(
|
||||||
|
"--pull",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help=(
|
||||||
|
"Try automatically pulling missing cache for outputs restored "
|
||||||
|
"from the run-cache."
|
||||||
|
),
|
||||||
|
)
|
||||||
|
repro_parser.add_argument(
|
||||||
|
"--glob",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Allows targets containing shell-style wildcards.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def add_parser(subparsers, parent_parser):
|
||||||
|
REPRO_HELP = (
|
||||||
|
"Reproduce complete or partial pipelines by executing their stages."
|
||||||
|
)
|
||||||
|
repro_parser = subparsers.add_parser(
|
||||||
|
"repro",
|
||||||
|
parents=[parent_parser],
|
||||||
|
description=append_doc_link(REPRO_HELP, "repro"),
|
||||||
|
help=REPRO_HELP,
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
)
|
||||||
|
add_arguments(repro_parser)
|
||||||
repro_parser.set_defaults(func=CmdRepro)
|
repro_parser.set_defaults(func=CmdRepro)
|
||||||
|
|||||||
+19
-136
@@ -2,6 +2,7 @@ import argparse
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dvc.command.base import CmdBase, append_doc_link
|
from dvc.command.base import CmdBase, append_doc_link
|
||||||
|
from dvc.command.stage import parse_cmd
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -20,8 +21,9 @@ class CmdRun(CmdBase):
|
|||||||
self.args.plots_no_cache,
|
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.checkpoints,
|
||||||
self.args.params,
|
self.args.params,
|
||||||
self.args.command,
|
self.args.cmd,
|
||||||
]
|
]
|
||||||
): # pragma: no cover
|
): # pragma: no cover
|
||||||
logger.error(
|
logger.error(
|
||||||
@@ -33,27 +35,33 @@ class CmdRun(CmdBase):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
self.repo.run(
|
self.repo.run(
|
||||||
cmd=self._parsed_cmd(),
|
cmd=parse_cmd(self.args.cmd),
|
||||||
outs=self.args.outs,
|
outs=self.args.outs,
|
||||||
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=self.args.plots,
|
||||||
plots_no_cache=self.args.plots_no_cache,
|
plots_no_cache=self.args.plots_no_cache,
|
||||||
|
live=self.args.live,
|
||||||
|
live_no_cache=self.args.live_no_cache,
|
||||||
|
live_no_summary=self.args.live_no_summary,
|
||||||
|
live_no_html=self.args.live_no_html,
|
||||||
deps=self.args.deps,
|
deps=self.args.deps,
|
||||||
params=self.args.params,
|
params=self.args.params,
|
||||||
fname=self.args.file,
|
fname=self.args.file,
|
||||||
wdir=self.args.wdir,
|
wdir=self.args.wdir,
|
||||||
no_exec=self.args.no_exec,
|
no_exec=(self.args.no_exec or bool(self.args.checkpoints)),
|
||||||
force=self.args.force,
|
force=self.args.force,
|
||||||
run_cache=not self.args.no_run_cache,
|
run_cache=not self.args.no_run_cache,
|
||||||
no_commit=self.args.no_commit,
|
no_commit=self.args.no_commit,
|
||||||
outs_persist=self.args.outs_persist,
|
outs_persist=self.args.outs_persist,
|
||||||
outs_persist_no_cache=self.args.outs_persist_no_cache,
|
outs_persist_no_cache=self.args.outs_persist_no_cache,
|
||||||
|
checkpoints=self.args.checkpoints,
|
||||||
always_changed=self.args.always_changed,
|
always_changed=self.args.always_changed,
|
||||||
name=self.args.name,
|
name=self.args.name,
|
||||||
single_stage=self.args.single_stage,
|
single_stage=self.args.single_stage,
|
||||||
external=self.args.external,
|
external=self.args.external,
|
||||||
|
desc=self.args.desc,
|
||||||
)
|
)
|
||||||
except DvcException:
|
except DvcException:
|
||||||
logger.exception("")
|
logger.exception("")
|
||||||
@@ -61,30 +69,13 @@ class CmdRun(CmdBase):
|
|||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def _parsed_cmd(self):
|
|
||||||
"""
|
|
||||||
We need to take into account two cases:
|
|
||||||
|
|
||||||
- ['python code.py foo bar']: Used mainly with dvc as a library
|
|
||||||
- ['echo', 'foo bar']: List of arguments received from the CLI
|
|
||||||
|
|
||||||
The second case would need quoting, as it was passed through:
|
|
||||||
dvc run echo "foo bar"
|
|
||||||
"""
|
|
||||||
if len(self.args.command) < 2:
|
|
||||||
return " ".join(self.args.command)
|
|
||||||
|
|
||||||
return " ".join(self._quote_argument(arg) for arg in self.args.command)
|
|
||||||
|
|
||||||
def _quote_argument(self, argument):
|
|
||||||
if " " not in argument or '"' in argument:
|
|
||||||
return argument
|
|
||||||
|
|
||||||
return f'"{argument}"'
|
|
||||||
|
|
||||||
|
|
||||||
def add_parser(subparsers, parent_parser):
|
def add_parser(subparsers, parent_parser):
|
||||||
RUN_HELP = "Generate a stage file from a command and execute the command."
|
from dvc.command.stage import _add_common_args
|
||||||
|
|
||||||
|
RUN_HELP = (
|
||||||
|
"Generate a dvc.yaml file from a command and execute the command."
|
||||||
|
)
|
||||||
run_parser = subparsers.add_parser(
|
run_parser = subparsers.add_parser(
|
||||||
"run",
|
"run",
|
||||||
parents=[parent_parser],
|
parents=[parent_parser],
|
||||||
@@ -92,95 +83,17 @@ def add_parser(subparsers, parent_parser):
|
|||||||
help=RUN_HELP,
|
help=RUN_HELP,
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
|
||||||
"-d",
|
|
||||||
"--deps",
|
|
||||||
action="append",
|
|
||||||
default=[],
|
|
||||||
help="Declare dependencies for reproducible cmd.",
|
|
||||||
metavar="<path>",
|
|
||||||
)
|
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
"-n", "--name", help="Stage name.",
|
"-n", "--name", help="Stage name.",
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
"-o",
|
"--file", metavar="<filename>", help=argparse.SUPPRESS,
|
||||||
"--outs",
|
|
||||||
action="append",
|
|
||||||
default=[],
|
|
||||||
help="Declare output file or directory.",
|
|
||||||
metavar="<filename>",
|
|
||||||
)
|
|
||||||
run_parser.add_argument(
|
|
||||||
"-O",
|
|
||||||
"--outs-no-cache",
|
|
||||||
action="append",
|
|
||||||
default=[],
|
|
||||||
help="Declare output file or directory "
|
|
||||||
"(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(
|
|
||||||
"-m",
|
|
||||||
"--metrics",
|
|
||||||
action="append",
|
|
||||||
default=[],
|
|
||||||
help="Declare output metric file.",
|
|
||||||
metavar="<path>",
|
|
||||||
)
|
|
||||||
run_parser.add_argument(
|
|
||||||
"-M",
|
|
||||||
"--metrics-no-cache",
|
|
||||||
action="append",
|
|
||||||
default=[],
|
|
||||||
help="Declare output metric file (do not put into DVC cache).",
|
|
||||||
metavar="<path>",
|
|
||||||
)
|
|
||||||
run_parser.add_argument(
|
|
||||||
"--plots",
|
|
||||||
action="append",
|
|
||||||
default=[],
|
|
||||||
help="Declare output plot file.",
|
|
||||||
metavar="<path>",
|
|
||||||
)
|
|
||||||
run_parser.add_argument(
|
|
||||||
"--plots-no-cache",
|
|
||||||
action="append",
|
|
||||||
default=[],
|
|
||||||
help="Declare output plot file (do not put into DVC cache).",
|
|
||||||
metavar="<path>",
|
|
||||||
)
|
|
||||||
run_parser.add_argument(
|
|
||||||
"--file",
|
|
||||||
help="Specify name of the DVC-file this command will generate.",
|
|
||||||
metavar="<filename>",
|
|
||||||
)
|
|
||||||
run_parser.add_argument(
|
|
||||||
"-w",
|
|
||||||
"--wdir",
|
|
||||||
help="Directory within your repo to run your command in.",
|
|
||||||
metavar="<path>",
|
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
"--no-exec",
|
"--no-exec",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
help="Only create stage file without actually running it.",
|
help="Only create dvc.yaml without actually running it.",
|
||||||
)
|
|
||||||
run_parser.add_argument(
|
|
||||||
"-f",
|
|
||||||
"--force",
|
|
||||||
action="store_true",
|
|
||||||
default=False,
|
|
||||||
help="Overwrite existing stage",
|
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
"--no-run-cache",
|
"--no-run-cache",
|
||||||
@@ -197,41 +110,11 @@ def add_parser(subparsers, parent_parser):
|
|||||||
default=False,
|
default=False,
|
||||||
help="Don't put files/directories into cache.",
|
help="Don't put files/directories into cache.",
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
|
||||||
"--outs-persist",
|
|
||||||
action="append",
|
|
||||||
default=[],
|
|
||||||
help="Declare output file or directory that will not be "
|
|
||||||
"removed upon repro.",
|
|
||||||
metavar="<filename>",
|
|
||||||
)
|
|
||||||
run_parser.add_argument(
|
|
||||||
"--outs-persist-no-cache",
|
|
||||||
action="append",
|
|
||||||
default=[],
|
|
||||||
help="Declare output file or directory that will not be "
|
|
||||||
"removed upon repro (do not put into DVC cache).",
|
|
||||||
metavar="<filename>",
|
|
||||||
)
|
|
||||||
run_parser.add_argument(
|
|
||||||
"--always-changed",
|
|
||||||
action="store_true",
|
|
||||||
default=False,
|
|
||||||
help="Always consider this DVC-file as changed.",
|
|
||||||
)
|
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
"--single-stage",
|
"--single-stage",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
help=argparse.SUPPRESS,
|
help=argparse.SUPPRESS,
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
_add_common_args(run_parser)
|
||||||
"--external",
|
|
||||||
action="store_true",
|
|
||||||
default=False,
|
|
||||||
help="Allow outputs that are outside of the DVC repository.",
|
|
||||||
)
|
|
||||||
run_parser.add_argument(
|
|
||||||
"command", nargs=argparse.REMAINDER, help="Command to execute."
|
|
||||||
)
|
|
||||||
run_parser.set_defaults(func=CmdRun)
|
run_parser.set_defaults(func=CmdRun)
|
||||||
|
|||||||
@@ -0,0 +1,364 @@
|
|||||||
|
import argparse
|
||||||
|
import logging
|
||||||
|
from itertools import chain, filterfalse
|
||||||
|
from typing import TYPE_CHECKING, Dict, Iterable, List
|
||||||
|
|
||||||
|
from dvc.command import completion
|
||||||
|
from dvc.command.base import CmdBase, append_doc_link, fix_subparsers
|
||||||
|
from dvc.utils.cli_parse import parse_params
|
||||||
|
from dvc.utils.humanize import truncate_text
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from dvc.output.base import BaseOutput
|
||||||
|
from dvc.stage import Stage
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
MAX_TEXT_LENGTH = 80
|
||||||
|
|
||||||
|
|
||||||
|
def generate_description(stage: "Stage") -> str:
|
||||||
|
def part_desc(outs: Iterable["BaseOutput"]) -> str:
|
||||||
|
return ", ".join(out.def_path for out in outs)
|
||||||
|
|
||||||
|
if not stage.deps and not stage.outs:
|
||||||
|
return "No outputs or dependencies"
|
||||||
|
|
||||||
|
if not stage.outs and stage.deps:
|
||||||
|
return "Depends on " + part_desc(stage.deps)
|
||||||
|
|
||||||
|
def is_plot_or_metric(out: "BaseOutput"):
|
||||||
|
return bool(out.plot) or bool(out.metric)
|
||||||
|
|
||||||
|
desc: List[str] = []
|
||||||
|
|
||||||
|
outs = list(filterfalse(is_plot_or_metric, stage.outs))
|
||||||
|
if outs:
|
||||||
|
desc.append("Outputs " + part_desc(outs))
|
||||||
|
|
||||||
|
plots_and_metrics = list(filter(is_plot_or_metric, stage.outs))
|
||||||
|
if plots_and_metrics:
|
||||||
|
desc.append("Reports " + part_desc(plots_and_metrics))
|
||||||
|
|
||||||
|
return "; ".join(desc)
|
||||||
|
|
||||||
|
|
||||||
|
def prepare_description(
|
||||||
|
stage: "Stage", max_length: int = MAX_TEXT_LENGTH
|
||||||
|
) -> str:
|
||||||
|
desc = stage.short_description() or generate_description(stage)
|
||||||
|
return truncate_text(desc, max_length)
|
||||||
|
|
||||||
|
|
||||||
|
def prepare_stages_data(
|
||||||
|
stages: Iterable["Stage"],
|
||||||
|
description: bool = True,
|
||||||
|
max_length: int = MAX_TEXT_LENGTH,
|
||||||
|
) -> Dict[str, str]:
|
||||||
|
return {
|
||||||
|
stage.addressing: prepare_description(stage, max_length=max_length)
|
||||||
|
if description
|
||||||
|
else ""
|
||||||
|
for stage in stages
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class CmdStageList(CmdBase):
|
||||||
|
def _get_stages(self) -> Iterable["Stage"]:
|
||||||
|
if self.args.all:
|
||||||
|
stages: List["Stage"] = self.repo.stages # type: ignore
|
||||||
|
logger.trace( # type: ignore[attr-defined]
|
||||||
|
"%d no. of stages found", len(stages)
|
||||||
|
)
|
||||||
|
return stages
|
||||||
|
|
||||||
|
# removing duplicates while maintaining order
|
||||||
|
collected = chain.from_iterable(
|
||||||
|
self.repo.stage.collect(
|
||||||
|
target=target,
|
||||||
|
recursive=self.args.recursive,
|
||||||
|
accept_group=True,
|
||||||
|
)
|
||||||
|
for target in self.args.targets
|
||||||
|
)
|
||||||
|
return dict.fromkeys(collected).keys()
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
from dvc.utils.diff import table
|
||||||
|
|
||||||
|
def log_error(relpath: str, exc: Exception):
|
||||||
|
if self.args.fail:
|
||||||
|
raise exc
|
||||||
|
logger.debug("Stages from %s failed to load", relpath)
|
||||||
|
|
||||||
|
# silence stage collection error by default
|
||||||
|
self.repo.stage_collection_error_handler = log_error
|
||||||
|
|
||||||
|
stages = self._get_stages()
|
||||||
|
names_only = self.args.names_only
|
||||||
|
|
||||||
|
data = prepare_stages_data(stages, description=not names_only)
|
||||||
|
if data:
|
||||||
|
print(table(header=(), rows=data.items()))
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def parse_cmd(commands: List[str]) -> str:
|
||||||
|
"""
|
||||||
|
We need to take into account two cases:
|
||||||
|
|
||||||
|
- ['python code.py foo bar']: Used mainly with dvc as a library
|
||||||
|
- ['echo', 'foo bar']: List of arguments received from the CLI
|
||||||
|
|
||||||
|
The second case would need quoting, as it was passed through:
|
||||||
|
dvc run echo "foo bar"
|
||||||
|
"""
|
||||||
|
|
||||||
|
def quote_argument(arg: str):
|
||||||
|
should_quote = " " in arg and '"' not in arg
|
||||||
|
return f'"{arg}"' if should_quote else arg
|
||||||
|
|
||||||
|
if len(commands) < 2:
|
||||||
|
return " ".join(commands)
|
||||||
|
return " ".join(map(quote_argument, commands))
|
||||||
|
|
||||||
|
|
||||||
|
class CmdStageAdd(CmdBase):
|
||||||
|
def run(self):
|
||||||
|
kwargs = vars(self.args)
|
||||||
|
kwargs.update(
|
||||||
|
{
|
||||||
|
"cmd": parse_cmd(kwargs.pop("cmd")),
|
||||||
|
"params": parse_params(self.args.params),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
self.repo.stage.add(**kwargs)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def _add_common_args(parser):
|
||||||
|
parser.add_argument(
|
||||||
|
"-d",
|
||||||
|
"--deps",
|
||||||
|
action="append",
|
||||||
|
default=[],
|
||||||
|
help="Declare dependencies for reproducible cmd.",
|
||||||
|
metavar="<path>",
|
||||||
|
).complete = completion.FILE
|
||||||
|
parser.add_argument(
|
||||||
|
"-o",
|
||||||
|
"--outs",
|
||||||
|
action="append",
|
||||||
|
default=[],
|
||||||
|
help="Declare output file or directory.",
|
||||||
|
metavar="<filename>",
|
||||||
|
).complete = completion.FILE
|
||||||
|
parser.add_argument(
|
||||||
|
"-O",
|
||||||
|
"--outs-no-cache",
|
||||||
|
action="append",
|
||||||
|
default=[],
|
||||||
|
help="Declare output file or directory "
|
||||||
|
"(do not put into DVC cache).",
|
||||||
|
metavar="<filename>",
|
||||||
|
).complete = completion.FILE
|
||||||
|
parser.add_argument(
|
||||||
|
"-p",
|
||||||
|
"--params",
|
||||||
|
action="append",
|
||||||
|
default=[],
|
||||||
|
help="Declare parameter to use as additional dependency.",
|
||||||
|
metavar="[<filename>:]<params_list>",
|
||||||
|
).complete = completion.FILE
|
||||||
|
parser.add_argument(
|
||||||
|
"-m",
|
||||||
|
"--metrics",
|
||||||
|
action="append",
|
||||||
|
default=[],
|
||||||
|
help="Declare output metrics file.",
|
||||||
|
metavar="<path>",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-M",
|
||||||
|
"--metrics-no-cache",
|
||||||
|
action="append",
|
||||||
|
default=[],
|
||||||
|
help="Declare output metrics file (do not put into DVC cache).",
|
||||||
|
metavar="<path>",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--plots",
|
||||||
|
action="append",
|
||||||
|
default=[],
|
||||||
|
help="Declare output plot file.",
|
||||||
|
metavar="<path>",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--plots-no-cache",
|
||||||
|
action="append",
|
||||||
|
default=[],
|
||||||
|
help="Declare output plot file (do not put into DVC cache).",
|
||||||
|
metavar="<path>",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--live", help="Declare output as dvclive.", metavar="<path>",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--live-no-cache",
|
||||||
|
help="Declare output as dvclive (do not put into DVC cache).",
|
||||||
|
metavar="<path>",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--live-no-summary",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Signal dvclive logger to not dump latest metrics file.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--live-no-html",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Signal dvclive logger to not produce training report.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-w",
|
||||||
|
"--wdir",
|
||||||
|
help="Directory within your repo to run your command in.",
|
||||||
|
metavar="<path>",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-f",
|
||||||
|
"--force",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Overwrite existing stage",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--outs-persist",
|
||||||
|
action="append",
|
||||||
|
default=[],
|
||||||
|
help="Declare output file or directory that will not be "
|
||||||
|
"removed upon repro.",
|
||||||
|
metavar="<filename>",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--outs-persist-no-cache",
|
||||||
|
action="append",
|
||||||
|
default=[],
|
||||||
|
help="Declare output file or directory that will not be "
|
||||||
|
"removed upon repro (do not put into DVC cache).",
|
||||||
|
metavar="<filename>",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-c",
|
||||||
|
"--checkpoints",
|
||||||
|
action="append",
|
||||||
|
default=[],
|
||||||
|
help=argparse.SUPPRESS,
|
||||||
|
metavar="<filename>",
|
||||||
|
).complete = completion.FILE
|
||||||
|
parser.add_argument(
|
||||||
|
"--always-changed",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Always consider this DVC-file as changed.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--external",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Allow outputs that are outside of the DVC repository.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--desc",
|
||||||
|
type=str,
|
||||||
|
metavar="<text>",
|
||||||
|
help=(
|
||||||
|
"User description of the stage (optional). "
|
||||||
|
"This doesn't affect any DVC operations."
|
||||||
|
),
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"cmd",
|
||||||
|
nargs=argparse.REMAINDER,
|
||||||
|
help="Command to execute.",
|
||||||
|
metavar="command",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def add_parser(subparsers, parent_parser):
|
||||||
|
STAGES_HELP = "Commands to list and create stages."
|
||||||
|
|
||||||
|
stage_parser = subparsers.add_parser(
|
||||||
|
"stage",
|
||||||
|
parents=[parent_parser],
|
||||||
|
description=append_doc_link(STAGES_HELP, "stage"),
|
||||||
|
help=STAGES_HELP,
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
)
|
||||||
|
|
||||||
|
stage_subparsers = stage_parser.add_subparsers(
|
||||||
|
dest="cmd",
|
||||||
|
help="Use `dvc stage CMD --help` to display command-specific help.",
|
||||||
|
)
|
||||||
|
|
||||||
|
fix_subparsers(stage_subparsers)
|
||||||
|
|
||||||
|
STAGE_ADD_HELP = "Create stage"
|
||||||
|
stage_add_parser = stage_subparsers.add_parser(
|
||||||
|
"add",
|
||||||
|
parents=[parent_parser],
|
||||||
|
description=append_doc_link(STAGE_ADD_HELP, "stage/add"),
|
||||||
|
help=STAGE_ADD_HELP,
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
)
|
||||||
|
stage_add_parser.add_argument(
|
||||||
|
"-n", "--name", help="Name of the stage to add", required=True
|
||||||
|
)
|
||||||
|
_add_common_args(stage_add_parser)
|
||||||
|
stage_add_parser.set_defaults(func=CmdStageAdd)
|
||||||
|
|
||||||
|
STAGE_LIST_HELP = "List stages."
|
||||||
|
stage_list_parser = stage_subparsers.add_parser(
|
||||||
|
"list",
|
||||||
|
parents=[parent_parser],
|
||||||
|
description=append_doc_link(STAGE_LIST_HELP, "stage/list"),
|
||||||
|
help=STAGE_LIST_HELP,
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
)
|
||||||
|
stage_list_parser.add_argument(
|
||||||
|
"targets",
|
||||||
|
nargs="*",
|
||||||
|
default=["dvc.yaml"],
|
||||||
|
help=(
|
||||||
|
"Show stages from a dvc.yaml/.dvc file or a directory. "
|
||||||
|
"'dvc.yaml' by default"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
stage_list_parser.add_argument(
|
||||||
|
"--all",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="List all of the stages in the repo.",
|
||||||
|
)
|
||||||
|
stage_list_parser.add_argument(
|
||||||
|
"--fail",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Fail immediately, do not suppress any syntax errors.",
|
||||||
|
)
|
||||||
|
stage_list_parser.add_argument(
|
||||||
|
"-R",
|
||||||
|
"--recursive",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="List all stages inside the specified directory.",
|
||||||
|
)
|
||||||
|
stage_list_parser.add_argument(
|
||||||
|
"--names-only",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="List only stage names.",
|
||||||
|
)
|
||||||
|
stage_list_parser.set_defaults(func=CmdStageList)
|
||||||
+16
-2
@@ -1,6 +1,8 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dvc.command.data_sync import CmdDataBase
|
from dvc.command.data_sync import CmdDataBase
|
||||||
|
from dvc.exceptions import DvcException
|
||||||
|
from dvc.utils import format_link
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -9,6 +11,11 @@ class CmdDataStatus(CmdDataBase):
|
|||||||
STATUS_LEN = 20
|
STATUS_LEN = 20
|
||||||
STATUS_INDENT = "\t"
|
STATUS_INDENT = "\t"
|
||||||
UP_TO_DATE_MSG = "Data and pipelines are up to date."
|
UP_TO_DATE_MSG = "Data and pipelines are up to date."
|
||||||
|
IN_SYNC_MSG = "Cache and remote '{remote}' are in sync."
|
||||||
|
EMPTY_PROJECT_MSG = (
|
||||||
|
"There are no data or pipelines tracked in this project yet.\n"
|
||||||
|
"See {link} to get started!"
|
||||||
|
).format(link=format_link("https://dvc.org/doc/start"))
|
||||||
|
|
||||||
def _normalize(self, s):
|
def _normalize(self, s):
|
||||||
s += ":"
|
s += ":"
|
||||||
@@ -60,10 +67,17 @@ class CmdDataStatus(CmdDataBase):
|
|||||||
logger.info(json.dumps(st))
|
logger.info(json.dumps(st))
|
||||||
elif st:
|
elif st:
|
||||||
self._show(st, indent)
|
self._show(st, indent)
|
||||||
|
elif not self.repo.stages:
|
||||||
|
logger.info(self.EMPTY_PROJECT_MSG)
|
||||||
|
elif self.args.cloud or self.args.remote:
|
||||||
|
remote = self.args.remote or self.repo.config["core"].get(
|
||||||
|
"remote"
|
||||||
|
)
|
||||||
|
logger.info(self.IN_SYNC_MSG.format(remote=remote))
|
||||||
else:
|
else:
|
||||||
logger.info(self.UP_TO_DATE_MSG)
|
logger.info(self.UP_TO_DATE_MSG)
|
||||||
|
|
||||||
except Exception:
|
except DvcException:
|
||||||
logger.exception("failed to obtain data status")
|
logger.exception("")
|
||||||
return 1
|
return 1
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@@ -33,10 +33,6 @@ def add_parser(subparsers, parent_parser):
|
|||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
)
|
)
|
||||||
unprotect_parser.add_argument(
|
unprotect_parser.add_argument(
|
||||||
"targets",
|
"targets", nargs="+", help="Data files/directories to unprotect.",
|
||||||
nargs="+",
|
).complete = completion.FILE
|
||||||
help="Data files/directories to unprotect.",
|
|
||||||
metavar="targets",
|
|
||||||
choices=completion.Required.FILE,
|
|
||||||
)
|
|
||||||
unprotect_parser.set_defaults(func=CmdUnprotect)
|
unprotect_parser.set_defaults(func=CmdUnprotect)
|
||||||
|
|||||||
+28
-6
@@ -16,6 +16,9 @@ class CmdUpdate(CmdBase):
|
|||||||
targets=self.args.targets,
|
targets=self.args.targets,
|
||||||
rev=self.args.rev,
|
rev=self.args.rev,
|
||||||
recursive=self.args.recursive,
|
recursive=self.args.recursive,
|
||||||
|
to_remote=self.args.to_remote,
|
||||||
|
remote=self.args.remote,
|
||||||
|
jobs=self.args.jobs,
|
||||||
)
|
)
|
||||||
except DvcException:
|
except DvcException:
|
||||||
logger.exception("failed update data")
|
logger.exception("failed update data")
|
||||||
@@ -33,12 +36,8 @@ def add_parser(subparsers, parent_parser):
|
|||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
)
|
)
|
||||||
update_parser.add_argument(
|
update_parser.add_argument(
|
||||||
"targets",
|
"targets", nargs="+", help=".dvc files to update.",
|
||||||
nargs="+",
|
).complete = completion.DVC_FILE
|
||||||
help="DVC-files to update.",
|
|
||||||
metavar="targets",
|
|
||||||
choices=completion.Required.DVC_FILE,
|
|
||||||
)
|
|
||||||
update_parser.add_argument(
|
update_parser.add_argument(
|
||||||
"--rev",
|
"--rev",
|
||||||
nargs="?",
|
nargs="?",
|
||||||
@@ -52,4 +51,27 @@ def add_parser(subparsers, parent_parser):
|
|||||||
default=False,
|
default=False,
|
||||||
help="Update all stages in the specified directory.",
|
help="Update all stages in the specified directory.",
|
||||||
)
|
)
|
||||||
|
update_parser.add_argument(
|
||||||
|
"--to-remote",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Update data directly on the remote",
|
||||||
|
)
|
||||||
|
update_parser.add_argument(
|
||||||
|
"-r",
|
||||||
|
"--remote",
|
||||||
|
help="Remote storage to perform updates to",
|
||||||
|
metavar="<name>",
|
||||||
|
)
|
||||||
|
update_parser.add_argument(
|
||||||
|
"-j",
|
||||||
|
"--jobs",
|
||||||
|
type=int,
|
||||||
|
help=(
|
||||||
|
"Number of jobs to run simultaneously. "
|
||||||
|
"The default value is 4 * cpu_count(). "
|
||||||
|
"For SSH remotes, the default is 4. "
|
||||||
|
),
|
||||||
|
metavar="<number>",
|
||||||
|
)
|
||||||
update_parser.set_defaults(func=CmdUpdate)
|
update_parser.set_defaults(func=CmdUpdate)
|
||||||
|
|||||||
+4
-130
@@ -1,146 +1,19 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import itertools
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import pathlib
|
|
||||||
import platform
|
|
||||||
import uuid
|
|
||||||
|
|
||||||
from dvc.command.base import CmdBaseNoRepo, append_doc_link
|
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:
|
|
||||||
import psutil
|
|
||||||
except ImportError:
|
|
||||||
psutil = None
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CmdVersion(CmdBaseNoRepo):
|
class CmdVersion(CmdBaseNoRepo):
|
||||||
def run(self):
|
def run(self):
|
||||||
from dvc.repo import Repo
|
from dvc.info import get_dvc_info
|
||||||
|
|
||||||
info = [
|
dvc_info = get_dvc_info()
|
||||||
f"DVC version: {__version__}",
|
logger.info(dvc_info)
|
||||||
f"Python version: {platform.python_version()}",
|
|
||||||
f"Platform: {platform.platform()}",
|
|
||||||
f"Binary: {is_binary()}",
|
|
||||||
f"Package: {PKG}",
|
|
||||||
f"Supported remotes: {self.get_supported_remotes()}",
|
|
||||||
]
|
|
||||||
|
|
||||||
try:
|
|
||||||
repo = Repo()
|
|
||||||
root_directory = repo.root_dir
|
|
||||||
|
|
||||||
# cache_dir might not exist yet (e.g. after `dvc init`), and we
|
|
||||||
# can't auto-create it, as it might cause issues if the user
|
|
||||||
# later decides to enable shared cache mode with
|
|
||||||
# `dvc config cache.shared group`.
|
|
||||||
if os.path.exists(repo.cache.local.cache_dir):
|
|
||||||
info.append(
|
|
||||||
"Cache: {}".format(self.get_linktype_support_info(repo))
|
|
||||||
)
|
|
||||||
if psutil:
|
|
||||||
fs_type = self.get_fs_type(repo.cache.local.cache_dir)
|
|
||||||
info.append(
|
|
||||||
f"Filesystem type (cache directory): {fs_type}"
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
logger.warning(
|
|
||||||
"Unable to detect supported link types, as cache "
|
|
||||||
"directory '{}' doesn't exist. It is usually auto-created "
|
|
||||||
"by commands such as `dvc add/fetch/pull/run/import`, "
|
|
||||||
"but you could create it manually to enable this "
|
|
||||||
"check.".format(relpath(repo.cache.local.cache_dir))
|
|
||||||
)
|
|
||||||
|
|
||||||
except NotDvcRepoError:
|
|
||||||
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:
|
|
||||||
fs_root = self.get_fs_type(os.path.abspath(root_directory))
|
|
||||||
info.append(f"Filesystem type (workspace): {fs_root}")
|
|
||||||
|
|
||||||
logger.info("\n".join(info))
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_fs_type(path):
|
|
||||||
partition = {
|
|
||||||
pathlib.Path(part.mountpoint): (part.fstype, part.device)
|
|
||||||
for part in psutil.disk_partitions(all=True)
|
|
||||||
}
|
|
||||||
|
|
||||||
path = pathlib.Path(path)
|
|
||||||
|
|
||||||
for parent in itertools.chain([path], path.parents):
|
|
||||||
if parent in partition:
|
|
||||||
return partition[parent]
|
|
||||||
return ("unknown", "none")
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_linktype_support_info(repo):
|
|
||||||
links = {
|
|
||||||
"reflink": (System.reflink, None),
|
|
||||||
"hardlink": (System.hardlink, System.is_hardlink),
|
|
||||||
"symlink": (System.symlink, System.is_symlink),
|
|
||||||
}
|
|
||||||
|
|
||||||
fname = "." + str(uuid.uuid4())
|
|
||||||
src = os.path.join(repo.cache.local.cache_dir, fname)
|
|
||||||
open(src, "w").close()
|
|
||||||
dst = os.path.join(repo.root_dir, fname)
|
|
||||||
|
|
||||||
cache = []
|
|
||||||
|
|
||||||
for name, (link, is_link) in links.items():
|
|
||||||
try:
|
|
||||||
link(src, dst)
|
|
||||||
status = "supported"
|
|
||||||
if is_link and not is_link(dst):
|
|
||||||
status = "broken"
|
|
||||||
os.unlink(dst)
|
|
||||||
except DvcException:
|
|
||||||
status = "not supported"
|
|
||||||
cache.append(f"{name} - {status}")
|
|
||||||
os.remove(src)
|
|
||||||
|
|
||||||
return ", ".join(cache)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_supported_remotes():
|
|
||||||
from dvc.remote import TREES
|
|
||||||
|
|
||||||
supported_remotes = []
|
|
||||||
for tree_cls in TREES:
|
|
||||||
if not tree_cls.get_missing_deps():
|
|
||||||
supported_remotes.append(tree_cls.scheme)
|
|
||||||
|
|
||||||
return ", ".join(supported_remotes)
|
|
||||||
|
|
||||||
|
|
||||||
def _get_dvc_repo_info(repo):
|
|
||||||
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):
|
def add_parser(subparsers, parent_parser):
|
||||||
VERSION_HELP = (
|
VERSION_HELP = (
|
||||||
@@ -152,5 +25,6 @@ def add_parser(subparsers, parent_parser):
|
|||||||
description=append_doc_link(VERSION_HELP, "version"),
|
description=append_doc_link(VERSION_HELP, "version"),
|
||||||
help=VERSION_HELP,
|
help=VERSION_HELP,
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
aliases=["doctor"],
|
||||||
)
|
)
|
||||||
version_parser.set_defaults(func=CmdVersion)
|
version_parser.set_defaults(func=CmdVersion)
|
||||||
|
|||||||
+102
-208
@@ -4,25 +4,11 @@ import os
|
|||||||
import re
|
import re
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from urllib.parse import urlparse
|
|
||||||
|
|
||||||
import configobj
|
from funcy import cached_property, compact, memoize, re_find
|
||||||
from funcy import cached_property, compact, re_find, walk_values
|
|
||||||
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.path_info import PathInfo
|
||||||
from dvc.utils import relpath
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -38,174 +24,19 @@ class NoRemoteError(ConfigError):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def supported_cache_type(types):
|
@memoize
|
||||||
"""Checks if link type config option consists only of valid values.
|
def get_compiled_schema():
|
||||||
|
from voluptuous import Schema
|
||||||
|
|
||||||
Args:
|
from .config_schema import SCHEMA
|
||||||
types (list/string): type(s) of links that dvc should try out.
|
|
||||||
"""
|
|
||||||
if types is None:
|
|
||||||
return None
|
|
||||||
if isinstance(types, str):
|
|
||||||
types = [typ.strip() for typ in types.split(",")]
|
|
||||||
|
|
||||||
unsupported = set(types) - {"reflink", "hardlink", "symlink", "copy"}
|
return Schema(SCHEMA)
|
||||||
if unsupported:
|
|
||||||
raise Invalid(
|
|
||||||
"Unsupported cache type(s): {}".format(", ".join(unsupported))
|
|
||||||
)
|
|
||||||
|
|
||||||
return types
|
|
||||||
|
|
||||||
|
|
||||||
# Checks that value is either true or false and converts it to bool
|
def to_bool(value):
|
||||||
to_bool = Bool = All(
|
from .config_schema import Bool
|
||||||
Lower,
|
|
||||||
Any("true", "false"),
|
|
||||||
lambda v: v == "true",
|
|
||||||
msg="expected true or false",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
return Bool(value)
|
||||||
def Choices(*choices):
|
|
||||||
"""Checks that value belongs to the specified set of values
|
|
||||||
|
|
||||||
Args:
|
|
||||||
*choices: pass allowed values as arguments, or pass a list or
|
|
||||||
tuple as a single argument
|
|
||||||
"""
|
|
||||||
return Any(*choices, msg="expected one of {}".format(", ".join(choices)))
|
|
||||||
|
|
||||||
|
|
||||||
def ByUrl(mapping):
|
|
||||||
schemas = walk_values(Schema, mapping)
|
|
||||||
|
|
||||||
def validate(data):
|
|
||||||
if "url" not in data:
|
|
||||||
raise Invalid("expected 'url'")
|
|
||||||
|
|
||||||
parsed = urlparse(data["url"])
|
|
||||||
# Windows absolute paths should really have scheme == "" (local)
|
|
||||||
if os.name == "nt" and len(parsed.scheme) == 1 and parsed.netloc == "":
|
|
||||||
return schemas[""](data)
|
|
||||||
if parsed.scheme not in schemas:
|
|
||||||
raise Invalid(f"Unsupported URL type {parsed.scheme}://")
|
|
||||||
|
|
||||||
return schemas[parsed.scheme](data)
|
|
||||||
|
|
||||||
return validate
|
|
||||||
|
|
||||||
|
|
||||||
class RelPath(str):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
REMOTE_COMMON = {
|
|
||||||
"url": str,
|
|
||||||
"checksum_jobs": All(Coerce(int), Range(1)),
|
|
||||||
Optional("no_traverse"): Bool, # obsoleted
|
|
||||||
"verify": Bool,
|
|
||||||
}
|
|
||||||
LOCAL_COMMON = {
|
|
||||||
"type": supported_cache_type,
|
|
||||||
Optional("protected", default=False): Bool, # obsoleted
|
|
||||||
"shared": All(Lower, Choices("group")),
|
|
||||||
Optional("slow_link_warning", default=True): Bool,
|
|
||||||
}
|
|
||||||
HTTP_COMMON = {
|
|
||||||
"auth": All(Lower, Choices("basic", "digest", "custom")),
|
|
||||||
"custom_auth_header": str,
|
|
||||||
"user": str,
|
|
||||||
"password": str,
|
|
||||||
"ask_password": Bool,
|
|
||||||
}
|
|
||||||
SCHEMA = {
|
|
||||||
"core": {
|
|
||||||
"remote": Lower,
|
|
||||||
"checksum_jobs": All(Coerce(int), Range(1)),
|
|
||||||
Optional("interactive", default=False): Bool,
|
|
||||||
Optional("analytics", default=True): Bool,
|
|
||||||
Optional("hardlink_lock", default=False): Bool,
|
|
||||||
Optional("no_scm", default=False): Bool,
|
|
||||||
},
|
|
||||||
"cache": {
|
|
||||||
"local": str,
|
|
||||||
"s3": str,
|
|
||||||
"gs": str,
|
|
||||||
"hdfs": str,
|
|
||||||
"ssh": str,
|
|
||||||
"azure": str,
|
|
||||||
# This is for default local cache
|
|
||||||
"dir": str,
|
|
||||||
**LOCAL_COMMON,
|
|
||||||
},
|
|
||||||
"remote": {
|
|
||||||
str: ByUrl(
|
|
||||||
{
|
|
||||||
"": {**LOCAL_COMMON, **REMOTE_COMMON},
|
|
||||||
"s3": {
|
|
||||||
"region": str,
|
|
||||||
"profile": str,
|
|
||||||
"credentialpath": str,
|
|
||||||
"endpointurl": str,
|
|
||||||
Optional("listobjects", default=False): Bool,
|
|
||||||
Optional("use_ssl", default=True): Bool,
|
|
||||||
"sse": str,
|
|
||||||
"sse_kms_key_id": str,
|
|
||||||
"acl": str,
|
|
||||||
"grant_read": str,
|
|
||||||
"grant_read_acp": str,
|
|
||||||
"grant_write_acp": str,
|
|
||||||
"grant_full_control": str,
|
|
||||||
**REMOTE_COMMON,
|
|
||||||
},
|
|
||||||
"gs": {
|
|
||||||
"projectname": str,
|
|
||||||
"credentialpath": str,
|
|
||||||
**REMOTE_COMMON,
|
|
||||||
},
|
|
||||||
"ssh": {
|
|
||||||
"type": supported_cache_type,
|
|
||||||
"port": Coerce(int),
|
|
||||||
"user": str,
|
|
||||||
"password": str,
|
|
||||||
"ask_password": Bool,
|
|
||||||
"keyfile": str,
|
|
||||||
"timeout": Coerce(int),
|
|
||||||
"gss_auth": Bool,
|
|
||||||
**REMOTE_COMMON,
|
|
||||||
},
|
|
||||||
"hdfs": {"user": str, **REMOTE_COMMON},
|
|
||||||
"azure": {"connection_string": str, **REMOTE_COMMON},
|
|
||||||
"oss": {
|
|
||||||
"oss_key_id": str,
|
|
||||||
"oss_key_secret": str,
|
|
||||||
"oss_endpoint": str,
|
|
||||||
**REMOTE_COMMON,
|
|
||||||
},
|
|
||||||
"gdrive": {
|
|
||||||
"gdrive_use_service_account": Bool,
|
|
||||||
"gdrive_client_id": str,
|
|
||||||
"gdrive_client_secret": str,
|
|
||||||
"gdrive_user_credentials_file": str,
|
|
||||||
"gdrive_service_account_email": str,
|
|
||||||
"gdrive_service_account_user_email": str,
|
|
||||||
"gdrive_service_account_p12_file_path": str,
|
|
||||||
Optional("gdrive_trash_only", default=False): Bool,
|
|
||||||
**REMOTE_COMMON,
|
|
||||||
},
|
|
||||||
"http": {**HTTP_COMMON, **REMOTE_COMMON},
|
|
||||||
"https": {**HTTP_COMMON, **REMOTE_COMMON},
|
|
||||||
"remote": {str: object}, # Any of the above options are valid
|
|
||||||
}
|
|
||||||
)
|
|
||||||
},
|
|
||||||
"state": {
|
|
||||||
"row_limit": All(Coerce(int), Range(1)),
|
|
||||||
"row_cleanup_quota": All(Coerce(int), Range(0, 100)),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
COMPILED_SCHEMA = Schema(SCHEMA)
|
|
||||||
|
|
||||||
|
|
||||||
class Config(dict):
|
class Config(dict):
|
||||||
@@ -231,7 +62,11 @@ class Config(dict):
|
|||||||
CONFIG = "config"
|
CONFIG = "config"
|
||||||
CONFIG_LOCAL = "config.local"
|
CONFIG_LOCAL = "config.local"
|
||||||
|
|
||||||
def __init__(self, dvc_dir=None, validate=True):
|
def __init__(
|
||||||
|
self, dvc_dir=None, validate=True, fs=None, config=None,
|
||||||
|
): # pylint: disable=super-init-not-called
|
||||||
|
from dvc.fs.local import LocalFileSystem
|
||||||
|
|
||||||
self.dvc_dir = dvc_dir
|
self.dvc_dir = dvc_dir
|
||||||
|
|
||||||
if not dvc_dir:
|
if not dvc_dir:
|
||||||
@@ -244,11 +79,14 @@ class Config(dict):
|
|||||||
else:
|
else:
|
||||||
self.dvc_dir = os.path.abspath(os.path.realpath(dvc_dir))
|
self.dvc_dir = os.path.abspath(os.path.realpath(dvc_dir))
|
||||||
|
|
||||||
self.load(validate=validate)
|
self.wfs = LocalFileSystem(None, {"url": self.dvc_dir})
|
||||||
|
self.fs = fs or self.wfs
|
||||||
|
|
||||||
|
self.load(validate=validate, config=config)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_dir(cls, level):
|
def get_dir(cls, level):
|
||||||
from appdirs import user_config_dir, site_config_dir
|
from appdirs import site_config_dir, user_config_dir
|
||||||
|
|
||||||
assert level in ("global", "system")
|
assert level in ("global", "system")
|
||||||
|
|
||||||
@@ -284,7 +122,7 @@ class Config(dict):
|
|||||||
open(config_file, "w+").close()
|
open(config_file, "w+").close()
|
||||||
return Config(dvc_dir)
|
return Config(dvc_dir)
|
||||||
|
|
||||||
def load(self, validate=True):
|
def load(self, validate=True, config=None):
|
||||||
"""Loads config from all the config files.
|
"""Loads config from all the config files.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
@@ -292,6 +130,9 @@ class Config(dict):
|
|||||||
"""
|
"""
|
||||||
conf = self.load_config_to_level()
|
conf = self.load_config_to_level()
|
||||||
|
|
||||||
|
if config is not None:
|
||||||
|
merge(conf, config)
|
||||||
|
|
||||||
if validate:
|
if validate:
|
||||||
conf = self.validate(conf)
|
conf = self.validate(conf)
|
||||||
|
|
||||||
@@ -302,12 +143,45 @@ class Config(dict):
|
|||||||
if not self["cache"].get("dir") and self.dvc_dir:
|
if not self["cache"].get("dir") and self.dvc_dir:
|
||||||
self["cache"]["dir"] = os.path.join(self.dvc_dir, "cache")
|
self["cache"]["dir"] = os.path.join(self.dvc_dir, "cache")
|
||||||
|
|
||||||
|
def _get_fs(self, level):
|
||||||
|
# NOTE: this might be a Gitfs, which doesn't see things outside of
|
||||||
|
# the repo.
|
||||||
|
return self.fs if level == "repo" else self.wfs
|
||||||
|
|
||||||
|
def _load_config(self, level):
|
||||||
|
from configobj import ConfigObj
|
||||||
|
|
||||||
|
filename = self.files[level]
|
||||||
|
fs = self._get_fs(level)
|
||||||
|
|
||||||
|
if fs.exists(filename, use_dvcignore=False):
|
||||||
|
with fs.open(filename) as fobj:
|
||||||
|
conf_obj = ConfigObj(fobj)
|
||||||
|
else:
|
||||||
|
conf_obj = ConfigObj()
|
||||||
|
return _parse_remotes(_lower_keys(conf_obj.dict()))
|
||||||
|
|
||||||
|
def _save_config(self, level, conf_dict):
|
||||||
|
from configobj import ConfigObj
|
||||||
|
|
||||||
|
filename = self.files[level]
|
||||||
|
fs = self._get_fs(level)
|
||||||
|
|
||||||
|
logger.debug(f"Writing '{filename}'.")
|
||||||
|
|
||||||
|
fs.makedirs(os.path.dirname(filename))
|
||||||
|
|
||||||
|
config = ConfigObj(_pack_remotes(conf_dict))
|
||||||
|
with fs.open(filename, "wb") as fobj:
|
||||||
|
config.write(fobj)
|
||||||
|
config.filename = filename
|
||||||
|
|
||||||
def load_one(self, level):
|
def load_one(self, level):
|
||||||
conf = _load_config(self.files[level])
|
conf = self._load_config(level)
|
||||||
conf = self._load_paths(conf, self.files[level])
|
conf = self._load_paths(conf, self.files[level])
|
||||||
|
|
||||||
# Auto-verify sections
|
# Auto-verify sections
|
||||||
for key in COMPILED_SCHEMA.schema:
|
for key in get_compiled_schema().schema:
|
||||||
conf.setdefault(key, {})
|
conf.setdefault(key, {})
|
||||||
|
|
||||||
return conf
|
return conf
|
||||||
@@ -317,14 +191,26 @@ class Config(dict):
|
|||||||
abs_conf_dir = os.path.abspath(os.path.dirname(filename))
|
abs_conf_dir = os.path.abspath(os.path.dirname(filename))
|
||||||
|
|
||||||
def resolve(path):
|
def resolve(path):
|
||||||
|
from .config_schema import RelPath
|
||||||
|
|
||||||
if os.path.isabs(path) or re.match(r"\w+://", path):
|
if os.path.isabs(path) or re.match(r"\w+://", path):
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
# on windows convert slashes to backslashes
|
||||||
|
# to have path compatible with abs_conf_dir
|
||||||
|
if os.path.sep == "\\" and "/" in path:
|
||||||
|
path = path.replace("/", "\\")
|
||||||
|
|
||||||
return RelPath(os.path.join(abs_conf_dir, path))
|
return RelPath(os.path.join(abs_conf_dir, path))
|
||||||
|
|
||||||
return Config._map_dirs(conf, resolve)
|
return Config._map_dirs(conf, resolve)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _to_relpath(conf_dir, path):
|
def _to_relpath(conf_dir, path):
|
||||||
|
from dvc.utils import relpath
|
||||||
|
|
||||||
|
from .config_schema import RelPath
|
||||||
|
|
||||||
if re.match(r"\w+://", path):
|
if re.match(r"\w+://", path):
|
||||||
return path
|
return path
|
||||||
|
|
||||||
@@ -342,10 +228,20 @@ class Config(dict):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _map_dirs(conf, func):
|
def _map_dirs(conf, func):
|
||||||
|
from voluptuous import ALLOW_EXTRA, Schema
|
||||||
|
|
||||||
dirs_schema = {
|
dirs_schema = {
|
||||||
"cache": {"dir": func},
|
"cache": {"dir": func},
|
||||||
"remote": {
|
"remote": {
|
||||||
str: {"url": func, "gdrive_user_credentials_file": func}
|
str: {
|
||||||
|
"url": func,
|
||||||
|
"gdrive_user_credentials_file": func,
|
||||||
|
"gdrive_service_account_json_file_path": func,
|
||||||
|
"credentialpath": func,
|
||||||
|
"keyfile": func,
|
||||||
|
"cert_path": func,
|
||||||
|
"key_path": func,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return Schema(dirs_schema, extra=ALLOW_EXTRA)(conf)
|
return Schema(dirs_schema, extra=ALLOW_EXTRA)(conf)
|
||||||
@@ -356,11 +252,19 @@ class Config(dict):
|
|||||||
if merge_level == level:
|
if merge_level == level:
|
||||||
break
|
break
|
||||||
if merge_level in self.files:
|
if merge_level in self.files:
|
||||||
_merge(merged_conf, self.load_one(merge_level))
|
merge(merged_conf, self.load_one(merge_level))
|
||||||
return merged_conf
|
return merged_conf
|
||||||
|
|
||||||
|
def read(self, level=None):
|
||||||
|
# NOTE: we read from a merged config by default, same as git config
|
||||||
|
if level is None:
|
||||||
|
return self.load_config_to_level()
|
||||||
|
return self.load_one(level)
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def edit(self, level="repo"):
|
def edit(self, level=None, validate=True):
|
||||||
|
# NOTE: we write to repo config by default, same as git config
|
||||||
|
level = level or "repo"
|
||||||
if level in {"repo", "local"} and self.dvc_dir is None:
|
if level in {"repo", "local"} and self.dvc_dir is None:
|
||||||
raise ConfigError("Not inside a DVC repo")
|
raise ConfigError("Not inside a DVC repo")
|
||||||
|
|
||||||
@@ -370,34 +274,24 @@ class Config(dict):
|
|||||||
conf = self._save_paths(conf, self.files[level])
|
conf = self._save_paths(conf, self.files[level])
|
||||||
|
|
||||||
merged_conf = self.load_config_to_level(level)
|
merged_conf = self.load_config_to_level(level)
|
||||||
_merge(merged_conf, conf)
|
merge(merged_conf, conf)
|
||||||
self.validate(merged_conf)
|
|
||||||
|
|
||||||
_save_config(self.files[level], conf)
|
if validate:
|
||||||
self.load()
|
self.validate(merged_conf)
|
||||||
|
|
||||||
|
self._save_config(level, conf)
|
||||||
|
self.load(validate=validate)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def validate(data):
|
def validate(data):
|
||||||
|
from voluptuous import Invalid
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return COMPILED_SCHEMA(data)
|
return get_compiled_schema()(data)
|
||||||
except Invalid as exc:
|
except Invalid as exc:
|
||||||
raise ConfigError(str(exc)) from None
|
raise ConfigError(str(exc)) from None
|
||||||
|
|
||||||
|
|
||||||
def _load_config(filename):
|
|
||||||
conf_obj = configobj.ConfigObj(filename)
|
|
||||||
return _parse_remotes(_lower_keys(conf_obj.dict()))
|
|
||||||
|
|
||||||
|
|
||||||
def _save_config(filename, conf_dict):
|
|
||||||
logger.debug(f"Writing '{filename}'.")
|
|
||||||
os.makedirs(os.path.dirname(filename), exist_ok=True)
|
|
||||||
|
|
||||||
config = configobj.ConfigObj(_pack_remotes(conf_dict))
|
|
||||||
config.filename = filename
|
|
||||||
config.write()
|
|
||||||
|
|
||||||
|
|
||||||
def _parse_remotes(conf):
|
def _parse_remotes(conf):
|
||||||
result = {"remote": {}}
|
result = {"remote": {}}
|
||||||
|
|
||||||
@@ -423,11 +317,11 @@ def _pack_remotes(conf):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def _merge(into, update):
|
def merge(into, update):
|
||||||
"""Merges second dict into first recursively"""
|
"""Merges second dict into first recursively"""
|
||||||
for key, val in update.items():
|
for key, val in update.items():
|
||||||
if isinstance(into.get(key), dict) and isinstance(val, dict):
|
if isinstance(into.get(key), dict) and isinstance(val, dict):
|
||||||
_merge(into[key], val)
|
merge(into[key], val)
|
||||||
else:
|
else:
|
||||||
into[key] = val
|
into[key] = val
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,224 @@
|
|||||||
|
import os
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
from funcy import walk_values
|
||||||
|
from voluptuous import (
|
||||||
|
All,
|
||||||
|
Any,
|
||||||
|
Coerce,
|
||||||
|
Invalid,
|
||||||
|
Lower,
|
||||||
|
Optional,
|
||||||
|
Range,
|
||||||
|
Schema,
|
||||||
|
)
|
||||||
|
|
||||||
|
Bool = All(
|
||||||
|
Lower,
|
||||||
|
Any("true", "false"),
|
||||||
|
lambda v: v == "true",
|
||||||
|
msg="expected true or false",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def supported_cache_type(types):
|
||||||
|
"""Checks if link type config option consists only of valid values.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
types (list/string): type(s) of links that dvc should try out.
|
||||||
|
"""
|
||||||
|
if types is None:
|
||||||
|
return None
|
||||||
|
if isinstance(types, str):
|
||||||
|
types = [typ.strip() for typ in types.split(",")]
|
||||||
|
|
||||||
|
unsupported = set(types) - {"reflink", "hardlink", "symlink", "copy"}
|
||||||
|
if unsupported:
|
||||||
|
raise Invalid(
|
||||||
|
"Unsupported cache type(s): {}".format(", ".join(unsupported))
|
||||||
|
)
|
||||||
|
|
||||||
|
return types
|
||||||
|
|
||||||
|
|
||||||
|
def Choices(*choices):
|
||||||
|
"""Checks that value belongs to the specified set of values
|
||||||
|
|
||||||
|
Args:
|
||||||
|
*choices: pass allowed values as arguments, or pass a list or
|
||||||
|
tuple as a single argument
|
||||||
|
"""
|
||||||
|
return Any(*choices, msg="expected one of {}".format(", ".join(choices)))
|
||||||
|
|
||||||
|
|
||||||
|
def ByUrl(mapping):
|
||||||
|
schemas = walk_values(Schema, mapping)
|
||||||
|
|
||||||
|
def validate(data):
|
||||||
|
if "url" not in data:
|
||||||
|
raise Invalid("expected 'url'")
|
||||||
|
|
||||||
|
parsed = urlparse(data["url"])
|
||||||
|
# Windows absolute paths should really have scheme == "" (local)
|
||||||
|
if os.name == "nt" and len(parsed.scheme) == 1 and parsed.netloc == "":
|
||||||
|
return schemas[""](data)
|
||||||
|
if parsed.scheme not in schemas:
|
||||||
|
raise Invalid(f"Unsupported URL type {parsed.scheme}://")
|
||||||
|
|
||||||
|
return schemas[parsed.scheme](data)
|
||||||
|
|
||||||
|
return validate
|
||||||
|
|
||||||
|
|
||||||
|
class RelPath(str):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
REMOTE_COMMON = {
|
||||||
|
"url": str,
|
||||||
|
"checksum_jobs": All(Coerce(int), Range(1)),
|
||||||
|
"jobs": All(Coerce(int), Range(1)),
|
||||||
|
Optional("no_traverse"): Bool, # obsoleted
|
||||||
|
"verify": Bool,
|
||||||
|
}
|
||||||
|
LOCAL_COMMON = {
|
||||||
|
"type": supported_cache_type,
|
||||||
|
Optional("protected", default=False): Bool, # obsoleted
|
||||||
|
"shared": All(Lower, Choices("group")),
|
||||||
|
Optional("slow_link_warning", default=True): Bool,
|
||||||
|
}
|
||||||
|
HTTP_COMMON = {
|
||||||
|
"auth": All(Lower, Choices("basic", "digest", "custom")),
|
||||||
|
"custom_auth_header": str,
|
||||||
|
"user": str,
|
||||||
|
"password": str,
|
||||||
|
"ask_password": Bool,
|
||||||
|
"ssl_verify": Bool,
|
||||||
|
"method": str,
|
||||||
|
}
|
||||||
|
WEBDAV_COMMON = {
|
||||||
|
"user": str,
|
||||||
|
"password": str,
|
||||||
|
"ask_password": Bool,
|
||||||
|
"token": str,
|
||||||
|
"cert_path": str,
|
||||||
|
"key_path": str,
|
||||||
|
"timeout": Coerce(int),
|
||||||
|
}
|
||||||
|
|
||||||
|
SCHEMA = {
|
||||||
|
"core": {
|
||||||
|
"remote": Lower,
|
||||||
|
"checksum_jobs": All(Coerce(int), Range(1)),
|
||||||
|
Optional("interactive", default=False): Bool,
|
||||||
|
Optional("analytics", default=True): Bool,
|
||||||
|
Optional("hardlink_lock", default=False): Bool,
|
||||||
|
Optional("no_scm", default=False): Bool,
|
||||||
|
Optional("autostage", default=False): Bool,
|
||||||
|
Optional("experiments"): Bool, # obsoleted
|
||||||
|
Optional("check_update", default=True): Bool,
|
||||||
|
},
|
||||||
|
"cache": {
|
||||||
|
"local": str,
|
||||||
|
"s3": str,
|
||||||
|
"gs": str,
|
||||||
|
"hdfs": str,
|
||||||
|
"webhdfs": str,
|
||||||
|
"ssh": str,
|
||||||
|
"azure": str,
|
||||||
|
# This is for default local cache
|
||||||
|
"dir": str,
|
||||||
|
**LOCAL_COMMON,
|
||||||
|
},
|
||||||
|
"remote": {
|
||||||
|
str: ByUrl(
|
||||||
|
{
|
||||||
|
"": {**LOCAL_COMMON, **REMOTE_COMMON},
|
||||||
|
"s3": {
|
||||||
|
"region": str,
|
||||||
|
"profile": str,
|
||||||
|
"credentialpath": str,
|
||||||
|
"configpath": str,
|
||||||
|
"endpointurl": str,
|
||||||
|
"access_key_id": str,
|
||||||
|
"secret_access_key": str,
|
||||||
|
"session_token": str,
|
||||||
|
Optional("listobjects", default=False): Bool, # obsoleted
|
||||||
|
Optional("use_ssl", default=True): Bool,
|
||||||
|
"sse": str,
|
||||||
|
"sse_kms_key_id": str,
|
||||||
|
"acl": str,
|
||||||
|
"grant_read": str,
|
||||||
|
"grant_read_acp": str,
|
||||||
|
"grant_write_acp": str,
|
||||||
|
"grant_full_control": str,
|
||||||
|
**REMOTE_COMMON,
|
||||||
|
},
|
||||||
|
"gs": {
|
||||||
|
"projectname": str,
|
||||||
|
"credentialpath": str,
|
||||||
|
**REMOTE_COMMON,
|
||||||
|
},
|
||||||
|
"ssh": {
|
||||||
|
"type": supported_cache_type,
|
||||||
|
"port": Coerce(int),
|
||||||
|
"user": str,
|
||||||
|
"password": str,
|
||||||
|
"ask_password": Bool,
|
||||||
|
"keyfile": str,
|
||||||
|
"timeout": Coerce(int),
|
||||||
|
"gss_auth": Bool,
|
||||||
|
"allow_agent": Bool,
|
||||||
|
**REMOTE_COMMON,
|
||||||
|
},
|
||||||
|
"hdfs": {"user": str, **REMOTE_COMMON},
|
||||||
|
"webhdfs": {
|
||||||
|
"hdfscli_config": str,
|
||||||
|
"webhdfs_token": str,
|
||||||
|
"user": str,
|
||||||
|
"webhdfs_alias": str,
|
||||||
|
**REMOTE_COMMON,
|
||||||
|
},
|
||||||
|
"azure": {
|
||||||
|
"connection_string": str,
|
||||||
|
"sas_token": str,
|
||||||
|
"account_name": str,
|
||||||
|
"tenant_id": str,
|
||||||
|
"client_id": str,
|
||||||
|
"client_secret": str,
|
||||||
|
**REMOTE_COMMON,
|
||||||
|
},
|
||||||
|
"oss": {
|
||||||
|
"oss_key_id": str,
|
||||||
|
"oss_key_secret": str,
|
||||||
|
"oss_endpoint": str,
|
||||||
|
**REMOTE_COMMON,
|
||||||
|
},
|
||||||
|
"gdrive": {
|
||||||
|
"gdrive_use_service_account": Bool,
|
||||||
|
"gdrive_client_id": str,
|
||||||
|
"gdrive_client_secret": str,
|
||||||
|
"gdrive_user_credentials_file": str,
|
||||||
|
"gdrive_service_account_user_email": str,
|
||||||
|
"gdrive_service_account_json_file_path": str,
|
||||||
|
Optional("gdrive_trash_only", default=False): Bool,
|
||||||
|
**REMOTE_COMMON,
|
||||||
|
},
|
||||||
|
"http": {**HTTP_COMMON, **REMOTE_COMMON},
|
||||||
|
"https": {**HTTP_COMMON, **REMOTE_COMMON},
|
||||||
|
"webdav": {**WEBDAV_COMMON, **REMOTE_COMMON},
|
||||||
|
"webdavs": {**WEBDAV_COMMON, **REMOTE_COMMON},
|
||||||
|
"remote": {str: object}, # Any of the above options are valid
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
"state": {
|
||||||
|
"row_limit": All(Coerce(int), Range(1)),
|
||||||
|
"row_cleanup_quota": All(Coerce(int), Range(0, 100)),
|
||||||
|
},
|
||||||
|
# section for experimental features
|
||||||
|
"feature": {
|
||||||
|
# enabled by default. It's of no use, kept for backward compatibility.
|
||||||
|
Optional("parametrization", default=True): Bool
|
||||||
|
},
|
||||||
|
}
|
||||||
+22
-13
@@ -3,6 +3,7 @@
|
|||||||
import inspect
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import platform
|
||||||
import sys
|
import sys
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
|
|
||||||
@@ -15,25 +16,30 @@ CREATE_NEW_PROCESS_GROUP = 0x00000200
|
|||||||
DETACHED_PROCESS = 0x00000008
|
DETACHED_PROCESS = 0x00000008
|
||||||
|
|
||||||
|
|
||||||
|
def _popen(cmd, **kwargs):
|
||||||
|
prefix = [sys.executable]
|
||||||
|
if not is_binary():
|
||||||
|
prefix += [sys.argv[0]]
|
||||||
|
|
||||||
|
return Popen(prefix + cmd, close_fds=True, shell=False, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def _spawn_windows(cmd, env):
|
def _spawn_windows(cmd, env):
|
||||||
from subprocess import STARTUPINFO, STARTF_USESHOWWINDOW
|
from subprocess import STARTF_USESHOWWINDOW, STARTUPINFO
|
||||||
|
|
||||||
creationflags = CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS
|
creationflags = CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS
|
||||||
|
|
||||||
startupinfo = STARTUPINFO()
|
startupinfo = STARTUPINFO()
|
||||||
startupinfo.dwFlags |= STARTF_USESHOWWINDOW
|
startupinfo.dwFlags |= STARTF_USESHOWWINDOW
|
||||||
|
|
||||||
Popen(
|
_popen(
|
||||||
cmd,
|
cmd, env=env, creationflags=creationflags, startupinfo=startupinfo,
|
||||||
env=env,
|
|
||||||
close_fds=True,
|
|
||||||
shell=False,
|
|
||||||
creationflags=creationflags,
|
|
||||||
startupinfo=startupinfo,
|
|
||||||
).communicate()
|
).communicate()
|
||||||
|
|
||||||
|
|
||||||
def _spawn_posix(cmd, env):
|
def _spawn_posix(cmd, env):
|
||||||
|
from dvc.main import main
|
||||||
|
|
||||||
# NOTE: using os._exit instead of sys.exit, because dvc built
|
# NOTE: using os._exit instead of sys.exit, because dvc built
|
||||||
# with PyInstaller has trouble with SystemExit exception and throws
|
# with PyInstaller has trouble with SystemExit exception and throws
|
||||||
# errors such as "[26338] Failed to execute script __main__"
|
# errors such as "[26338] Failed to execute script __main__"
|
||||||
@@ -59,7 +65,13 @@ def _spawn_posix(cmd, env):
|
|||||||
sys.stdout.close()
|
sys.stdout.close()
|
||||||
sys.stderr.close()
|
sys.stderr.close()
|
||||||
|
|
||||||
Popen(cmd, env=env, close_fds=True, shell=False).communicate()
|
if platform.system() == "Darwin":
|
||||||
|
# workaround for MacOS bug
|
||||||
|
# https://github.com/iterative/dvc/issues/4294
|
||||||
|
_popen(cmd, env=env).communicate()
|
||||||
|
else:
|
||||||
|
os.environ.update(env)
|
||||||
|
main(cmd)
|
||||||
|
|
||||||
os._exit(0) # pylint: disable=protected-access
|
os._exit(0) # pylint: disable=protected-access
|
||||||
|
|
||||||
@@ -87,10 +99,7 @@ def daemon(args):
|
|||||||
logger.debug("skipping launching a new daemon.")
|
logger.debug("skipping launching a new daemon.")
|
||||||
return
|
return
|
||||||
|
|
||||||
cmd = [sys.executable]
|
cmd = ["daemon", "-q"] + args
|
||||||
if not is_binary():
|
|
||||||
cmd += [sys.argv[0]]
|
|
||||||
cmd += ["daemon", "-q"] + args
|
|
||||||
|
|
||||||
env = fix_env()
|
env = fix_env()
|
||||||
file_path = os.path.abspath(inspect.stack()[0][1])
|
file_path = os.path.abspath(inspect.stack()[0][1])
|
||||||
|
|||||||
+49
-22
@@ -2,9 +2,6 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dvc.config import NoRemoteError
|
|
||||||
from dvc.remote import get_remote
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -23,6 +20,8 @@ class DataCloud:
|
|||||||
self.repo = repo
|
self.repo = repo
|
||||||
|
|
||||||
def get_remote(self, name=None, command="<command>"):
|
def get_remote(self, name=None, command="<command>"):
|
||||||
|
from dvc.config import NoRemoteError
|
||||||
|
|
||||||
if not name:
|
if not name:
|
||||||
name = self.repo.config["core"].get("remote")
|
name = self.repo.config["core"].get("remote")
|
||||||
|
|
||||||
@@ -45,6 +44,8 @@ class DataCloud:
|
|||||||
raise NoRemoteError(error_msg)
|
raise NoRemoteError(error_msg)
|
||||||
|
|
||||||
def _init_remote(self, name):
|
def _init_remote(self, name):
|
||||||
|
from dvc.remote import get_remote
|
||||||
|
|
||||||
return get_remote(self.repo, name=name)
|
return get_remote(self.repo, name=name)
|
||||||
|
|
||||||
def push(
|
def push(
|
||||||
@@ -62,8 +63,11 @@ class DataCloud:
|
|||||||
"""
|
"""
|
||||||
remote = self.get_remote(remote, "push")
|
remote = self.get_remote(remote, "push")
|
||||||
|
|
||||||
return self.repo.cache.local.push(
|
return remote.push(
|
||||||
cache, jobs=jobs, remote=remote, show_checksums=show_checksums,
|
self.repo.odb.local,
|
||||||
|
cache,
|
||||||
|
jobs=jobs,
|
||||||
|
show_checksums=show_checksums,
|
||||||
)
|
)
|
||||||
|
|
||||||
def pull(
|
def pull(
|
||||||
@@ -81,26 +85,39 @@ class DataCloud:
|
|||||||
"""
|
"""
|
||||||
remote = self.get_remote(remote, "pull")
|
remote = self.get_remote(remote, "pull")
|
||||||
|
|
||||||
downloaded_items_num = self.repo.cache.local.pull(
|
return remote.pull(
|
||||||
cache, jobs=jobs, remote=remote, show_checksums=show_checksums
|
self.repo.odb.local,
|
||||||
|
cache,
|
||||||
|
jobs=jobs,
|
||||||
|
show_checksums=show_checksums,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not remote.tree.verify:
|
def transfer(self, source, jobs=None, remote=None, command=None):
|
||||||
self._save_pulled_checksums(cache)
|
"""Transfer data items in a cloud-agnostic way.
|
||||||
|
|
||||||
return downloaded_items_num
|
Args:
|
||||||
|
source (str): url for the source location.
|
||||||
|
jobs (int): number of jobs that can be running simultaneously.
|
||||||
|
remote (dvc.remote.base.BaseRemote): optional remote to compare
|
||||||
|
cache to. By default remote from core.remote config option
|
||||||
|
is used.
|
||||||
|
command (str): the command which is benefitting from this function
|
||||||
|
(to be used for reporting better error messages).
|
||||||
|
"""
|
||||||
|
from dvc.fs import get_cloud_fs
|
||||||
|
|
||||||
def _save_pulled_checksums(self, cache):
|
from_fs = get_cloud_fs(self.repo, url=source)
|
||||||
for checksum in cache.scheme_keys("local"):
|
remote = self.get_remote(remote, command)
|
||||||
cache_file = self.repo.cache.local.hash_to_path_info(checksum)
|
return remote.transfer(from_fs, from_fs.path_info, jobs=jobs)
|
||||||
if self.repo.cache.local.tree.exists(cache_file):
|
|
||||||
# We can safely save here, as existing corrupted files will
|
|
||||||
# be removed upon status, while files corrupted during
|
|
||||||
# download will not be moved from tmp_file
|
|
||||||
# (see `RemoteBASE.download()`)
|
|
||||||
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,
|
||||||
|
log_missing=True,
|
||||||
|
):
|
||||||
"""Check status of data items in a cloud-agnostic way.
|
"""Check status of data items in a cloud-agnostic way.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -111,8 +128,18 @@ class DataCloud:
|
|||||||
is used.
|
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.
|
||||||
|
log_missing (bool): log warning messages if file doesn't exist
|
||||||
|
neither in cache, neither in cloud.
|
||||||
"""
|
"""
|
||||||
remote = self.get_remote(remote, "status")
|
remote = self.get_remote(remote, "status")
|
||||||
return self.repo.cache.local.status(
|
return remote.status(
|
||||||
cache, jobs=jobs, remote=remote, show_checksums=show_checksums
|
self.repo.odb.local,
|
||||||
|
cache,
|
||||||
|
jobs=jobs,
|
||||||
|
show_checksums=show_checksums,
|
||||||
|
log_missing=log_missing,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_url_for(self, remote, checksum):
|
||||||
|
remote = self.get_remote(remote)
|
||||||
|
return str(remote.odb.hash_to_path_info(checksum))
|
||||||
|
|||||||
+15
-24
@@ -11,23 +11,15 @@ from dvc.dependency.local import LocalDependency
|
|||||||
from dvc.dependency.param import ParamsDependency
|
from dvc.dependency.param import ParamsDependency
|
||||||
from dvc.dependency.s3 import S3Dependency
|
from dvc.dependency.s3 import S3Dependency
|
||||||
from dvc.dependency.ssh import SSHDependency
|
from dvc.dependency.ssh import SSHDependency
|
||||||
|
from dvc.dependency.webdav import WebDAVDependency
|
||||||
|
from dvc.dependency.webdavs import WebDAVSDependency
|
||||||
|
from dvc.dependency.webhdfs import WebHDFSDependency
|
||||||
from dvc.output.base import BaseOutput
|
from dvc.output.base import BaseOutput
|
||||||
from dvc.remote import get_remote
|
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
|
|
||||||
|
from ..fs import get_cloud_fs
|
||||||
from .repo import RepoDependency
|
from .repo import RepoDependency
|
||||||
|
|
||||||
DEPS = [
|
|
||||||
AzureDependency,
|
|
||||||
GSDependency,
|
|
||||||
HDFSDependency,
|
|
||||||
HTTPDependency,
|
|
||||||
HTTPSDependency,
|
|
||||||
S3Dependency,
|
|
||||||
SSHDependency,
|
|
||||||
# NOTE: LocalDependency is the default choice
|
|
||||||
]
|
|
||||||
|
|
||||||
DEP_MAP = {
|
DEP_MAP = {
|
||||||
Schemes.LOCAL: LocalDependency,
|
Schemes.LOCAL: LocalDependency,
|
||||||
Schemes.SSH: SSHDependency,
|
Schemes.SSH: SSHDependency,
|
||||||
@@ -37,16 +29,20 @@ DEP_MAP = {
|
|||||||
Schemes.HDFS: HDFSDependency,
|
Schemes.HDFS: HDFSDependency,
|
||||||
Schemes.HTTP: HTTPDependency,
|
Schemes.HTTP: HTTPDependency,
|
||||||
Schemes.HTTPS: HTTPSDependency,
|
Schemes.HTTPS: HTTPSDependency,
|
||||||
|
Schemes.WEBDAV: WebDAVDependency,
|
||||||
|
Schemes.WEBDAVS: WebDAVSDependency,
|
||||||
|
Schemes.WEBHDFS: WebHDFSDependency,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# NOTE: schema for dependencies is basically the same as for outputs, but
|
# NOTE: schema for dependencies is basically the same as for outputs, but
|
||||||
# without output-specific entries like 'cache' (whether or not output is
|
# without output-specific entries like 'cache' (whether or not output is
|
||||||
# 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 metrics file and how to parse it, see `-M` flag for `dvc run`).
|
||||||
SCHEMA = output.SCHEMA.copy()
|
SCHEMA = output.SCHEMA.copy()
|
||||||
del SCHEMA[BaseOutput.PARAM_CACHE]
|
del SCHEMA[BaseOutput.PARAM_CACHE]
|
||||||
del SCHEMA[BaseOutput.PARAM_METRIC]
|
del SCHEMA[BaseOutput.PARAM_METRIC]
|
||||||
|
del SCHEMA[BaseOutput.PARAM_DESC]
|
||||||
SCHEMA.update(RepoDependency.REPO_SCHEMA)
|
SCHEMA.update(RepoDependency.REPO_SCHEMA)
|
||||||
SCHEMA.update(ParamsDependency.PARAM_SCHEMA)
|
SCHEMA.update(ParamsDependency.PARAM_SCHEMA)
|
||||||
|
|
||||||
@@ -54,8 +50,8 @@ SCHEMA.update(ParamsDependency.PARAM_SCHEMA)
|
|||||||
def _get(stage, p, info):
|
def _get(stage, p, info):
|
||||||
parsed = urlparse(p) if p else None
|
parsed = urlparse(p) if p else None
|
||||||
if parsed and parsed.scheme == "remote":
|
if parsed and parsed.scheme == "remote":
|
||||||
remote = get_remote(stage.repo, name=parsed.netloc)
|
fs = get_cloud_fs(stage.repo, name=parsed.netloc)
|
||||||
return DEP_MAP[remote.scheme](stage, p, info, remote=remote)
|
return DEP_MAP[fs.scheme](stage, p, info, fs=fs)
|
||||||
|
|
||||||
if info and info.get(RepoDependency.PARAM_REPO):
|
if info and info.get(RepoDependency.PARAM_REPO):
|
||||||
repo = info.pop(RepoDependency.PARAM_REPO)
|
repo = info.pop(RepoDependency.PARAM_REPO)
|
||||||
@@ -65,10 +61,8 @@ def _get(stage, p, info):
|
|||||||
params = info.pop(ParamsDependency.PARAM_PARAMS)
|
params = info.pop(ParamsDependency.PARAM_PARAMS)
|
||||||
return ParamsDependency(stage, p, params)
|
return ParamsDependency(stage, p, params)
|
||||||
|
|
||||||
for d in DEPS:
|
dep_cls = DEP_MAP.get(parsed.scheme, LocalDependency)
|
||||||
if d.supported(p):
|
return dep_cls(stage, p, info)
|
||||||
return d(stage, p, info)
|
|
||||||
return LocalDependency(stage, p, info)
|
|
||||||
|
|
||||||
|
|
||||||
def loadd_from(stage, d_list):
|
def loadd_from(stage, d_list):
|
||||||
@@ -81,11 +75,8 @@ def loadd_from(stage, d_list):
|
|||||||
|
|
||||||
def loads_from(stage, s_list, erepo=None):
|
def loads_from(stage, s_list, erepo=None):
|
||||||
assert isinstance(s_list, list)
|
assert isinstance(s_list, list)
|
||||||
ret = []
|
info = {RepoDependency.PARAM_REPO: erepo} if erepo else {}
|
||||||
for s in s_list:
|
return [_get(stage, s, info.copy()) for s in s_list]
|
||||||
info = {RepoDependency.PARAM_REPO: erepo} if erepo else {}
|
|
||||||
ret.append(_get(stage, s, info))
|
|
||||||
return ret
|
|
||||||
|
|
||||||
|
|
||||||
def _merge_params(s_list):
|
def _merge_params(s_list):
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
from dvc.dependency.base import BaseDependency
|
from dvc.dependency.base import BaseDependency
|
||||||
from dvc.output.base import BaseOutput
|
from dvc.output.base import BaseOutput
|
||||||
from dvc.remote.azure import AzureRemoteTree
|
|
||||||
|
from ..fs.azure import AzureFileSystem
|
||||||
|
|
||||||
|
|
||||||
class AzureDependency(BaseDependency, BaseOutput):
|
class AzureDependency(BaseDependency, BaseOutput):
|
||||||
TREE_CLS = AzureRemoteTree
|
FS_CLS = AzureFileSystem
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
from typing import Type
|
||||||
|
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
|
|
||||||
|
|
||||||
@@ -15,15 +17,17 @@ class DependencyIsNotFileOrDirError(DvcException):
|
|||||||
|
|
||||||
class DependencyIsStageFileError(DvcException):
|
class DependencyIsStageFileError(DvcException):
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
super().__init__(f"Stage file '{path}' cannot be a dependency.")
|
super().__init__(f"DVC file '{path}' cannot be a dependency.")
|
||||||
|
|
||||||
|
|
||||||
class BaseDependency:
|
class BaseDependency:
|
||||||
IS_DEPENDENCY = True
|
IS_DEPENDENCY = True
|
||||||
|
|
||||||
DoesNotExistError = DependencyDoesNotExistError
|
DoesNotExistError = DependencyDoesNotExistError # type: Type[DvcException]
|
||||||
IsNotFileOrDirError = DependencyIsNotFileOrDirError
|
IsNotFileOrDirError = (
|
||||||
IsStageFileError = DependencyIsStageFileError
|
DependencyIsNotFileOrDirError
|
||||||
|
) # type: Type[DvcException]
|
||||||
|
IsStageFileError = DependencyIsStageFileError # type: Type[DvcException]
|
||||||
|
|
||||||
def update(self, rev=None):
|
def update(self, rev=None):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
from dvc.dependency.base import BaseDependency
|
from dvc.dependency.base import BaseDependency
|
||||||
from dvc.output.base import BaseOutput
|
from dvc.output.base import BaseOutput
|
||||||
from dvc.remote.http import HTTPRemoteTree
|
|
||||||
|
from ..fs.http import HTTPFileSystem
|
||||||
|
|
||||||
|
|
||||||
class HTTPDependency(BaseDependency, BaseOutput):
|
class HTTPDependency(BaseDependency, BaseOutput):
|
||||||
TREE_CLS = HTTPRemoteTree
|
FS_CLS = HTTPFileSystem
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from dvc.remote.https import HTTPSRemoteTree
|
from ..fs.https import HTTPSFileSystem
|
||||||
|
|
||||||
from .http import HTTPDependency
|
from .http import HTTPDependency
|
||||||
|
|
||||||
|
|
||||||
class HTTPSDependency(HTTPDependency):
|
class HTTPSDependency(HTTPDependency):
|
||||||
TREE_CLS = HTTPSRemoteTree
|
FS_CLS = HTTPSFileSystem
|
||||||
|
|||||||
+34
-31
@@ -2,11 +2,12 @@ import os
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
import dpath.util
|
import dpath.util
|
||||||
import yaml
|
|
||||||
from voluptuous import Any
|
from voluptuous import Any
|
||||||
|
|
||||||
from dvc.dependency.local import LocalDependency
|
from dvc.dependency.local import LocalDependency
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
|
from dvc.hash_info import HashInfo
|
||||||
|
from dvc.utils.serialize import LOADERS, ParseError
|
||||||
|
|
||||||
|
|
||||||
class MissingParamsError(DvcException):
|
class MissingParamsError(DvcException):
|
||||||
@@ -31,7 +32,7 @@ class ParamsDependency(LocalDependency):
|
|||||||
else:
|
else:
|
||||||
assert isinstance(params, dict)
|
assert isinstance(params, dict)
|
||||||
self.params = list(params.keys())
|
self.params = list(params.keys())
|
||||||
info = params
|
info = {self.PARAM_PARAMS: params}
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
stage,
|
stage,
|
||||||
@@ -40,59 +41,61 @@ class ParamsDependency(LocalDependency):
|
|||||||
info=info,
|
info=info,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def dumpd(self):
|
||||||
|
ret = super().dumpd()
|
||||||
|
if not self.hash_info:
|
||||||
|
ret[self.PARAM_PARAMS] = self.params
|
||||||
|
return ret
|
||||||
|
|
||||||
def fill_values(self, values=None):
|
def fill_values(self, values=None):
|
||||||
"""Load params values dynamically."""
|
"""Load params values dynamically."""
|
||||||
if not values:
|
if not values:
|
||||||
return
|
return
|
||||||
|
info = {}
|
||||||
for param in self.params:
|
for param in self.params:
|
||||||
value = values.get(param)
|
if param in values:
|
||||||
if value:
|
info[param] = values[param]
|
||||||
self.info[param] = value
|
self.hash_info = HashInfo(self.PARAM_PARAMS, info)
|
||||||
|
|
||||||
def save(self):
|
def workspace_status(self):
|
||||||
super().save()
|
status = super().workspace_status()
|
||||||
self.info = self.save_info()
|
|
||||||
|
|
||||||
def status(self):
|
if status.get(str(self)) == "deleted":
|
||||||
status = super().status()
|
|
||||||
|
|
||||||
if status[str(self)] == "deleted":
|
|
||||||
return status
|
return status
|
||||||
|
|
||||||
status = defaultdict(dict)
|
status = defaultdict(dict)
|
||||||
info = self.read_params()
|
info = self.hash_info.value if self.hash_info else {}
|
||||||
|
actual = self.read_params()
|
||||||
for param in self.params:
|
for param in self.params:
|
||||||
if param not in info.keys():
|
if param not in actual.keys():
|
||||||
st = "deleted"
|
st = "deleted"
|
||||||
elif param not in self.info:
|
elif param not in info:
|
||||||
st = "new"
|
st = "new"
|
||||||
elif info[param] != self.info[param]:
|
elif actual[param] != info[param]:
|
||||||
st = "modified"
|
st = "modified"
|
||||||
else:
|
else:
|
||||||
assert info[param] == self.info[param]
|
assert actual[param] == info[param]
|
||||||
continue
|
continue
|
||||||
|
|
||||||
status[str(self)][param] = st
|
status[str(self)][param] = st
|
||||||
|
|
||||||
return status
|
return status
|
||||||
|
|
||||||
def dumpd(self):
|
def status(self):
|
||||||
return {
|
return self.workspace_status()
|
||||||
self.PARAM_PATH: self.def_path,
|
|
||||||
self.PARAM_PARAMS: self.info or self.params,
|
|
||||||
}
|
|
||||||
|
|
||||||
def read_params(self):
|
def read_params(self):
|
||||||
if not self.exists:
|
if not self.exists:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
with self.repo.tree.open(self.path_info, "r") as fobj:
|
suffix = self.path_info.suffix.lower()
|
||||||
try:
|
loader = LOADERS[suffix]
|
||||||
config = yaml.safe_load(fobj)
|
try:
|
||||||
except yaml.YAMLError as exc:
|
config = loader(self.path_info, fs=self.repo.fs)
|
||||||
raise BadParamFileError(
|
except ParseError as exc:
|
||||||
f"Unable to read parameters from '{self}'"
|
raise BadParamFileError(
|
||||||
) from exc
|
f"Unable to read parameters from '{self}'"
|
||||||
|
) from exc
|
||||||
|
|
||||||
ret = {}
|
ret = {}
|
||||||
for param in self.params:
|
for param in self.params:
|
||||||
@@ -102,7 +105,7 @@ class ParamsDependency(LocalDependency):
|
|||||||
pass
|
pass
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def save_info(self):
|
def get_hash(self):
|
||||||
info = self.read_params()
|
info = self.read_params()
|
||||||
|
|
||||||
missing_params = set(self.params) - set(info.keys())
|
missing_params = set(self.params) - set(info.keys())
|
||||||
@@ -113,4 +116,4 @@ class ParamsDependency(LocalDependency):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
return info
|
return HashInfo(self.PARAM_PARAMS, info)
|
||||||
|
|||||||
+36
-31
@@ -1,8 +1,5 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
from voluptuous import Required
|
from voluptuous import Required
|
||||||
|
|
||||||
from dvc.exceptions import OutputNotFoundError
|
|
||||||
from dvc.path_info import PathInfo
|
from dvc.path_info import PathInfo
|
||||||
|
|
||||||
from .local import LocalDependency
|
from .local import LocalDependency
|
||||||
@@ -26,7 +23,7 @@ class RepoDependency(LocalDependency):
|
|||||||
self.def_repo = def_repo
|
self.def_repo = def_repo
|
||||||
super().__init__(stage, *args, **kwargs)
|
super().__init__(stage, *args, **kwargs)
|
||||||
|
|
||||||
def _parse_path(self, remote, path):
|
def _parse_path(self, fs, path):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -42,55 +39,57 @@ class RepoDependency(LocalDependency):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{} ({})".format(self.def_path, self.def_repo[self.PARAM_URL])
|
return "{} ({})".format(self.def_path, self.def_repo[self.PARAM_URL])
|
||||||
|
|
||||||
def _make_repo(self, *, locked=True):
|
def _make_repo(self, *, locked=True, **kwargs):
|
||||||
from dvc.external_repo import external_repo
|
from dvc.external_repo import external_repo
|
||||||
|
|
||||||
d = self.def_repo
|
d = self.def_repo
|
||||||
rev = (d.get("rev_lock") if locked else None) or d.get("rev")
|
rev = (d.get("rev_lock") if locked else None) or d.get("rev")
|
||||||
return external_repo(d["url"], rev=rev)
|
return external_repo(d["url"], rev=rev, **kwargs)
|
||||||
|
|
||||||
def _get_checksum(self, locked=True):
|
def _get_hash(self, locked=True):
|
||||||
from dvc.repo.tree import RepoTree
|
from dvc.objects.stage import get_hash
|
||||||
|
|
||||||
with self._make_repo(locked=locked) as repo:
|
with self._make_repo(locked=locked) as repo:
|
||||||
try:
|
path_info = PathInfo(repo.root_dir) / self.def_path
|
||||||
return repo.find_out_by_relpath(self.def_path).info["md5"]
|
return get_hash(
|
||||||
except OutputNotFoundError:
|
path_info, repo.repo_fs, "md5", follow_subrepos=False
|
||||||
path = PathInfo(os.path.join(repo.root_dir, self.def_path))
|
)
|
||||||
|
|
||||||
# we want stream but not fetch, so DVC out directories are
|
def workspace_status(self):
|
||||||
# walked, but dir contents is not fetched
|
current = self._get_hash(locked=True)
|
||||||
tree = RepoTree(repo, stream=True)
|
updated = self._get_hash(locked=False)
|
||||||
|
|
||||||
# We are polluting our repo cache with some dir listing here
|
if current != updated:
|
||||||
if tree.isdir(path):
|
|
||||||
return self.repo.cache.local.get_hash(path, tree)
|
|
||||||
return tree.get_file_hash(path)
|
|
||||||
|
|
||||||
def status(self):
|
|
||||||
current_checksum = self._get_checksum(locked=True)
|
|
||||||
updated_checksum = self._get_checksum(locked=False)
|
|
||||||
|
|
||||||
if current_checksum != updated_checksum:
|
|
||||||
return {str(self): "update available"}
|
return {str(self): "update available"}
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
def status(self):
|
||||||
|
return self.workspace_status()
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def dumpd(self):
|
def dumpd(self):
|
||||||
return {self.PARAM_PATH: self.def_path, self.PARAM_REPO: self.def_repo}
|
return {self.PARAM_PATH: self.def_path, self.PARAM_REPO: self.def_repo}
|
||||||
|
|
||||||
def download(self, to):
|
def download(self, to, jobs=None):
|
||||||
with self._make_repo() as repo:
|
from dvc.checkout import checkout
|
||||||
|
from dvc.objects import save
|
||||||
|
from dvc.objects.stage import stage
|
||||||
|
|
||||||
|
odb = self.repo.odb.local
|
||||||
|
|
||||||
|
with self._make_repo(cache_dir=odb.cache_dir) 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.get_rev()
|
self.def_repo[self.PARAM_REV_LOCK] = repo.get_rev()
|
||||||
|
path_info = PathInfo(repo.root_dir) / self.def_path
|
||||||
|
obj = stage(
|
||||||
|
odb, path_info, repo.repo_fs, jobs=jobs, follow_subrepos=False,
|
||||||
|
)
|
||||||
|
save(odb, obj, jobs=jobs)
|
||||||
|
|
||||||
cache = self.repo.cache.local
|
checkout(to.path_info, to.fs, obj, odb)
|
||||||
with repo.use_cache(cache):
|
|
||||||
_, _, cache_infos = repo.fetch_external([self.def_path])
|
|
||||||
cache.checkout(to.path_info, cache_infos[0])
|
|
||||||
|
|
||||||
def update(self, rev=None):
|
def update(self, rev=None):
|
||||||
if rev:
|
if rev:
|
||||||
@@ -98,3 +97,9 @@ class RepoDependency(LocalDependency):
|
|||||||
|
|
||||||
with self._make_repo(locked=False) as repo:
|
with self._make_repo(locked=False) as repo:
|
||||||
self.def_repo[self.PARAM_REV_LOCK] = repo.get_rev()
|
self.def_repo[self.PARAM_REV_LOCK] = repo.get_rev()
|
||||||
|
|
||||||
|
def changed_checksum(self):
|
||||||
|
# From current repo point of view what describes RepoDependency is its
|
||||||
|
# origin project url and rev_lock, and it makes RepoDependency
|
||||||
|
# immutable, hence its impossible for checksum to change.
|
||||||
|
return False
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
from dvc.dependency.base import BaseDependency
|
||||||
|
from dvc.output.base import BaseOutput
|
||||||
|
|
||||||
|
from ..fs.webdav import WebDAVFileSystem
|
||||||
|
|
||||||
|
|
||||||
|
class WebDAVDependency(BaseDependency, BaseOutput):
|
||||||
|
FS_CLS = WebDAVFileSystem
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
from ..fs.webdavs import WebDAVSFileSystem
|
||||||
|
from .webdav import WebDAVDependency
|
||||||
|
|
||||||
|
|
||||||
|
class WebDAVSDependency(WebDAVDependency):
|
||||||
|
FS_CLS = WebDAVSFileSystem
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
from dvc.dependency.base import BaseDependency
|
||||||
|
from dvc.output.webhdfs import WebHDFSOutput
|
||||||
|
|
||||||
|
|
||||||
|
class WebHDFSDependency(BaseDependency, WebHDFSOutput):
|
||||||
|
pass
|
||||||
+102
@@ -0,0 +1,102 @@
|
|||||||
|
import posixpath
|
||||||
|
from operator import itemgetter
|
||||||
|
|
||||||
|
from pygtrie import Trie
|
||||||
|
|
||||||
|
from .hash_info import HashInfo
|
||||||
|
|
||||||
|
|
||||||
|
def _diff(ancestor, other, allow_removed=False):
|
||||||
|
from dictdiffer import diff
|
||||||
|
|
||||||
|
from dvc.exceptions import MergeError
|
||||||
|
|
||||||
|
allowed = ["add"]
|
||||||
|
if allow_removed:
|
||||||
|
allowed.append("remove")
|
||||||
|
|
||||||
|
result = list(diff(ancestor, other))
|
||||||
|
for typ, _, _ in result:
|
||||||
|
if typ not in allowed:
|
||||||
|
raise MergeError(
|
||||||
|
"unable to auto-merge directories with diff that contains "
|
||||||
|
f"'{typ}'ed files"
|
||||||
|
)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def _merge(ancestor, our, their):
|
||||||
|
import copy
|
||||||
|
|
||||||
|
from dictdiffer import patch
|
||||||
|
|
||||||
|
our_diff = _diff(ancestor, our)
|
||||||
|
if not our_diff:
|
||||||
|
return copy.deepcopy(their)
|
||||||
|
|
||||||
|
their_diff = _diff(ancestor, their)
|
||||||
|
if not their_diff:
|
||||||
|
return copy.deepcopy(our)
|
||||||
|
|
||||||
|
# make sure there are no conflicting files
|
||||||
|
_diff(our, their, allow_removed=True)
|
||||||
|
|
||||||
|
return patch(our_diff + their_diff, ancestor)
|
||||||
|
|
||||||
|
|
||||||
|
class DirInfo:
|
||||||
|
PARAM_RELPATH = "relpath"
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.trie = Trie()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def size(self):
|
||||||
|
try:
|
||||||
|
return sum(
|
||||||
|
hash_info.size
|
||||||
|
for _, hash_info in self.trie.iteritems() # noqa: B301
|
||||||
|
)
|
||||||
|
except TypeError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def nfiles(self):
|
||||||
|
return len(self.trie)
|
||||||
|
|
||||||
|
def items(self, path_info=None):
|
||||||
|
for key, hash_info in self.trie.iteritems(): # noqa: B301
|
||||||
|
path = posixpath.sep.join(key)
|
||||||
|
if path_info is not None:
|
||||||
|
path = path_info / path
|
||||||
|
yield path, hash_info
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_list(cls, lst):
|
||||||
|
ret = DirInfo()
|
||||||
|
for _entry in lst:
|
||||||
|
entry = _entry.copy()
|
||||||
|
relpath = entry.pop(cls.PARAM_RELPATH)
|
||||||
|
parts = tuple(relpath.split(posixpath.sep))
|
||||||
|
ret.trie[parts] = HashInfo.from_dict(entry)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def to_list(self):
|
||||||
|
# Sorting the list by path to ensure reproducibility
|
||||||
|
return sorted(
|
||||||
|
(
|
||||||
|
{
|
||||||
|
# NOTE: not using hash_info.to_dict() because we don't want
|
||||||
|
# size/nfiles fields at this point.
|
||||||
|
hash_info.name: hash_info.value,
|
||||||
|
self.PARAM_RELPATH: posixpath.sep.join(parts),
|
||||||
|
}
|
||||||
|
for parts, hash_info in self.trie.iteritems() # noqa: B301
|
||||||
|
),
|
||||||
|
key=itemgetter(self.PARAM_RELPATH),
|
||||||
|
)
|
||||||
|
|
||||||
|
def merge(self, ancestor, their):
|
||||||
|
merged = DirInfo()
|
||||||
|
merged.trie = _merge(ancestor.trie, self.trie, their.trie)
|
||||||
|
return merged
|
||||||
+215
-83
@@ -1,10 +1,13 @@
|
|||||||
|
import collections
|
||||||
import contextlib
|
import contextlib
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
from typing import TYPE_CHECKING, Any, Union
|
||||||
|
|
||||||
from voluptuous import MultipleInvalid
|
from voluptuous import MultipleInvalid
|
||||||
|
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
|
from dvc.parsing.versions import LOCKFILE_VERSION, SCHEMA_KWD
|
||||||
from dvc.stage import serialize
|
from dvc.stage import serialize
|
||||||
from dvc.stage.exceptions import (
|
from dvc.stage.exceptions import (
|
||||||
StageFileBadNameError,
|
StageFileBadNameError,
|
||||||
@@ -12,10 +15,18 @@ from dvc.stage.exceptions import (
|
|||||||
StageFileFormatError,
|
StageFileFormatError,
|
||||||
StageFileIsNotDvcFileError,
|
StageFileIsNotDvcFileError,
|
||||||
)
|
)
|
||||||
from dvc.stage.loader import SingleStageLoader, StageLoader
|
from dvc.types import AnyPath
|
||||||
from dvc.utils import relpath
|
from dvc.utils import relpath
|
||||||
from dvc.utils.collections import apply_diff
|
from dvc.utils.collections import apply_diff
|
||||||
from dvc.utils.yaml import dump_yaml, parse_yaml, parse_yaml_for_update
|
from dvc.utils.serialize import (
|
||||||
|
dump_yaml,
|
||||||
|
modify_yaml,
|
||||||
|
parse_yaml,
|
||||||
|
parse_yaml_for_update,
|
||||||
|
)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from dvc.repo import Repo
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -25,10 +36,19 @@ PIPELINE_FILE = "dvc.yaml"
|
|||||||
PIPELINE_LOCK = "dvc.lock"
|
PIPELINE_LOCK = "dvc.lock"
|
||||||
|
|
||||||
|
|
||||||
|
class FileIsGitIgnored(DvcException):
|
||||||
|
def __init__(self, path):
|
||||||
|
super().__init__(f"'{path}' is git-ignored.")
|
||||||
|
|
||||||
|
|
||||||
class LockfileCorruptedError(DvcException):
|
class LockfileCorruptedError(DvcException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ParametrizedDumpError(DvcException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def is_valid_filename(path):
|
def is_valid_filename(path):
|
||||||
return path.endswith(DVC_FILE_SUFFIX) or os.path.basename(path) in [
|
return path.endswith(DVC_FILE_SUFFIX) or os.path.basename(path) in [
|
||||||
DVC_FILE,
|
DVC_FILE,
|
||||||
@@ -38,16 +58,20 @@ def is_valid_filename(path):
|
|||||||
|
|
||||||
def is_dvc_file(path):
|
def is_dvc_file(path):
|
||||||
return os.path.isfile(path) and (
|
return os.path.isfile(path) and (
|
||||||
is_valid_filename(path) or os.path.basename(path) == PIPELINE_LOCK
|
is_valid_filename(path) or is_lock_file(path)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def is_lock_file(path):
|
||||||
|
return os.path.basename(path) == PIPELINE_LOCK
|
||||||
|
|
||||||
|
|
||||||
def check_dvc_filename(path):
|
def check_dvc_filename(path):
|
||||||
if not is_valid_filename(path):
|
if not is_valid_filename(path):
|
||||||
raise StageFileBadNameError(
|
raise StageFileBadNameError(
|
||||||
"bad DVC-file name '{}'. DVC-files should be named "
|
"bad DVC file name '{}'. DVC files should be named "
|
||||||
"'Dvcfile' or have a '.dvc' suffix (e.g. '{}.dvc').".format(
|
"'{}' or have a '.dvc' suffix (e.g. '{}.dvc').".format(
|
||||||
relpath(path), os.path.basename(path)
|
relpath(path), PIPELINE_FILE, os.path.basename(path)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -55,9 +79,10 @@ def check_dvc_filename(path):
|
|||||||
class FileMixin:
|
class FileMixin:
|
||||||
SCHEMA = None
|
SCHEMA = None
|
||||||
|
|
||||||
def __init__(self, repo, path, **kwargs):
|
def __init__(self, repo, path, verify=True, **kwargs):
|
||||||
self.repo = repo
|
self.repo = repo
|
||||||
self.path = path
|
self.path = path
|
||||||
|
self.verify = verify
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "{}: {}".format(
|
return "{}: {}".format(
|
||||||
@@ -80,123 +105,156 @@ class FileMixin:
|
|||||||
return relpath(self.path)
|
return relpath(self.path)
|
||||||
|
|
||||||
def exists(self):
|
def exists(self):
|
||||||
return self.repo.tree.exists(self.path)
|
return self.repo.fs.exists(self.path)
|
||||||
|
|
||||||
|
def _is_git_ignored(self):
|
||||||
|
from dvc.fs.local import LocalFileSystem
|
||||||
|
|
||||||
|
return isinstance(
|
||||||
|
self.repo.fs, LocalFileSystem
|
||||||
|
) and self.repo.scm.is_ignored(self.path)
|
||||||
|
|
||||||
|
def _verify_filename(self):
|
||||||
|
if self.verify:
|
||||||
|
check_dvc_filename(self.path)
|
||||||
|
|
||||||
|
def _check_gitignored(self):
|
||||||
|
if self._is_git_ignored():
|
||||||
|
raise FileIsGitIgnored(self.path)
|
||||||
|
|
||||||
def _load(self):
|
def _load(self):
|
||||||
# it raises the proper exceptions by priority:
|
# it raises the proper exceptions by priority:
|
||||||
# 1. when the file doesn't exists
|
# 1. when the file doesn't exists
|
||||||
# 2. filename is not a DVC-file
|
# 2. filename is not a DVC file
|
||||||
# 3. path doesn't represent a regular file
|
# 3. path doesn't represent a regular file
|
||||||
|
# 4. when the file is git ignored
|
||||||
if not self.exists():
|
if not self.exists():
|
||||||
raise StageFileDoesNotExistError(self.path)
|
is_ignored = self.repo.fs.exists(self.path, use_dvcignore=False)
|
||||||
check_dvc_filename(self.path)
|
raise StageFileDoesNotExistError(self.path, dvc_ignored=is_ignored)
|
||||||
if not self.repo.tree.isfile(self.path):
|
|
||||||
|
self._verify_filename()
|
||||||
|
if not self.repo.fs.isfile(self.path):
|
||||||
raise StageFileIsNotDvcFileError(self.path)
|
raise StageFileIsNotDvcFileError(self.path)
|
||||||
|
|
||||||
with self.repo.tree.open(self.path) as fd:
|
self._check_gitignored()
|
||||||
|
with self.repo.fs.open(self.path, encoding="utf-8") as fd:
|
||||||
stage_text = fd.read()
|
stage_text = fd.read()
|
||||||
d = parse_yaml(stage_text, self.path)
|
d = parse_yaml(stage_text, self.path)
|
||||||
self.validate(d, self.relpath)
|
return self.validate(d, self.relpath), stage_text
|
||||||
return d, stage_text
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate(cls, d, fname=None):
|
def validate(cls, d, fname=None):
|
||||||
assert cls.SCHEMA
|
assert isinstance(cls.SCHEMA, collections.abc.Callable)
|
||||||
try:
|
try:
|
||||||
cls.SCHEMA(d)
|
return cls.SCHEMA(d) # pylint: disable=not-callable
|
||||||
except MultipleInvalid as exc:
|
except MultipleInvalid as exc:
|
||||||
raise StageFileFormatError(f"'{fname}' format error: {exc}")
|
raise StageFileFormatError(f"'{fname}' format error: {exc}")
|
||||||
|
|
||||||
def remove(self, force=False):
|
def remove(self, force=False): # pylint: disable=unused-argument
|
||||||
with contextlib.suppress(FileNotFoundError):
|
with contextlib.suppress(FileNotFoundError):
|
||||||
os.unlink(self.path)
|
os.unlink(self.path)
|
||||||
|
|
||||||
def dump(self, stage, **kwargs):
|
def dump(self, stage, **kwargs):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def merge(self, ancestor, other):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class SingleStageFile(FileMixin):
|
class SingleStageFile(FileMixin):
|
||||||
from dvc.schema import COMPILED_SINGLE_STAGE_SCHEMA as SCHEMA
|
from dvc.schema import COMPILED_SINGLE_STAGE_SCHEMA as SCHEMA
|
||||||
|
from dvc.stage.loader import SingleStageLoader as LOADER
|
||||||
def __init__(self, repo, path):
|
|
||||||
super().__init__(repo, path)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def stage(self):
|
def stage(self):
|
||||||
data, raw = self._load()
|
data, raw = self._load()
|
||||||
return SingleStageLoader.load_stage(self, data, raw)
|
return self.LOADER.load_stage(self, data, raw)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def stages(self):
|
def stages(self):
|
||||||
data, raw = self._load()
|
data, raw = self._load()
|
||||||
return SingleStageLoader(self, data, raw)
|
return self.LOADER(self, data, raw)
|
||||||
|
|
||||||
def dump(self, stage, **kwargs):
|
def dump(self, stage, **kwargs):
|
||||||
"""Dumps given stage appropriately in the dvcfile."""
|
"""Dumps given stage appropriately in the dvcfile."""
|
||||||
from dvc.stage import PipelineStage
|
from dvc.stage import PipelineStage
|
||||||
|
|
||||||
assert not isinstance(stage, PipelineStage)
|
assert not isinstance(stage, PipelineStage)
|
||||||
check_dvc_filename(self.path)
|
if self.verify:
|
||||||
|
check_dvc_filename(self.path)
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Saving information to '{file}'.".format(file=relpath(self.path))
|
"Saving information to '{file}'.".format(file=relpath(self.path))
|
||||||
)
|
)
|
||||||
dump_yaml(self.path, serialize.to_single_stage_file(stage))
|
dump_yaml(self.path, serialize.to_single_stage_file(stage))
|
||||||
self.repo.scm.track_file(self.relpath)
|
self.repo.scm.track_file(self.relpath)
|
||||||
|
|
||||||
def remove_stage(self, stage):
|
def remove_stage(self, stage): # pylint: disable=unused-argument
|
||||||
self.remove()
|
self.remove()
|
||||||
|
|
||||||
|
def merge(self, ancestor, other):
|
||||||
|
assert isinstance(ancestor, SingleStageFile)
|
||||||
|
assert isinstance(other, SingleStageFile)
|
||||||
|
|
||||||
|
stage = self.stage
|
||||||
|
stage.merge(ancestor.stage, other.stage)
|
||||||
|
self.dump(stage)
|
||||||
|
|
||||||
|
|
||||||
class PipelineFile(FileMixin):
|
class PipelineFile(FileMixin):
|
||||||
"""Abstraction for pipelines file, .yaml + .lock combined."""
|
"""Abstraction for pipelines file, .yaml + .lock combined."""
|
||||||
|
|
||||||
from dvc.schema import COMPILED_MULTI_STAGE_SCHEMA as SCHEMA
|
from dvc.schema import COMPILED_MULTI_STAGE_SCHEMA as SCHEMA
|
||||||
|
from dvc.stage.loader import StageLoader as LOADER
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _lockfile(self):
|
def _lockfile(self):
|
||||||
return Lockfile(self.repo, os.path.splitext(self.path)[0] + ".lock")
|
return Lockfile(self.repo, os.path.splitext(self.path)[0] + ".lock")
|
||||||
|
|
||||||
def dump(self, stage, update_pipeline=False, no_lock=False):
|
def dump(
|
||||||
|
self, stage, update_pipeline=True, update_lock=True, **kwargs
|
||||||
|
): # pylint: disable=arguments-differ
|
||||||
"""Dumps given stage appropriately in the dvcfile."""
|
"""Dumps given stage appropriately in the dvcfile."""
|
||||||
from dvc.stage import PipelineStage
|
from dvc.stage import PipelineStage
|
||||||
|
|
||||||
assert isinstance(stage, PipelineStage)
|
assert isinstance(stage, PipelineStage)
|
||||||
check_dvc_filename(self.path)
|
if self.verify:
|
||||||
|
check_dvc_filename(self.path)
|
||||||
|
|
||||||
if update_pipeline and not stage.is_data_source:
|
if update_pipeline and not stage.is_data_source:
|
||||||
self._dump_pipeline_file(stage)
|
self._dump_pipeline_file(stage)
|
||||||
|
|
||||||
if not no_lock:
|
if update_lock:
|
||||||
self._dump_lockfile(stage)
|
self._dump_lockfile(stage)
|
||||||
|
|
||||||
def _dump_lockfile(self, stage):
|
def _dump_lockfile(self, stage):
|
||||||
self._lockfile.dump(stage)
|
self._lockfile.dump(stage)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _check_if_parametrized(stage):
|
||||||
|
if stage.raw_data.parametrized:
|
||||||
|
raise ParametrizedDumpError(f"cannot dump a parametrized {stage}")
|
||||||
|
|
||||||
def _dump_pipeline_file(self, stage):
|
def _dump_pipeline_file(self, stage):
|
||||||
data = {}
|
self._check_if_parametrized(stage)
|
||||||
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)
|
stage_data = serialize.to_pipeline_file(stage)
|
||||||
existing_entry = stage.name in data["stages"]
|
|
||||||
|
|
||||||
action = "Modifying" if existing_entry else "Adding"
|
with modify_yaml(self.path, fs=self.repo.fs) as data:
|
||||||
logger.info("%s stage '%s' in '%s'", action, stage.name, self.relpath)
|
if not data:
|
||||||
|
logger.info("Creating '%s'", self.relpath)
|
||||||
|
|
||||||
if existing_entry:
|
data["stages"] = data.get("stages", {})
|
||||||
orig_stage_data = data["stages"][stage.name]
|
existing_entry = stage.name in data["stages"]
|
||||||
if "meta" in orig_stage_data:
|
action = "Modifying" if existing_entry else "Adding"
|
||||||
stage_data[stage.name]["meta"] = orig_stage_data["meta"]
|
logger.info(
|
||||||
apply_diff(stage_data[stage.name], orig_stage_data)
|
"%s stage '%s' in '%s'", action, stage.name, self.relpath
|
||||||
else:
|
)
|
||||||
data["stages"].update(stage_data)
|
|
||||||
|
if existing_entry:
|
||||||
|
orig_stage_data = data["stages"][stage.name]
|
||||||
|
apply_diff(stage_data[stage.name], orig_stage_data)
|
||||||
|
else:
|
||||||
|
data["stages"].update(stage_data)
|
||||||
|
|
||||||
dump_yaml(self.path, data)
|
|
||||||
self.repo.scm.track_file(self.relpath)
|
self.repo.scm.track_file(self.relpath)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -209,7 +267,7 @@ class PipelineFile(FileMixin):
|
|||||||
def stages(self):
|
def stages(self):
|
||||||
data, _ = self._load()
|
data, _ = self._load()
|
||||||
lockfile_data = self._lockfile.load()
|
lockfile_data = self._lockfile.load()
|
||||||
return StageLoader(self, data.get("stages", {}), lockfile_data)
|
return self.LOADER(self, data, lockfile_data)
|
||||||
|
|
||||||
def remove(self, force=False):
|
def remove(self, force=False):
|
||||||
if not force:
|
if not force:
|
||||||
@@ -224,7 +282,7 @@ class PipelineFile(FileMixin):
|
|||||||
if not self.exists():
|
if not self.exists():
|
||||||
return
|
return
|
||||||
|
|
||||||
with open(self.path, "r") as f:
|
with open(self.path, "r", encoding="utf-8") as f:
|
||||||
d = parse_yaml_for_update(f.read(), self.path)
|
d = parse_yaml_for_update(f.read(), self.path)
|
||||||
|
|
||||||
self.validate(d, self.path)
|
self.validate(d, self.path)
|
||||||
@@ -233,42 +291,101 @@ class PipelineFile(FileMixin):
|
|||||||
|
|
||||||
logger.debug("Removing '%s' from '%s'", stage.name, self.path)
|
logger.debug("Removing '%s' from '%s'", stage.name, self.path)
|
||||||
del d["stages"][stage.name]
|
del d["stages"][stage.name]
|
||||||
dump_yaml(self.path, d)
|
|
||||||
|
if d["stages"]:
|
||||||
|
dump_yaml(self.path, d)
|
||||||
|
else:
|
||||||
|
super().remove()
|
||||||
|
|
||||||
|
def merge(self, ancestor, other):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
|
def get_lockfile_schema(d):
|
||||||
|
from dvc.schema import (
|
||||||
|
COMPILED_LOCKFILE_V1_SCHEMA,
|
||||||
|
COMPILED_LOCKFILE_V2_SCHEMA,
|
||||||
|
)
|
||||||
|
|
||||||
|
schema = {
|
||||||
|
LOCKFILE_VERSION.V1: COMPILED_LOCKFILE_V1_SCHEMA,
|
||||||
|
LOCKFILE_VERSION.V2: COMPILED_LOCKFILE_V2_SCHEMA,
|
||||||
|
}
|
||||||
|
|
||||||
|
version = LOCKFILE_VERSION.from_dict(d)
|
||||||
|
return schema[version]
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_lock_v1_to_v2(d, version_info):
|
||||||
|
stages = {k: v for k, v in d.items()}
|
||||||
|
|
||||||
|
for key in stages:
|
||||||
|
d.pop(key)
|
||||||
|
|
||||||
|
# forcing order, meta should always be at the top
|
||||||
|
d.update(version_info)
|
||||||
|
d["stages"] = stages
|
||||||
|
|
||||||
|
|
||||||
class Lockfile(FileMixin):
|
class Lockfile(FileMixin):
|
||||||
from dvc.schema import COMPILED_LOCKFILE_SCHEMA as SCHEMA
|
@classmethod
|
||||||
|
def validate(cls, d, fname=None):
|
||||||
def load(self):
|
schema = get_lockfile_schema(d)
|
||||||
if not self.exists():
|
|
||||||
return {}
|
|
||||||
with self.repo.tree.open(self.path) as fd:
|
|
||||||
data = parse_yaml(fd.read(), self.path)
|
|
||||||
try:
|
try:
|
||||||
self.validate(data, fname=self.relpath)
|
return schema(d)
|
||||||
except StageFileFormatError:
|
except MultipleInvalid as exc:
|
||||||
|
raise StageFileFormatError(f"'{fname}' format error: {exc}")
|
||||||
|
|
||||||
|
def _verify_filename(self):
|
||||||
|
pass # lockfile path is hardcoded, so no need to verify here
|
||||||
|
|
||||||
|
def _load(self):
|
||||||
|
try:
|
||||||
|
return super()._load()
|
||||||
|
except StageFileDoesNotExistError:
|
||||||
|
# we still need to account for git-ignored dvc.lock file
|
||||||
|
# even though it may not exist or have been .dvcignored
|
||||||
|
self._check_gitignored()
|
||||||
|
return {}, ""
|
||||||
|
except StageFileFormatError as exc:
|
||||||
raise LockfileCorruptedError(
|
raise LockfileCorruptedError(
|
||||||
f"Lockfile '{self.relpath}' is corrupted."
|
f"Lockfile '{self.relpath}' is corrupted."
|
||||||
)
|
) from exc
|
||||||
return data
|
|
||||||
|
def load(self):
|
||||||
|
d, _ = self._load()
|
||||||
|
return d
|
||||||
|
|
||||||
|
@property
|
||||||
|
def latest_version_info(self):
|
||||||
|
version = LOCKFILE_VERSION.V2.value # pylint:disable=no-member
|
||||||
|
return {SCHEMA_KWD: version}
|
||||||
|
|
||||||
def dump(self, stage, **kwargs):
|
def dump(self, stage, **kwargs):
|
||||||
stage_data = serialize.to_lockfile(stage)
|
stage_data = serialize.to_lockfile(stage)
|
||||||
if not self.exists():
|
|
||||||
modified = True
|
with modify_yaml(self.path, fs=self.repo.fs) as data:
|
||||||
logger.info("Generating lock file '%s'", self.relpath)
|
version = LOCKFILE_VERSION.from_dict(data)
|
||||||
data = stage_data
|
if version == LOCKFILE_VERSION.V1:
|
||||||
open(self.path, "w+").close()
|
logger.info(
|
||||||
else:
|
"Migrating lock file '%s' from v1 to v2", self.relpath
|
||||||
with self.repo.tree.open(self.path, "r") as fd:
|
)
|
||||||
data = parse_yaml_for_update(fd.read(), self.path)
|
migrate_lock_v1_to_v2(data, self.latest_version_info)
|
||||||
modified = data.get(stage.name, {}) != stage_data.get(
|
else:
|
||||||
|
if not data:
|
||||||
|
data.update(self.latest_version_info)
|
||||||
|
# order is important, meta should always be at the top
|
||||||
|
logger.info("Generating lock file '%s'", self.relpath)
|
||||||
|
|
||||||
|
data["stages"] = data.get("stages", {})
|
||||||
|
modified = data["stages"].get(stage.name, {}) != stage_data.get(
|
||||||
stage.name, {}
|
stage.name, {}
|
||||||
)
|
)
|
||||||
if modified:
|
if modified:
|
||||||
logger.info("Updating lock file '%s'", self.relpath)
|
logger.info("Updating lock file '%s'", self.relpath)
|
||||||
data.update(stage_data)
|
|
||||||
dump_yaml(self.path, data)
|
data["stages"].update(stage_data)
|
||||||
|
|
||||||
if modified:
|
if modified:
|
||||||
self.repo.scm.track_file(self.relpath)
|
self.repo.scm.track_file(self.relpath)
|
||||||
|
|
||||||
@@ -276,26 +393,41 @@ class Lockfile(FileMixin):
|
|||||||
if not self.exists():
|
if not self.exists():
|
||||||
return
|
return
|
||||||
|
|
||||||
with open(self.path) as f:
|
with open(self.path, encoding="utf-8") as f:
|
||||||
d = parse_yaml_for_update(f.read(), self.path)
|
d = parse_yaml_for_update(f.read(), self.path)
|
||||||
self.validate(d, self.path)
|
self.validate(d, self.path)
|
||||||
|
|
||||||
if stage.name not in d:
|
version = LOCKFILE_VERSION.from_dict(d)
|
||||||
|
data = d if version == LOCKFILE_VERSION.V1 else d.get("stages", {})
|
||||||
|
if stage.name not in data:
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.debug("Removing '%s' from '%s'", stage.name, self.path)
|
logger.debug("Removing '%s' from '%s'", stage.name, self.path)
|
||||||
del d[stage.name]
|
del data[stage.name]
|
||||||
|
|
||||||
dump_yaml(self.path, d)
|
if data:
|
||||||
|
dump_yaml(self.path, d)
|
||||||
|
else:
|
||||||
|
self.remove()
|
||||||
|
|
||||||
|
def merge(self, ancestor, other):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class Dvcfile:
|
class Dvcfile:
|
||||||
def __new__(cls, repo, path, **kwargs):
|
def __new__(cls, repo: "Repo", path: AnyPath, **kwargs: Any):
|
||||||
assert path
|
assert path
|
||||||
assert repo
|
assert repo
|
||||||
|
|
||||||
_, ext = os.path.splitext(path)
|
return make_dvcfile(repo, path, **kwargs)
|
||||||
if ext in [".yaml", ".yml"]:
|
|
||||||
return PipelineFile(repo, path, **kwargs)
|
|
||||||
# fallback to single stage file for better error messages
|
DVCFile = Union["PipelineFile", "SingleStageFile"]
|
||||||
return SingleStageFile(repo, path, **kwargs)
|
|
||||||
|
|
||||||
|
def make_dvcfile(repo: "Repo", path: AnyPath, **kwargs: Any) -> DVCFile:
|
||||||
|
_, ext = os.path.splitext(str(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)
|
||||||
|
|||||||
@@ -1,2 +1,8 @@
|
|||||||
|
DVC_CHECKPOINT = "DVC_CHECKPOINT"
|
||||||
DVC_DAEMON = "DVC_DAEMON"
|
DVC_DAEMON = "DVC_DAEMON"
|
||||||
DVC_PAGER = "DVC_PAGER"
|
DVC_PAGER = "DVC_PAGER"
|
||||||
|
DVC_ROOT = "DVC_ROOT"
|
||||||
|
DVCLIVE_PATH = "DVCLIVE_PATH"
|
||||||
|
DVCLIVE_SUMMARY = "DVCLIVE_SUMMARY"
|
||||||
|
DVCLIVE_HTML = "DVCLIVE_HTML"
|
||||||
|
DVCLIVE_RESUME = "DVCLIVE_RESUME"
|
||||||
|
|||||||
+64
-24
@@ -1,7 +1,5 @@
|
|||||||
"""Exceptions raised by the dvc."""
|
"""Exceptions raised by the dvc."""
|
||||||
from funcy import first
|
from typing import List
|
||||||
|
|
||||||
from dvc.utils import format_link, relpath
|
|
||||||
|
|
||||||
|
|
||||||
class DvcException(Exception):
|
class DvcException(Exception):
|
||||||
@@ -9,6 +7,7 @@ class DvcException(Exception):
|
|||||||
|
|
||||||
def __init__(self, msg, *args):
|
def __init__(self, msg, *args):
|
||||||
assert msg
|
assert msg
|
||||||
|
self.msg = msg
|
||||||
super().__init__(msg, *args)
|
super().__init__(msg, *args)
|
||||||
|
|
||||||
|
|
||||||
@@ -26,6 +25,8 @@ class OutputDuplicationError(DvcException):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, output, stages):
|
def __init__(self, output, stages):
|
||||||
|
from funcy import first
|
||||||
|
|
||||||
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)
|
||||||
if len(stages) == 1:
|
if len(stages) == 1:
|
||||||
@@ -42,17 +43,19 @@ class OutputDuplicationError(DvcException):
|
|||||||
|
|
||||||
|
|
||||||
class OutputNotFoundError(DvcException):
|
class OutputNotFoundError(DvcException):
|
||||||
"""Thrown if a file/directory not found in repository pipelines.
|
"""Thrown if a file/directory is not found as an output in any pipeline.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
output (unicode): path to the file/directory.
|
output (unicode): path to the file/directory.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, output, repo=None):
|
def __init__(self, output, repo=None):
|
||||||
|
from dvc.utils import relpath
|
||||||
|
|
||||||
self.output = output
|
self.output = output
|
||||||
self.repo = repo
|
self.repo = repo
|
||||||
super().__init__(
|
super().__init__(
|
||||||
"Unable to find DVC-file with output '{path}'".format(
|
"Unable to find DVC file with output '{path}'".format(
|
||||||
path=relpath(self.output)
|
path=relpath(self.output)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -105,7 +108,7 @@ class ArgumentDuplicationError(DvcException):
|
|||||||
|
|
||||||
|
|
||||||
class MoveNotDataSourceError(DvcException):
|
class MoveNotDataSourceError(DvcException):
|
||||||
"""Thrown if attempted to move a file/directory that is not an output
|
"""Thrown when trying to move a file/directory that is not an output
|
||||||
in a data source stage.
|
in a data source stage.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -164,34 +167,40 @@ class BadMetricError(DvcException):
|
|||||||
def __init__(self, paths):
|
def __init__(self, paths):
|
||||||
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 metrics files or are malformed: {paths}".format(
|
||||||
paths=", ".join(f"'{path}'" for path in paths)
|
paths=", ".join(f"'{path}'" for path in paths)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class NoMetricsError(DvcException):
|
class MetricsError(DvcException):
|
||||||
def __init__(self):
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class NoMetricsParsedError(MetricsError):
|
||||||
|
def __init__(self, command):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
"no metric files in this repository. Use `-m/-M` options for "
|
f"Could not parse {command} files. Use `-v` option to see more "
|
||||||
"`dvc run` to mark stage outputs as metrics."
|
"details."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class NoPlotsError(DvcException):
|
class NoMetricsFoundError(MetricsError):
|
||||||
def __init__(self):
|
def __init__(self, command, run_options):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
"no plots in this repository. Use `--plots/--plots-no-cache` "
|
f"No {command} files in this repository. "
|
||||||
"options for `dvc run` to mark stage outputs as plots."
|
f"Use `{run_options}` options for "
|
||||||
|
f"`dvc run` to mark stage outputs as {command}."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class YAMLFileCorruptedError(DvcException):
|
class MetricDoesNotExistError(MetricsError):
|
||||||
def __init__(self, path):
|
def __init__(self, targets: List[str]):
|
||||||
path = relpath(path)
|
if len(targets) == 1:
|
||||||
super().__init__(
|
msg = "'{}' does not exist."
|
||||||
f"unable to read: '{path}', YAML file structure is corrupted"
|
else:
|
||||||
)
|
msg = "'{}' do not exist."
|
||||||
|
super().__init__(msg.format(", ".join(targets)))
|
||||||
|
|
||||||
|
|
||||||
class RecursiveAddingWhileUsingFilename(DvcException):
|
class RecursiveAddingWhileUsingFilename(DvcException):
|
||||||
@@ -240,6 +249,8 @@ class DvcIgnoreInCollectedDirError(DvcException):
|
|||||||
|
|
||||||
class GitHookAlreadyExistsError(DvcException):
|
class GitHookAlreadyExistsError(DvcException):
|
||||||
def __init__(self, hook_name):
|
def __init__(self, hook_name):
|
||||||
|
from dvc.utils import format_link
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
"Hook '{}' already exists. Please refer to {} for more "
|
"Hook '{}' already exists. Please refer to {} for more "
|
||||||
"info.".format(
|
"info.".format(
|
||||||
@@ -264,12 +275,16 @@ class UploadError(DvcException):
|
|||||||
|
|
||||||
class CheckoutError(DvcException):
|
class CheckoutError(DvcException):
|
||||||
def __init__(self, target_infos, stats=None):
|
def __init__(self, target_infos, stats=None):
|
||||||
|
from dvc.utils import error_link
|
||||||
|
|
||||||
self.target_infos = target_infos
|
self.target_infos = target_infos
|
||||||
self.stats = stats
|
self.stats = stats
|
||||||
targets = [str(t) for t in target_infos]
|
targets = [str(t) for t in target_infos]
|
||||||
m = (
|
m = (
|
||||||
"Checkout failed for following targets:\n{}\nDid you "
|
"Checkout failed for following targets:\n{}\nIs your "
|
||||||
"forget to fetch?".format("\n".join(targets))
|
"cache up to date?\n{}".format(
|
||||||
|
"\n".join(targets), error_link("missing-files"),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
super().__init__(m)
|
super().__init__(m)
|
||||||
|
|
||||||
@@ -287,6 +302,8 @@ class NoRemoteInExternalRepoError(DvcException):
|
|||||||
|
|
||||||
class NoOutputInExternalRepoError(DvcException):
|
class NoOutputInExternalRepoError(DvcException):
|
||||||
def __init__(self, path, external_repo_path, external_repo_url):
|
def __init__(self, path, external_repo_path, external_repo_url):
|
||||||
|
from dvc.utils import relpath
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
"Output '{}' not found in target repository '{}'".format(
|
"Output '{}' not found in target repository '{}'".format(
|
||||||
relpath(path, external_repo_path), external_repo_url
|
relpath(path, external_repo_path), external_repo_url
|
||||||
@@ -317,6 +334,8 @@ class PathMissingError(DvcException):
|
|||||||
|
|
||||||
class RemoteCacheRequiredError(DvcException):
|
class RemoteCacheRequiredError(DvcException):
|
||||||
def __init__(self, path_info):
|
def __init__(self, path_info):
|
||||||
|
from dvc.utils import format_link
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
(
|
(
|
||||||
"Current operation was unsuccessful because '{}' requires "
|
"Current operation was unsuccessful because '{}' requires "
|
||||||
@@ -330,7 +349,7 @@ class RemoteCacheRequiredError(DvcException):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class IsADirectoryError(DvcException):
|
class IsADirectoryError(DvcException): # noqa,pylint:disable=redefined-builtin
|
||||||
"""Raised when a file operation is requested on a directory."""
|
"""Raised when a file operation is requested on a directory."""
|
||||||
|
|
||||||
|
|
||||||
@@ -344,3 +363,24 @@ class NoOutputOrStageError(DvcException):
|
|||||||
f"'{target}' "
|
f"'{target}' "
|
||||||
f"does not exist as an output or a stage name in '{file}'"
|
f"does not exist as an output or a stage name in '{file}'"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class MergeError(DvcException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class CacheLinkError(DvcException):
|
||||||
|
from dvc.utils import format_link
|
||||||
|
|
||||||
|
SUPPORT_LINK = "See {} for more information.".format(
|
||||||
|
format_link(
|
||||||
|
"https://dvc.org/doc/user-guide/troubleshooting#cache-types"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def __init__(self, path_infos):
|
||||||
|
msg = "No possible cache link types for '{}'. {}".format(
|
||||||
|
", ".join([str(path) for path in path_infos]), self.SUPPORT_LINK,
|
||||||
|
)
|
||||||
|
super().__init__(msg)
|
||||||
|
self.path_infos = path_infos
|
||||||
|
|||||||
+153
-204
@@ -3,63 +3,109 @@ import os
|
|||||||
import tempfile
|
import tempfile
|
||||||
import threading
|
import threading
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from distutils.dir_util import copy_tree
|
from typing import Dict
|
||||||
from typing import Iterable
|
|
||||||
|
|
||||||
from funcy import cached_property, retry, wrap_with
|
from funcy import retry, wrap_with
|
||||||
|
|
||||||
from dvc.config import NoRemoteError, NotDvcRepoError
|
|
||||||
from dvc.exceptions import (
|
from dvc.exceptions import (
|
||||||
FileMissingError,
|
FileMissingError,
|
||||||
NoOutputInExternalRepoError,
|
NoOutputInExternalRepoError,
|
||||||
NoRemoteInExternalRepoError,
|
NoRemoteInExternalRepoError,
|
||||||
|
NotDvcRepoError,
|
||||||
OutputNotFoundError,
|
OutputNotFoundError,
|
||||||
PathMissingError,
|
PathMissingError,
|
||||||
)
|
)
|
||||||
from dvc.path_info import PathInfo
|
|
||||||
from dvc.repo import Repo
|
from dvc.repo import Repo
|
||||||
from dvc.repo.tree import RepoTree
|
from dvc.utils import relpath
|
||||||
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__)
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def external_repo(url, rev=None, for_write=False):
|
def external_repo(
|
||||||
|
url, rev=None, for_write=False, cache_dir=None, cache_types=None, **kwargs
|
||||||
|
):
|
||||||
|
from dvc.config import NoRemoteError
|
||||||
|
from dvc.scm.git import Git
|
||||||
|
|
||||||
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:
|
# Local HEAD points to the tip of whatever branch we first cloned from
|
||||||
rev = "HEAD"
|
# (which may not be the default branch), use origin/HEAD here to get
|
||||||
try:
|
# the tip of the default branch
|
||||||
repo = ExternalRepo(path, url, rev, for_write=for_write)
|
rev = rev or "refs/remotes/origin/HEAD"
|
||||||
except NotDvcRepoError:
|
|
||||||
repo = ExternalGitRepo(path, url, rev)
|
cache_config = {
|
||||||
|
"cache": {
|
||||||
|
"dir": cache_dir or _get_cache_dir(url),
|
||||||
|
"type": cache_types,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
config = _get_remote_config(url) if os.path.isdir(url) else {}
|
||||||
|
config.update(cache_config)
|
||||||
|
|
||||||
|
def make_repo(path, **_kwargs):
|
||||||
|
_config = cache_config.copy()
|
||||||
|
if os.path.isdir(url):
|
||||||
|
rel = os.path.relpath(path, _kwargs["scm"].root_dir)
|
||||||
|
repo_path = os.path.join(url, rel)
|
||||||
|
_config.update(_get_remote_config(repo_path))
|
||||||
|
return Repo(path, config=_config, **_kwargs)
|
||||||
|
|
||||||
|
root_dir = path if for_write else os.path.realpath(path)
|
||||||
|
repo_kwargs = dict(
|
||||||
|
root_dir=root_dir,
|
||||||
|
url=url,
|
||||||
|
scm=None if for_write else Git(root_dir),
|
||||||
|
rev=None if for_write else rev,
|
||||||
|
config=config,
|
||||||
|
repo_factory=make_repo,
|
||||||
|
**kwargs,
|
||||||
|
)
|
||||||
|
|
||||||
|
if "subrepos" not in repo_kwargs:
|
||||||
|
repo_kwargs["subrepos"] = True
|
||||||
|
|
||||||
|
if "uninitialized" not in repo_kwargs:
|
||||||
|
repo_kwargs["uninitialized"] = True
|
||||||
|
|
||||||
|
repo = Repo(**repo_kwargs)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
yield repo
|
yield repo
|
||||||
except NoRemoteError:
|
except NoRemoteError as exc:
|
||||||
raise NoRemoteInExternalRepoError(url)
|
raise NoRemoteInExternalRepoError(url) from exc
|
||||||
except OutputNotFoundError as exc:
|
except OutputNotFoundError as exc:
|
||||||
if exc.repo is repo:
|
if exc.repo is repo:
|
||||||
raise NoOutputInExternalRepoError(exc.output, repo.root_dir, url)
|
raise NoOutputInExternalRepoError(
|
||||||
|
exc.output, repo.root_dir, url
|
||||||
|
) from exc
|
||||||
raise
|
raise
|
||||||
except FileMissingError as exc:
|
except FileMissingError as exc:
|
||||||
raise PathMissingError(exc.path, url)
|
raise PathMissingError(exc.path, url) from exc
|
||||||
finally:
|
finally:
|
||||||
repo.close()
|
repo.close()
|
||||||
if for_write:
|
if for_write:
|
||||||
_remove(path)
|
_remove(path)
|
||||||
|
|
||||||
|
|
||||||
CLONES = {}
|
CLONES: Dict[str, str] = {}
|
||||||
CACHE_DIRS = {}
|
CACHE_DIRS: Dict[str, str] = {}
|
||||||
|
|
||||||
|
|
||||||
|
@wrap_with(threading.Lock())
|
||||||
|
def _get_cache_dir(url):
|
||||||
|
try:
|
||||||
|
cache_dir = CACHE_DIRS[url]
|
||||||
|
except KeyError:
|
||||||
|
cache_dir = CACHE_DIRS[url] = tempfile.mkdtemp("dvc-cache")
|
||||||
|
return cache_dir
|
||||||
|
|
||||||
|
|
||||||
def clean_repos():
|
def clean_repos():
|
||||||
# Outside code should not see cache while we are removing
|
# Outside code should not see cache while we are removing
|
||||||
paths = list(CLONES.values()) + list(CACHE_DIRS.values())
|
paths = [path for path, _ in CLONES.values()] + list(CACHE_DIRS.values())
|
||||||
CLONES.clear()
|
CLONES.clear()
|
||||||
CACHE_DIRS.clear()
|
CACHE_DIRS.clear()
|
||||||
|
|
||||||
@@ -67,177 +113,28 @@ def clean_repos():
|
|||||||
_remove(path)
|
_remove(path)
|
||||||
|
|
||||||
|
|
||||||
class BaseExternalRepo:
|
def _get_remote_config(url):
|
||||||
|
try:
|
||||||
|
repo = Repo(url)
|
||||||
|
except NotDvcRepoError:
|
||||||
|
return {}
|
||||||
|
|
||||||
_local_cache = None
|
try:
|
||||||
|
name = repo.config["core"].get("remote")
|
||||||
|
if not name:
|
||||||
|
# Fill the empty upstream entry with a new remote pointing to the
|
||||||
|
# original repo's cache location.
|
||||||
|
name = "auto-generated-upstream"
|
||||||
|
return {
|
||||||
|
"core": {"remote": name},
|
||||||
|
"remote": {name: {"url": repo.odb.local.cache_dir}},
|
||||||
|
}
|
||||||
|
|
||||||
@property
|
# Use original remote to make sure that we are using correct url,
|
||||||
def local_cache(self):
|
# credential paths, etc if they are relative to the config location.
|
||||||
if hasattr(self, "cache"):
|
return {"remote": {name: repo.config["remote"][name]}}
|
||||||
return self.cache.local
|
finally:
|
||||||
return self._local_cache
|
repo.close()
|
||||||
|
|
||||||
@contextmanager
|
|
||||||
def use_cache(self, cache):
|
|
||||||
"""Use the specified cache in place of default tmpdir cache for
|
|
||||||
download operations.
|
|
||||||
"""
|
|
||||||
if hasattr(self, "cache"):
|
|
||||||
save_cache = self.cache.local
|
|
||||||
self.cache.local = cache
|
|
||||||
self._local_cache = cache
|
|
||||||
|
|
||||||
yield
|
|
||||||
|
|
||||||
if hasattr(self, "cache"):
|
|
||||||
self.cache.local = save_cache
|
|
||||||
self._local_cache = None
|
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def repo_tree(self):
|
|
||||||
return RepoTree(self, fetch=True)
|
|
||||||
|
|
||||||
def get_rev(self):
|
|
||||||
if is_working_tree(self.tree):
|
|
||||||
return self.scm.get_rev()
|
|
||||||
if hasattr(self.tree, "tree"):
|
|
||||||
return self.tree.tree.rev
|
|
||||||
return self.tree.rev
|
|
||||||
|
|
||||||
def fetch_external(self, paths: Iterable, **kwargs):
|
|
||||||
"""Fetch specified external repo paths into cache.
|
|
||||||
|
|
||||||
Returns 3-tuple in the form
|
|
||||||
(downloaded, failed, list(cache_infos))
|
|
||||||
where cache_infos can be used as checkout targets for the
|
|
||||||
fetched paths.
|
|
||||||
"""
|
|
||||||
download_results = []
|
|
||||||
failed = 0
|
|
||||||
|
|
||||||
paths = [PathInfo(self.root_dir) / path for path in paths]
|
|
||||||
|
|
||||||
def download_update(result):
|
|
||||||
download_results.append(result)
|
|
||||||
|
|
||||||
save_infos = []
|
|
||||||
for path in paths:
|
|
||||||
if not self.repo_tree.exists(path):
|
|
||||||
raise PathMissingError(path, self.url)
|
|
||||||
save_info = self.local_cache.save(
|
|
||||||
path,
|
|
||||||
self.repo_tree,
|
|
||||||
None,
|
|
||||||
save_link=False,
|
|
||||||
download_callback=download_update,
|
|
||||||
)
|
|
||||||
save_infos.append(save_info)
|
|
||||||
|
|
||||||
return sum(download_results), failed, save_infos
|
|
||||||
|
|
||||||
def get_external(self, path, dest):
|
|
||||||
"""Convenience wrapper for fetch_external and checkout."""
|
|
||||||
if self.local_cache:
|
|
||||||
# fetch DVC and git files to tmpdir cache, then checkout
|
|
||||||
_, _, save_infos = self.fetch_external([path])
|
|
||||||
self.local_cache.checkout(PathInfo(dest), save_infos[0])
|
|
||||||
else:
|
|
||||||
# git-only erepo with no cache, just copy files directly
|
|
||||||
# to dest
|
|
||||||
path = PathInfo(self.root_dir) / path
|
|
||||||
if not self.repo_tree.exists(path):
|
|
||||||
raise PathMissingError(path, self.url)
|
|
||||||
self.repo_tree.copytree(path, dest)
|
|
||||||
|
|
||||||
|
|
||||||
class ExternalRepo(Repo, BaseExternalRepo):
|
|
||||||
def __init__(self, root_dir, url, rev, for_write=False):
|
|
||||||
if for_write:
|
|
||||||
super().__init__(root_dir)
|
|
||||||
else:
|
|
||||||
root_dir = os.path.realpath(root_dir)
|
|
||||||
super().__init__(root_dir, scm=Git(root_dir), rev=rev)
|
|
||||||
self.url = url
|
|
||||||
self._set_cache_dir()
|
|
||||||
self._fix_upstream()
|
|
||||||
|
|
||||||
@wrap_with(threading.Lock())
|
|
||||||
def _set_cache_dir(self):
|
|
||||||
try:
|
|
||||||
cache_dir = CACHE_DIRS[self.url]
|
|
||||||
except KeyError:
|
|
||||||
cache_dir = CACHE_DIRS[self.url] = tempfile.mkdtemp("dvc-cache")
|
|
||||||
|
|
||||||
self.cache.local.cache_dir = cache_dir
|
|
||||||
self._local_cache = self.cache.local
|
|
||||||
|
|
||||||
def _fix_upstream(self):
|
|
||||||
if not os.path.isdir(self.url):
|
|
||||||
return
|
|
||||||
|
|
||||||
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:
|
|
||||||
self._fix_local_remote(src_repo, remote_name)
|
|
||||||
else:
|
|
||||||
self._add_upstream(src_repo)
|
|
||||||
finally:
|
|
||||||
src_repo.close()
|
|
||||||
|
|
||||||
def _fix_local_remote(self, src_repo, remote_name):
|
|
||||||
# If a remote URL is relative to the source repo,
|
|
||||||
# it will have changed upon config load and made
|
|
||||||
# relative to this new repo. Restore the old one here.
|
|
||||||
new_remote = self.config["remote"][remote_name]
|
|
||||||
old_remote = src_repo.config["remote"][remote_name]
|
|
||||||
if new_remote["url"] != old_remote["url"]:
|
|
||||||
new_remote["url"] = old_remote["url"]
|
|
||||||
|
|
||||||
def _add_upstream(self, src_repo):
|
|
||||||
# Fill the empty upstream entry with a new remote pointing to the
|
|
||||||
# original repo's cache location.
|
|
||||||
cache_dir = src_repo.cache.local.cache_dir
|
|
||||||
self.config["remote"]["auto-generated-upstream"] = {"url": cache_dir}
|
|
||||||
self.config["core"]["remote"] = "auto-generated-upstream"
|
|
||||||
|
|
||||||
|
|
||||||
class ExternalGitRepo(BaseExternalRepo):
|
|
||||||
def __init__(self, root_dir, url, rev):
|
|
||||||
self.root_dir = os.path.realpath(root_dir)
|
|
||||||
self.url = url
|
|
||||||
self.tree = self.scm.get_tree(rev)
|
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def scm(self):
|
|
||||||
return Git(self.root_dir)
|
|
||||||
|
|
||||||
def close(self):
|
|
||||||
if "scm" in self.__dict__:
|
|
||||||
self.scm.close()
|
|
||||||
|
|
||||||
def find_out_by_relpath(self, path):
|
|
||||||
raise OutputNotFoundError(path, self)
|
|
||||||
|
|
||||||
@contextmanager
|
|
||||||
def open_by_relpath(self, path, mode="r", encoding=None, **kwargs):
|
|
||||||
"""Opens a specified resource as a file object."""
|
|
||||||
tree = RepoTree(self)
|
|
||||||
try:
|
|
||||||
with tree.open(
|
|
||||||
path, mode=mode, encoding=encoding, **kwargs
|
|
||||||
) as fobj:
|
|
||||||
yield fobj
|
|
||||||
except FileNotFoundError:
|
|
||||||
raise PathMissingError(path, self.url)
|
|
||||||
|
|
||||||
|
|
||||||
def _cached_clone(url, rev, for_write=False):
|
def _cached_clone(url, rev, for_write=False):
|
||||||
@@ -247,12 +144,14 @@ 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.
|
||||||
"""
|
"""
|
||||||
|
from distutils.dir_util import copy_tree
|
||||||
|
|
||||||
# even if we have already cloned this repo, we may need to
|
# even if we have already cloned this repo, we may need to
|
||||||
# fetch/fast-forward to get specified rev
|
# fetch/fast-forward to get specified rev
|
||||||
clone_path = _clone_default_branch(url, rev)
|
clone_path, shallow = _clone_default_branch(url, rev, for_write=for_write)
|
||||||
|
|
||||||
if not for_write and (url) in CLONES:
|
if not for_write and (url) in CLONES:
|
||||||
return CLONES[url]
|
return CLONES[url][0]
|
||||||
|
|
||||||
# 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")
|
||||||
@@ -263,17 +162,19 @@ def _cached_clone(url, rev, for_write=False):
|
|||||||
if for_write:
|
if for_write:
|
||||||
_git_checkout(repo_path, rev)
|
_git_checkout(repo_path, rev)
|
||||||
else:
|
else:
|
||||||
CLONES[url] = repo_path
|
CLONES[url] = (repo_path, shallow)
|
||||||
return repo_path
|
return repo_path
|
||||||
|
|
||||||
|
|
||||||
@wrap_with(threading.Lock())
|
@wrap_with(threading.Lock())
|
||||||
def _clone_default_branch(url, rev):
|
def _clone_default_branch(url, rev, for_write=False):
|
||||||
"""Get or create a clean clone of the url.
|
"""Get or create a clean clone of the url.
|
||||||
|
|
||||||
The cloned is reactualized with git pull unless rev is a known sha.
|
The cloned is reactualized with git pull unless rev is a known sha.
|
||||||
"""
|
"""
|
||||||
clone_path = CLONES.get(url)
|
from dvc.scm.git import Git
|
||||||
|
|
||||||
|
clone_path, shallow = CLONES.get(url, (None, False))
|
||||||
|
|
||||||
git = None
|
git = None
|
||||||
try:
|
try:
|
||||||
@@ -281,21 +182,62 @@ def _clone_default_branch(url, rev):
|
|||||||
git = Git(clone_path)
|
git = Git(clone_path)
|
||||||
# Do not pull for known shas, branches and tags might move
|
# Do not pull for known shas, branches and tags might move
|
||||||
if not Git.is_sha(rev) or not git.has_rev(rev):
|
if not Git.is_sha(rev) or not git.has_rev(rev):
|
||||||
logger.debug("erepo: git pull %s", url)
|
if shallow:
|
||||||
git.pull()
|
# If we are missing a rev in a shallow clone, fallback to
|
||||||
|
# a full (unshallowed) clone. Since fetching specific rev
|
||||||
|
# SHAs is only available in certain git versions, if we
|
||||||
|
# have need to reference multiple specific revs for a
|
||||||
|
# given repo URL it is easier/safer for us to work with
|
||||||
|
# full clones in this case.
|
||||||
|
logger.debug("erepo: unshallowing clone for '%s'", url)
|
||||||
|
_unshallow(git)
|
||||||
|
shallow = False
|
||||||
|
CLONES[url] = (clone_path, shallow)
|
||||||
|
else:
|
||||||
|
logger.debug("erepo: git pull '%s'", url)
|
||||||
|
git.pull()
|
||||||
else:
|
else:
|
||||||
logger.debug("erepo: git clone %s to a temporary dir", url)
|
logger.debug("erepo: git clone '%s' to a temporary dir", url)
|
||||||
clone_path = tempfile.mkdtemp("dvc-clone")
|
clone_path = tempfile.mkdtemp("dvc-clone")
|
||||||
git = Git.clone(url, clone_path)
|
if not for_write and rev and not Git.is_sha(rev):
|
||||||
CLONES[url] = clone_path
|
# If rev is a tag or branch name try shallow clone first
|
||||||
|
from dvc.scm.base import CloneError
|
||||||
|
|
||||||
|
try:
|
||||||
|
git = Git.clone(url, clone_path, shallow_branch=rev)
|
||||||
|
shallow = True
|
||||||
|
logger.debug(
|
||||||
|
"erepo: using shallow clone for branch '%s'", rev
|
||||||
|
)
|
||||||
|
except CloneError:
|
||||||
|
pass
|
||||||
|
if not git:
|
||||||
|
git = Git.clone(url, clone_path)
|
||||||
|
shallow = False
|
||||||
|
CLONES[url] = (clone_path, shallow)
|
||||||
finally:
|
finally:
|
||||||
if git:
|
if git:
|
||||||
git.close()
|
git.close()
|
||||||
|
|
||||||
return clone_path
|
return clone_path, shallow
|
||||||
|
|
||||||
|
|
||||||
|
def _unshallow(git):
|
||||||
|
if git.gitpython.repo.head.is_detached:
|
||||||
|
# If this is a detached head (i.e. we shallow cloned a tag) switch to
|
||||||
|
# the default branch
|
||||||
|
origin_refs = git.gitpython.repo.remotes["origin"].refs
|
||||||
|
ref = origin_refs["HEAD"].reference
|
||||||
|
branch_name = ref.name.split("/")[-1]
|
||||||
|
branch = git.gitpython.repo.create_head(branch_name, ref)
|
||||||
|
branch.set_tracking_branch(ref)
|
||||||
|
branch.checkout()
|
||||||
|
git.pull(unshallow=True)
|
||||||
|
|
||||||
|
|
||||||
def _git_checkout(repo_path, rev):
|
def _git_checkout(repo_path, rev):
|
||||||
|
from dvc.scm.git import Git
|
||||||
|
|
||||||
logger.debug("erepo: git checkout %s@%s", repo_path, rev)
|
logger.debug("erepo: git checkout %s@%s", repo_path, rev)
|
||||||
git = Git(repo_path)
|
git = Git(repo_path)
|
||||||
try:
|
try:
|
||||||
@@ -305,9 +247,16 @@ def _git_checkout(repo_path, rev):
|
|||||||
|
|
||||||
|
|
||||||
def _remove(path):
|
def _remove(path):
|
||||||
|
from dvc.utils.fs import remove
|
||||||
|
|
||||||
if os.name == "nt":
|
if os.name == "nt":
|
||||||
# git.exe may hang for a while not permitting to remove temp dir
|
# git.exe may hang for a while not permitting to remove temp dir
|
||||||
os_retry = retry(5, errors=OSError, timeout=0.1)
|
os_retry = retry(5, errors=OSError, timeout=0.1)
|
||||||
os_retry(remove)(path)
|
try:
|
||||||
|
os_retry(remove)(path)
|
||||||
|
except PermissionError:
|
||||||
|
logger.warning(
|
||||||
|
"Failed to remove '%s'", relpath(path), exc_info=True
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
remove(path)
|
remove(path)
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
import posixpath
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
from ..scheme import Schemes
|
||||||
|
from .azure import AzureFileSystem
|
||||||
|
from .gdrive import GDriveFileSystem
|
||||||
|
from .gs import GSFileSystem
|
||||||
|
from .hdfs import HDFSFileSystem
|
||||||
|
from .http import HTTPFileSystem
|
||||||
|
from .https import HTTPSFileSystem
|
||||||
|
from .local import LocalFileSystem
|
||||||
|
from .oss import OSSFileSystem
|
||||||
|
from .s3 import S3FileSystem
|
||||||
|
from .ssh import SSHFileSystem
|
||||||
|
from .webdav import WebDAVFileSystem
|
||||||
|
from .webdavs import WebDAVSFileSystem
|
||||||
|
from .webhdfs import WebHDFSFileSystem
|
||||||
|
|
||||||
|
FS_MAP = {
|
||||||
|
Schemes.AZURE: AzureFileSystem,
|
||||||
|
Schemes.GDRIVE: GDriveFileSystem,
|
||||||
|
Schemes.GS: GSFileSystem,
|
||||||
|
Schemes.HDFS: HDFSFileSystem,
|
||||||
|
Schemes.WEBHDFS: WebHDFSFileSystem,
|
||||||
|
Schemes.HTTP: HTTPFileSystem,
|
||||||
|
Schemes.HTTPS: HTTPSFileSystem,
|
||||||
|
Schemes.S3: S3FileSystem,
|
||||||
|
Schemes.SSH: SSHFileSystem,
|
||||||
|
Schemes.OSS: OSSFileSystem,
|
||||||
|
Schemes.WEBDAV: WebDAVFileSystem,
|
||||||
|
Schemes.WEBDAVS: WebDAVSFileSystem,
|
||||||
|
# NOTE: LocalFileSystem is the default
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_fs_cls(remote_conf):
|
||||||
|
scheme = urlparse(remote_conf["url"]).scheme
|
||||||
|
return FS_MAP.get(scheme, LocalFileSystem)
|
||||||
|
|
||||||
|
|
||||||
|
def get_fs_config(config, **kwargs):
|
||||||
|
name = kwargs.get("name")
|
||||||
|
if name:
|
||||||
|
remote_conf = config["remote"][name.lower()]
|
||||||
|
else:
|
||||||
|
remote_conf = kwargs
|
||||||
|
return _resolve_remote_refs(config, remote_conf)
|
||||||
|
|
||||||
|
|
||||||
|
def _resolve_remote_refs(config, remote_conf):
|
||||||
|
# Support for cross referenced remotes.
|
||||||
|
# This will merge the settings, shadowing base ref with remote_conf.
|
||||||
|
# For example, having:
|
||||||
|
#
|
||||||
|
# dvc remote add server ssh://localhost
|
||||||
|
# dvc remote modify server user root
|
||||||
|
# dvc remote modify server ask_password true
|
||||||
|
#
|
||||||
|
# dvc remote add images remote://server/tmp/pictures
|
||||||
|
# dvc remote modify images user alice
|
||||||
|
# dvc remote modify images ask_password false
|
||||||
|
# dvc remote modify images password asdf1234
|
||||||
|
#
|
||||||
|
# Results on a config dictionary like:
|
||||||
|
#
|
||||||
|
# {
|
||||||
|
# "url": "ssh://localhost/tmp/pictures",
|
||||||
|
# "user": "alice",
|
||||||
|
# "password": "asdf1234",
|
||||||
|
# "ask_password": False,
|
||||||
|
# }
|
||||||
|
parsed = urlparse(remote_conf["url"])
|
||||||
|
if parsed.scheme != "remote":
|
||||||
|
return remote_conf
|
||||||
|
|
||||||
|
base = get_fs_config(config, name=parsed.netloc)
|
||||||
|
url = posixpath.join(base["url"], parsed.path.lstrip("/"))
|
||||||
|
return {**base, **remote_conf, "url": url}
|
||||||
|
|
||||||
|
|
||||||
|
def get_cloud_fs(repo, **kwargs):
|
||||||
|
from dvc.config import ConfigError
|
||||||
|
from dvc.config_schema import SCHEMA, Invalid
|
||||||
|
|
||||||
|
remote_conf = get_fs_config(repo.config, **kwargs)
|
||||||
|
try:
|
||||||
|
remote_conf = SCHEMA["remote"][str](remote_conf)
|
||||||
|
except Invalid as exc:
|
||||||
|
raise ConfigError(str(exc)) from None
|
||||||
|
return get_fs_cls(remote_conf)(repo, remote_conf)
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
from dataclasses import dataclass, field
|
||||||
|
from typing import TYPE_CHECKING, List
|
||||||
|
|
||||||
|
from dvc.output import BaseOutput
|
||||||
|
from dvc.path_info import PathInfo
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from dvc.repo import Repo
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Metadata:
|
||||||
|
"""
|
||||||
|
Container for storing metadata for a given path, similar in spirit to
|
||||||
|
`os.stat_result`.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# required field
|
||||||
|
path_info: PathInfo
|
||||||
|
repo: "Repo"
|
||||||
|
|
||||||
|
# computed fields
|
||||||
|
is_output: bool = field(init=False, default=False) # is it an output?
|
||||||
|
# is the path part of an output?
|
||||||
|
part_of_output: bool = field(init=False, default=False)
|
||||||
|
# does the path contain outputs?
|
||||||
|
contains_outputs: bool = field(init=False, default=False)
|
||||||
|
# is the path tracked by dvc? equivalent to (is_output or part_of_output)
|
||||||
|
is_dvc: bool = field(init=False, default=False)
|
||||||
|
# does dvc has any output in that path or inside it? equiv. to bool(outs)
|
||||||
|
output_exists: bool = field(init=False)
|
||||||
|
|
||||||
|
# optional fields
|
||||||
|
isdir: bool = False # is it a directory?
|
||||||
|
is_exec: bool = False # is it an executable?
|
||||||
|
outs: List[BaseOutput] = field(default_factory=list) # list of outputs
|
||||||
|
|
||||||
|
def __post_init__(self):
|
||||||
|
self.output_exists = bool(self.outs)
|
||||||
|
|
||||||
|
if not self.output_exists:
|
||||||
|
return
|
||||||
|
|
||||||
|
# it can contain multiple outputs
|
||||||
|
if len(self.outs) > 1:
|
||||||
|
self.contains_outputs = True
|
||||||
|
else:
|
||||||
|
out = self.outs[0]
|
||||||
|
# or, the path itself could be an output
|
||||||
|
self.is_output = self.path_info == out.path_info
|
||||||
|
|
||||||
|
# or, a directory must have an output somewhere deep inside it
|
||||||
|
if not self.is_output:
|
||||||
|
self.contains_outputs = out.path_info.isin(self.path_info)
|
||||||
|
|
||||||
|
# or, the path could be a part of an output, i.e. inside of an output
|
||||||
|
self.part_of_output = not self.is_output and not self.contains_outputs
|
||||||
|
|
||||||
|
self.is_dvc = self.is_output or self.part_of_output
|
||||||
|
# if it contains outputs, it must be a dir
|
||||||
|
self.isdir = self.contains_outputs
|
||||||
|
|
||||||
|
@property
|
||||||
|
def isfile(self):
|
||||||
|
# self.isdir might require additional computation, especially if it's
|
||||||
|
# a dir that's inside a dvc-tracked dir
|
||||||
|
# since, `Metadata()` does not support being used as null (i.e. when
|
||||||
|
# path does not exist), `isfile` becomes `isdir`'s complement.
|
||||||
|
return not self.isdir
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"Metadata: {self.path_info}"
|
||||||
+216
@@ -0,0 +1,216 @@
|
|||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import threading
|
||||||
|
|
||||||
|
from funcy import cached_property, wrap_prop
|
||||||
|
|
||||||
|
from dvc.exceptions import DvcException
|
||||||
|
from dvc.path_info import CloudURLInfo
|
||||||
|
from dvc.progress import Tqdm
|
||||||
|
from dvc.scheme import Schemes
|
||||||
|
from dvc.utils import format_link
|
||||||
|
|
||||||
|
from .base import BaseFileSystem
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
_DEFAULT_CREDS_STEPS = (
|
||||||
|
"https://azuresdkdocs.blob.core.windows.net/$web/python/"
|
||||||
|
"azure-identity/1.4.0/azure.identity.html#azure.identity"
|
||||||
|
".DefaultAzureCredential"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class AzureAuthError(DvcException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class AzureFileSystem(BaseFileSystem):
|
||||||
|
scheme = Schemes.AZURE
|
||||||
|
PATH_CLS = CloudURLInfo
|
||||||
|
PARAM_CHECKSUM = "etag"
|
||||||
|
DETAIL_FIELDS = frozenset(("etag", "size"))
|
||||||
|
REQUIRES = {
|
||||||
|
"adlfs": "adlfs",
|
||||||
|
"knack": "knack",
|
||||||
|
"azure-identity": "azure.identity",
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, repo, config):
|
||||||
|
super().__init__(repo, config)
|
||||||
|
|
||||||
|
url = config.get("url")
|
||||||
|
self.path_info = self.PATH_CLS(url)
|
||||||
|
self.bucket = self.path_info.bucket
|
||||||
|
|
||||||
|
if not self.bucket:
|
||||||
|
container = self._az_config.get("storage", "container_name", None)
|
||||||
|
url = f"azure://{container}"
|
||||||
|
|
||||||
|
self.path_info = self.PATH_CLS(url)
|
||||||
|
self.bucket = self.path_info.bucket
|
||||||
|
|
||||||
|
self.login_method, self.login_info = self._prepare_credentials(config)
|
||||||
|
|
||||||
|
def _prepare_credentials(self, config):
|
||||||
|
from azure.identity.aio import DefaultAzureCredential
|
||||||
|
|
||||||
|
login_info = {}
|
||||||
|
login_info["connection_string"] = config.get(
|
||||||
|
"connection_string",
|
||||||
|
self._az_config.get("storage", "connection_string", None),
|
||||||
|
)
|
||||||
|
login_info["account_name"] = config.get(
|
||||||
|
"account_name", self._az_config.get("storage", "account", None)
|
||||||
|
)
|
||||||
|
login_info["account_key"] = config.get(
|
||||||
|
"account_key", self._az_config.get("storage", "key", None)
|
||||||
|
)
|
||||||
|
login_info["sas_token"] = config.get(
|
||||||
|
"sas_token", self._az_config.get("storage", "sas_token", None)
|
||||||
|
)
|
||||||
|
login_info["tenant_id"] = config.get("tenant_id")
|
||||||
|
login_info["client_id"] = config.get("client_id")
|
||||||
|
login_info["client_secret"] = config.get("client_secret")
|
||||||
|
|
||||||
|
if not any(login_info.values()):
|
||||||
|
login_info["credentials"] = DefaultAzureCredential()
|
||||||
|
|
||||||
|
for login_method, required_keys in [ # noqa
|
||||||
|
("connection string", ["connection_string"]),
|
||||||
|
("account key", ["account_name", "account_key"]),
|
||||||
|
("SAS token", ["account_name", "sas_token"]),
|
||||||
|
("anonymous login", ["account_name"]),
|
||||||
|
(f"default credentials ({_DEFAULT_CREDS_STEPS})", ["credentials"]),
|
||||||
|
]:
|
||||||
|
if all(login_info.get(key) is not None for key in required_keys):
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
login_method = None
|
||||||
|
|
||||||
|
return login_method, login_info
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def _az_config(self):
|
||||||
|
# NOTE: ideally we would've used get_default_cli().config from
|
||||||
|
# azure.cli.core, but azure-cli-core has a lot of conflicts with other
|
||||||
|
# dependencies. So instead we are just use knack directly
|
||||||
|
from knack.config import CLIConfig
|
||||||
|
|
||||||
|
config_dir = os.getenv(
|
||||||
|
"AZURE_CONFIG_DIR", os.path.expanduser(os.path.join("~", ".azure"))
|
||||||
|
)
|
||||||
|
return CLIConfig(config_dir=config_dir, config_env_var_prefix="AZURE")
|
||||||
|
|
||||||
|
@wrap_prop(threading.Lock())
|
||||||
|
@cached_property
|
||||||
|
def fs(self):
|
||||||
|
from adlfs import AzureBlobFileSystem
|
||||||
|
from azure.core.exceptions import AzureError
|
||||||
|
|
||||||
|
try:
|
||||||
|
file_system = AzureBlobFileSystem(**self.login_info)
|
||||||
|
if self.bucket not in [
|
||||||
|
container.rstrip("/") for container in file_system.ls("/")
|
||||||
|
]:
|
||||||
|
file_system.mkdir(self.bucket)
|
||||||
|
except (ValueError, AzureError) as e:
|
||||||
|
raise AzureAuthError(
|
||||||
|
f"Authentication to Azure Blob Storage via {self.login_method}"
|
||||||
|
" failed.\nLearn more about configuration settings at"
|
||||||
|
f" {format_link('https://man.dvc.org/remote/modify')}"
|
||||||
|
) from e
|
||||||
|
|
||||||
|
return file_system
|
||||||
|
|
||||||
|
def _with_bucket(self, path):
|
||||||
|
if isinstance(path, self.PATH_CLS):
|
||||||
|
return f"{path.bucket}/{path.path}"
|
||||||
|
return path
|
||||||
|
|
||||||
|
def open(
|
||||||
|
self, path_info, mode="r", **kwargs
|
||||||
|
): # pylint: disable=arguments-differ
|
||||||
|
return self.fs.open(self._with_bucket(path_info), mode=mode)
|
||||||
|
|
||||||
|
def exists(self, path_info, use_dvcignore=False):
|
||||||
|
return self.fs.exists(self._with_bucket(path_info))
|
||||||
|
|
||||||
|
def _strip_bucket(self, entry):
|
||||||
|
_, entry = entry.split("/", 1)
|
||||||
|
return entry
|
||||||
|
|
||||||
|
def _strip_buckets(self, entries, detail, prefix=None):
|
||||||
|
for entry in entries:
|
||||||
|
if detail:
|
||||||
|
entry = entry.copy()
|
||||||
|
entry["name"] = self._strip_bucket(entry["name"])
|
||||||
|
else:
|
||||||
|
entry = self._strip_bucket(
|
||||||
|
f"{prefix}/{entry}" if prefix else entry
|
||||||
|
)
|
||||||
|
yield entry
|
||||||
|
|
||||||
|
def ls(
|
||||||
|
self, path_info, detail=False, recursive=False
|
||||||
|
): # pylint: disable=arguments-differ
|
||||||
|
path = self._with_bucket(path_info)
|
||||||
|
if recursive:
|
||||||
|
for root, _, files in self.fs.walk(path, detail=detail):
|
||||||
|
if detail:
|
||||||
|
files = files.values()
|
||||||
|
yield from self._strip_buckets(files, detail, prefix=root)
|
||||||
|
return None
|
||||||
|
|
||||||
|
yield from self._strip_buckets(self.ls(path, detail=detail), detail)
|
||||||
|
|
||||||
|
def walk_files(self, path_info, **kwargs):
|
||||||
|
for file in self.ls(path_info, recursive=True):
|
||||||
|
yield path_info.replace(path=file)
|
||||||
|
|
||||||
|
def remove(self, path_info):
|
||||||
|
self.fs.delete(self._with_bucket(path_info))
|
||||||
|
|
||||||
|
def info(self, path_info):
|
||||||
|
info = self.fs.info(self._with_bucket(path_info)).copy()
|
||||||
|
info["name"] = self._strip_bucket(info["name"])
|
||||||
|
return info
|
||||||
|
|
||||||
|
def _upload_fobj(self, fobj, to_info):
|
||||||
|
from adlfs import AzureBlobFile
|
||||||
|
|
||||||
|
with self.open(to_info, "wb") as fdest:
|
||||||
|
shutil.copyfileobj(
|
||||||
|
fobj, fdest, length=AzureBlobFile.DEFAULT_BLOCK_SIZE
|
||||||
|
)
|
||||||
|
|
||||||
|
def _upload(
|
||||||
|
self, from_file, to_info, name=None, no_progress_bar=False, **kwargs
|
||||||
|
):
|
||||||
|
total = os.path.getsize(from_file)
|
||||||
|
with open(from_file, "rb") as fobj:
|
||||||
|
self.upload_fobj(
|
||||||
|
fobj,
|
||||||
|
self._with_bucket(to_info),
|
||||||
|
desc=name,
|
||||||
|
total=total,
|
||||||
|
no_progress_bar=no_progress_bar,
|
||||||
|
)
|
||||||
|
self.fs.invalidate_cache(self._with_bucket(to_info.parent))
|
||||||
|
|
||||||
|
def _download(
|
||||||
|
self, from_info, to_file, name=None, no_progress_bar=False, **pbar_args
|
||||||
|
):
|
||||||
|
total = self.getsize(self._with_bucket(from_info))
|
||||||
|
with self.open(from_info, "rb") as fobj:
|
||||||
|
with Tqdm.wrapattr(
|
||||||
|
fobj,
|
||||||
|
"read",
|
||||||
|
desc=name,
|
||||||
|
disable=no_progress_bar,
|
||||||
|
bytes=True,
|
||||||
|
total=total,
|
||||||
|
**pbar_args,
|
||||||
|
) as wrapped:
|
||||||
|
with open(to_file, "wb") as fdest:
|
||||||
|
shutil.copyfileobj(wrapped, fdest)
|
||||||
+339
@@ -0,0 +1,339 @@
|
|||||||
|
import logging
|
||||||
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
|
from functools import partial
|
||||||
|
from multiprocessing import cpu_count
|
||||||
|
from typing import Any, ClassVar, Dict, FrozenSet, Optional
|
||||||
|
|
||||||
|
from funcy import cached_property
|
||||||
|
|
||||||
|
from dvc.exceptions import DvcException
|
||||||
|
from dvc.path_info import URLInfo
|
||||||
|
from dvc.progress import Tqdm
|
||||||
|
from dvc.utils import tmp_fname
|
||||||
|
from dvc.utils.fs import makedirs, move
|
||||||
|
from dvc.utils.http import open_url
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class RemoteCmdError(DvcException):
|
||||||
|
def __init__(self, remote, cmd, ret, err):
|
||||||
|
super().__init__(
|
||||||
|
"{remote} command '{cmd}' finished with non-zero return code"
|
||||||
|
" {ret}': {err}".format(remote=remote, cmd=cmd, ret=ret, err=err)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class RemoteActionNotImplemented(DvcException):
|
||||||
|
def __init__(self, action, scheme):
|
||||||
|
m = f"{action} is not supported for {scheme} remotes"
|
||||||
|
super().__init__(m)
|
||||||
|
|
||||||
|
|
||||||
|
class RemoteMissingDepsError(DvcException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class BaseFileSystem:
|
||||||
|
scheme = "base"
|
||||||
|
REQUIRES: ClassVar[Dict[str, str]] = {}
|
||||||
|
PATH_CLS = URLInfo # type: Any
|
||||||
|
JOBS = 4 * cpu_count()
|
||||||
|
|
||||||
|
CHECKSUM_DIR_SUFFIX = ".dir"
|
||||||
|
HASH_JOBS = max(1, min(4, cpu_count() // 2))
|
||||||
|
LIST_OBJECT_PAGE_SIZE = 1000
|
||||||
|
TRAVERSE_WEIGHT_MULTIPLIER = 5
|
||||||
|
TRAVERSE_PREFIX_LEN = 3
|
||||||
|
TRAVERSE_THRESHOLD_SIZE = 500000
|
||||||
|
CAN_TRAVERSE = True
|
||||||
|
|
||||||
|
# Needed for some providers, and http open()
|
||||||
|
CHUNK_SIZE = 64 * 1024 * 1024 # 64 MiB
|
||||||
|
|
||||||
|
PARAM_CHECKSUM: ClassVar[Optional[str]] = None
|
||||||
|
DETAIL_FIELDS: FrozenSet[str] = frozenset()
|
||||||
|
|
||||||
|
def __init__(self, repo, config):
|
||||||
|
self.repo = repo
|
||||||
|
self.config = config
|
||||||
|
|
||||||
|
self._check_requires()
|
||||||
|
|
||||||
|
self.path_info = None
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def jobs(self):
|
||||||
|
return (
|
||||||
|
self.config.get("jobs")
|
||||||
|
or (self.repo and self.repo.config["core"].get("jobs"))
|
||||||
|
or self.JOBS
|
||||||
|
)
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def hash_jobs(self):
|
||||||
|
return (
|
||||||
|
self.config.get("checksum_jobs")
|
||||||
|
or (self.repo and self.repo.config["core"].get("checksum_jobs"))
|
||||||
|
or self.HASH_JOBS
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_missing_deps(cls):
|
||||||
|
import importlib
|
||||||
|
|
||||||
|
missing = []
|
||||||
|
for package, module in cls.REQUIRES.items():
|
||||||
|
try:
|
||||||
|
importlib.import_module(module)
|
||||||
|
except ImportError:
|
||||||
|
missing.append(package)
|
||||||
|
|
||||||
|
return missing
|
||||||
|
|
||||||
|
def _check_requires(self):
|
||||||
|
from ..scheme import Schemes
|
||||||
|
from ..utils import format_link
|
||||||
|
from ..utils.pkg import PKG
|
||||||
|
|
||||||
|
missing = self.get_missing_deps()
|
||||||
|
if not missing:
|
||||||
|
return
|
||||||
|
|
||||||
|
url = self.config.get("url", f"{self.scheme}://")
|
||||||
|
|
||||||
|
scheme = self.scheme
|
||||||
|
if scheme == Schemes.WEBDAVS:
|
||||||
|
scheme = Schemes.WEBDAV
|
||||||
|
|
||||||
|
by_pkg = {
|
||||||
|
"pip": f"pip install 'dvc[{scheme}]'",
|
||||||
|
"conda": f"conda install -c conda-forge dvc-{scheme}",
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = by_pkg.get(PKG)
|
||||||
|
if cmd:
|
||||||
|
link = format_link("https://dvc.org/doc/install")
|
||||||
|
hint = (
|
||||||
|
f"To install dvc with those dependencies, run:\n"
|
||||||
|
"\n"
|
||||||
|
f"\t{cmd}\n"
|
||||||
|
"\n"
|
||||||
|
f"See {link} for more info."
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
link = format_link("https://github.com/iterative/dvc/issues")
|
||||||
|
hint = f"Please report this bug to {link}. Thank you!"
|
||||||
|
|
||||||
|
raise RemoteMissingDepsError(
|
||||||
|
f"URL '{url}' is supported but requires these missing "
|
||||||
|
f"dependencies: {missing}. {hint}"
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def odb(self):
|
||||||
|
return getattr(self.repo.odb, self.scheme)
|
||||||
|
|
||||||
|
def open(self, path_info, mode: str = "r", encoding: str = None, **kwargs):
|
||||||
|
if hasattr(self, "_generate_download_url"):
|
||||||
|
# pylint:disable=no-member
|
||||||
|
func = self._generate_download_url # type: ignore[attr-defined]
|
||||||
|
get_url = partial(func, path_info)
|
||||||
|
return open_url(get_url, mode=mode, encoding=encoding, **kwargs)
|
||||||
|
|
||||||
|
raise RemoteActionNotImplemented("open", self.scheme)
|
||||||
|
|
||||||
|
def exists(self, path_info, use_dvcignore=True) -> bool:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
|
||||||
|
def isdir(self, path_info):
|
||||||
|
"""Optional: Overwrite only if the remote has a way to distinguish
|
||||||
|
between a directory and a file.
|
||||||
|
"""
|
||||||
|
return False
|
||||||
|
|
||||||
|
def isfile(self, path_info):
|
||||||
|
"""Optional: Overwrite only if the remote has a way to distinguish
|
||||||
|
between a directory and a file.
|
||||||
|
"""
|
||||||
|
return True
|
||||||
|
|
||||||
|
def isexec(self, path_info):
|
||||||
|
"""Optional: Overwrite only if the remote has a way to distinguish
|
||||||
|
between executable and non-executable file.
|
||||||
|
"""
|
||||||
|
return False
|
||||||
|
|
||||||
|
def iscopy(self, path_info):
|
||||||
|
"""Check if this file is an independent copy."""
|
||||||
|
return False # We can't be sure by default
|
||||||
|
|
||||||
|
def walk_files(self, path_info, **kwargs):
|
||||||
|
"""Return a generator with `PathInfo`s to all the files.
|
||||||
|
|
||||||
|
Optional kwargs:
|
||||||
|
prefix (bool): If true `path_info` will be treated as a prefix
|
||||||
|
rather than directory path.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def ls(self, path_info, detail=False, **kwargs):
|
||||||
|
raise RemoteActionNotImplemented("ls", self.scheme)
|
||||||
|
|
||||||
|
def is_empty(self, path_info):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def info(self, path_info):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def getsize(self, path_info):
|
||||||
|
return self.info(path_info).get("size")
|
||||||
|
|
||||||
|
def remove(self, path_info):
|
||||||
|
raise RemoteActionNotImplemented("remove", self.scheme)
|
||||||
|
|
||||||
|
def makedirs(self, path_info):
|
||||||
|
"""Optional: Implement only if the remote needs to create
|
||||||
|
directories before copying/linking/moving data
|
||||||
|
"""
|
||||||
|
|
||||||
|
def move(self, from_info, to_info):
|
||||||
|
self.copy(from_info, to_info)
|
||||||
|
self.remove(from_info)
|
||||||
|
|
||||||
|
def copy(self, from_info, to_info):
|
||||||
|
raise RemoteActionNotImplemented("copy", self.scheme)
|
||||||
|
|
||||||
|
def symlink(self, from_info, to_info):
|
||||||
|
raise RemoteActionNotImplemented("symlink", self.scheme)
|
||||||
|
|
||||||
|
def hardlink(self, from_info, to_info):
|
||||||
|
raise RemoteActionNotImplemented("hardlink", self.scheme)
|
||||||
|
|
||||||
|
def reflink(self, from_info, to_info):
|
||||||
|
raise RemoteActionNotImplemented("reflink", self.scheme)
|
||||||
|
|
||||||
|
# pylint: enable=unused-argument
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def is_dir_hash(cls, hash_):
|
||||||
|
if not hash_:
|
||||||
|
return False
|
||||||
|
return hash_.endswith(cls.CHECKSUM_DIR_SUFFIX)
|
||||||
|
|
||||||
|
def upload(
|
||||||
|
self, from_info, to_info, name=None, no_progress_bar=False,
|
||||||
|
):
|
||||||
|
if not hasattr(self, "_upload"):
|
||||||
|
raise RemoteActionNotImplemented("upload", self.scheme)
|
||||||
|
|
||||||
|
if to_info.scheme != self.scheme:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
if from_info.scheme != "local":
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
logger.debug("Uploading '%s' to '%s'", from_info, to_info)
|
||||||
|
|
||||||
|
name = name or from_info.name
|
||||||
|
|
||||||
|
self._upload( # noqa, pylint: disable=no-member
|
||||||
|
from_info.fspath,
|
||||||
|
to_info,
|
||||||
|
name=name,
|
||||||
|
no_progress_bar=no_progress_bar,
|
||||||
|
)
|
||||||
|
|
||||||
|
def upload_fobj(self, fobj, to_info, no_progress_bar=False, **pbar_args):
|
||||||
|
if not hasattr(self, "_upload_fobj"):
|
||||||
|
raise RemoteActionNotImplemented("upload_fobj", self.scheme)
|
||||||
|
|
||||||
|
with Tqdm.wrapattr(
|
||||||
|
fobj, "read", disable=no_progress_bar, bytes=True, **pbar_args
|
||||||
|
) as wrapped:
|
||||||
|
self._upload_fobj(wrapped, to_info) # pylint: disable=no-member
|
||||||
|
|
||||||
|
def download(
|
||||||
|
self,
|
||||||
|
from_info,
|
||||||
|
to_info,
|
||||||
|
name=None,
|
||||||
|
no_progress_bar=False,
|
||||||
|
jobs=None,
|
||||||
|
**kwargs,
|
||||||
|
):
|
||||||
|
if not hasattr(self, "_download"):
|
||||||
|
raise RemoteActionNotImplemented("download", self.scheme)
|
||||||
|
|
||||||
|
if from_info.scheme != self.scheme:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
if to_info.scheme == self.scheme != "local":
|
||||||
|
self.copy(from_info, to_info)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if to_info.scheme != "local":
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
if self.isdir(from_info):
|
||||||
|
return self._download_dir(
|
||||||
|
from_info, to_info, name, no_progress_bar, jobs, **kwargs,
|
||||||
|
)
|
||||||
|
return self._download_file(from_info, to_info, name, no_progress_bar,)
|
||||||
|
|
||||||
|
def _download_dir(
|
||||||
|
self, from_info, to_info, name, no_progress_bar, jobs, **kwargs,
|
||||||
|
):
|
||||||
|
from_infos = list(self.walk_files(from_info, **kwargs))
|
||||||
|
to_infos = (
|
||||||
|
to_info / info.relative_to(from_info) for info in from_infos
|
||||||
|
)
|
||||||
|
|
||||||
|
with Tqdm(
|
||||||
|
total=len(from_infos),
|
||||||
|
desc="Downloading directory",
|
||||||
|
unit="Files",
|
||||||
|
disable=no_progress_bar,
|
||||||
|
) as pbar:
|
||||||
|
download_files = pbar.wrap_fn(
|
||||||
|
partial(self._download_file, name=name, no_progress_bar=True,)
|
||||||
|
)
|
||||||
|
max_workers = jobs or self.jobs
|
||||||
|
with ThreadPoolExecutor(max_workers=max_workers) as executor:
|
||||||
|
futures = [
|
||||||
|
executor.submit(download_files, from_info, to_info)
|
||||||
|
for from_info, to_info in zip(from_infos, to_infos)
|
||||||
|
]
|
||||||
|
|
||||||
|
# NOTE: unlike pulling/fetching cache, where we need to
|
||||||
|
# download everything we can, not raising an error here might
|
||||||
|
# turn very ugly, as the user might think that he has
|
||||||
|
# downloaded a complete directory, while having a partial one,
|
||||||
|
# which might cause unexpected results in his pipeline.
|
||||||
|
for future in as_completed(futures):
|
||||||
|
# NOTE: executor won't let us raise until all futures that
|
||||||
|
# it has are finished, so we need to cancel them ourselves
|
||||||
|
# before re-raising.
|
||||||
|
exc = future.exception()
|
||||||
|
if exc:
|
||||||
|
for entry in futures:
|
||||||
|
entry.cancel()
|
||||||
|
raise exc
|
||||||
|
|
||||||
|
def _download_file(
|
||||||
|
self, from_info, to_info, name, no_progress_bar,
|
||||||
|
):
|
||||||
|
makedirs(to_info.parent, exist_ok=True)
|
||||||
|
|
||||||
|
logger.debug("Downloading '%s' to '%s'", from_info, to_info)
|
||||||
|
name = name or to_info.name
|
||||||
|
|
||||||
|
tmp_file = tmp_fname(to_info)
|
||||||
|
|
||||||
|
self._download( # noqa, pylint: disable=no-member
|
||||||
|
from_info, tmp_file, name=name, no_progress_bar=no_progress_bar
|
||||||
|
)
|
||||||
|
|
||||||
|
move(tmp_file, to_info)
|
||||||
+249
@@ -0,0 +1,249 @@
|
|||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import typing
|
||||||
|
|
||||||
|
from dvc.exceptions import OutputNotFoundError
|
||||||
|
from dvc.path_info import PathInfo
|
||||||
|
from dvc.utils import relpath
|
||||||
|
|
||||||
|
from ._metadata import Metadata
|
||||||
|
from .base import BaseFileSystem
|
||||||
|
|
||||||
|
if typing.TYPE_CHECKING:
|
||||||
|
from dvc.output.base import BaseOutput
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class DvcFileSystem(BaseFileSystem): # pylint:disable=abstract-method
|
||||||
|
"""DVC repo fs.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
repo: DVC repo.
|
||||||
|
"""
|
||||||
|
|
||||||
|
scheme = "local"
|
||||||
|
PARAM_CHECKSUM = "md5"
|
||||||
|
|
||||||
|
def __init__(self, repo):
|
||||||
|
super().__init__(repo, {"url": repo.root_dir})
|
||||||
|
|
||||||
|
def _find_outs(self, path, *args, **kwargs):
|
||||||
|
outs = self.repo.find_outs_by_path(path, *args, **kwargs)
|
||||||
|
|
||||||
|
def _is_cached(out):
|
||||||
|
return out.use_cache
|
||||||
|
|
||||||
|
outs = list(filter(_is_cached, outs))
|
||||||
|
if not outs:
|
||||||
|
raise OutputNotFoundError(path, self.repo)
|
||||||
|
|
||||||
|
return outs
|
||||||
|
|
||||||
|
def _get_granular_hash(
|
||||||
|
self, path_info: PathInfo, out: "BaseOutput", remote=None
|
||||||
|
):
|
||||||
|
assert isinstance(path_info, PathInfo)
|
||||||
|
# NOTE: use string paths here for performance reasons
|
||||||
|
key = tuple(relpath(path_info, out.path_info).split(os.sep))
|
||||||
|
out.get_dir_cache(remote=remote)
|
||||||
|
file_hash = out.hash_info.dir_info.trie.get(key)
|
||||||
|
if file_hash:
|
||||||
|
return file_hash
|
||||||
|
raise FileNotFoundError
|
||||||
|
|
||||||
|
def open( # type: ignore
|
||||||
|
self, path: PathInfo, mode="r", encoding=None, remote=None, **kwargs
|
||||||
|
): # pylint: disable=arguments-differ
|
||||||
|
try:
|
||||||
|
outs = self._find_outs(path, strict=False)
|
||||||
|
except OutputNotFoundError as exc:
|
||||||
|
raise FileNotFoundError from exc
|
||||||
|
|
||||||
|
if len(outs) != 1 or (
|
||||||
|
outs[0].is_dir_checksum and path == outs[0].path_info
|
||||||
|
):
|
||||||
|
raise IsADirectoryError
|
||||||
|
|
||||||
|
out = outs[0]
|
||||||
|
if out.changed_cache(filter_info=path):
|
||||||
|
from dvc.config import NoRemoteError
|
||||||
|
|
||||||
|
try:
|
||||||
|
remote_obj = self.repo.cloud.get_remote(remote)
|
||||||
|
except NoRemoteError:
|
||||||
|
raise FileNotFoundError
|
||||||
|
if out.is_dir_checksum:
|
||||||
|
checksum = self._get_granular_hash(path, out).value
|
||||||
|
else:
|
||||||
|
checksum = out.hash_info.value
|
||||||
|
remote_info = remote_obj.odb.hash_to_path_info(checksum)
|
||||||
|
return remote_obj.fs.open(
|
||||||
|
remote_info, mode=mode, encoding=encoding
|
||||||
|
)
|
||||||
|
|
||||||
|
if out.is_dir_checksum:
|
||||||
|
checksum = self._get_granular_hash(path, out).value
|
||||||
|
cache_path = out.odb.hash_to_path_info(checksum).url
|
||||||
|
else:
|
||||||
|
cache_path = out.cache_path
|
||||||
|
return open(cache_path, mode=mode, encoding=encoding)
|
||||||
|
|
||||||
|
def exists(self, path): # pylint: disable=arguments-differ
|
||||||
|
try:
|
||||||
|
self.metadata(path)
|
||||||
|
return True
|
||||||
|
except FileNotFoundError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def isdir(self, path): # pylint: disable=arguments-differ
|
||||||
|
try:
|
||||||
|
meta = self.metadata(path)
|
||||||
|
return meta.isdir
|
||||||
|
except FileNotFoundError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def check_isdir(self, path_info, outs):
|
||||||
|
if len(outs) != 1:
|
||||||
|
return True
|
||||||
|
|
||||||
|
out = outs[0]
|
||||||
|
if not out.is_dir_checksum:
|
||||||
|
return out.path_info != path_info
|
||||||
|
if out.path_info == path_info:
|
||||||
|
return True
|
||||||
|
|
||||||
|
try:
|
||||||
|
self._get_granular_hash(path_info, out)
|
||||||
|
return False
|
||||||
|
except FileNotFoundError:
|
||||||
|
return True
|
||||||
|
|
||||||
|
def isfile(self, path): # pylint: disable=arguments-differ
|
||||||
|
try:
|
||||||
|
meta = self.metadata(path)
|
||||||
|
return meta.isfile
|
||||||
|
except FileNotFoundError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def _fetch_dir(self, out, **kwargs):
|
||||||
|
# pull dir cache if needed
|
||||||
|
out.get_dir_cache(**kwargs)
|
||||||
|
|
||||||
|
dir_cache = out.dir_cache
|
||||||
|
if not dir_cache:
|
||||||
|
raise FileNotFoundError
|
||||||
|
|
||||||
|
from dvc.objects import Tree
|
||||||
|
|
||||||
|
hash_info = Tree.save_dir_info(out.odb, dir_cache)
|
||||||
|
if hash_info != out.hash_info:
|
||||||
|
raise FileNotFoundError
|
||||||
|
|
||||||
|
def _add_dir(self, trie, out, **kwargs):
|
||||||
|
self._fetch_dir(out, **kwargs)
|
||||||
|
|
||||||
|
base = out.path_info.parts
|
||||||
|
for key in out.dir_cache.trie.iterkeys(): # noqa: B301
|
||||||
|
trie[base + key] = None
|
||||||
|
|
||||||
|
def _walk(self, root, trie, topdown=True, **kwargs):
|
||||||
|
dirs = set()
|
||||||
|
files = []
|
||||||
|
|
||||||
|
out = trie.get(root.parts)
|
||||||
|
if out and out.is_dir_checksum:
|
||||||
|
self._add_dir(trie, out, **kwargs)
|
||||||
|
|
||||||
|
root_len = len(root.parts)
|
||||||
|
for key, out in trie.iteritems(prefix=root.parts): # noqa: B301
|
||||||
|
if key == root.parts:
|
||||||
|
continue
|
||||||
|
|
||||||
|
name = key[root_len]
|
||||||
|
if len(key) > root_len + 1 or (out and out.is_dir_checksum):
|
||||||
|
dirs.add(name)
|
||||||
|
continue
|
||||||
|
|
||||||
|
files.append(name)
|
||||||
|
|
||||||
|
assert topdown
|
||||||
|
dirs = list(dirs)
|
||||||
|
yield root.fspath, dirs, files
|
||||||
|
|
||||||
|
for dname in dirs:
|
||||||
|
yield from self._walk(root / dname, trie)
|
||||||
|
|
||||||
|
def walk(self, top, topdown=True, onerror=None, **kwargs):
|
||||||
|
from pygtrie import Trie
|
||||||
|
|
||||||
|
assert topdown
|
||||||
|
root = PathInfo(os.path.abspath(top))
|
||||||
|
try:
|
||||||
|
meta = self.metadata(root)
|
||||||
|
except FileNotFoundError:
|
||||||
|
if onerror is not None:
|
||||||
|
onerror(FileNotFoundError(top))
|
||||||
|
return
|
||||||
|
|
||||||
|
if not meta.isdir:
|
||||||
|
if onerror is not None:
|
||||||
|
onerror(NotADirectoryError(top))
|
||||||
|
return
|
||||||
|
|
||||||
|
trie = Trie()
|
||||||
|
for out in meta.outs:
|
||||||
|
trie[out.path_info.parts] = out
|
||||||
|
|
||||||
|
if out.is_dir_checksum and root.isin_or_eq(out.path_info):
|
||||||
|
self._add_dir(trie, out, **kwargs)
|
||||||
|
|
||||||
|
yield from self._walk(root, trie, topdown=topdown, **kwargs)
|
||||||
|
|
||||||
|
def walk_files(self, path_info, **kwargs):
|
||||||
|
for root, _, files in self.walk(path_info):
|
||||||
|
for fname in files:
|
||||||
|
# NOTE: os.path.join is ~5.5 times slower
|
||||||
|
yield PathInfo(f"{root}{os.sep}{fname}")
|
||||||
|
|
||||||
|
def isdvc(self, path, recursive=False, strict=True):
|
||||||
|
try:
|
||||||
|
meta = self.metadata(path)
|
||||||
|
except FileNotFoundError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
recurse = recursive or not strict
|
||||||
|
return meta.output_exists if recurse else meta.is_output
|
||||||
|
|
||||||
|
def isexec(self, path_info): # pylint: disable=unused-argument
|
||||||
|
return False
|
||||||
|
|
||||||
|
def metadata(self, path_info):
|
||||||
|
path_info = PathInfo(os.path.abspath(path_info))
|
||||||
|
|
||||||
|
try:
|
||||||
|
outs = self._find_outs(path_info, strict=False, recursive=True)
|
||||||
|
except OutputNotFoundError as exc:
|
||||||
|
raise FileNotFoundError from exc
|
||||||
|
|
||||||
|
meta = Metadata(path_info=path_info, outs=outs, repo=self.repo)
|
||||||
|
meta.isdir = meta.isdir or self.check_isdir(meta.path_info, meta.outs)
|
||||||
|
return meta
|
||||||
|
|
||||||
|
def info(self, path_info):
|
||||||
|
meta = self.metadata(path_info)
|
||||||
|
ret = {"type": "dir" if meta.isdir else "file"}
|
||||||
|
if meta.is_output and len(meta.outs) == 1 and meta.outs[0].hash_info:
|
||||||
|
hash_info = meta.outs[0].hash_info
|
||||||
|
ret["size"] = hash_info.size
|
||||||
|
ret[hash_info.name] = hash_info.value
|
||||||
|
elif meta.part_of_output:
|
||||||
|
(out,) = meta.outs
|
||||||
|
key = path_info.relative_to(out.path_info).parts
|
||||||
|
hash_info = out.hash_info.dir_info.trie.get(key)
|
||||||
|
if hash_info:
|
||||||
|
ret["size"] = hash_info.size
|
||||||
|
ret[hash_info.name] = hash_info.value
|
||||||
|
|
||||||
|
return ret
|
||||||
@@ -14,11 +14,12 @@ from funcy.py3 import cat
|
|||||||
from dvc.exceptions import DvcException, FileMissingError
|
from dvc.exceptions import DvcException, FileMissingError
|
||||||
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 BaseRemoteTree
|
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
from dvc.utils import format_link, tmp_fname
|
from dvc.utils import format_link, tmp_fname
|
||||||
from dvc.utils.stream import IterStream
|
from dvc.utils.stream import IterStream
|
||||||
|
|
||||||
|
from .base import BaseFileSystem
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
FOLDER_MIME_TYPE = "application/vnd.google-apps.folder"
|
FOLDER_MIME_TYPE = "application/vnd.google-apps.folder"
|
||||||
|
|
||||||
@@ -84,11 +85,11 @@ class GDriveURLInfo(CloudURLInfo):
|
|||||||
self._spath = re.sub("/{2,}", "/", self._spath.rstrip("/"))
|
self._spath = re.sub("/{2,}", "/", self._spath.rstrip("/"))
|
||||||
|
|
||||||
|
|
||||||
class GDriveRemoteTree(BaseRemoteTree):
|
class GDriveFileSystem(BaseFileSystem):
|
||||||
scheme = Schemes.GDRIVE
|
scheme = Schemes.GDRIVE
|
||||||
PATH_CLS = GDriveURLInfo
|
PATH_CLS = GDriveURLInfo
|
||||||
|
PARAM_CHECKSUM = "checksum"
|
||||||
REQUIRES = {"pydrive2": "pydrive2"}
|
REQUIRES = {"pydrive2": "pydrive2"}
|
||||||
DEFAULT_VERIFY = True
|
|
||||||
# Always prefer traverse for GDrive since API usage quotas are a concern.
|
# Always prefer traverse for GDrive since API usage quotas are a concern.
|
||||||
TRAVERSE_WEIGHT_MULTIPLIER = 1
|
TRAVERSE_WEIGHT_MULTIPLIER = 1
|
||||||
TRAVERSE_PREFIX_LEN = 2
|
TRAVERSE_PREFIX_LEN = 2
|
||||||
@@ -113,23 +114,21 @@ class GDriveRemoteTree(BaseRemoteTree):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self._bucket = self.path_info.bucket
|
self._bucket = self.path_info.bucket
|
||||||
|
self._path = self.path_info.path
|
||||||
self._trash_only = config.get("gdrive_trash_only")
|
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(
|
|
||||||
"gdrive_service_account_email"
|
|
||||||
)
|
|
||||||
self._service_account_user_email = config.get(
|
self._service_account_user_email = config.get(
|
||||||
"gdrive_service_account_user_email"
|
"gdrive_service_account_user_email"
|
||||||
)
|
)
|
||||||
self._service_account_p12_file_path = config.get(
|
self._service_account_json_file_path = config.get(
|
||||||
"gdrive_service_account_p12_file_path"
|
"gdrive_service_account_json_file_path"
|
||||||
)
|
)
|
||||||
self._client_id = config.get("gdrive_client_id")
|
self._client_id = config.get("gdrive_client_id")
|
||||||
self._client_secret = config.get("gdrive_client_secret")
|
self._client_secret = config.get("gdrive_client_secret")
|
||||||
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(GDriveRemoteTree.GDRIVE_CREDENTIALS_DATA)
|
if os.getenv(GDriveFileSystem.GDRIVE_CREDENTIALS_DATA)
|
||||||
else config.get(
|
else config.get(
|
||||||
"gdrive_user_credentials_file",
|
"gdrive_user_credentials_file",
|
||||||
os.path.join(
|
os.path.join(
|
||||||
@@ -140,14 +139,14 @@ class GDriveRemoteTree(BaseRemoteTree):
|
|||||||
|
|
||||||
def _validate_config(self):
|
def _validate_config(self):
|
||||||
# Validate Service Account configuration
|
# Validate Service Account configuration
|
||||||
if self._use_service_account and (
|
if (
|
||||||
not self._service_account_email
|
self._use_service_account
|
||||||
or not self._service_account_p12_file_path
|
and not self._service_account_json_file_path
|
||||||
):
|
):
|
||||||
raise DvcException(
|
raise DvcException(
|
||||||
"To use service account, set `gdrive_service_account_email`,\n"
|
"To use service account, set "
|
||||||
"`gdrive_service_account_p12_file_path`, and optionally "
|
"`gdrive_service_account_json_file_path`, and optionally"
|
||||||
"`gdrive_service_account_user_email`\nin DVC config. "
|
"`gdrive_service_account_user_email` in DVC config\n"
|
||||||
"Learn more at {}".format(
|
"Learn more at {}".format(
|
||||||
format_link("https://man.dvc.org/remote/modify")
|
format_link("https://man.dvc.org/remote/modify")
|
||||||
)
|
)
|
||||||
@@ -171,8 +170,8 @@ class GDriveRemoteTree(BaseRemoteTree):
|
|||||||
Useful for tests, exception messages, etc. Returns either env variable
|
Useful for tests, exception messages, etc. Returns either env variable
|
||||||
name if it's set or actual path to the credentials file.
|
name if it's set or actual path to the credentials file.
|
||||||
"""
|
"""
|
||||||
if os.getenv(GDriveRemoteTree.GDRIVE_CREDENTIALS_DATA):
|
if os.getenv(GDriveFileSystem.GDRIVE_CREDENTIALS_DATA):
|
||||||
return GDriveRemoteTree.GDRIVE_CREDENTIALS_DATA
|
return GDriveFileSystem.GDRIVE_CREDENTIALS_DATA
|
||||||
if os.path.exists(self._gdrive_user_credentials_path):
|
if os.path.exists(self._gdrive_user_credentials_path):
|
||||||
return self._gdrive_user_credentials_path
|
return self._gdrive_user_credentials_path
|
||||||
return None
|
return None
|
||||||
@@ -186,7 +185,7 @@ class GDriveRemoteTree(BaseRemoteTree):
|
|||||||
DVC config client id or secret but forgets to remove the cached
|
DVC config client id or secret but forgets to remove the cached
|
||||||
credentials file.
|
credentials file.
|
||||||
"""
|
"""
|
||||||
if not os.getenv(GDriveRemoteTree.GDRIVE_CREDENTIALS_DATA):
|
if not os.getenv(GDriveFileSystem.GDRIVE_CREDENTIALS_DATA):
|
||||||
if (
|
if (
|
||||||
settings["client_config"]["client_id"]
|
settings["client_config"]["client_id"]
|
||||||
!= auth.credentials.client_id
|
!= auth.credentials.client_id
|
||||||
@@ -209,16 +208,15 @@ class GDriveRemoteTree(BaseRemoteTree):
|
|||||||
from pydrive2.auth import GoogleAuth
|
from pydrive2.auth import GoogleAuth
|
||||||
from pydrive2.drive import GoogleDrive
|
from pydrive2.drive import GoogleDrive
|
||||||
|
|
||||||
if os.getenv(GDriveRemoteTree.GDRIVE_CREDENTIALS_DATA):
|
if os.getenv(GDriveFileSystem.GDRIVE_CREDENTIALS_DATA):
|
||||||
with open(self._gdrive_user_credentials_path, "w") as cred_file:
|
with open(self._gdrive_user_credentials_path, "w") as cred_file:
|
||||||
cred_file.write(
|
cred_file.write(
|
||||||
os.getenv(GDriveRemoteTree.GDRIVE_CREDENTIALS_DATA)
|
os.getenv(GDriveFileSystem.GDRIVE_CREDENTIALS_DATA)
|
||||||
)
|
)
|
||||||
|
|
||||||
auth_settings = {
|
auth_settings = {
|
||||||
"client_config_backend": "settings",
|
"client_config_backend": "settings",
|
||||||
"save_credentials": True,
|
"save_credentials": True,
|
||||||
"save_credentials_backend": "file",
|
|
||||||
"save_credentials_file": self._gdrive_user_credentials_path,
|
"save_credentials_file": self._gdrive_user_credentials_path,
|
||||||
"get_refresh_token": True,
|
"get_refresh_token": True,
|
||||||
"oauth_scope": [
|
"oauth_scope": [
|
||||||
@@ -228,12 +226,13 @@ class GDriveRemoteTree(BaseRemoteTree):
|
|||||||
}
|
}
|
||||||
|
|
||||||
if self._use_service_account:
|
if self._use_service_account:
|
||||||
|
auth_settings["save_credentials_backend"] = "json"
|
||||||
auth_settings["service_config"] = {
|
auth_settings["service_config"] = {
|
||||||
"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_json_file_path": self._service_account_json_file_path,
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
|
auth_settings["save_credentials_backend"] = "file"
|
||||||
auth_settings["client_config"] = {
|
auth_settings["client_config"] = {
|
||||||
"client_id": self._client_id or self.DEFAULT_GDRIVE_CLIENT_ID,
|
"client_id": self._client_id or self.DEFAULT_GDRIVE_CLIENT_ID,
|
||||||
"client_secret": self._client_secret
|
"client_secret": self._client_secret
|
||||||
@@ -259,7 +258,7 @@ class GDriveRemoteTree(BaseRemoteTree):
|
|||||||
gauth.ServiceAuth()
|
gauth.ServiceAuth()
|
||||||
else:
|
else:
|
||||||
gauth.CommandLineAuth()
|
gauth.CommandLineAuth()
|
||||||
GDriveRemoteTree._validate_credentials(gauth, auth_settings)
|
GDriveFileSystem._validate_credentials(gauth, auth_settings)
|
||||||
|
|
||||||
# Handle AuthenticationError, RefreshError and other auth failures
|
# Handle AuthenticationError, RefreshError and other auth failures
|
||||||
# It's hard to come up with a narrow exception, since PyDrive throws
|
# It's hard to come up with a narrow exception, since PyDrive throws
|
||||||
@@ -268,7 +267,7 @@ class GDriveRemoteTree(BaseRemoteTree):
|
|||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise GDriveAuthError(self.credentials_location) from exc
|
raise GDriveAuthError(self.credentials_location) from exc
|
||||||
finally:
|
finally:
|
||||||
if os.getenv(GDriveRemoteTree.GDRIVE_CREDENTIALS_DATA):
|
if os.getenv(GDriveFileSystem.GDRIVE_CREDENTIALS_DATA):
|
||||||
os.remove(self._gdrive_user_credentials_path)
|
os.remove(self._gdrive_user_credentials_path)
|
||||||
|
|
||||||
return GoogleDrive(gauth)
|
return GoogleDrive(gauth)
|
||||||
@@ -286,20 +285,21 @@ class GDriveRemoteTree(BaseRemoteTree):
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
self._cache_path_id(self.path_info.path, cache["root_id"], cache)
|
self._cache_path_id(self._path, cache["root_id"], cache=cache)
|
||||||
|
|
||||||
for item in self._gdrive_list(
|
for item in self._gdrive_list(
|
||||||
"'{}' in parents and trashed=false".format(cache["root_id"])
|
"'{}' in parents and trashed=false".format(cache["root_id"])
|
||||||
):
|
):
|
||||||
item_path = (self.path_info / item["title"]).path
|
item_path = (self.path_info / item["title"]).path
|
||||||
self._cache_path_id(item_path, item["id"], cache)
|
self._cache_path_id(item_path, item["id"], cache=cache)
|
||||||
|
|
||||||
return cache
|
return cache
|
||||||
|
|
||||||
def _cache_path_id(self, path, item_id, cache=None):
|
def _cache_path_id(self, path, *item_ids, cache=None):
|
||||||
cache = cache or self._ids_cache
|
cache = cache or self._ids_cache
|
||||||
cache["dirs"][path].append(item_id)
|
for item_id in item_ids:
|
||||||
cache["ids"][item_id] = path
|
cache["dirs"][path].append(item_id)
|
||||||
|
cache["ids"][item_id] = path
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def _list_params(self):
|
def _list_params(self):
|
||||||
@@ -346,32 +346,12 @@ class GDriveRemoteTree(BaseRemoteTree):
|
|||||||
return item.get("driveId", None)
|
return item.get("driveId", None)
|
||||||
|
|
||||||
@_gdrive_retry
|
@_gdrive_retry
|
||||||
def _gdrive_upload_file(
|
def _gdrive_upload_fobj(self, fobj, parent_id, title):
|
||||||
self,
|
|
||||||
parent_id,
|
|
||||||
title,
|
|
||||||
no_progress_bar=False,
|
|
||||||
from_file="",
|
|
||||||
progress_name="",
|
|
||||||
):
|
|
||||||
item = self._drive.CreateFile(
|
item = self._drive.CreateFile(
|
||||||
{"title": title, "parents": [{"id": parent_id}]}
|
{"title": title, "parents": [{"id": parent_id}]}
|
||||||
)
|
)
|
||||||
|
item.content = fobj
|
||||||
with open(from_file, "rb") as fobj:
|
item.Upload()
|
||||||
total = os.path.getsize(from_file)
|
|
||||||
with Tqdm.wrapattr(
|
|
||||||
fobj,
|
|
||||||
"read",
|
|
||||||
desc=progress_name,
|
|
||||||
total=total,
|
|
||||||
disable=no_progress_bar,
|
|
||||||
) as wrapped:
|
|
||||||
# PyDrive doesn't like content property setting for empty files
|
|
||||||
# https://github.com/gsuitedevs/PyDrive/issues/121
|
|
||||||
if total:
|
|
||||||
item.content = wrapped
|
|
||||||
item.Upload()
|
|
||||||
return item
|
return item
|
||||||
|
|
||||||
@_gdrive_retry
|
@_gdrive_retry
|
||||||
@@ -393,7 +373,7 @@ class GDriveRemoteTree(BaseRemoteTree):
|
|||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
@_gdrive_retry
|
@_gdrive_retry
|
||||||
def open(self, path_info, mode="r", encoding=None):
|
def open(self, path_info, mode="r", encoding=None, **kwargs):
|
||||||
assert mode in {"r", "rt", "rb"}
|
assert mode in {"r", "rt", "rb"}
|
||||||
|
|
||||||
item_id = self._get_item_id(path_info)
|
item_id = self._get_item_id(path_info)
|
||||||
@@ -498,7 +478,7 @@ class GDriveRemoteTree(BaseRemoteTree):
|
|||||||
return self._ids_cache["dirs"].get(path, [])
|
return self._ids_cache["dirs"].get(path, [])
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def _path_to_item_ids(self, path, create, use_cache):
|
def _path_to_item_ids(self, path, create=False, use_cache=True):
|
||||||
item_ids = self._get_cached_item_ids(path, use_cache)
|
item_ids = self._get_cached_item_ids(path, use_cache)
|
||||||
if item_ids:
|
if item_ids:
|
||||||
return item_ids
|
return item_ids
|
||||||
@@ -523,7 +503,7 @@ class GDriveRemoteTree(BaseRemoteTree):
|
|||||||
assert not create
|
assert not create
|
||||||
raise FileMissingError(path_info, hint)
|
raise FileMissingError(path_info, hint)
|
||||||
|
|
||||||
def exists(self, path_info):
|
def exists(self, path_info, use_dvcignore=True):
|
||||||
try:
|
try:
|
||||||
self._get_item_id(path_info)
|
self._get_item_id(path_info)
|
||||||
except FileMissingError:
|
except FileMissingError:
|
||||||
@@ -531,50 +511,116 @@ class GDriveRemoteTree(BaseRemoteTree):
|
|||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _list_paths(self, prefix=None):
|
def _gdrive_list_ids(self, query_ids):
|
||||||
if not self._ids_cache["ids"]:
|
query = " or ".join(
|
||||||
return
|
f"'{query_id}' in parents" for query_id in query_ids
|
||||||
|
|
||||||
if prefix:
|
|
||||||
dir_ids = self._ids_cache["dirs"].get(prefix[:2])
|
|
||||||
if not dir_ids:
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
dir_ids = self._ids_cache["ids"]
|
|
||||||
parents_query = " or ".join(
|
|
||||||
f"'{dir_id}' in parents" for dir_id in dir_ids
|
|
||||||
)
|
)
|
||||||
query = f"({parents_query}) and trashed=false"
|
query = f"({query}) and trashed=false"
|
||||||
|
return self._gdrive_list(query)
|
||||||
|
|
||||||
for item in self._gdrive_list(query):
|
def _ls_recursive(self, path_info, detail=False):
|
||||||
parent_id = item["parents"][0]["id"]
|
root_path = path_info.path
|
||||||
yield posixpath.join(
|
seen_paths = set()
|
||||||
self._ids_cache["ids"][parent_id], item["title"]
|
|
||||||
)
|
dir_ids = [self._ids_cache["ids"].copy()]
|
||||||
|
while dir_ids:
|
||||||
|
query_ids = {
|
||||||
|
dir_id: dir_name
|
||||||
|
for dir_id, dir_name in dir_ids.pop().items()
|
||||||
|
if posixpath.commonpath([root_path, dir_name]) == root_path
|
||||||
|
if dir_id not in seen_paths
|
||||||
|
}
|
||||||
|
if not query_ids:
|
||||||
|
continue
|
||||||
|
|
||||||
|
seen_paths |= query_ids.keys()
|
||||||
|
|
||||||
|
new_query_ids = {}
|
||||||
|
dir_ids.append(new_query_ids)
|
||||||
|
for item in self._gdrive_list_ids(query_ids):
|
||||||
|
parent_id = item["parents"][0]["id"]
|
||||||
|
item_path = posixpath.join(query_ids[parent_id], item["title"])
|
||||||
|
if item["mimeType"] == FOLDER_MIME_TYPE:
|
||||||
|
new_query_ids[item["id"]] = item_path
|
||||||
|
self._cache_path_id(item_path, item["id"])
|
||||||
|
continue
|
||||||
|
|
||||||
|
if detail:
|
||||||
|
yield {
|
||||||
|
"type": "file",
|
||||||
|
"name": item_path,
|
||||||
|
"size": item["fileSize"],
|
||||||
|
"checksum": item["md5Checksum"],
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
yield item_path
|
||||||
|
|
||||||
|
def ls(
|
||||||
|
self, path_info, detail=False, recursive=False
|
||||||
|
): # pylint: disable=arguments-differ
|
||||||
|
if recursive:
|
||||||
|
yield from self._ls_recursive(path_info, detail=detail)
|
||||||
|
return None
|
||||||
|
|
||||||
|
cached = path_info.path in self._ids_cache["dirs"]
|
||||||
|
if cached:
|
||||||
|
dir_ids = self._ids_cache["dirs"][path_info.path]
|
||||||
|
else:
|
||||||
|
dir_ids = self._path_to_item_ids(path_info.path)
|
||||||
|
|
||||||
|
if not dir_ids:
|
||||||
|
return None
|
||||||
|
|
||||||
|
root_path = path_info.path
|
||||||
|
for item in self._gdrive_list_ids(dir_ids):
|
||||||
|
item_path = posixpath.join(root_path, item["title"])
|
||||||
|
if detail:
|
||||||
|
if item["mimeType"] == FOLDER_MIME_TYPE:
|
||||||
|
yield {"type": "directory", "name": item_path}
|
||||||
|
else:
|
||||||
|
yield {
|
||||||
|
"type": "file",
|
||||||
|
"name": item_path,
|
||||||
|
"size": item["fileSize"],
|
||||||
|
"checksum": item["md5Checksum"],
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
yield item_path
|
||||||
|
|
||||||
|
if not cached:
|
||||||
|
self._cache_path_id(root_path, *dir_ids)
|
||||||
|
|
||||||
def walk_files(self, path_info, **kwargs):
|
def walk_files(self, path_info, **kwargs):
|
||||||
if path_info == self.path_info:
|
for filename in self.ls(path_info, recursive=True):
|
||||||
prefix = None
|
yield path_info.replace(path=filename)
|
||||||
else:
|
|
||||||
prefix = path_info.path
|
|
||||||
for fname in self._list_paths(prefix=prefix, **kwargs):
|
|
||||||
yield path_info.replace(fname)
|
|
||||||
|
|
||||||
def remove(self, path_info):
|
def remove(self, path_info):
|
||||||
item_id = self._get_item_id(path_info)
|
item_id = self._get_item_id(path_info)
|
||||||
self.gdrive_delete_file(item_id)
|
self.gdrive_delete_file(item_id)
|
||||||
|
|
||||||
def get_file_hash(self, path_info):
|
def info(self, path_info):
|
||||||
raise NotImplementedError
|
item_id = self._get_item_id(path_info)
|
||||||
|
gdrive_file = self._drive.CreateFile({"id": item_id})
|
||||||
|
gdrive_file.FetchMetadata(fields="fileSize")
|
||||||
|
return {"size": gdrive_file.get("fileSize")}
|
||||||
|
|
||||||
def _upload(self, from_file, to_info, name=None, no_progress_bar=False):
|
def _upload_fobj(self, fobj, to_info):
|
||||||
dirname = to_info.parent
|
dirname = to_info.parent
|
||||||
assert dirname
|
assert dirname
|
||||||
parent_id = self._get_item_id(dirname, True)
|
parent_id = self._get_item_id(dirname, create=True)
|
||||||
|
self._gdrive_upload_fobj(fobj, parent_id, to_info.name)
|
||||||
|
|
||||||
self._gdrive_upload_file(
|
def _upload(
|
||||||
parent_id, to_info.name, no_progress_bar, from_file, name
|
self, from_file, to_info, name=None, no_progress_bar=False, **_kwargs
|
||||||
)
|
):
|
||||||
|
with open(from_file, "rb") as fobj:
|
||||||
|
self.upload_fobj(
|
||||||
|
fobj,
|
||||||
|
to_info,
|
||||||
|
no_progress_bar=no_progress_bar,
|
||||||
|
desc=name or to_info.name,
|
||||||
|
total=os.path.getsize(from_file),
|
||||||
|
)
|
||||||
|
|
||||||
def _download(self, from_info, to_file, name=None, no_progress_bar=False):
|
def _download(self, from_info, to_file, name=None, no_progress_bar=False):
|
||||||
item_id = self._get_item_id(from_info)
|
item_id = self._get_item_id(from_info)
|
||||||
+174
@@ -0,0 +1,174 @@
|
|||||||
|
import errno
|
||||||
|
import os
|
||||||
|
|
||||||
|
from funcy import cached_property
|
||||||
|
|
||||||
|
from dvc.utils import is_exec, relpath
|
||||||
|
|
||||||
|
from .base import BaseFileSystem
|
||||||
|
|
||||||
|
|
||||||
|
class GitFileSystem(BaseFileSystem): # pylint:disable=abstract-method
|
||||||
|
"""Proxies the repo file access methods to Git objects"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self, root_dir, trie, use_dvcignore=False, dvcignore_root=None
|
||||||
|
):
|
||||||
|
super().__init__(None, {})
|
||||||
|
self._fs_root = root_dir
|
||||||
|
self.trie = trie
|
||||||
|
self.use_dvcignore = use_dvcignore
|
||||||
|
self.dvcignore_root = dvcignore_root
|
||||||
|
|
||||||
|
@property
|
||||||
|
def rev(self):
|
||||||
|
return self.trie.rev
|
||||||
|
|
||||||
|
@property
|
||||||
|
def fs_root(self):
|
||||||
|
return self._fs_root
|
||||||
|
|
||||||
|
def _get_key(self, path):
|
||||||
|
if isinstance(path, str):
|
||||||
|
if not os.path.isabs(path):
|
||||||
|
relparts = path.split(os.sep)
|
||||||
|
else:
|
||||||
|
relparts = relpath(path, self.fs_root).split(os.sep)
|
||||||
|
else:
|
||||||
|
relparts = path.relative_to(self.fs_root).parts
|
||||||
|
if relparts == ["."]:
|
||||||
|
return ()
|
||||||
|
return tuple(relparts)
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def dvcignore(self):
|
||||||
|
from dvc.ignore import DvcIgnoreFilter, DvcIgnoreFilterNoop
|
||||||
|
|
||||||
|
root = self.dvcignore_root or self.fs_root
|
||||||
|
cls = DvcIgnoreFilter if self.use_dvcignore else DvcIgnoreFilterNoop
|
||||||
|
return cls(self, root)
|
||||||
|
|
||||||
|
def open(
|
||||||
|
self, path, mode="r", encoding=None
|
||||||
|
): # pylint: disable=arguments-differ
|
||||||
|
# NOTE: this is incorrect, we need to use locale to determine default
|
||||||
|
# encoding.
|
||||||
|
encoding = encoding or "utf-8"
|
||||||
|
|
||||||
|
key = self._get_key(path)
|
||||||
|
try:
|
||||||
|
return self.trie.open(key, mode=mode, encoding=encoding)
|
||||||
|
except KeyError as exc:
|
||||||
|
msg = os.strerror(errno.ENOENT) + f"in branch '{self.rev}'"
|
||||||
|
raise FileNotFoundError(errno.ENOENT, msg, path) from exc
|
||||||
|
except IsADirectoryError as exc:
|
||||||
|
raise IsADirectoryError(
|
||||||
|
errno.EISDIR, os.strerror(errno.EISDIR), path
|
||||||
|
) from exc
|
||||||
|
|
||||||
|
def exists(
|
||||||
|
self, path, use_dvcignore=True
|
||||||
|
): # pylint: disable=arguments-differ
|
||||||
|
def _is_ignored(path):
|
||||||
|
return self.dvcignore.is_ignored_file(
|
||||||
|
path
|
||||||
|
) or self.dvcignore.is_ignored_dir(path)
|
||||||
|
|
||||||
|
if use_dvcignore and _is_ignored(path):
|
||||||
|
return False
|
||||||
|
|
||||||
|
key = self._get_key(path)
|
||||||
|
return self.trie.exists(key)
|
||||||
|
|
||||||
|
def isdir(
|
||||||
|
self, path, use_dvcignore=True
|
||||||
|
): # pylint: disable=arguments-differ
|
||||||
|
if use_dvcignore and self.dvcignore.is_ignored_dir(path):
|
||||||
|
return False
|
||||||
|
key = self._get_key(path)
|
||||||
|
return self.trie.isdir(key)
|
||||||
|
|
||||||
|
def isfile(self, path): # pylint: disable=arguments-differ
|
||||||
|
if self.dvcignore.is_ignored_file(path):
|
||||||
|
return False
|
||||||
|
key = self._get_key(path)
|
||||||
|
return self.trie.isfile(key)
|
||||||
|
|
||||||
|
def walk(
|
||||||
|
self,
|
||||||
|
top,
|
||||||
|
topdown=True,
|
||||||
|
onerror=None,
|
||||||
|
use_dvcignore=True,
|
||||||
|
ignore_subrepos=True,
|
||||||
|
):
|
||||||
|
"""Directory tree generator.
|
||||||
|
|
||||||
|
See `os.walk` for the docs. Differences:
|
||||||
|
- no support for symlinks
|
||||||
|
"""
|
||||||
|
if not self.isdir(top, use_dvcignore=use_dvcignore):
|
||||||
|
if onerror:
|
||||||
|
if self.exists(top, use_dvcignore=use_dvcignore):
|
||||||
|
exc = NotADirectoryError(
|
||||||
|
errno.ENOTDIR, os.strerror(errno.ENOTDIR), top
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
exc = FileNotFoundError(
|
||||||
|
errno.ENOENT, os.strerror(errno.ENOENT), top
|
||||||
|
)
|
||||||
|
onerror(exc)
|
||||||
|
return []
|
||||||
|
|
||||||
|
key = self._get_key(top)
|
||||||
|
for prefix, dirs, files in self.trie.walk(key, topdown=topdown):
|
||||||
|
if prefix:
|
||||||
|
root = os.path.join(self.fs_root, os.sep.join(prefix))
|
||||||
|
else:
|
||||||
|
root = self.fs_root
|
||||||
|
if use_dvcignore:
|
||||||
|
dirs[:], files[:] = self.dvcignore(
|
||||||
|
root, dirs, files, ignore_subrepos=ignore_subrepos,
|
||||||
|
)
|
||||||
|
yield root, dirs, files
|
||||||
|
|
||||||
|
def isexec(self, path_info):
|
||||||
|
if not self.exists(path_info):
|
||||||
|
return False
|
||||||
|
|
||||||
|
mode = self.stat(path_info).st_mode
|
||||||
|
return is_exec(mode)
|
||||||
|
|
||||||
|
def info(self, path_info):
|
||||||
|
key = self._get_key(path_info)
|
||||||
|
try:
|
||||||
|
st = self.trie.stat(key)
|
||||||
|
except KeyError:
|
||||||
|
raise FileNotFoundError(
|
||||||
|
errno.ENOENT, os.strerror(errno.ENOENT), path_info
|
||||||
|
)
|
||||||
|
return {"size": st.st_size}
|
||||||
|
|
||||||
|
def stat(self, path):
|
||||||
|
key = self._get_key(path)
|
||||||
|
try:
|
||||||
|
return self.trie.stat(key)
|
||||||
|
except KeyError:
|
||||||
|
raise FileNotFoundError(
|
||||||
|
errno.ENOENT, os.strerror(errno.ENOENT), path
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def hash_jobs(self): # pylint: disable=invalid-overridden-method
|
||||||
|
# NOTE: gitpython is not threadsafe. See
|
||||||
|
# https://github.com/iterative/dvc/issues/4079
|
||||||
|
return 1
|
||||||
|
|
||||||
|
def walk_files(self, top): # pylint: disable=arguments-differ
|
||||||
|
for root, _, files in self.walk(top):
|
||||||
|
for file in files:
|
||||||
|
# NOTE: os.path.join is ~5.5 times slower
|
||||||
|
yield f"{root}{os.sep}{file}"
|
||||||
|
|
||||||
|
def _reset(self):
|
||||||
|
return self.__dict__.pop("dvcignore", None)
|
||||||
@@ -9,9 +9,10 @@ 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 BaseRemoteTree
|
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
|
|
||||||
|
from .base import BaseFileSystem
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -27,12 +28,12 @@ def dynamic_chunk_size(func):
|
|||||||
# Note: must be multiple of 256K.
|
# Note: must be multiple of 256K.
|
||||||
#
|
#
|
||||||
# [#2572]: https://github.com/iterative/dvc/issues/2572
|
# [#2572]: https://github.com/iterative/dvc/issues/2572
|
||||||
|
|
||||||
# skipcq: PYL-W0212
|
# skipcq: PYL-W0212
|
||||||
multiplier = 40
|
multiplier = 40
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
# skipcq: PYL-W0212
|
# skipcq: PYL-W0212
|
||||||
|
# pylint: disable=protected-access
|
||||||
chunk_size = Blob._CHUNK_SIZE_MULTIPLE * multiplier
|
chunk_size = Blob._CHUNK_SIZE_MULTIPLE * multiplier
|
||||||
return func(*args, chunk_size=chunk_size, **kwargs)
|
return func(*args, chunk_size=chunk_size, **kwargs)
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
@@ -44,31 +45,17 @@ def dynamic_chunk_size(func):
|
|||||||
|
|
||||||
|
|
||||||
@dynamic_chunk_size
|
@dynamic_chunk_size
|
||||||
def _upload_to_bucket(
|
def _upload_to_bucket(bucket, fobj, to_info, chunk_size=None):
|
||||||
bucket,
|
|
||||||
from_file,
|
|
||||||
to_info,
|
|
||||||
chunk_size=None,
|
|
||||||
name=None,
|
|
||||||
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 open(from_file, mode="rb") as fobj:
|
blob.upload_from_file(fobj)
|
||||||
with Tqdm.wrapattr(
|
|
||||||
fobj,
|
|
||||||
"read",
|
|
||||||
desc=name or to_info.path,
|
|
||||||
total=os.path.getsize(from_file),
|
|
||||||
disable=no_progress_bar,
|
|
||||||
) as wrapped:
|
|
||||||
blob.upload_from_file(wrapped)
|
|
||||||
|
|
||||||
|
|
||||||
class GSRemoteTree(BaseRemoteTree):
|
class GSFileSystem(BaseFileSystem):
|
||||||
scheme = Schemes.GS
|
scheme = Schemes.GS
|
||||||
PATH_CLS = CloudURLInfo
|
PATH_CLS = CloudURLInfo
|
||||||
REQUIRES = {"google-cloud-storage": "google.cloud.storage"}
|
REQUIRES = {"google-cloud-storage": "google.cloud.storage"}
|
||||||
PARAM_CHECKSUM = "md5"
|
PARAM_CHECKSUM = "md5"
|
||||||
|
DETAIL_FIELDS = frozenset(("md5", "size"))
|
||||||
|
|
||||||
def __init__(self, repo, config):
|
def __init__(self, repo, config):
|
||||||
super().__init__(repo, config)
|
super().__init__(repo, config)
|
||||||
@@ -102,7 +89,8 @@ class GSRemoteTree(BaseRemoteTree):
|
|||||||
raise FileNotFoundError
|
raise FileNotFoundError
|
||||||
|
|
||||||
if isinstance(
|
if isinstance(
|
||||||
blob.client._credentials, google.auth.credentials.Signing
|
blob.client._credentials, # pylint: disable=protected-access
|
||||||
|
google.auth.credentials.Signing,
|
||||||
):
|
):
|
||||||
# sign if we're able to sign with credentials.
|
# sign if we're able to sign with credentials.
|
||||||
return blob.generate_signed_url(expiration=expiration)
|
return blob.generate_signed_url(expiration=expiration)
|
||||||
@@ -116,7 +104,7 @@ class GSRemoteTree(BaseRemoteTree):
|
|||||||
)
|
)
|
||||||
return signing_credentials.signer.sign(blob)
|
return signing_credentials.signer.sign(blob)
|
||||||
|
|
||||||
def exists(self, path_info):
|
def exists(self, path_info, use_dvcignore=True):
|
||||||
"""Check if the blob exists. If it does not exist,
|
"""Check if the blob exists. If it does not exist,
|
||||||
it could be a part of a directory path.
|
it could be a part of a directory path.
|
||||||
|
|
||||||
@@ -135,6 +123,11 @@ class GSRemoteTree(BaseRemoteTree):
|
|||||||
blob = self.gs.bucket(path_info.bucket).blob(path_info.path)
|
blob = self.gs.bucket(path_info.bucket).blob(path_info.path)
|
||||||
return blob.exists()
|
return blob.exists()
|
||||||
|
|
||||||
|
def info(self, path_info):
|
||||||
|
bucket = self.gs.bucket(path_info.bucket)
|
||||||
|
blob = bucket.get_blob(path_info.path)
|
||||||
|
return {"type": "file", "size": blob.size, "etag": blob.etag}
|
||||||
|
|
||||||
def _list_paths(self, path_info, max_items=None):
|
def _list_paths(self, path_info, max_items=None):
|
||||||
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
|
||||||
@@ -142,12 +135,36 @@ class GSRemoteTree(BaseRemoteTree):
|
|||||||
yield blob.name
|
yield blob.name
|
||||||
|
|
||||||
def walk_files(self, path_info, **kwargs):
|
def walk_files(self, path_info, **kwargs):
|
||||||
for fname in self._list_paths(path_info / "", **kwargs):
|
if not kwargs.pop("prefix", False):
|
||||||
|
path_info = path_info / ""
|
||||||
|
for fname in self._list_paths(path_info, **kwargs):
|
||||||
# skip nested empty directories
|
# skip nested empty directories
|
||||||
if fname.endswith("/"):
|
if fname.endswith("/"):
|
||||||
continue
|
continue
|
||||||
yield path_info.replace(fname)
|
yield path_info.replace(fname)
|
||||||
|
|
||||||
|
def ls(
|
||||||
|
self, path_info, detail=False, recursive=False
|
||||||
|
): # pylint: disable=arguments-differ
|
||||||
|
import base64
|
||||||
|
|
||||||
|
assert recursive
|
||||||
|
|
||||||
|
for blob in self.gs.bucket(path_info.bucket).list_blobs(
|
||||||
|
prefix=path_info.path
|
||||||
|
):
|
||||||
|
if detail:
|
||||||
|
md5_hash = base64.b64decode(blob.md5_hash)
|
||||||
|
yield {
|
||||||
|
"type": "file",
|
||||||
|
"name": blob.name,
|
||||||
|
"md5": md5_hash.hex(),
|
||||||
|
"size": blob.size,
|
||||||
|
"etag": blob.etag,
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
yield blob.name
|
||||||
|
|
||||||
def remove(self, path_info):
|
def remove(self, path_info):
|
||||||
if path_info.scheme != "gs":
|
if path_info.scheme != "gs":
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
@@ -177,29 +194,25 @@ class GSRemoteTree(BaseRemoteTree):
|
|||||||
to_bucket = self.gs.bucket(to_info.bucket)
|
to_bucket = self.gs.bucket(to_info.bucket)
|
||||||
from_bucket.copy_blob(blob, to_bucket, new_name=to_info.path)
|
from_bucket.copy_blob(blob, to_bucket, new_name=to_info.path)
|
||||||
|
|
||||||
def get_file_hash(self, path_info):
|
def _upload_fobj(self, fobj, to_info):
|
||||||
import base64
|
|
||||||
import codecs
|
|
||||||
|
|
||||||
bucket = path_info.bucket
|
|
||||||
path = path_info.path
|
|
||||||
blob = self.gs.bucket(bucket).get_blob(path)
|
|
||||||
if not blob:
|
|
||||||
return None
|
|
||||||
|
|
||||||
b64_md5 = blob.md5_hash
|
|
||||||
md5 = base64.b64decode(b64_md5)
|
|
||||||
return codecs.getencoder("hex")(md5)[0].decode("utf-8")
|
|
||||||
|
|
||||||
def _upload(self, from_file, to_info, name=None, no_progress_bar=False):
|
|
||||||
bucket = self.gs.bucket(to_info.bucket)
|
bucket = self.gs.bucket(to_info.bucket)
|
||||||
_upload_to_bucket(
|
# With other references being given in the @dynamic_chunk_size
|
||||||
bucket,
|
# this function does not respect fs.CHUNK_SIZE, since it is
|
||||||
from_file,
|
# too big for GS to handle. Rather it dynamically calculates the
|
||||||
to_info,
|
# best possible chunk size
|
||||||
name=name,
|
_upload_to_bucket(bucket, fobj, to_info)
|
||||||
no_progress_bar=no_progress_bar,
|
|
||||||
)
|
def _upload(
|
||||||
|
self, from_file, to_info, name=None, no_progress_bar=False, **_kwargs
|
||||||
|
):
|
||||||
|
with open(from_file, mode="rb") as fobj:
|
||||||
|
self.upload_fobj(
|
||||||
|
fobj,
|
||||||
|
to_info,
|
||||||
|
desc=name or to_info.path,
|
||||||
|
total=os.path.getsize(from_file),
|
||||||
|
no_progress_bar=no_progress_bar,
|
||||||
|
)
|
||||||
|
|
||||||
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)
|
||||||
+275
@@ -0,0 +1,275 @@
|
|||||||
|
import io
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
from collections import deque
|
||||||
|
from contextlib import closing, contextmanager
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
from dvc.hash_info import HashInfo
|
||||||
|
from dvc.progress import Tqdm
|
||||||
|
from dvc.scheme import Schemes
|
||||||
|
from dvc.utils import fix_env, tmp_fname
|
||||||
|
|
||||||
|
from .base import BaseFileSystem, RemoteCmdError
|
||||||
|
from .pool import get_connection
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def _hadoop_fs(cmd, user=None):
|
||||||
|
cmd = "hadoop fs -" + cmd
|
||||||
|
if user:
|
||||||
|
cmd = f"HADOOP_USER_NAME={user} " + cmd
|
||||||
|
|
||||||
|
# NOTE: close_fds doesn't work with redirected stdin/stdout/stderr.
|
||||||
|
# See https://github.com/iterative/dvc/issues/1197.
|
||||||
|
close_fds = os.name != "nt"
|
||||||
|
|
||||||
|
executable = os.getenv("SHELL") if os.name != "nt" else None
|
||||||
|
p = subprocess.Popen(
|
||||||
|
cmd,
|
||||||
|
shell=True,
|
||||||
|
close_fds=close_fds,
|
||||||
|
executable=executable,
|
||||||
|
env=fix_env(os.environ),
|
||||||
|
stdin=subprocess.PIPE,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
)
|
||||||
|
out, err = p.communicate()
|
||||||
|
if p.returncode != 0:
|
||||||
|
raise RemoteCmdError("hdfs", cmd, p.returncode, err)
|
||||||
|
return out.decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
def _group(regex, s, gname):
|
||||||
|
match = re.match(regex, s)
|
||||||
|
assert match is not None
|
||||||
|
return match.group(gname)
|
||||||
|
|
||||||
|
|
||||||
|
def _hadoop_fs_checksum(path_info):
|
||||||
|
# NOTE: pyarrow doesn't support checksum, so we need to use hadoop
|
||||||
|
regex = r".*\t.*\t(?P<checksum>.*)"
|
||||||
|
stdout = _hadoop_fs(f"checksum {path_info.url}", user=path_info.user)
|
||||||
|
return _group(regex, stdout, "checksum")
|
||||||
|
|
||||||
|
|
||||||
|
class HDFSFileSystem(BaseFileSystem):
|
||||||
|
scheme = Schemes.HDFS
|
||||||
|
REQUIRES = {"pyarrow": "pyarrow"}
|
||||||
|
REGEX = r"^hdfs://((?P<user>.*)@)?.*$"
|
||||||
|
PARAM_CHECKSUM = "checksum"
|
||||||
|
TRAVERSE_PREFIX_LEN = 2
|
||||||
|
|
||||||
|
def __init__(self, repo, config):
|
||||||
|
super().__init__(repo, config)
|
||||||
|
|
||||||
|
self.path_info = None
|
||||||
|
url = config.get("url")
|
||||||
|
if not url:
|
||||||
|
return
|
||||||
|
|
||||||
|
parsed = urlparse(url)
|
||||||
|
user = parsed.username or config.get("user")
|
||||||
|
|
||||||
|
self.path_info = self.PATH_CLS.from_parts(
|
||||||
|
scheme=self.scheme,
|
||||||
|
host=parsed.hostname,
|
||||||
|
user=user,
|
||||||
|
port=parsed.port,
|
||||||
|
path=parsed.path,
|
||||||
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def hdfs(path_info):
|
||||||
|
import pyarrow.fs
|
||||||
|
|
||||||
|
# NOTE: HadoopFileSystem is not meant to be closed by us and doesn't
|
||||||
|
# have close() method or alternative, so we add a noop one to satisfy
|
||||||
|
# our connection pool.
|
||||||
|
class HDFSConnection(pyarrow.fs.HadoopFileSystem):
|
||||||
|
def close(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
return get_connection(
|
||||||
|
HDFSConnection,
|
||||||
|
path_info.host,
|
||||||
|
path_info.port,
|
||||||
|
user=path_info.user,
|
||||||
|
)
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def open(self, path_info, mode="r", encoding=None, **kwargs):
|
||||||
|
assert mode in {"r", "rt", "rb"}
|
||||||
|
|
||||||
|
try:
|
||||||
|
with self.hdfs(path_info) as hdfs, closing(
|
||||||
|
hdfs.open_input_stream(path_info.path)
|
||||||
|
) as fd:
|
||||||
|
if mode == "rb":
|
||||||
|
yield fd
|
||||||
|
else:
|
||||||
|
yield io.TextIOWrapper(fd, encoding=encoding)
|
||||||
|
except OSError as e:
|
||||||
|
# Empty .errno and not specific enough error class in pyarrow,
|
||||||
|
# see https://issues.apache.org/jira/browse/ARROW-6248
|
||||||
|
if "file does not exist" in str(e):
|
||||||
|
raise FileNotFoundError(*e.args)
|
||||||
|
raise
|
||||||
|
|
||||||
|
def exists(self, path_info, use_dvcignore=True):
|
||||||
|
assert not isinstance(path_info, list)
|
||||||
|
assert path_info.scheme == "hdfs"
|
||||||
|
with self.hdfs(path_info) as hdfs:
|
||||||
|
import pyarrow.fs
|
||||||
|
|
||||||
|
file_info = hdfs.get_file_info(path_info.path)
|
||||||
|
return file_info.type != pyarrow.fs.FileType.NotFound
|
||||||
|
|
||||||
|
def _walk(self, hdfs, root, topdown=True):
|
||||||
|
import posixpath
|
||||||
|
|
||||||
|
from pyarrow.fs import FileSelector, FileType
|
||||||
|
|
||||||
|
dirs = deque()
|
||||||
|
nondirs = deque()
|
||||||
|
|
||||||
|
selector = FileSelector(root)
|
||||||
|
for entry in hdfs.get_file_info(selector):
|
||||||
|
if entry.type == FileType.Directory:
|
||||||
|
dirs.append(entry.base_name)
|
||||||
|
else:
|
||||||
|
nondirs.append(entry.base_name)
|
||||||
|
|
||||||
|
if topdown:
|
||||||
|
yield root, dirs, nondirs
|
||||||
|
|
||||||
|
for dname in dirs:
|
||||||
|
# NOTE: posixpath.join() is slower
|
||||||
|
yield from self._walk(
|
||||||
|
hdfs, f"{root}{posixpath.sep}{dname}", topdown=topdown
|
||||||
|
)
|
||||||
|
|
||||||
|
if not topdown:
|
||||||
|
yield root, dirs, nondirs
|
||||||
|
|
||||||
|
def walk(self, path_info, **kwargs):
|
||||||
|
if not self.isdir(path_info):
|
||||||
|
return
|
||||||
|
|
||||||
|
with self.hdfs(path_info) as hdfs:
|
||||||
|
for root, dnames, fnames in self._walk(
|
||||||
|
hdfs, path_info.path, **kwargs
|
||||||
|
):
|
||||||
|
yield path_info.replace(path=root), dnames, fnames
|
||||||
|
|
||||||
|
def walk_files(self, path_info, **kwargs):
|
||||||
|
for root, _, fnames in self.walk(path_info):
|
||||||
|
yield from (root / fname for fname in fnames)
|
||||||
|
|
||||||
|
def remove(self, path_info):
|
||||||
|
if path_info.scheme != "hdfs":
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
if self.exists(path_info):
|
||||||
|
logger.debug(f"Removing {path_info.path}")
|
||||||
|
with self.hdfs(path_info) as hdfs:
|
||||||
|
import pyarrow.fs
|
||||||
|
|
||||||
|
file_info = hdfs.get_file_info(path_info.path)
|
||||||
|
if file_info.type == pyarrow.fs.FileType.Directory:
|
||||||
|
hdfs.delete_dir(path_info.path)
|
||||||
|
else:
|
||||||
|
hdfs.delete_file(path_info.path)
|
||||||
|
|
||||||
|
def makedirs(self, path_info):
|
||||||
|
with self.hdfs(path_info) as hdfs:
|
||||||
|
# NOTE: fs.create_dir creates parents by default
|
||||||
|
hdfs.create_dir(path_info.path)
|
||||||
|
|
||||||
|
def copy(self, from_info, to_info, **_kwargs):
|
||||||
|
# NOTE: hdfs.copy_file is not supported yet in pyarrow
|
||||||
|
with self.hdfs(to_info) as hdfs:
|
||||||
|
# NOTE: this is how `hadoop fs -cp` works too: it copies through
|
||||||
|
# your local machine.
|
||||||
|
with closing(hdfs.open_input_stream(from_info.path)) as from_fobj:
|
||||||
|
tmp_info = to_info.parent / tmp_fname(to_info.name)
|
||||||
|
try:
|
||||||
|
with closing(
|
||||||
|
hdfs.open_output_stream(tmp_info.path)
|
||||||
|
) as tmp_fobj:
|
||||||
|
shutil.copyfileobj(from_fobj, tmp_fobj)
|
||||||
|
hdfs.move(tmp_info.path, to_info.path)
|
||||||
|
except Exception:
|
||||||
|
self.remove(tmp_info)
|
||||||
|
raise
|
||||||
|
|
||||||
|
def isfile(self, path_info):
|
||||||
|
with self.hdfs(path_info) as hdfs:
|
||||||
|
import pyarrow.fs
|
||||||
|
|
||||||
|
file_info = hdfs.get_file_info(path_info.path)
|
||||||
|
return file_info.type == pyarrow.fs.FileType.File
|
||||||
|
|
||||||
|
def isdir(self, path_info):
|
||||||
|
with self.hdfs(path_info) as hdfs:
|
||||||
|
import pyarrow.fs
|
||||||
|
|
||||||
|
file_info = hdfs.get_file_info(path_info.path)
|
||||||
|
return file_info.type == pyarrow.fs.FileType.Directory
|
||||||
|
|
||||||
|
def info(self, path_info):
|
||||||
|
with self.hdfs(path_info) as hdfs:
|
||||||
|
finfo = hdfs.get_file_info(path_info.path)
|
||||||
|
return {"size": finfo.size}
|
||||||
|
|
||||||
|
def checksum(self, path_info):
|
||||||
|
return HashInfo(
|
||||||
|
"checksum",
|
||||||
|
_hadoop_fs_checksum(path_info),
|
||||||
|
size=self.getsize(path_info),
|
||||||
|
)
|
||||||
|
|
||||||
|
def _upload_fobj(self, fobj, to_info):
|
||||||
|
with self.hdfs(to_info) as hdfs:
|
||||||
|
with hdfs.open_output_stream(to_info.path) as fdest:
|
||||||
|
shutil.copyfileobj(fobj, fdest)
|
||||||
|
|
||||||
|
def _upload(
|
||||||
|
self, from_file, to_info, name=None, no_progress_bar=False, **_kwargs
|
||||||
|
):
|
||||||
|
with self.hdfs(to_info) as hdfs:
|
||||||
|
tmp_file = tmp_fname(to_info.path)
|
||||||
|
total = os.path.getsize(from_file)
|
||||||
|
with open(from_file, "rb") as fobj:
|
||||||
|
with Tqdm.wrapattr(
|
||||||
|
fobj,
|
||||||
|
"read",
|
||||||
|
desc=name,
|
||||||
|
total=total,
|
||||||
|
disable=no_progress_bar,
|
||||||
|
) as wrapped:
|
||||||
|
with hdfs.open_output_stream(tmp_file) as sobj:
|
||||||
|
sobj.write(wrapped.read())
|
||||||
|
hdfs.move(tmp_file, to_info.path)
|
||||||
|
|
||||||
|
def _download(
|
||||||
|
self, from_info, to_file, name=None, no_progress_bar=False, **_kwargs
|
||||||
|
):
|
||||||
|
with self.hdfs(from_info) as hdfs:
|
||||||
|
file_info = hdfs.get_file_info(from_info.path)
|
||||||
|
total = file_info.size
|
||||||
|
with open(to_file, "wb+") as fobj:
|
||||||
|
with Tqdm.wrapattr(
|
||||||
|
fobj,
|
||||||
|
"write",
|
||||||
|
desc=name,
|
||||||
|
total=total,
|
||||||
|
disable=no_progress_bar,
|
||||||
|
) as wrapped:
|
||||||
|
with hdfs.open_input_stream(from_info.path) as sobj:
|
||||||
|
wrapped.write(sobj.read())
|
||||||
@@ -8,9 +8,10 @@ import dvc.prompt as prompt
|
|||||||
from dvc.exceptions import DvcException, HTTPError
|
from dvc.exceptions import DvcException, HTTPError
|
||||||
from dvc.path_info import HTTPURLInfo
|
from dvc.path_info import HTTPURLInfo
|
||||||
from dvc.progress import Tqdm
|
from dvc.progress import Tqdm
|
||||||
from dvc.remote.base import BaseRemoteTree
|
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
|
|
||||||
|
from .base import BaseFileSystem
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -23,7 +24,7 @@ def ask_password(host, user):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class HTTPRemoteTree(BaseRemoteTree):
|
class HTTPFileSystem(BaseFileSystem): # pylint:disable=abstract-method
|
||||||
scheme = Schemes.HTTP
|
scheme = Schemes.HTTP
|
||||||
PATH_CLS = HTTPURLInfo
|
PATH_CLS = HTTPURLInfo
|
||||||
PARAM_CHECKSUM = "etag"
|
PARAM_CHECKSUM = "etag"
|
||||||
@@ -31,7 +32,7 @@ class HTTPRemoteTree(BaseRemoteTree):
|
|||||||
|
|
||||||
SESSION_RETRIES = 5
|
SESSION_RETRIES = 5
|
||||||
SESSION_BACKOFF_FACTOR = 0.1
|
SESSION_BACKOFF_FACTOR = 0.1
|
||||||
REQUEST_TIMEOUT = 10
|
REQUEST_TIMEOUT = 60
|
||||||
CHUNK_SIZE = 2 ** 16
|
CHUNK_SIZE = 2 ** 16
|
||||||
|
|
||||||
def __init__(self, repo, config):
|
def __init__(self, repo, config):
|
||||||
@@ -40,9 +41,8 @@ class HTTPRemoteTree(BaseRemoteTree):
|
|||||||
url = config.get("url")
|
url = config.get("url")
|
||||||
if url:
|
if url:
|
||||||
self.path_info = self.PATH_CLS(url)
|
self.path_info = self.PATH_CLS(url)
|
||||||
user = config.get("user", None)
|
self.user = config.get("user", None)
|
||||||
if user:
|
self.host = self.path_info.host
|
||||||
self.path_info.user = user
|
|
||||||
else:
|
else:
|
||||||
self.path_info = None
|
self.path_info = None
|
||||||
|
|
||||||
@@ -51,25 +51,26 @@ class HTTPRemoteTree(BaseRemoteTree):
|
|||||||
self.password = config.get("password", None)
|
self.password = config.get("password", None)
|
||||||
self.ask_password = config.get("ask_password", False)
|
self.ask_password = config.get("ask_password", False)
|
||||||
self.headers = {}
|
self.headers = {}
|
||||||
|
self.ssl_verify = config.get("ssl_verify", True)
|
||||||
|
self.method = config.get("method", "POST")
|
||||||
|
|
||||||
def _auth_method(self, path_info=None):
|
def _auth_method(self):
|
||||||
from requests.auth import HTTPBasicAuth, HTTPDigestAuth
|
from requests.auth import HTTPBasicAuth, HTTPDigestAuth
|
||||||
|
|
||||||
if path_info is None:
|
|
||||||
path_info = self.path_info
|
|
||||||
|
|
||||||
if self.auth:
|
if self.auth:
|
||||||
if self.ask_password and self.password is None:
|
if self.ask_password and self.password is None:
|
||||||
host, user = path_info.host, path_info.user
|
self.password = ask_password(self.host, self.user)
|
||||||
self.password = ask_password(host, user)
|
|
||||||
if self.auth == "basic":
|
if self.auth == "basic":
|
||||||
return HTTPBasicAuth(path_info.user, self.password)
|
return HTTPBasicAuth(self.user, self.password)
|
||||||
if self.auth == "digest":
|
if self.auth == "digest":
|
||||||
return HTTPDigestAuth(path_info.user, self.password)
|
return HTTPDigestAuth(self.user, self.password)
|
||||||
if self.auth == "custom" and self.custom_auth_header:
|
if self.auth == "custom" and self.custom_auth_header:
|
||||||
self.headers.update({self.custom_auth_header: self.password})
|
self.headers.update({self.custom_auth_header: self.password})
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def _generate_download_url(self, path_info):
|
||||||
|
return path_info.url
|
||||||
|
|
||||||
@wrap_prop(threading.Lock())
|
@wrap_prop(threading.Lock())
|
||||||
@cached_property
|
@cached_property
|
||||||
def _session(self):
|
def _session(self):
|
||||||
@@ -79,6 +80,8 @@ class HTTPRemoteTree(BaseRemoteTree):
|
|||||||
|
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
|
|
||||||
|
session.verify = self.ssl_verify
|
||||||
|
|
||||||
retries = Retry(
|
retries = Retry(
|
||||||
total=self.SESSION_RETRIES,
|
total=self.SESSION_RETRIES,
|
||||||
backoff_factor=self.SESSION_BACKOFF_FACTOR,
|
backoff_factor=self.SESSION_BACKOFF_FACTOR,
|
||||||
@@ -121,27 +124,45 @@ class HTTPRemoteTree(BaseRemoteTree):
|
|||||||
except requests.exceptions.RequestException:
|
except requests.exceptions.RequestException:
|
||||||
raise DvcException(f"could not perform a {method} request")
|
raise DvcException(f"could not perform a {method} request")
|
||||||
|
|
||||||
def exists(self, path_info):
|
def _head(self, url):
|
||||||
return bool(self.request("HEAD", path_info.url))
|
response = self.request("HEAD", url)
|
||||||
|
if response.ok:
|
||||||
|
return response
|
||||||
|
|
||||||
def get_file_hash(self, path_info):
|
# Sometimes servers are configured to forbid HEAD requests
|
||||||
|
# Context: https://github.com/iterative/dvc/issues/4131
|
||||||
|
with self.request("GET", url, stream=True) as r:
|
||||||
|
if r.ok:
|
||||||
|
return r
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
def exists(self, path_info, use_dvcignore=True):
|
||||||
|
res = self._head(path_info.url)
|
||||||
|
if res.status_code == 404:
|
||||||
|
return False
|
||||||
|
if bool(res):
|
||||||
|
return True
|
||||||
|
raise HTTPError(res.status_code, res.reason)
|
||||||
|
|
||||||
|
def info(self, path_info):
|
||||||
url = path_info.url
|
url = path_info.url
|
||||||
headers = self.request("HEAD", url).headers
|
headers = self._head(url).headers
|
||||||
etag = headers.get("ETag") or headers.get("Content-MD5")
|
etag = headers.get("ETag") or headers.get("Content-MD5")
|
||||||
|
size = int(headers.get("Content-Length"))
|
||||||
|
return {"etag": etag, "size": size}
|
||||||
|
|
||||||
if not etag:
|
def _upload_fobj(self, fobj, to_info):
|
||||||
raise DvcException(
|
def chunks(fobj):
|
||||||
"could not find an ETag or "
|
while True:
|
||||||
"Content-MD5 header for '{url}'".format(url=url)
|
chunk = fobj.read(self.CHUNK_SIZE)
|
||||||
)
|
if not chunk:
|
||||||
|
break
|
||||||
|
yield chunk
|
||||||
|
|
||||||
if etag.startswith("W/"):
|
response = self.request(self.method, to_info.url, data=chunks(fobj))
|
||||||
raise DvcException(
|
if response.status_code not in (200, 201):
|
||||||
"Weak ETags are not supported."
|
raise HTTPError(response.status_code, response.reason)
|
||||||
" (Etag: '{etag}', URL: '{url}')".format(etag=etag, url=url)
|
|
||||||
)
|
|
||||||
|
|
||||||
return etag
|
|
||||||
|
|
||||||
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):
|
||||||
response = self.request("GET", from_info.url, stream=True)
|
response = self.request("GET", from_info.url, stream=True)
|
||||||
@@ -161,28 +182,17 @@ class HTTPRemoteTree(BaseRemoteTree):
|
|||||||
for chunk in response.iter_content(chunk_size=self.CHUNK_SIZE):
|
for chunk in response.iter_content(chunk_size=self.CHUNK_SIZE):
|
||||||
fd_wrapped.write(chunk)
|
fd_wrapped.write(chunk)
|
||||||
|
|
||||||
def _upload(self, from_file, to_info, name=None, no_progress_bar=False):
|
def _upload(
|
||||||
def chunks():
|
self, from_file, to_info, name=None, no_progress_bar=False, **_kwargs
|
||||||
with open(from_file, "rb") as fd:
|
):
|
||||||
with Tqdm.wrapattr(
|
with open(from_file, "rb") as fobj:
|
||||||
fd,
|
self.upload_fobj(
|
||||||
"read",
|
fobj,
|
||||||
total=None
|
to_info,
|
||||||
if no_progress_bar
|
no_progress_bar=no_progress_bar,
|
||||||
else os.path.getsize(from_file),
|
desc=name or to_info.url,
|
||||||
leave=False,
|
total=None if no_progress_bar else os.path.getsize(from_file),
|
||||||
desc=to_info.url if name is None else name,
|
)
|
||||||
disable=no_progress_bar,
|
|
||||||
) as fd_wrapped:
|
|
||||||
while True:
|
|
||||||
chunk = fd_wrapped.read(self.CHUNK_SIZE)
|
|
||||||
if not chunk:
|
|
||||||
break
|
|
||||||
yield chunk
|
|
||||||
|
|
||||||
response = self.request("POST", to_info.url, data=chunks())
|
|
||||||
if response.status_code not in (200, 201):
|
|
||||||
raise HTTPError(response.status_code, response.reason)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _content_length(response):
|
def _content_length(response):
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
from dvc.scheme import Schemes
|
||||||
|
|
||||||
|
from .http import HTTPFileSystem
|
||||||
|
|
||||||
|
|
||||||
|
class HTTPSFileSystem(HTTPFileSystem): # pylint:disable=abstract-method
|
||||||
|
scheme = Schemes.HTTPS
|
||||||
+232
@@ -0,0 +1,232 @@
|
|||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import stat
|
||||||
|
|
||||||
|
from funcy import cached_property
|
||||||
|
|
||||||
|
from dvc.path_info import PathInfo
|
||||||
|
from dvc.scheme import Schemes
|
||||||
|
from dvc.system import System
|
||||||
|
from dvc.utils import is_exec, tmp_fname
|
||||||
|
from dvc.utils.fs import copy_fobj_to_file, copyfile, makedirs, move, remove
|
||||||
|
|
||||||
|
from .base import BaseFileSystem
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class LocalFileSystem(BaseFileSystem):
|
||||||
|
scheme = Schemes.LOCAL
|
||||||
|
PATH_CLS = PathInfo
|
||||||
|
PARAM_CHECKSUM = "md5"
|
||||||
|
PARAM_PATH = "path"
|
||||||
|
TRAVERSE_PREFIX_LEN = 2
|
||||||
|
|
||||||
|
def __init__(self, repo, config, use_dvcignore=False, dvcignore_root=None):
|
||||||
|
super().__init__(repo, config)
|
||||||
|
url = config.get("url")
|
||||||
|
self.path_info = self.PATH_CLS(url) if url else None
|
||||||
|
self.use_dvcignore = use_dvcignore
|
||||||
|
self.dvcignore_root = dvcignore_root
|
||||||
|
|
||||||
|
@property
|
||||||
|
def fs_root(self):
|
||||||
|
return self.config.get("url")
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def dvcignore(self):
|
||||||
|
from dvc.ignore import DvcIgnoreFilter, DvcIgnoreFilterNoop
|
||||||
|
|
||||||
|
root = self.dvcignore_root or self.fs_root
|
||||||
|
cls = DvcIgnoreFilter if self.use_dvcignore else DvcIgnoreFilterNoop
|
||||||
|
return cls(self, root)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def open(path_info, mode="r", encoding=None, **kwargs):
|
||||||
|
return open(path_info, mode=mode, encoding=encoding)
|
||||||
|
|
||||||
|
def exists(self, path_info, use_dvcignore=True):
|
||||||
|
assert isinstance(path_info, str) or path_info.scheme == "local"
|
||||||
|
if self.repo:
|
||||||
|
ret = os.path.lexists(path_info)
|
||||||
|
else:
|
||||||
|
ret = os.path.exists(path_info)
|
||||||
|
if not ret:
|
||||||
|
return False
|
||||||
|
if not use_dvcignore:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return not self.dvcignore.is_ignored_file(
|
||||||
|
path_info
|
||||||
|
) and not self.dvcignore.is_ignored_dir(path_info)
|
||||||
|
|
||||||
|
def isfile(self, path_info):
|
||||||
|
if not os.path.isfile(path_info):
|
||||||
|
return False
|
||||||
|
|
||||||
|
return not self.dvcignore.is_ignored_file(path_info)
|
||||||
|
|
||||||
|
def isdir(
|
||||||
|
self, path_info, use_dvcignore=True
|
||||||
|
): # pylint: disable=arguments-differ
|
||||||
|
if not os.path.isdir(path_info):
|
||||||
|
return False
|
||||||
|
return not (use_dvcignore and self.dvcignore.is_ignored_dir(path_info))
|
||||||
|
|
||||||
|
def iscopy(self, path_info):
|
||||||
|
return not (
|
||||||
|
System.is_symlink(path_info) or System.is_hardlink(path_info)
|
||||||
|
)
|
||||||
|
|
||||||
|
def walk(
|
||||||
|
self,
|
||||||
|
top,
|
||||||
|
topdown=True,
|
||||||
|
onerror=None,
|
||||||
|
use_dvcignore=True,
|
||||||
|
ignore_subrepos=True,
|
||||||
|
):
|
||||||
|
"""Directory fs generator.
|
||||||
|
|
||||||
|
See `os.walk` for the docs. Differences:
|
||||||
|
- no support for symlinks
|
||||||
|
"""
|
||||||
|
for root, dirs, files in os.walk(
|
||||||
|
top, topdown=topdown, onerror=onerror
|
||||||
|
):
|
||||||
|
if use_dvcignore:
|
||||||
|
dirs[:], files[:] = self.dvcignore(
|
||||||
|
os.path.abspath(root),
|
||||||
|
dirs,
|
||||||
|
files,
|
||||||
|
ignore_subrepos=ignore_subrepos,
|
||||||
|
)
|
||||||
|
|
||||||
|
yield os.path.normpath(root), dirs, files
|
||||||
|
|
||||||
|
def walk_files(self, path_info, **kwargs):
|
||||||
|
for root, _, files in self.walk(path_info):
|
||||||
|
for file in files:
|
||||||
|
# NOTE: os.path.join is ~5.5 times slower
|
||||||
|
yield PathInfo(f"{root}{os.sep}{file}")
|
||||||
|
|
||||||
|
def is_empty(self, path_info):
|
||||||
|
if self.isfile(path_info) and os.path.getsize(path_info) == 0:
|
||||||
|
return True
|
||||||
|
|
||||||
|
if self.isdir(path_info) and len(os.listdir(path_info)) == 0:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
def remove(self, path_info):
|
||||||
|
if isinstance(path_info, PathInfo):
|
||||||
|
if path_info.scheme != "local":
|
||||||
|
raise NotImplementedError
|
||||||
|
remove(path_info)
|
||||||
|
|
||||||
|
def makedirs(self, path_info):
|
||||||
|
makedirs(path_info, exist_ok=True)
|
||||||
|
|
||||||
|
def isexec(self, path_info):
|
||||||
|
mode = self.stat(path_info).st_mode
|
||||||
|
return is_exec(mode)
|
||||||
|
|
||||||
|
def stat(self, path):
|
||||||
|
if self.dvcignore.is_ignored(path):
|
||||||
|
raise FileNotFoundError
|
||||||
|
|
||||||
|
return os.stat(path)
|
||||||
|
|
||||||
|
def move(self, from_info, to_info):
|
||||||
|
if from_info.scheme != "local" or to_info.scheme != "local":
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
self.makedirs(to_info.parent)
|
||||||
|
move(from_info, to_info)
|
||||||
|
|
||||||
|
def copy(self, from_info, to_info):
|
||||||
|
tmp_info = to_info.parent / tmp_fname("")
|
||||||
|
try:
|
||||||
|
copyfile(from_info, tmp_info)
|
||||||
|
os.rename(tmp_info, to_info)
|
||||||
|
except Exception:
|
||||||
|
self.remove(tmp_info)
|
||||||
|
raise
|
||||||
|
|
||||||
|
def _upload_fobj(self, fobj, to_info):
|
||||||
|
self.makedirs(to_info.parent)
|
||||||
|
tmp_info = to_info.parent / tmp_fname("")
|
||||||
|
try:
|
||||||
|
copy_fobj_to_file(fobj, tmp_info)
|
||||||
|
os.rename(tmp_info, to_info)
|
||||||
|
except Exception:
|
||||||
|
self.remove(tmp_info)
|
||||||
|
raise
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def symlink(from_info, to_info):
|
||||||
|
System.symlink(from_info, to_info)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def is_symlink(path_info):
|
||||||
|
return System.is_symlink(path_info)
|
||||||
|
|
||||||
|
def hardlink(self, from_info, to_info):
|
||||||
|
# If there are a lot of empty files (which happens a lot in datasets),
|
||||||
|
# and the cache type is `hardlink`, we might reach link limits and
|
||||||
|
# will get something like: `too many links error`
|
||||||
|
#
|
||||||
|
# This is because all those empty files will have the same hash
|
||||||
|
# (i.e. 68b329da9893e34099c7d8ad5cb9c940), therefore, they will be
|
||||||
|
# linked to the same file in the cache.
|
||||||
|
#
|
||||||
|
# From https://en.wikipedia.org/wiki/Hard_link
|
||||||
|
# * ext4 limits the number of hard links on a file to 65,000
|
||||||
|
# * Windows with NTFS has a limit of 1024 hard links on a file
|
||||||
|
#
|
||||||
|
# That's why we simply create an empty file rather than a link.
|
||||||
|
if self.getsize(from_info) == 0:
|
||||||
|
self.open(to_info, "w").close()
|
||||||
|
|
||||||
|
logger.debug("Created empty file: %s -> %s", from_info, to_info)
|
||||||
|
return
|
||||||
|
|
||||||
|
System.hardlink(from_info, to_info)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def is_hardlink(path_info):
|
||||||
|
return System.is_hardlink(path_info)
|
||||||
|
|
||||||
|
def reflink(self, from_info, to_info):
|
||||||
|
System.reflink(from_info, to_info)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def info(path_info):
|
||||||
|
st = os.stat(path_info)
|
||||||
|
return {
|
||||||
|
"size": st.st_size,
|
||||||
|
"type": "dir" if stat.S_ISDIR(st.st_mode) else "file",
|
||||||
|
}
|
||||||
|
|
||||||
|
def _upload(
|
||||||
|
self, from_file, to_info, name=None, no_progress_bar=False, **_kwargs,
|
||||||
|
):
|
||||||
|
makedirs(to_info.parent, exist_ok=True)
|
||||||
|
|
||||||
|
tmp_file = tmp_fname(to_info)
|
||||||
|
copyfile(
|
||||||
|
from_file, tmp_file, name=name, no_progress_bar=no_progress_bar
|
||||||
|
)
|
||||||
|
os.replace(tmp_file, to_info)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _download(
|
||||||
|
from_info, to_file, name=None, no_progress_bar=False, **_kwargs
|
||||||
|
):
|
||||||
|
copyfile(
|
||||||
|
from_info, to_file, no_progress_bar=no_progress_bar, name=name
|
||||||
|
)
|
||||||
|
|
||||||
|
def _reset(self):
|
||||||
|
return self.__dict__.pop("dvcignore", None)
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
from .base import BaseFileSystem
|
||||||
|
|
||||||
|
|
||||||
|
class MemoryFileSystem(BaseFileSystem):
|
||||||
|
scheme = "local"
|
||||||
|
PARAM_CHECKSUM = "md5"
|
||||||
|
|
||||||
|
def __init__(self, repo, config):
|
||||||
|
from fsspec.implementations.memory import MemoryFileSystem as MemFS
|
||||||
|
|
||||||
|
super().__init__(repo, config)
|
||||||
|
|
||||||
|
self.fs = MemFS()
|
||||||
|
|
||||||
|
def exists(self, path_info, use_dvcignore=True):
|
||||||
|
return self.fs.exists(path_info.path)
|
||||||
|
|
||||||
|
def open(self, path_info, mode="r", encoding=None, **kwargs):
|
||||||
|
return self.fs.open(
|
||||||
|
path_info.fspath, mode=mode, encoding=encoding, **kwargs
|
||||||
|
)
|
||||||
|
|
||||||
|
def stat(self, path_info):
|
||||||
|
import os
|
||||||
|
|
||||||
|
info = self.fs.info(path_info.fspath)
|
||||||
|
|
||||||
|
return os.stat_result((0, 0, 0, 0, 0, 0, info["size"], 0, 0, 0))
|
||||||
|
|
||||||
|
def walk_files(self, path_info, **kwargs):
|
||||||
|
raise NotImplementedError
|
||||||
@@ -6,13 +6,14 @@ 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 BaseRemoteTree
|
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
|
|
||||||
|
from .base import BaseFileSystem
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class OSSRemoteTree(BaseRemoteTree):
|
class OSSFileSystem(BaseFileSystem): # pylint:disable=abstract-method
|
||||||
"""
|
"""
|
||||||
oss2 document:
|
oss2 document:
|
||||||
https://www.alibabacloud.com/help/doc-detail/32026.htm
|
https://www.alibabacloud.com/help/doc-detail/32026.htm
|
||||||
@@ -44,6 +45,7 @@ class OSSRemoteTree(BaseRemoteTree):
|
|||||||
url = config.get("url")
|
url = config.get("url")
|
||||||
self.path_info = self.PATH_CLS(url) if url else None
|
self.path_info = self.PATH_CLS(url) if url else None
|
||||||
|
|
||||||
|
self.bucket = self.path_info.bucket
|
||||||
self.endpoint = config.get("oss_endpoint") or os.getenv("OSS_ENDPOINT")
|
self.endpoint = config.get("oss_endpoint") or os.getenv("OSS_ENDPOINT")
|
||||||
|
|
||||||
self.key_id = (
|
self.key_id = (
|
||||||
@@ -63,12 +65,11 @@ class OSSRemoteTree(BaseRemoteTree):
|
|||||||
def oss_service(self):
|
def oss_service(self):
|
||||||
import oss2
|
import oss2
|
||||||
|
|
||||||
logger.debug(f"URL: {self.path_info}")
|
|
||||||
logger.debug(f"key id: {self.key_id}")
|
logger.debug(f"key id: {self.key_id}")
|
||||||
logger.debug(f"key secret: {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.bucket)
|
||||||
|
|
||||||
# Ensure bucket exists
|
# Ensure bucket exists
|
||||||
try:
|
try:
|
||||||
@@ -83,11 +84,11 @@ class OSSRemoteTree(BaseRemoteTree):
|
|||||||
return bucket
|
return bucket
|
||||||
|
|
||||||
def _generate_download_url(self, path_info, expires=3600):
|
def _generate_download_url(self, path_info, expires=3600):
|
||||||
assert path_info.bucket == self.path_info.bucket
|
assert path_info.bucket == self.bucket
|
||||||
|
|
||||||
return self.oss_service.sign_url("GET", path_info.path, expires)
|
return self.oss_service.sign_url("GET", path_info.path, expires)
|
||||||
|
|
||||||
def exists(self, path_info):
|
def exists(self, path_info, use_dvcignore=True):
|
||||||
paths = self._list_paths(path_info)
|
paths = self._list_paths(path_info)
|
||||||
return any(path_info.path == path for path in paths)
|
return any(path_info.path == path for path in paths)
|
||||||
|
|
||||||
@@ -100,6 +101,8 @@ class OSSRemoteTree(BaseRemoteTree):
|
|||||||
yield blob.key
|
yield blob.key
|
||||||
|
|
||||||
def walk_files(self, path_info, **kwargs):
|
def walk_files(self, path_info, **kwargs):
|
||||||
|
if not kwargs.pop("prefix", False):
|
||||||
|
path_info = path_info / ""
|
||||||
for fname in self._list_paths(path_info):
|
for fname in self._list_paths(path_info):
|
||||||
if fname.endswith("/"):
|
if fname.endswith("/"):
|
||||||
continue
|
continue
|
||||||
@@ -113,6 +116,9 @@ class OSSRemoteTree(BaseRemoteTree):
|
|||||||
logger.debug(f"Removing oss://{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 _upload_fobj(self, fobj, to_info):
|
||||||
|
self.oss_service.put_object(to_info.path, fobj)
|
||||||
|
|
||||||
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
|
||||||
):
|
):
|
||||||
@@ -125,6 +131,11 @@ class OSSRemoteTree(BaseRemoteTree):
|
|||||||
self, from_info, to_file, name=None, no_progress_bar=False, **_kwargs
|
self, from_info, to_file, name=None, no_progress_bar=False, **_kwargs
|
||||||
):
|
):
|
||||||
with Tqdm(desc=name, disable=no_progress_bar, bytes=True) as pbar:
|
with Tqdm(desc=name, disable=no_progress_bar, bytes=True) as pbar:
|
||||||
self.oss_service.get_object_to_file(
|
import oss2
|
||||||
from_info.path, to_file, progress_callback=pbar.update_to
|
|
||||||
|
oss2.resumable_download(
|
||||||
|
self.oss_service,
|
||||||
|
from_info.path,
|
||||||
|
to_file,
|
||||||
|
progress_callback=pbar.update_to,
|
||||||
)
|
)
|
||||||
@@ -11,7 +11,7 @@ def get_connection(conn_func, *args, **kwargs):
|
|||||||
conn = pool.get_connection()
|
conn = pool.get_connection()
|
||||||
try:
|
try:
|
||||||
yield conn
|
yield conn
|
||||||
except BaseException:
|
except Exception:
|
||||||
conn.close()
|
conn.close()
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
+431
@@ -0,0 +1,431 @@
|
|||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import stat
|
||||||
|
import threading
|
||||||
|
from contextlib import suppress
|
||||||
|
from itertools import takewhile
|
||||||
|
from typing import TYPE_CHECKING, Callable, Optional, Tuple, Type, Union
|
||||||
|
|
||||||
|
from funcy import lfilter, wrap_with
|
||||||
|
|
||||||
|
from dvc.path_info import PathInfo
|
||||||
|
|
||||||
|
from .base import BaseFileSystem
|
||||||
|
from .dvc import DvcFileSystem
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from dvc.repo import Repo
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
RepoFactory = Union[Callable[[str], "Repo"], Type["Repo"]]
|
||||||
|
|
||||||
|
|
||||||
|
class RepoFileSystem(BaseFileSystem): # pylint:disable=abstract-method
|
||||||
|
"""DVC + git-tracked files fs.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
repo: DVC or git repo.
|
||||||
|
subrepos: traverse to subrepos (by default, it ignores subrepos)
|
||||||
|
repo_factory: A function to initialize subrepo with, default is Repo.
|
||||||
|
kwargs: Additional keyword arguments passed to the `DvcFileSystem()`.
|
||||||
|
"""
|
||||||
|
|
||||||
|
scheme = "local"
|
||||||
|
PARAM_CHECKSUM = "md5"
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self, repo, subrepos=False, repo_factory: RepoFactory = None,
|
||||||
|
):
|
||||||
|
super().__init__(repo, {"url": repo.root_dir})
|
||||||
|
|
||||||
|
from dvc.utils.collections import PathStringTrie
|
||||||
|
|
||||||
|
if not repo_factory:
|
||||||
|
from dvc.repo import Repo
|
||||||
|
|
||||||
|
self.repo_factory: RepoFactory = Repo
|
||||||
|
else:
|
||||||
|
self.repo_factory = repo_factory
|
||||||
|
|
||||||
|
self._main_repo = repo
|
||||||
|
self.root_dir = repo.root_dir
|
||||||
|
self._traverse_subrepos = subrepos
|
||||||
|
|
||||||
|
self._subrepos_trie = PathStringTrie()
|
||||||
|
"""Keeps track of each and every path with the corresponding repo."""
|
||||||
|
|
||||||
|
self._subrepos_trie[self.root_dir] = repo
|
||||||
|
|
||||||
|
self._dvcfss = {}
|
||||||
|
"""Keep a dvcfs instance of each repo."""
|
||||||
|
|
||||||
|
if hasattr(repo, "dvc_dir"):
|
||||||
|
self._dvcfss[repo.root_dir] = DvcFileSystem(repo)
|
||||||
|
|
||||||
|
def _get_repo(self, path) -> Optional["Repo"]:
|
||||||
|
"""Returns repo that the path falls in, using prefix.
|
||||||
|
|
||||||
|
If the path is already tracked/collected, it just returns the repo.
|
||||||
|
|
||||||
|
Otherwise, it collects the repos that might be in the path's parents
|
||||||
|
and then returns the appropriate one.
|
||||||
|
"""
|
||||||
|
repo = self._subrepos_trie.get(path)
|
||||||
|
if repo:
|
||||||
|
return repo
|
||||||
|
|
||||||
|
prefix, repo = self._subrepos_trie.longest_prefix(path)
|
||||||
|
if not prefix:
|
||||||
|
return None
|
||||||
|
|
||||||
|
parents = (parent.fspath for parent in PathInfo(path).parents)
|
||||||
|
dirs = [path] + list(takewhile(lambda p: p != prefix, parents))
|
||||||
|
dirs.reverse()
|
||||||
|
self._update(dirs, starting_repo=repo)
|
||||||
|
return self._subrepos_trie.get(path)
|
||||||
|
|
||||||
|
@wrap_with(threading.Lock())
|
||||||
|
def _update(self, dirs, starting_repo):
|
||||||
|
"""Checks for subrepo in directories and updates them."""
|
||||||
|
repo = starting_repo
|
||||||
|
for d in dirs:
|
||||||
|
if self._is_dvc_repo(d):
|
||||||
|
repo = self.repo_factory(
|
||||||
|
d,
|
||||||
|
scm=self.repo.scm,
|
||||||
|
rev=self.repo.get_rev(),
|
||||||
|
repo_factory=self.repo_factory,
|
||||||
|
)
|
||||||
|
self._dvcfss[repo.root_dir] = DvcFileSystem(repo)
|
||||||
|
self._subrepos_trie[d] = repo
|
||||||
|
|
||||||
|
def _is_dvc_repo(self, dir_path):
|
||||||
|
"""Check if the directory is a dvc repo."""
|
||||||
|
if not self._traverse_subrepos:
|
||||||
|
return False
|
||||||
|
|
||||||
|
from dvc.repo import Repo
|
||||||
|
|
||||||
|
repo_path = os.path.join(dir_path, Repo.DVC_DIR)
|
||||||
|
# dvcignore will ignore subrepos, therefore using `use_dvcignore=False`
|
||||||
|
return self._main_repo.fs.isdir(repo_path, use_dvcignore=False)
|
||||||
|
|
||||||
|
def _get_fs_pair(
|
||||||
|
self, path
|
||||||
|
) -> Tuple[BaseFileSystem, Optional[DvcFileSystem]]:
|
||||||
|
"""
|
||||||
|
Returns a pair of fss based on repo the path falls in, using prefix.
|
||||||
|
"""
|
||||||
|
path = os.path.abspath(path)
|
||||||
|
|
||||||
|
# fallback to the top-level repo if repo was not found
|
||||||
|
# this can happen if the path is outside of the repo
|
||||||
|
repo = self._get_repo(path) or self._main_repo
|
||||||
|
|
||||||
|
dvc_fs = self._dvcfss.get(repo.root_dir)
|
||||||
|
return repo.fs, dvc_fs
|
||||||
|
|
||||||
|
def open(
|
||||||
|
self, path, mode="r", encoding="utf-8", **kwargs
|
||||||
|
): # pylint: disable=arguments-differ
|
||||||
|
if "b" in mode:
|
||||||
|
encoding = None
|
||||||
|
|
||||||
|
fs, dvc_fs = self._get_fs_pair(path)
|
||||||
|
path_info = PathInfo(path)
|
||||||
|
try:
|
||||||
|
return fs.open(path_info, mode=mode, encoding=encoding)
|
||||||
|
except FileNotFoundError:
|
||||||
|
if not dvc_fs:
|
||||||
|
raise
|
||||||
|
|
||||||
|
return dvc_fs.open(path_info, mode=mode, encoding=encoding, **kwargs)
|
||||||
|
|
||||||
|
def exists(
|
||||||
|
self, path, use_dvcignore=True
|
||||||
|
): # pylint: disable=arguments-differ
|
||||||
|
fs, dvc_fs = self._get_fs_pair(path)
|
||||||
|
|
||||||
|
if not dvc_fs:
|
||||||
|
return fs.exists(path)
|
||||||
|
|
||||||
|
if fs.exists(path):
|
||||||
|
return True
|
||||||
|
|
||||||
|
try:
|
||||||
|
meta = dvc_fs.metadata(path)
|
||||||
|
except FileNotFoundError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
(out,) = meta.outs
|
||||||
|
assert len(meta.outs) == 1
|
||||||
|
if fs.exists(out.path_info):
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def isdir(self, path): # pylint: disable=arguments-differ
|
||||||
|
fs, dvc_fs = self._get_fs_pair(path)
|
||||||
|
|
||||||
|
try:
|
||||||
|
st = fs.stat(path)
|
||||||
|
return stat.S_ISDIR(st.st_mode)
|
||||||
|
except (OSError, ValueError):
|
||||||
|
# from CPython's os.path.isdir()
|
||||||
|
pass
|
||||||
|
|
||||||
|
if not dvc_fs:
|
||||||
|
return False
|
||||||
|
|
||||||
|
try:
|
||||||
|
meta = dvc_fs.metadata(path)
|
||||||
|
except FileNotFoundError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
(out,) = meta.outs
|
||||||
|
assert len(meta.outs) == 1
|
||||||
|
if fs.exists(out.path_info):
|
||||||
|
return False
|
||||||
|
return meta.isdir
|
||||||
|
|
||||||
|
def isdvc(self, path, **kwargs):
|
||||||
|
_, dvc_fs = self._get_fs_pair(path)
|
||||||
|
return dvc_fs is not None and dvc_fs.isdvc(path, **kwargs)
|
||||||
|
|
||||||
|
def isfile(self, path): # pylint: disable=arguments-differ
|
||||||
|
fs, dvc_fs = self._get_fs_pair(path)
|
||||||
|
|
||||||
|
try:
|
||||||
|
st = fs.stat(path)
|
||||||
|
return stat.S_ISREG(st.st_mode)
|
||||||
|
except (OSError, ValueError):
|
||||||
|
# from CPython's os.path.isfile()
|
||||||
|
pass
|
||||||
|
|
||||||
|
if not dvc_fs:
|
||||||
|
return False
|
||||||
|
|
||||||
|
try:
|
||||||
|
meta = dvc_fs.metadata(path)
|
||||||
|
except FileNotFoundError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
(out,) = meta.outs
|
||||||
|
assert len(meta.outs) == 1
|
||||||
|
if fs.exists(out.path_info):
|
||||||
|
return False
|
||||||
|
return meta.isfile
|
||||||
|
|
||||||
|
def isexec(self, path_info):
|
||||||
|
fs, dvc_fs = self._get_fs_pair(path_info)
|
||||||
|
if dvc_fs and dvc_fs.exists(path_info):
|
||||||
|
return dvc_fs.isexec(path_info)
|
||||||
|
return fs.isexec(path_info)
|
||||||
|
|
||||||
|
def stat(self, path):
|
||||||
|
fs, _ = self._get_fs_pair(path)
|
||||||
|
return fs.stat(path)
|
||||||
|
|
||||||
|
def _dvc_walk(self, walk):
|
||||||
|
try:
|
||||||
|
root, dirs, files = next(walk)
|
||||||
|
except StopIteration:
|
||||||
|
return
|
||||||
|
yield root, dirs, files
|
||||||
|
for _ in dirs:
|
||||||
|
yield from self._dvc_walk(walk)
|
||||||
|
|
||||||
|
def _subrepo_walk(self, dir_path, **kwargs):
|
||||||
|
"""Walk into a new repo.
|
||||||
|
|
||||||
|
NOTE: subrepo will only be discovered when walking if
|
||||||
|
ignore_subrepos is set to False.
|
||||||
|
"""
|
||||||
|
fs, dvc_fs = self._get_fs_pair(dir_path)
|
||||||
|
fs_walk = fs.walk(
|
||||||
|
dir_path, topdown=True, ignore_subrepos=not self._traverse_subrepos
|
||||||
|
)
|
||||||
|
if dvc_fs:
|
||||||
|
dvc_walk = dvc_fs.walk(dir_path, topdown=True, **kwargs)
|
||||||
|
else:
|
||||||
|
dvc_walk = None
|
||||||
|
yield from self._walk(fs_walk, dvc_walk, **kwargs)
|
||||||
|
|
||||||
|
def _walk(self, repo_walk, dvc_walk=None, dvcfiles=False):
|
||||||
|
from dvc.dvcfile import is_valid_filename
|
||||||
|
from dvc.ignore import DvcIgnore
|
||||||
|
|
||||||
|
assert repo_walk
|
||||||
|
try:
|
||||||
|
_, dvc_dirs, dvc_fnames = (
|
||||||
|
next(dvc_walk) if dvc_walk else (None, [], [])
|
||||||
|
)
|
||||||
|
repo_root, repo_dirs, repo_fnames = next(repo_walk)
|
||||||
|
except StopIteration:
|
||||||
|
return
|
||||||
|
|
||||||
|
# separate subdirs into shared dirs, dvc-only dirs, repo-only dirs
|
||||||
|
dvc_set = set(dvc_dirs)
|
||||||
|
repo_set = set(repo_dirs)
|
||||||
|
dvc_only = list(dvc_set - repo_set)
|
||||||
|
repo_only = list(repo_set - dvc_set)
|
||||||
|
shared = list(dvc_set & repo_set)
|
||||||
|
dirs = shared + dvc_only + repo_only
|
||||||
|
|
||||||
|
def _func(fname):
|
||||||
|
if dvcfiles:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return not (
|
||||||
|
is_valid_filename(fname) or fname == DvcIgnore.DVCIGNORE_FILE
|
||||||
|
)
|
||||||
|
|
||||||
|
# merge file lists
|
||||||
|
files = set(filter(_func, dvc_fnames + repo_fnames))
|
||||||
|
|
||||||
|
yield repo_root, dirs, list(files)
|
||||||
|
|
||||||
|
def is_dvc_repo(d):
|
||||||
|
return self._is_dvc_repo(os.path.join(repo_root, d))
|
||||||
|
|
||||||
|
# remove subrepos to prevent it from being traversed
|
||||||
|
subrepos = set(filter(is_dvc_repo, repo_only))
|
||||||
|
# set dir order for next recursion level - shared dirs first so that
|
||||||
|
# next() for both generators recurses into the same shared directory
|
||||||
|
dvc_dirs[:] = [dirname for dirname in dirs if dirname in dvc_set]
|
||||||
|
repo_dirs[:] = lfilter(lambda d: d in (repo_set - subrepos), dirs)
|
||||||
|
|
||||||
|
for dirname in dirs:
|
||||||
|
if dirname in subrepos:
|
||||||
|
dir_path = os.path.join(repo_root, dirname)
|
||||||
|
yield from self._subrepo_walk(dir_path, dvcfiles=dvcfiles)
|
||||||
|
elif dirname in shared:
|
||||||
|
yield from self._walk(repo_walk, dvc_walk, dvcfiles=dvcfiles)
|
||||||
|
elif dirname in dvc_set:
|
||||||
|
yield from self._dvc_walk(dvc_walk)
|
||||||
|
elif dirname in repo_set:
|
||||||
|
yield from self._walk(repo_walk, None, dvcfiles=dvcfiles)
|
||||||
|
|
||||||
|
def walk(
|
||||||
|
self,
|
||||||
|
top,
|
||||||
|
topdown=True,
|
||||||
|
onerror=None,
|
||||||
|
dvcfiles=False,
|
||||||
|
follow_subrepos=None,
|
||||||
|
**kwargs
|
||||||
|
): # pylint: disable=arguments-differ
|
||||||
|
"""Walk and merge both DVC and repo fss.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
top: path to walk from
|
||||||
|
topdown: if True, fs will be walked from top down.
|
||||||
|
onerror: if set, onerror function will be called if an error
|
||||||
|
occurs (by default errors are ignored).
|
||||||
|
dvcfiles: if True, dvcfiles will be included in the files list
|
||||||
|
for walked directories.
|
||||||
|
|
||||||
|
Any kwargs will be passed into methods used for fetching and/or
|
||||||
|
streaming DVC outs from remotes.
|
||||||
|
"""
|
||||||
|
assert topdown
|
||||||
|
|
||||||
|
if not self.exists(top):
|
||||||
|
if onerror is not None:
|
||||||
|
onerror(FileNotFoundError(top))
|
||||||
|
return
|
||||||
|
|
||||||
|
if not self.isdir(top):
|
||||||
|
if onerror is not None:
|
||||||
|
onerror(NotADirectoryError(top))
|
||||||
|
return
|
||||||
|
|
||||||
|
ignore_subrepos = not self._traverse_subrepos
|
||||||
|
if follow_subrepos is not None:
|
||||||
|
ignore_subrepos = not follow_subrepos
|
||||||
|
|
||||||
|
fs, dvc_fs = self._get_fs_pair(top)
|
||||||
|
repo_exists = fs.exists(top)
|
||||||
|
repo_walk = fs.walk(
|
||||||
|
top,
|
||||||
|
topdown=topdown,
|
||||||
|
onerror=onerror,
|
||||||
|
ignore_subrepos=ignore_subrepos,
|
||||||
|
)
|
||||||
|
|
||||||
|
if not dvc_fs or (repo_exists and dvc_fs.isdvc(top)):
|
||||||
|
yield from self._walk(repo_walk, None, dvcfiles=dvcfiles)
|
||||||
|
return
|
||||||
|
|
||||||
|
if not repo_exists:
|
||||||
|
yield from dvc_fs.walk(top, topdown=topdown, **kwargs)
|
||||||
|
|
||||||
|
dvc_walk = None
|
||||||
|
if dvc_fs.exists(top):
|
||||||
|
dvc_walk = dvc_fs.walk(top, topdown=topdown, **kwargs)
|
||||||
|
|
||||||
|
yield from self._walk(repo_walk, dvc_walk, dvcfiles=dvcfiles)
|
||||||
|
|
||||||
|
def walk_files(self, top, **kwargs): # pylint: disable=arguments-differ
|
||||||
|
for root, _, files in self.walk(top, **kwargs):
|
||||||
|
for fname in files:
|
||||||
|
yield PathInfo(root) / fname
|
||||||
|
|
||||||
|
def _download(
|
||||||
|
self, from_info, to_file, name=None, no_progress_bar=False, **kwargs
|
||||||
|
):
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
from dvc.progress import Tqdm
|
||||||
|
|
||||||
|
with open(to_file, "wb+") as to_fobj:
|
||||||
|
with Tqdm.wrapattr(
|
||||||
|
to_fobj, "write", desc=name, disable=no_progress_bar,
|
||||||
|
) as wrapped:
|
||||||
|
with self.open(from_info, "rb", **kwargs) as from_fobj:
|
||||||
|
shutil.copyfileobj(from_fobj, wrapped)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def hash_jobs(self): # pylint: disable=invalid-overridden-method
|
||||||
|
return self._main_repo.fs.hash_jobs
|
||||||
|
|
||||||
|
def metadata(self, path):
|
||||||
|
abspath = os.path.abspath(path)
|
||||||
|
path_info = PathInfo(abspath)
|
||||||
|
fs, dvc_fs = self._get_fs_pair(path_info)
|
||||||
|
|
||||||
|
dvc_meta = None
|
||||||
|
if dvc_fs:
|
||||||
|
with suppress(FileNotFoundError):
|
||||||
|
dvc_meta = dvc_fs.metadata(path_info)
|
||||||
|
|
||||||
|
stat_result = None
|
||||||
|
with suppress(FileNotFoundError):
|
||||||
|
stat_result = fs.stat(path_info)
|
||||||
|
|
||||||
|
if not stat_result and not dvc_meta:
|
||||||
|
raise FileNotFoundError
|
||||||
|
|
||||||
|
from ._metadata import Metadata
|
||||||
|
|
||||||
|
meta = dvc_meta or Metadata(
|
||||||
|
path_info=path_info,
|
||||||
|
repo=self._get_repo(abspath) or self._main_repo,
|
||||||
|
)
|
||||||
|
|
||||||
|
isdir = bool(stat_result) and stat.S_ISDIR(stat_result.st_mode)
|
||||||
|
meta.isdir = meta.isdir or isdir
|
||||||
|
|
||||||
|
if not dvc_meta:
|
||||||
|
from dvc.utils import is_exec
|
||||||
|
|
||||||
|
meta.is_exec = bool(stat_result) and is_exec(stat_result.st_mode)
|
||||||
|
return meta
|
||||||
|
|
||||||
|
def info(self, path_info):
|
||||||
|
fs, dvc_fs = self._get_fs_pair(path_info)
|
||||||
|
|
||||||
|
try:
|
||||||
|
return fs.info(path_info)
|
||||||
|
except FileNotFoundError:
|
||||||
|
return dvc_fs.info(path_info)
|
||||||
+206
-88
@@ -1,24 +1,31 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import threading
|
import threading
|
||||||
|
from contextlib import contextmanager
|
||||||
|
|
||||||
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, ETagMismatchError
|
from dvc.exceptions import DvcException, ETagMismatchError
|
||||||
|
from dvc.hash_info import HashInfo
|
||||||
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 BaseRemoteTree
|
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
|
from dvc.utils import conversions, error_link
|
||||||
|
|
||||||
|
from .base import BaseFileSystem
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
_AWS_CONFIG_PATH = os.path.join(os.path.expanduser("~"), ".aws", "config")
|
||||||
|
|
||||||
class S3RemoteTree(BaseRemoteTree):
|
|
||||||
|
class S3FileSystem(BaseFileSystem):
|
||||||
scheme = Schemes.S3
|
scheme = Schemes.S3
|
||||||
PATH_CLS = CloudURLInfo
|
PATH_CLS = CloudURLInfo
|
||||||
REQUIRES = {"boto3": "boto3"}
|
REQUIRES = {"boto3": "boto3"}
|
||||||
PARAM_CHECKSUM = "etag"
|
PARAM_CHECKSUM = "etag"
|
||||||
|
DETAIL_FIELDS = frozenset(("etag", "size"))
|
||||||
|
|
||||||
def __init__(self, repo, config):
|
def __init__(self, repo, config):
|
||||||
super().__init__(repo, config)
|
super().__init__(repo, config)
|
||||||
@@ -30,11 +37,6 @@ class S3RemoteTree(BaseRemoteTree):
|
|||||||
self.profile = config.get("profile")
|
self.profile = config.get("profile")
|
||||||
self.endpoint_url = config.get("endpointurl")
|
self.endpoint_url = config.get("endpointurl")
|
||||||
|
|
||||||
if config.get("listobjects"):
|
|
||||||
self.list_objects_api = "list_objects"
|
|
||||||
else:
|
|
||||||
self.list_objects_api = "list_objects_v2"
|
|
||||||
|
|
||||||
self.use_ssl = config.get("use_ssl", True)
|
self.use_ssl = config.get("use_ssl", True)
|
||||||
|
|
||||||
self.extra_args = {}
|
self.extra_args = {}
|
||||||
@@ -53,37 +55,132 @@ class S3RemoteTree(BaseRemoteTree):
|
|||||||
|
|
||||||
self._append_aws_grants_to_extra_args(config)
|
self._append_aws_grants_to_extra_args(config)
|
||||||
|
|
||||||
|
self.access_key_id = config.get("access_key_id")
|
||||||
|
self.secret_access_key = config.get("secret_access_key")
|
||||||
|
self.session_token = config.get("session_token")
|
||||||
|
|
||||||
shared_creds = config.get("credentialpath")
|
shared_creds = config.get("credentialpath")
|
||||||
if shared_creds:
|
if shared_creds:
|
||||||
os.environ.setdefault("AWS_SHARED_CREDENTIALS_FILE", shared_creds)
|
os.environ.setdefault("AWS_SHARED_CREDENTIALS_FILE", shared_creds)
|
||||||
|
|
||||||
|
config_path = config.get("configpath")
|
||||||
|
if config_path:
|
||||||
|
os.environ.setdefault("AWS_CONFIG_FILE", config_path)
|
||||||
|
self._transfer_config = None
|
||||||
|
|
||||||
|
# https://github.com/aws/aws-cli/blob/0376c6262d6b15dc36c82e6da6e1aad10249cc8c/awscli/customizations/s3/transferconfig.py#L107-L113
|
||||||
|
_TRANSFER_CONFIG_ALIASES = {
|
||||||
|
"max_queue_size": "max_io_queue",
|
||||||
|
"max_concurrent_requests": "max_concurrency",
|
||||||
|
"multipart_threshold": "multipart_threshold",
|
||||||
|
"multipart_chunksize": "multipart_chunksize",
|
||||||
|
}
|
||||||
|
|
||||||
|
def _transform_config(self, s3_config):
|
||||||
|
"""Splits the general s3 config into 2 different config
|
||||||
|
objects, one for transfer.TransferConfig and other is the
|
||||||
|
general session config"""
|
||||||
|
|
||||||
|
config, transfer_config = {}, {}
|
||||||
|
for key, value in s3_config.items():
|
||||||
|
if key in self._TRANSFER_CONFIG_ALIASES:
|
||||||
|
if key in {"multipart_chunksize", "multipart_threshold"}:
|
||||||
|
# cast human readable sizes (like 24MiB) to integers
|
||||||
|
value = conversions.human_readable_to_bytes(value)
|
||||||
|
else:
|
||||||
|
value = int(value)
|
||||||
|
transfer_config[self._TRANSFER_CONFIG_ALIASES[key]] = value
|
||||||
|
else:
|
||||||
|
config[key] = value
|
||||||
|
|
||||||
|
return config, transfer_config
|
||||||
|
|
||||||
|
def _process_config(self):
|
||||||
|
from boto3.s3.transfer import TransferConfig
|
||||||
|
from botocore.configloader import load_config
|
||||||
|
|
||||||
|
config_path = os.environ.get("AWS_CONFIG_FILE", _AWS_CONFIG_PATH)
|
||||||
|
if not os.path.exists(config_path):
|
||||||
|
return None
|
||||||
|
|
||||||
|
config = load_config(config_path)
|
||||||
|
profile = config["profiles"].get(self.profile or "default")
|
||||||
|
if not profile:
|
||||||
|
return None
|
||||||
|
|
||||||
|
s3_config = profile.get("s3", {})
|
||||||
|
s3_config, transfer_config = self._transform_config(s3_config)
|
||||||
|
self._transfer_config = TransferConfig(**transfer_config)
|
||||||
|
return s3_config
|
||||||
|
|
||||||
@wrap_prop(threading.Lock())
|
@wrap_prop(threading.Lock())
|
||||||
@cached_property
|
@cached_property
|
||||||
def s3(self):
|
def s3(self):
|
||||||
import boto3
|
import boto3
|
||||||
|
|
||||||
session = boto3.session.Session(
|
session_opts = {
|
||||||
profile_name=self.profile, region_name=self.region
|
"profile_name": self.profile,
|
||||||
|
"region_name": self.region,
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.access_key_id:
|
||||||
|
session_opts["aws_access_key_id"] = self.access_key_id
|
||||||
|
if self.secret_access_key:
|
||||||
|
session_opts["aws_secret_access_key"] = self.secret_access_key
|
||||||
|
if self.session_token:
|
||||||
|
session_opts["aws_session_token"] = self.session_token
|
||||||
|
|
||||||
|
session = boto3.session.Session(**session_opts)
|
||||||
|
s3_config = self._process_config()
|
||||||
|
|
||||||
|
return session.resource(
|
||||||
|
"s3",
|
||||||
|
endpoint_url=self.endpoint_url,
|
||||||
|
use_ssl=self.use_ssl,
|
||||||
|
config=boto3.session.Config(
|
||||||
|
signature_version="s3v4", s3=s3_config
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
return session.client(
|
@contextmanager
|
||||||
"s3", endpoint_url=self.endpoint_url, use_ssl=self.use_ssl
|
def _get_s3(self):
|
||||||
|
from botocore.exceptions import (
|
||||||
|
EndpointConnectionError,
|
||||||
|
NoCredentialsError,
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_etag(cls, s3, bucket, path):
|
|
||||||
obj = cls.get_head_object(s3, bucket, path)
|
|
||||||
|
|
||||||
return obj["ETag"].strip('"')
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_head_object(s3, bucket, path, *args, **kwargs):
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
obj = s3.head_object(Bucket=bucket, Key=path, *args, **kwargs)
|
yield self.s3
|
||||||
except Exception as exc:
|
except NoCredentialsError as exc:
|
||||||
raise DvcException(f"s3://{bucket}/{path} does not exist") from exc
|
link = error_link("no-credentials")
|
||||||
return obj
|
raise DvcException(
|
||||||
|
f"Unable to find AWS credentials. {link}"
|
||||||
|
) from exc
|
||||||
|
except EndpointConnectionError as exc:
|
||||||
|
link = error_link("connection-error")
|
||||||
|
name = self.endpoint_url or "AWS S3"
|
||||||
|
raise DvcException(
|
||||||
|
f"Unable to connect to '{name}'. {link}"
|
||||||
|
) from exc
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def _get_bucket(self, bucket):
|
||||||
|
with self._get_s3() as s3:
|
||||||
|
try:
|
||||||
|
yield s3.Bucket(bucket)
|
||||||
|
except s3.meta.client.exceptions.NoSuchBucket as exc:
|
||||||
|
link = error_link("no-bucket")
|
||||||
|
raise DvcException(
|
||||||
|
f"Bucket '{bucket}' does not exist. {link}"
|
||||||
|
) from exc
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def _get_obj(self, path_info):
|
||||||
|
with self._get_bucket(path_info.bucket) as bucket:
|
||||||
|
try:
|
||||||
|
yield bucket.Object(path_info.path)
|
||||||
|
except bucket.meta.client.exceptions.NoSuchKey as exc:
|
||||||
|
raise DvcException(f"{path_info.url} does not exist") from exc
|
||||||
|
|
||||||
def _append_aws_grants_to_extra_args(self, config):
|
def _append_aws_grants_to_extra_args(self, config):
|
||||||
# Keys for extra_args can be one of the following list:
|
# Keys for extra_args can be one of the following list:
|
||||||
@@ -118,11 +215,14 @@ class S3RemoteTree(BaseRemoteTree):
|
|||||||
|
|
||||||
def _generate_download_url(self, path_info, expires=3600):
|
def _generate_download_url(self, path_info, expires=3600):
|
||||||
params = {"Bucket": path_info.bucket, "Key": path_info.path}
|
params = {"Bucket": path_info.bucket, "Key": path_info.path}
|
||||||
return self.s3.generate_presigned_url(
|
with self._get_s3() as s3:
|
||||||
ClientMethod="get_object", Params=params, ExpiresIn=int(expires)
|
return s3.meta.client.generate_presigned_url(
|
||||||
)
|
ClientMethod="get_object",
|
||||||
|
Params=params,
|
||||||
|
ExpiresIn=int(expires),
|
||||||
|
)
|
||||||
|
|
||||||
def exists(self, path_info):
|
def exists(self, path_info, use_dvcignore=True):
|
||||||
"""Check if the blob exists. If it does not exist,
|
"""Check if the blob exists. If it does not exist,
|
||||||
it could be a part of a directory path.
|
it could be a part of a directory path.
|
||||||
|
|
||||||
@@ -155,50 +255,61 @@ class S3RemoteTree(BaseRemoteTree):
|
|||||||
return bool(list(self._list_paths(dir_path, max_items=1)))
|
return bool(list(self._list_paths(dir_path, max_items=1)))
|
||||||
|
|
||||||
def isfile(self, path_info):
|
def isfile(self, path_info):
|
||||||
from botocore.exceptions import ClientError
|
|
||||||
|
|
||||||
if path_info.path.endswith("/"):
|
if path_info.path.endswith("/"):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
return path_info.path in self._list_paths(path_info)
|
||||||
self.s3.head_object(Bucket=path_info.bucket, Key=path_info.path)
|
|
||||||
except ClientError as exc:
|
|
||||||
if exc.response["Error"]["Code"] != "404":
|
|
||||||
raise
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
def info(self, path_info):
|
||||||
|
with self._get_obj(path_info) as obj:
|
||||||
def _list_objects(self, path_info, max_items=None):
|
return {
|
||||||
""" Read config for list object api, paginate through list objects."""
|
"etag": obj.e_tag.strip('"'),
|
||||||
kwargs = {
|
"size": obj.content_length,
|
||||||
"Bucket": path_info.bucket,
|
}
|
||||||
"Prefix": path_info.path,
|
|
||||||
"PaginationConfig": {"MaxItems": max_items},
|
|
||||||
}
|
|
||||||
paginator = self.s3.get_paginator(self.list_objects_api)
|
|
||||||
for page in paginator.paginate(**kwargs):
|
|
||||||
contents = page.get("Contents", ())
|
|
||||||
yield from contents
|
|
||||||
|
|
||||||
def _list_paths(self, path_info, max_items=None):
|
def _list_paths(self, path_info, max_items=None):
|
||||||
return (
|
with self._get_bucket(path_info.bucket) as bucket:
|
||||||
item["Key"] for item in self._list_objects(path_info, max_items)
|
obj_summaries = bucket.objects.filter(Prefix=path_info.path)
|
||||||
)
|
if max_items is not None:
|
||||||
|
obj_summaries = obj_summaries.page_size(max_items).limit(
|
||||||
|
max_items
|
||||||
|
)
|
||||||
|
for obj_summary in obj_summaries:
|
||||||
|
yield obj_summary.key
|
||||||
|
|
||||||
def walk_files(self, path_info, **kwargs):
|
def walk_files(self, path_info, **kwargs):
|
||||||
for fname in self._list_paths(path_info / "", **kwargs):
|
if not kwargs.pop("prefix", False):
|
||||||
|
path_info = path_info / ""
|
||||||
|
for fname in self._list_paths(path_info, **kwargs):
|
||||||
if fname.endswith("/"):
|
if fname.endswith("/"):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
yield path_info.replace(path=fname)
|
yield path_info.replace(path=fname)
|
||||||
|
|
||||||
|
def ls(
|
||||||
|
self, path_info, detail=False, recursive=False
|
||||||
|
): # pylint: disable=arguments-differ
|
||||||
|
assert recursive
|
||||||
|
|
||||||
|
with self._get_bucket(path_info.bucket) as bucket:
|
||||||
|
for obj_summary in bucket.objects.filter(Prefix=path_info.path):
|
||||||
|
if detail:
|
||||||
|
yield {
|
||||||
|
"type": "file",
|
||||||
|
"name": obj_summary.key,
|
||||||
|
"size": obj_summary.size,
|
||||||
|
"etag": obj_summary.e_tag.strip('"'),
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
yield obj_summary.key
|
||||||
|
|
||||||
def remove(self, path_info):
|
def remove(self, path_info):
|
||||||
if path_info.scheme != "s3":
|
if path_info.scheme != "s3":
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
logger.debug(f"Removing {path_info}")
|
logger.debug(f"Removing {path_info}")
|
||||||
self.s3.delete_object(Bucket=path_info.bucket, Key=path_info.path)
|
with self._get_obj(path_info) as obj:
|
||||||
|
obj.delete()
|
||||||
|
|
||||||
def makedirs(self, path_info):
|
def makedirs(self, path_info):
|
||||||
# We need to support creating empty directories, which means
|
# We need to support creating empty directories, which means
|
||||||
@@ -210,10 +321,12 @@ class S3RemoteTree(BaseRemoteTree):
|
|||||||
return
|
return
|
||||||
|
|
||||||
dir_path = path_info / ""
|
dir_path = path_info / ""
|
||||||
self.s3.put_object(Bucket=path_info.bucket, Key=dir_path.path, Body="")
|
with self._get_obj(dir_path) as obj:
|
||||||
|
obj.put(Body="")
|
||||||
|
|
||||||
def copy(self, from_info, to_info):
|
def copy(self, from_info, to_info):
|
||||||
self._copy(self.s3, from_info, to_info, self.extra_args)
|
with self._get_s3() as s3:
|
||||||
|
self._copy(s3.meta.client, from_info, to_info, self.extra_args)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _copy_multipart(
|
def _copy_multipart(
|
||||||
@@ -227,8 +340,8 @@ class S3RemoteTree(BaseRemoteTree):
|
|||||||
parts = []
|
parts = []
|
||||||
byte_position = 0
|
byte_position = 0
|
||||||
for i in range(1, n_parts + 1):
|
for i in range(1, n_parts + 1):
|
||||||
obj = S3RemoteTree.get_head_object(
|
obj = s3.head_object(
|
||||||
s3, from_info.bucket, from_info.path, PartNumber=i
|
Bucket=from_info.bucket, Key=from_info.path, PartNumber=i
|
||||||
)
|
)
|
||||||
part_size = obj["ContentLength"]
|
part_size = obj["ContentLength"]
|
||||||
lastbyte = byte_position + part_size - 1
|
lastbyte = byte_position + part_size - 1
|
||||||
@@ -282,9 +395,7 @@ class S3RemoteTree(BaseRemoteTree):
|
|||||||
# object is transfered in the same chunks as it was originally.
|
# object is transfered in the same chunks as it was originally.
|
||||||
from boto3.s3.transfer import TransferConfig
|
from boto3.s3.transfer import TransferConfig
|
||||||
|
|
||||||
obj = S3RemoteTree.get_head_object(
|
obj = s3.head_object(Bucket=from_info.bucket, Key=from_info.path)
|
||||||
s3, from_info.bucket, from_info.path
|
|
||||||
)
|
|
||||||
etag = obj["ETag"].strip('"')
|
etag = obj["ETag"].strip('"')
|
||||||
size = obj["ContentLength"]
|
size = obj["ContentLength"]
|
||||||
|
|
||||||
@@ -304,36 +415,43 @@ class S3RemoteTree(BaseRemoteTree):
|
|||||||
Config=TransferConfig(multipart_threshold=size + 1),
|
Config=TransferConfig(multipart_threshold=size + 1),
|
||||||
)
|
)
|
||||||
|
|
||||||
cached_etag = S3RemoteTree.get_etag(s3, to_info.bucket, to_info.path)
|
cached_etag = s3.head_object(Bucket=to_info.bucket, Key=to_info.path)[
|
||||||
|
"ETag"
|
||||||
|
].strip('"')
|
||||||
if etag != cached_etag:
|
if etag != cached_etag:
|
||||||
raise ETagMismatchError(etag, cached_etag)
|
raise ETagMismatchError(etag, cached_etag)
|
||||||
|
|
||||||
def get_file_hash(self, path_info):
|
def etag(self, path_info):
|
||||||
return self.get_etag(self.s3, path_info.bucket, path_info.path)
|
with self._get_obj(path_info) as obj:
|
||||||
|
return HashInfo("etag", size=obj.content_length,)
|
||||||
|
|
||||||
def _upload(self, from_file, to_info, name=None, no_progress_bar=False):
|
def _upload_fobj(self, fobj, to_info):
|
||||||
total = os.path.getsize(from_file)
|
with self._get_obj(to_info) as obj:
|
||||||
with Tqdm(
|
obj.upload_fileobj(fobj, Config=self._transfer_config)
|
||||||
disable=no_progress_bar, total=total, bytes=True, desc=name
|
|
||||||
) as pbar:
|
def _upload(
|
||||||
self.s3.upload_file(
|
self, from_file, to_info, name=None, no_progress_bar=False, **_kwargs
|
||||||
from_file,
|
):
|
||||||
to_info.bucket,
|
with self._get_obj(to_info) as obj:
|
||||||
to_info.path,
|
total = os.path.getsize(from_file)
|
||||||
Callback=pbar.update,
|
with Tqdm(
|
||||||
ExtraArgs=self.extra_args,
|
disable=no_progress_bar, total=total, bytes=True, desc=name
|
||||||
)
|
) as pbar:
|
||||||
|
obj.upload_file(
|
||||||
|
from_file,
|
||||||
|
Callback=pbar.update,
|
||||||
|
ExtraArgs=self.extra_args,
|
||||||
|
Config=self._transfer_config,
|
||||||
|
)
|
||||||
|
|
||||||
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):
|
||||||
if no_progress_bar:
|
with self._get_obj(from_info) as obj:
|
||||||
total = None
|
with Tqdm(
|
||||||
else:
|
disable=no_progress_bar,
|
||||||
total = self.s3.head_object(
|
total=obj.content_length,
|
||||||
Bucket=from_info.bucket, Key=from_info.path
|
bytes=True,
|
||||||
)["ContentLength"]
|
desc=name,
|
||||||
with Tqdm(
|
) as pbar:
|
||||||
disable=no_progress_bar, total=total, bytes=True, desc=name
|
obj.download_file(
|
||||||
) as pbar:
|
to_file, Callback=pbar.update, Config=self._transfer_config
|
||||||
self.s3.download_file(
|
)
|
||||||
from_info.bucket, from_info.path, to_file, Callback=pbar.update
|
|
||||||
)
|
|
||||||
@@ -1,23 +1,20 @@
|
|||||||
import errno
|
|
||||||
import getpass
|
import getpass
|
||||||
import io
|
import io
|
||||||
import itertools
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import posixpath
|
import shutil
|
||||||
import threading
|
import threading
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
|
||||||
from contextlib import closing, contextmanager
|
from contextlib import closing, contextmanager
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from funcy import first, memoize, silent, wrap_with
|
from funcy import first, memoize, silent, wrap_with
|
||||||
|
|
||||||
import dvc.prompt as prompt
|
import dvc.prompt as prompt
|
||||||
from dvc.progress import Tqdm
|
from dvc.hash_info import HashInfo
|
||||||
from dvc.remote.base import BaseRemoteTree, Remote
|
|
||||||
from dvc.remote.pool import get_connection
|
|
||||||
from dvc.scheme import Schemes
|
from dvc.scheme import Schemes
|
||||||
from dvc.utils import to_chunks
|
|
||||||
|
from ..base import BaseFileSystem
|
||||||
|
from ..pool import get_connection
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -33,7 +30,7 @@ def ask_password(host, user, port):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class SSHRemoteTree(BaseRemoteTree):
|
class SSHFileSystem(BaseFileSystem):
|
||||||
scheme = Schemes.SSH
|
scheme = Schemes.SSH
|
||||||
REQUIRES = {"paramiko": "paramiko"}
|
REQUIRES = {"paramiko": "paramiko"}
|
||||||
JOBS = 4
|
JOBS = 4
|
||||||
@@ -94,6 +91,7 @@ class SSHRemoteTree(BaseRemoteTree):
|
|||||||
self.sock = paramiko.ProxyCommand(proxy_command)
|
self.sock = paramiko.ProxyCommand(proxy_command)
|
||||||
else:
|
else:
|
||||||
self.sock = None
|
self.sock = None
|
||||||
|
self.allow_agent = config.get("allow_agent", True)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def ssh_config_filename():
|
def ssh_config_filename():
|
||||||
@@ -103,7 +101,7 @@ class SSHRemoteTree(BaseRemoteTree):
|
|||||||
def _load_user_ssh_config(hostname):
|
def _load_user_ssh_config(hostname):
|
||||||
import paramiko
|
import paramiko
|
||||||
|
|
||||||
user_config_file = SSHRemoteTree.ssh_config_filename()
|
user_config_file = SSHFileSystem.ssh_config_filename()
|
||||||
user_ssh_config = {}
|
user_ssh_config = {}
|
||||||
if hostname and os.path.exists(user_config_file):
|
if hostname and os.path.exists(user_config_file):
|
||||||
ssh_config = paramiko.SSHConfig()
|
ssh_config = paramiko.SSHConfig()
|
||||||
@@ -146,10 +144,11 @@ class SSHRemoteTree(BaseRemoteTree):
|
|||||||
password=self.password,
|
password=self.password,
|
||||||
gss_auth=self.gss_auth,
|
gss_auth=self.gss_auth,
|
||||||
sock=self.sock,
|
sock=self.sock,
|
||||||
|
allow_agent=self.allow_agent,
|
||||||
)
|
)
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def open(self, path_info, mode="r", encoding=None):
|
def open(self, path_info, mode="r", encoding=None, **kwargs):
|
||||||
assert mode in {"r", "rt", "rb", "wb"}
|
assert mode in {"r", "rt", "rb", "wb"}
|
||||||
|
|
||||||
with self.ssh(path_info) as ssh, closing(
|
with self.ssh(path_info) as ssh, closing(
|
||||||
@@ -160,7 +159,7 @@ class SSHRemoteTree(BaseRemoteTree):
|
|||||||
else:
|
else:
|
||||||
yield io.TextIOWrapper(fd, encoding=encoding)
|
yield io.TextIOWrapper(fd, encoding=encoding)
|
||||||
|
|
||||||
def exists(self, path_info):
|
def exists(self, path_info, use_dvcignore=True):
|
||||||
with self.ssh(path_info) as ssh:
|
with self.ssh(path_info) as ssh:
|
||||||
return ssh.exists(path_info.path)
|
return ssh.exists(path_info.path)
|
||||||
|
|
||||||
@@ -188,8 +187,7 @@ class SSHRemoteTree(BaseRemoteTree):
|
|||||||
with self.ssh(path_info) as ssh:
|
with self.ssh(path_info) as ssh:
|
||||||
ssh.makedirs(path_info.path)
|
ssh.makedirs(path_info.path)
|
||||||
|
|
||||||
def move(self, from_info, to_info, mode=None):
|
def move(self, from_info, to_info):
|
||||||
assert mode is None
|
|
||||||
if from_info.scheme != self.scheme or to_info.scheme != self.scheme:
|
if from_info.scheme != self.scheme or to_info.scheme != self.scheme:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@@ -237,20 +235,25 @@ class SSHRemoteTree(BaseRemoteTree):
|
|||||||
with self.ssh(from_info) as ssh:
|
with self.ssh(from_info) as ssh:
|
||||||
ssh.reflink(from_info.path, to_info.path)
|
ssh.reflink(from_info.path, to_info.path)
|
||||||
|
|
||||||
def get_file_hash(self, path_info):
|
def md5(self, path_info):
|
||||||
if path_info.scheme != self.scheme:
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
with self.ssh(path_info) as ssh:
|
with self.ssh(path_info) as ssh:
|
||||||
return ssh.md5(path_info.path)
|
return HashInfo(
|
||||||
|
"md5",
|
||||||
|
ssh.md5(path_info.path),
|
||||||
|
size=ssh.getsize(path_info.path),
|
||||||
|
)
|
||||||
|
|
||||||
def getsize(self, path_info):
|
def info(self, path_info):
|
||||||
with self.ssh(path_info) as ssh:
|
with self.ssh(path_info) as ssh:
|
||||||
return ssh.getsize(path_info.path)
|
return ssh.info(path_info.path)
|
||||||
|
|
||||||
|
def _upload_fobj(self, fobj, to_info):
|
||||||
|
self.makedirs(to_info.parent)
|
||||||
|
with self.open(to_info, mode="wb") as fdest:
|
||||||
|
shutil.copyfileobj(fobj, fdest)
|
||||||
|
|
||||||
def _download(self, from_info, to_file, name=None, no_progress_bar=False):
|
def _download(self, from_info, to_file, name=None, no_progress_bar=False):
|
||||||
assert from_info.isin(self.path_info)
|
with self.ssh(from_info) as ssh:
|
||||||
with self.ssh(self.path_info) as ssh:
|
|
||||||
ssh.download(
|
ssh.download(
|
||||||
from_info.path,
|
from_info.path,
|
||||||
to_file,
|
to_file,
|
||||||
@@ -258,90 +261,13 @@ class SSHRemoteTree(BaseRemoteTree):
|
|||||||
no_progress_bar=no_progress_bar,
|
no_progress_bar=no_progress_bar,
|
||||||
)
|
)
|
||||||
|
|
||||||
def _upload(self, from_file, to_info, name=None, no_progress_bar=False):
|
def _upload(
|
||||||
assert to_info.isin(self.path_info)
|
self, from_file, to_info, name=None, no_progress_bar=False, **_kwargs
|
||||||
with self.ssh(self.path_info) as ssh:
|
):
|
||||||
|
with self.ssh(to_info) as ssh:
|
||||||
ssh.upload(
|
ssh.upload(
|
||||||
from_file,
|
from_file,
|
||||||
to_info.path,
|
to_info.path,
|
||||||
progress_title=name,
|
progress_title=name,
|
||||||
no_progress_bar=no_progress_bar,
|
no_progress_bar=no_progress_bar,
|
||||||
)
|
)
|
||||||
|
|
||||||
def list_paths(self, prefix=None, progress_callback=None):
|
|
||||||
if prefix:
|
|
||||||
root = posixpath.join(self.path_info.path, prefix[:2])
|
|
||||||
else:
|
|
||||||
root = self.path_info.path
|
|
||||||
with self.ssh(self.path_info) as ssh:
|
|
||||||
if prefix and not ssh.exists(root):
|
|
||||||
return
|
|
||||||
# If we simply return an iterator then with above closes instantly
|
|
||||||
if progress_callback:
|
|
||||||
for path in ssh.walk_files(root):
|
|
||||||
progress_callback()
|
|
||||||
yield path
|
|
||||||
else:
|
|
||||||
yield from ssh.walk_files(root)
|
|
||||||
|
|
||||||
|
|
||||||
class SSHRemote(Remote):
|
|
||||||
def batch_exists(self, path_infos, callback):
|
|
||||||
def _exists(chunk_and_channel):
|
|
||||||
chunk, channel = chunk_and_channel
|
|
||||||
ret = []
|
|
||||||
for path in chunk:
|
|
||||||
try:
|
|
||||||
channel.stat(path)
|
|
||||||
ret.append(True)
|
|
||||||
except OSError as exc:
|
|
||||||
if exc.errno != errno.ENOENT:
|
|
||||||
raise
|
|
||||||
ret.append(False)
|
|
||||||
callback(path)
|
|
||||||
return ret
|
|
||||||
|
|
||||||
with self.tree.ssh(path_infos[0]) as ssh:
|
|
||||||
channels = ssh.open_max_sftp_channels()
|
|
||||||
max_workers = len(channels)
|
|
||||||
|
|
||||||
with ThreadPoolExecutor(max_workers=max_workers) as executor:
|
|
||||||
paths = [path_info.path for path_info in path_infos]
|
|
||||||
chunks = to_chunks(paths, num_chunks=max_workers)
|
|
||||||
chunks_and_channels = zip(chunks, channels)
|
|
||||||
outcome = executor.map(_exists, chunks_and_channels)
|
|
||||||
results = list(itertools.chain.from_iterable(outcome))
|
|
||||||
|
|
||||||
return results
|
|
||||||
|
|
||||||
def hashes_exist(self, hashes, jobs=None, name=None):
|
|
||||||
"""This is older implementation used in remote/base.py
|
|
||||||
We are reusing it in RemoteSSH, because SSH's batch_exists proved to be
|
|
||||||
faster than current approach (relying on exists(path_info)) applied in
|
|
||||||
remote/base.
|
|
||||||
"""
|
|
||||||
if not self.tree.CAN_TRAVERSE:
|
|
||||||
return list(set(hashes) & set(self.tree.all()))
|
|
||||||
|
|
||||||
# possibly prompt for credentials before "Querying" progress output
|
|
||||||
self.tree.ensure_credentials()
|
|
||||||
|
|
||||||
with Tqdm(
|
|
||||||
desc="Querying "
|
|
||||||
+ ("cache in " + name if name else "remote cache"),
|
|
||||||
total=len(hashes),
|
|
||||||
unit="file",
|
|
||||||
) as pbar:
|
|
||||||
|
|
||||||
def exists_with_progress(chunks):
|
|
||||||
return self.batch_exists(chunks, callback=pbar.update_msg)
|
|
||||||
|
|
||||||
with ThreadPoolExecutor(
|
|
||||||
max_workers=jobs or self.tree.JOBS
|
|
||||||
) as executor:
|
|
||||||
path_infos = [self.hash_to_path_info(x) for x in hashes]
|
|
||||||
chunks = to_chunks(path_infos, num_chunks=self.tree.JOBS)
|
|
||||||
results = executor.map(exists_with_progress, chunks)
|
|
||||||
in_remote = itertools.chain.from_iterable(results)
|
|
||||||
ret = list(itertools.compress(hashes, in_remote))
|
|
||||||
return ret
|
|
||||||
@@ -2,6 +2,7 @@ import errno
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import posixpath
|
import posixpath
|
||||||
|
import shlex
|
||||||
import stat
|
import stat
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
|
|
||||||
@@ -9,9 +10,10 @@ from funcy import cached_property
|
|||||||
|
|
||||||
from dvc.exceptions import DvcException
|
from dvc.exceptions import DvcException
|
||||||
from dvc.progress import Tqdm
|
from dvc.progress import Tqdm
|
||||||
from dvc.remote.base import RemoteCmdError
|
|
||||||
from dvc.utils import tmp_fname
|
from dvc.utils import tmp_fname
|
||||||
|
|
||||||
|
from ..base import RemoteCmdError
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import paramiko
|
import paramiko
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@@ -68,18 +70,23 @@ class SSHConnection:
|
|||||||
self._ssh.close()
|
self._ssh.close()
|
||||||
|
|
||||||
def st_mode(self, path):
|
def st_mode(self, path):
|
||||||
|
lstat = None
|
||||||
with suppress(FileNotFoundError):
|
with suppress(FileNotFoundError):
|
||||||
return self.sftp.lstat(path).st_mode
|
lstat = self.sftp.lstat(path)
|
||||||
|
|
||||||
return 0
|
return lstat.st_mode if lstat else 0
|
||||||
|
|
||||||
|
def info(self, path):
|
||||||
|
st = self.sftp.stat(path)
|
||||||
|
return {
|
||||||
|
"size": st.st_size,
|
||||||
|
"type": "dir" if stat.S_ISDIR(st.st_mode) else "file",
|
||||||
|
}
|
||||||
|
|
||||||
def getsize(self, path):
|
def getsize(self, path):
|
||||||
with suppress(FileNotFoundError):
|
return self.info(path)["size"]
|
||||||
return self.sftp.lstat(path).st_size
|
|
||||||
|
|
||||||
return 0
|
def exists(self, path):
|
||||||
|
|
||||||
def exists(self, path, sftp=None):
|
|
||||||
return bool(self.st_mode(path))
|
return bool(self.st_mode(path))
|
||||||
|
|
||||||
def isdir(self, path):
|
def isdir(self, path):
|
||||||
@@ -185,6 +192,7 @@ class SSHConnection:
|
|||||||
desc=progress_title or os.path.basename(src),
|
desc=progress_title or os.path.basename(src),
|
||||||
disable=no_progress_bar,
|
disable=no_progress_bar,
|
||||||
bytes=True,
|
bytes=True,
|
||||||
|
total=self.getsize(src),
|
||||||
) as pbar:
|
) as pbar:
|
||||||
self.sftp.get(src, dest, callback=pbar.update_to)
|
self.sftp.get(src, dest, callback=pbar.update_to)
|
||||||
|
|
||||||
@@ -217,7 +225,10 @@ class SSHConnection:
|
|||||||
progress_title = posixpath.basename(dest)
|
progress_title = posixpath.basename(dest)
|
||||||
|
|
||||||
with Tqdm(
|
with Tqdm(
|
||||||
desc=progress_title, disable=no_progress_bar, bytes=True
|
desc=progress_title,
|
||||||
|
disable=no_progress_bar,
|
||||||
|
bytes=True,
|
||||||
|
total=os.path.getsize(src),
|
||||||
) as pbar:
|
) as pbar:
|
||||||
self.sftp.put(src, tmp_file, callback=pbar.update_to)
|
self.sftp.put(src, tmp_file, callback=pbar.update_to)
|
||||||
|
|
||||||
@@ -290,6 +301,7 @@ class SSHConnection:
|
|||||||
Example:
|
Example:
|
||||||
MD5 (foo.txt) = f3d220a856b52aabbf294351e8a24300
|
MD5 (foo.txt) = f3d220a856b52aabbf294351e8a24300
|
||||||
"""
|
"""
|
||||||
|
path = shlex.quote(path)
|
||||||
if self.uname == "Linux":
|
if self.uname == "Linux":
|
||||||
md5 = self.execute("md5sum " + path).split()[0]
|
md5 = self.execute("md5sum " + path).split()[0]
|
||||||
elif self.uname == "Darwin":
|
elif self.uname == "Darwin":
|
||||||
@@ -303,6 +315,8 @@ class SSHConnection:
|
|||||||
return md5
|
return md5
|
||||||
|
|
||||||
def copy(self, src, dest):
|
def copy(self, src, dest):
|
||||||
|
dest = shlex.quote(dest)
|
||||||
|
src = shlex.quote(src)
|
||||||
self.execute(f"cp {src} {dest}")
|
self.execute(f"cp {src} {dest}")
|
||||||
|
|
||||||
def open_max_sftp_channels(self):
|
def open_max_sftp_channels(self):
|
||||||
@@ -324,6 +338,8 @@ class SSHConnection:
|
|||||||
self.sftp.symlink(src, dest)
|
self.sftp.symlink(src, dest)
|
||||||
|
|
||||||
def reflink(self, src, dest):
|
def reflink(self, src, dest):
|
||||||
|
dest = shlex.quote(dest)
|
||||||
|
src = shlex.quote(src)
|
||||||
if self.uname == "Linux":
|
if self.uname == "Linux":
|
||||||
return self.execute(f"cp --reflink {src} {dest}")
|
return self.execute(f"cp --reflink {src} {dest}")
|
||||||
|
|
||||||
@@ -333,4 +349,6 @@ class SSHConnection:
|
|||||||
raise DvcException(f"'{self.uname}' is not supported as a SSH remote")
|
raise DvcException(f"'{self.uname}' is not supported as a SSH remote")
|
||||||
|
|
||||||
def hardlink(self, src, dest):
|
def hardlink(self, src, dest):
|
||||||
|
dest = shlex.quote(dest)
|
||||||
|
src = shlex.quote(src)
|
||||||
self.execute(f"ln {src} {dest}")
|
self.execute(f"ln {src} {dest}")
|
||||||
@@ -0,0 +1,284 @@
|
|||||||
|
import io
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import threading
|
||||||
|
from collections import deque
|
||||||
|
|
||||||
|
from funcy import cached_property, nullcontext, wrap_prop
|
||||||
|
|
||||||
|
from dvc.config import ConfigError
|
||||||
|
from dvc.exceptions import DvcException
|
||||||
|
from dvc.path_info import HTTPURLInfo, WebDAVURLInfo
|
||||||
|
from dvc.progress import Tqdm
|
||||||
|
from dvc.scheme import Schemes
|
||||||
|
|
||||||
|
from .base import BaseFileSystem
|
||||||
|
from .http import ask_password
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class WebDAVConnectionError(DvcException):
|
||||||
|
def __init__(self, host):
|
||||||
|
super().__init__(f"Unable to connect to WebDAV {host}.")
|
||||||
|
|
||||||
|
|
||||||
|
class WebDAVFileSystem(BaseFileSystem): # pylint:disable=abstract-method
|
||||||
|
# Use webdav scheme
|
||||||
|
scheme = Schemes.WEBDAV
|
||||||
|
|
||||||
|
# URLInfo for Webdav ~ replaces webdav -> http
|
||||||
|
PATH_CLS = WebDAVURLInfo
|
||||||
|
|
||||||
|
# Traversable as walk_files is implemented
|
||||||
|
CAN_TRAVERSE = True
|
||||||
|
|
||||||
|
# Length of walk_files prefix
|
||||||
|
TRAVERSE_PREFIX_LEN = 2
|
||||||
|
|
||||||
|
# Implementation based on webdav3.client
|
||||||
|
REQUIRES = {"webdavclient3": "webdav3.client"}
|
||||||
|
|
||||||
|
# Chunk size for buffered upload/download with progress bar
|
||||||
|
CHUNK_SIZE = 2 ** 16
|
||||||
|
|
||||||
|
PARAM_CHECKSUM = "etag"
|
||||||
|
DETAIL_FIELDS = frozenset(("etag", "size"))
|
||||||
|
|
||||||
|
# Constructor
|
||||||
|
def __init__(self, repo, config):
|
||||||
|
# Call BaseFileSystem constructor
|
||||||
|
super().__init__(repo, config)
|
||||||
|
|
||||||
|
# Get username from configuration
|
||||||
|
self.user = config.get("user", None)
|
||||||
|
|
||||||
|
# Get password from configuration (might be None ~ not set)
|
||||||
|
self.password = config.get("password", None)
|
||||||
|
|
||||||
|
# Whether to ask for password if it is not set
|
||||||
|
self.ask_password = config.get("ask_password", False)
|
||||||
|
|
||||||
|
# Use token for webdav auth
|
||||||
|
self.token = config.get("token", None)
|
||||||
|
|
||||||
|
# Path to certificate
|
||||||
|
self.cert_path = config.get("cert_path", None)
|
||||||
|
|
||||||
|
# Path to private key
|
||||||
|
self.key_path = config.get("key_path", None)
|
||||||
|
|
||||||
|
# Connection timeout
|
||||||
|
self.timeout = config.get("timeout", 30)
|
||||||
|
|
||||||
|
# Get URL from configuration
|
||||||
|
self.url = config.get("url", None)
|
||||||
|
|
||||||
|
# If URL in config parse path_info
|
||||||
|
if self.url:
|
||||||
|
self.path_info = self.PATH_CLS(self.url)
|
||||||
|
|
||||||
|
# If username not specified try to use from URL
|
||||||
|
if self.user is None and self.path_info.user is not None:
|
||||||
|
self.user = self.path_info.user
|
||||||
|
|
||||||
|
# Construct hostname from path_info by stripping path
|
||||||
|
http_info = HTTPURLInfo(self.path_info.url)
|
||||||
|
self.hostname = http_info.replace(path="").url
|
||||||
|
|
||||||
|
# Webdav client
|
||||||
|
@wrap_prop(threading.Lock())
|
||||||
|
@cached_property
|
||||||
|
def _client(self):
|
||||||
|
from webdav3.client import Client
|
||||||
|
|
||||||
|
# Set password or ask for it
|
||||||
|
if self.ask_password and self.password is None and self.token is None:
|
||||||
|
self.password = ask_password(self.hostname, self.user)
|
||||||
|
|
||||||
|
# Setup webdav client options dictionary
|
||||||
|
options = {
|
||||||
|
"webdav_hostname": self.hostname,
|
||||||
|
"webdav_login": self.user,
|
||||||
|
"webdav_password": self.password,
|
||||||
|
"webdav_token": self.token,
|
||||||
|
"webdav_cert_path": self.cert_path,
|
||||||
|
"webdav_key_path": self.key_path,
|
||||||
|
"webdav_timeout": self.timeout,
|
||||||
|
"webdav_chunk_size": self.CHUNK_SIZE,
|
||||||
|
}
|
||||||
|
|
||||||
|
client = Client(options)
|
||||||
|
|
||||||
|
# Check whether client options are valid
|
||||||
|
if not client.valid():
|
||||||
|
raise ConfigError(
|
||||||
|
f"Configuration for WebDAV {self.hostname} is invalid."
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check whether connection is valid (root should always exist)
|
||||||
|
if not client.check("/"):
|
||||||
|
raise WebDAVConnectionError(self.hostname)
|
||||||
|
|
||||||
|
return client
|
||||||
|
|
||||||
|
def open(self, path_info, mode="r", encoding=None, **kwargs):
|
||||||
|
from webdav3.exceptions import RemoteResourceNotFound
|
||||||
|
|
||||||
|
assert mode in {"r", "rt", "rb"}
|
||||||
|
|
||||||
|
fobj = io.BytesIO()
|
||||||
|
|
||||||
|
try:
|
||||||
|
self._client.download_from(buff=fobj, remote_path=path_info.path)
|
||||||
|
except RemoteResourceNotFound as exc:
|
||||||
|
raise FileNotFoundError from exc
|
||||||
|
|
||||||
|
fobj.seek(0)
|
||||||
|
|
||||||
|
if "mode" == "rb":
|
||||||
|
return fobj
|
||||||
|
|
||||||
|
return io.TextIOWrapper(fobj, encoding=encoding)
|
||||||
|
|
||||||
|
# Checks whether file/directory exists at remote
|
||||||
|
def exists(self, path_info, use_dvcignore=True):
|
||||||
|
# Use webdav check to test for file existence
|
||||||
|
return self._client.check(path_info.path)
|
||||||
|
|
||||||
|
# Checks whether path points to directory
|
||||||
|
def isdir(self, path_info):
|
||||||
|
# Use webdav is_dir to test whether path points to a directory
|
||||||
|
return self._client.is_dir(path_info.path)
|
||||||
|
|
||||||
|
# Yields path info to all files
|
||||||
|
def walk_files(self, path_info, **kwargs):
|
||||||
|
# Check whether directory exists
|
||||||
|
if not self.exists(path_info):
|
||||||
|
return
|
||||||
|
|
||||||
|
# Collect directories
|
||||||
|
dirs = deque([path_info.path])
|
||||||
|
|
||||||
|
# Iterate all directories found so far
|
||||||
|
while dirs:
|
||||||
|
# Iterate directory content
|
||||||
|
for entry in self._client.list(dirs.pop(), get_info=True):
|
||||||
|
# Construct path_info to entry
|
||||||
|
info = path_info.replace(path=entry["path"])
|
||||||
|
|
||||||
|
# Check whether entry is a directory
|
||||||
|
if entry["isdir"]:
|
||||||
|
# Append new found directory to directory list
|
||||||
|
dirs.append(info.path)
|
||||||
|
else:
|
||||||
|
# Yield path info to non directory
|
||||||
|
yield info
|
||||||
|
|
||||||
|
def ls(
|
||||||
|
self, path_info, detail=False, recursive=False
|
||||||
|
): # pylint: disable=arguments-differ
|
||||||
|
dirs = deque([path_info.path])
|
||||||
|
|
||||||
|
while dirs:
|
||||||
|
for entry in self._client.list(dirs.pop(), get_info=True):
|
||||||
|
path = entry["path"]
|
||||||
|
if entry["isdir"]:
|
||||||
|
dirs.append(path)
|
||||||
|
continue
|
||||||
|
|
||||||
|
if detail:
|
||||||
|
yield {
|
||||||
|
"type": "file",
|
||||||
|
"name": path,
|
||||||
|
"size": entry["size"],
|
||||||
|
"etag": entry["etag"],
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
yield path
|
||||||
|
|
||||||
|
if not recursive:
|
||||||
|
for entry in dirs:
|
||||||
|
if detail:
|
||||||
|
yield {"type": "directory", "name": entry}
|
||||||
|
else:
|
||||||
|
yield entry
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Removes file/directory
|
||||||
|
def remove(self, path_info):
|
||||||
|
# Use webdav client clean (DELETE) method to remove file/directory
|
||||||
|
self._client.clean(path_info.path)
|
||||||
|
|
||||||
|
# Creates directories
|
||||||
|
def makedirs(self, path_info):
|
||||||
|
# Terminate recursion
|
||||||
|
if path_info.path == "/" or self.exists(path_info):
|
||||||
|
return
|
||||||
|
|
||||||
|
# Recursively descent to root
|
||||||
|
self.makedirs(path_info.parent)
|
||||||
|
|
||||||
|
# Construct directory at current recursion depth
|
||||||
|
self._client.mkdir(path_info.path)
|
||||||
|
|
||||||
|
# Moves file/directory at remote
|
||||||
|
def move(self, from_info, to_info):
|
||||||
|
# Webdav client move
|
||||||
|
self._client.move(from_info.path, to_info.path)
|
||||||
|
|
||||||
|
def _upload_fobj(self, fobj, to_info):
|
||||||
|
# In contrast to other upload_fobj implementations, this one does not
|
||||||
|
# exactly do a chunked-upload but rather put everything in one request.
|
||||||
|
self.makedirs(to_info.parent)
|
||||||
|
self._client.upload_to(buff=fobj, remote_path=to_info.path)
|
||||||
|
|
||||||
|
# Downloads file from remote to file
|
||||||
|
def _download(self, from_info, to_file, name=None, no_progress_bar=False):
|
||||||
|
# Progress from HTTPFileSystem
|
||||||
|
with open(to_file, "wb") as fd:
|
||||||
|
with Tqdm.wrapattr(
|
||||||
|
fd,
|
||||||
|
"write",
|
||||||
|
total=None if no_progress_bar else self.getsize(from_info),
|
||||||
|
leave=False,
|
||||||
|
desc=from_info.url if name is None else name,
|
||||||
|
disable=no_progress_bar,
|
||||||
|
) as fd_wrapped:
|
||||||
|
# Download from WebDAV via buffer
|
||||||
|
self._client.download_from(
|
||||||
|
buff=fd_wrapped, remote_path=from_info.path
|
||||||
|
)
|
||||||
|
|
||||||
|
# Uploads file to remote
|
||||||
|
def _upload(
|
||||||
|
self, from_file, to_info, name=None, no_progress_bar=False, **_kwargs,
|
||||||
|
):
|
||||||
|
# First try to create parent directories
|
||||||
|
self.makedirs(to_info.parent)
|
||||||
|
|
||||||
|
file_size = os.path.getsize(from_file)
|
||||||
|
with open(from_file, "rb") as fd:
|
||||||
|
progress_context = (
|
||||||
|
nullcontext(fd)
|
||||||
|
if file_size == 0
|
||||||
|
else Tqdm.wrapattr(
|
||||||
|
fd,
|
||||||
|
"read",
|
||||||
|
total=None if no_progress_bar else file_size,
|
||||||
|
leave=False,
|
||||||
|
desc=to_info.url if name is None else name,
|
||||||
|
disable=no_progress_bar,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
with progress_context as fd_wrapped:
|
||||||
|
self._client.upload_to(
|
||||||
|
buff=fd_wrapped, remote_path=to_info.path
|
||||||
|
)
|
||||||
|
|
||||||
|
def info(self, path_info):
|
||||||
|
info = self._client.info(path_info.path)
|
||||||
|
return {
|
||||||
|
"size": int(info["size"]),
|
||||||
|
"etag": info["etag"],
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user