dvc-utils 0.0.4__tar.gz → 0.0.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dvc-utils-0.0.4 → dvc-utils-0.0.6}/PKG-INFO +13 -9
- {dvc-utils-0.0.4 → dvc-utils-0.0.6}/README.md +12 -8
- {dvc-utils-0.0.4 → dvc-utils-0.0.6}/dvc_utils/main.py +83 -33
- {dvc-utils-0.0.4 → dvc-utils-0.0.6}/dvc_utils.egg-info/PKG-INFO +13 -9
- {dvc-utils-0.0.4 → dvc-utils-0.0.6}/dvc_utils.egg-info/entry_points.txt +1 -0
- {dvc-utils-0.0.4 → dvc-utils-0.0.6}/setup.py +2 -1
- {dvc-utils-0.0.4 → dvc-utils-0.0.6}/LICENSE +0 -0
- {dvc-utils-0.0.4 → dvc-utils-0.0.6}/dvc_utils/__init__.py +0 -0
- {dvc-utils-0.0.4 → dvc-utils-0.0.6}/dvc_utils/named_pipes.py +0 -0
- {dvc-utils-0.0.4 → dvc-utils-0.0.6}/dvc_utils.egg-info/SOURCES.txt +0 -0
- {dvc-utils-0.0.4 → dvc-utils-0.0.6}/dvc_utils.egg-info/dependency_links.txt +0 -0
- {dvc-utils-0.0.4 → dvc-utils-0.0.6}/dvc_utils.egg-info/top_level.txt +0 -0
- {dvc-utils-0.0.4 → dvc-utils-0.0.6}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: dvc-utils
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.6
|
4
4
|
Summary: CLI for diffing DVC files at two commits (or one commit vs. current worktree), optionally passing both through another command first
|
5
5
|
Home-page: https://github.com/runsascoded/dvc-utils
|
6
6
|
Author: Ryan Williams
|
@@ -15,7 +15,7 @@ CLI for diffing [DVC] files, optionally passing both through another command fir
|
|
15
15
|
<!-- toc -->
|
16
16
|
- [Installation](#installation)
|
17
17
|
- [Usage](#usage)
|
18
|
-
- [`dvc-
|
18
|
+
- [`dvc-diff`](#dvc-diff)
|
19
19
|
- [Examples](#examples)
|
20
20
|
- [Parquet file](#parquet-diff)
|
21
21
|
- [Schema diff](#parquet-schema-diff)
|
@@ -42,11 +42,13 @@ dvc-utils --help
|
|
42
42
|
# worktree), optionally passing both through another command first
|
43
43
|
```
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
The single subcommand, `dvc-utils diff`, is also exposed directly as `dvc-dff`:
|
46
|
+
|
47
|
+
### `dvc-diff` <a id="dvc-diff"></a>
|
48
|
+
<!-- `bmdf -- dvc-diff --help` -->
|
47
49
|
```bash
|
48
|
-
dvc-
|
49
|
-
# Usage: dvc-
|
50
|
+
dvc-diff --help
|
51
|
+
# Usage: dvc-diff [OPTIONS] [exec_cmd...] <path>
|
50
52
|
#
|
51
53
|
# Diff a file at two commits (or one commit vs. current worktree), optionally
|
52
54
|
# passing both through `cmd` first
|
@@ -69,6 +71,8 @@ dvc-utils diff --help
|
|
69
71
|
# to `diff`)
|
70
72
|
# -v, --verbose Log intermediate commands to stderr
|
71
73
|
# -w, --ignore-whitespace Ignore whitespace differences (pass `-w` to `diff`)
|
74
|
+
# -x, --exec-cmd TEXT Command(s) to execute before diffing; alternate
|
75
|
+
# syntax to passing commands as positional arguments
|
72
76
|
# --help Show this message and exit.
|
73
77
|
```
|
74
78
|
|
@@ -91,7 +95,7 @@ parquet_schema() {
|
|
91
95
|
parquet2json "$1" schema
|
92
96
|
}
|
93
97
|
export -f parquet_schema
|
94
|
-
dvc-
|
98
|
+
dvc-diff -r $commit^..$commit parquet_schema $path
|
95
99
|
```
|
96
100
|
<details><summary>Output</summary>
|
97
101
|
|
@@ -149,7 +153,7 @@ pretty_print_first_row() {
|
|
149
153
|
parquet2json "$1" cat -l 1 | jq .
|
150
154
|
}
|
151
155
|
export -f pretty_print_first_row
|
152
|
-
dvc-
|
156
|
+
dvc-diff -r $commit^..$commit pretty_print_first_row $path
|
153
157
|
```
|
154
158
|
|
155
159
|
<details><summary>Output</summary>
|
@@ -208,7 +212,7 @@ parquet_row_count() {
|
|
208
212
|
parquet2json "$1" rowcount
|
209
213
|
}
|
210
214
|
export -f parquet_row_count
|
211
|
-
dvc-
|
215
|
+
dvc-diff -r $commit^..$commit parquet_row_count $path
|
212
216
|
```
|
213
217
|
|
214
218
|
This time we get no output; [the given `$commit`][commit] didn't change the row count in the DVC-tracked Parquet file [`$path`][commit path].
|
@@ -4,7 +4,7 @@ CLI for diffing [DVC] files, optionally passing both through another command fir
|
|
4
4
|
<!-- toc -->
|
5
5
|
- [Installation](#installation)
|
6
6
|
- [Usage](#usage)
|
7
|
-
- [`dvc-
|
7
|
+
- [`dvc-diff`](#dvc-diff)
|
8
8
|
- [Examples](#examples)
|
9
9
|
- [Parquet file](#parquet-diff)
|
10
10
|
- [Schema diff](#parquet-schema-diff)
|
@@ -31,11 +31,13 @@ dvc-utils --help
|
|
31
31
|
# worktree), optionally passing both through another command first
|
32
32
|
```
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
The single subcommand, `dvc-utils diff`, is also exposed directly as `dvc-dff`:
|
35
|
+
|
36
|
+
### `dvc-diff` <a id="dvc-diff"></a>
|
37
|
+
<!-- `bmdf -- dvc-diff --help` -->
|
36
38
|
```bash
|
37
|
-
dvc-
|
38
|
-
# Usage: dvc-
|
39
|
+
dvc-diff --help
|
40
|
+
# Usage: dvc-diff [OPTIONS] [exec_cmd...] <path>
|
39
41
|
#
|
40
42
|
# Diff a file at two commits (or one commit vs. current worktree), optionally
|
41
43
|
# passing both through `cmd` first
|
@@ -58,6 +60,8 @@ dvc-utils diff --help
|
|
58
60
|
# to `diff`)
|
59
61
|
# -v, --verbose Log intermediate commands to stderr
|
60
62
|
# -w, --ignore-whitespace Ignore whitespace differences (pass `-w` to `diff`)
|
63
|
+
# -x, --exec-cmd TEXT Command(s) to execute before diffing; alternate
|
64
|
+
# syntax to passing commands as positional arguments
|
61
65
|
# --help Show this message and exit.
|
62
66
|
```
|
63
67
|
|
@@ -80,7 +84,7 @@ parquet_schema() {
|
|
80
84
|
parquet2json "$1" schema
|
81
85
|
}
|
82
86
|
export -f parquet_schema
|
83
|
-
dvc-
|
87
|
+
dvc-diff -r $commit^..$commit parquet_schema $path
|
84
88
|
```
|
85
89
|
<details><summary>Output</summary>
|
86
90
|
|
@@ -138,7 +142,7 @@ pretty_print_first_row() {
|
|
138
142
|
parquet2json "$1" cat -l 1 | jq .
|
139
143
|
}
|
140
144
|
export -f pretty_print_first_row
|
141
|
-
dvc-
|
145
|
+
dvc-diff -r $commit^..$commit pretty_print_first_row $path
|
142
146
|
```
|
143
147
|
|
144
148
|
<details><summary>Output</summary>
|
@@ -197,7 +201,7 @@ parquet_row_count() {
|
|
197
201
|
parquet2json "$1" rowcount
|
198
202
|
}
|
199
203
|
export -f parquet_row_count
|
200
|
-
dvc-
|
204
|
+
dvc-diff -r $commit^..$commit parquet_row_count $path
|
201
205
|
```
|
202
206
|
|
203
207
|
This time we get no output; [the given `$commit`][commit] didn't change the row count in the DVC-tracked Parquet file [`$path`][commit path].
|
@@ -1,14 +1,11 @@
|
|
1
1
|
from functools import cache
|
2
2
|
from os import environ as env, getcwd
|
3
|
-
|
4
|
-
from typing import Optional, Tuple
|
5
|
-
|
6
|
-
import shlex
|
7
3
|
from os.path import join, relpath
|
4
|
+
import shlex
|
5
|
+
from subprocess import Popen, PIPE
|
6
|
+
from typing import Optional, Tuple
|
8
7
|
|
9
8
|
from click import option, argument, group
|
10
|
-
from subprocess import Popen
|
11
|
-
|
12
9
|
import click
|
13
10
|
import yaml
|
14
11
|
from utz import process, singleton, err
|
@@ -52,7 +49,7 @@ def dvc_cache_dir(log: bool = False) -> str:
|
|
52
49
|
def dvc_md5(git_ref: str, dvc_path: str, log: bool = False) -> str:
|
53
50
|
dir_path = get_dir_path()
|
54
51
|
dir_path = '' if dir_path == '.' else f'{dir_path}/'
|
55
|
-
dvc_spec = process.output('git', 'show', f'{git_ref}:{dir_path}{dvc_path}', log=log)
|
52
|
+
dvc_spec = process.output('git', 'show', f'{git_ref}:{dir_path}{dvc_path}', log=err if log else None)
|
56
53
|
dvc_obj = yaml.safe_load(dvc_spec)
|
57
54
|
out = singleton(dvc_obj['outs'], dedupe=False)
|
58
55
|
md5 = out['md5']
|
@@ -73,15 +70,28 @@ def dvc_cache_path(ref: str, dvc_path: Optional[str] = None, log: bool = False)
|
|
73
70
|
|
74
71
|
|
75
72
|
def diff_cmds(
|
76
|
-
|
77
|
-
|
73
|
+
cmds1: list[str],
|
74
|
+
cmds2: list[str],
|
78
75
|
verbose: bool = False,
|
79
76
|
color: bool = False,
|
80
77
|
unified: int | None = None,
|
81
78
|
ignore_whitespace: bool = False,
|
82
79
|
**kwargs,
|
83
80
|
):
|
84
|
-
"""Run two commands and diff their output.
|
81
|
+
"""Run two sequences of piped commands and diff their output.
|
82
|
+
|
83
|
+
Args:
|
84
|
+
cmds1: First sequence of commands to pipe together
|
85
|
+
cmds2: Second sequence of commands to pipe together
|
86
|
+
verbose: Whether to print commands being executed
|
87
|
+
color: Whether to show colored diff output
|
88
|
+
unified: Number of unified context lines, or None
|
89
|
+
ignore_whitespace: Whether to ignore whitespace changes
|
90
|
+
**kwargs: Additional arguments passed to subprocess.Popen
|
91
|
+
|
92
|
+
Each command sequence will be piped together before being compared.
|
93
|
+
For example, if cmds1 = ['cat foo.txt', 'sort'], the function will
|
94
|
+
execute 'cat foo.txt | sort' before comparing with cmds2's output.
|
85
95
|
|
86
96
|
Adapted from https://stackoverflow.com/a/28840955"""
|
87
97
|
with named_pipes(n=2) as pipes:
|
@@ -96,11 +106,45 @@ def diff_cmds(
|
|
96
106
|
]
|
97
107
|
diff = Popen(diff_cmd)
|
98
108
|
processes = []
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
109
|
+
|
110
|
+
for pipe, cmds in ((pipe1, cmds1), (pipe2, cmds2)):
|
111
|
+
if verbose:
|
112
|
+
err(f"Running pipeline: {' | '.join(cmds)}")
|
113
|
+
|
114
|
+
# Create the pipeline of processes
|
115
|
+
prev_process = None
|
116
|
+
for i, cmd in enumerate(cmds):
|
117
|
+
is_last = i + 1 == len(cmds)
|
118
|
+
|
119
|
+
# For the first process, take input from the original source
|
120
|
+
stdin = None if prev_process is None else prev_process.stdout
|
121
|
+
|
122
|
+
# For the last process, output to the named pipe
|
123
|
+
if is_last:
|
124
|
+
with open(pipe, 'wb', 0) as pipe_fd:
|
125
|
+
proc = Popen(
|
126
|
+
cmd,
|
127
|
+
stdin=stdin,
|
128
|
+
stdout=pipe_fd,
|
129
|
+
close_fds=True,
|
130
|
+
**kwargs
|
131
|
+
)
|
132
|
+
# For intermediate processes, output to a pipe
|
133
|
+
else:
|
134
|
+
proc = Popen(
|
135
|
+
cmd,
|
136
|
+
stdin=stdin,
|
137
|
+
stdout=PIPE,
|
138
|
+
close_fds=True,
|
139
|
+
**kwargs
|
140
|
+
)
|
141
|
+
|
142
|
+
if prev_process is not None:
|
143
|
+
prev_process.stdout.close()
|
144
|
+
|
145
|
+
processes.append(proc)
|
146
|
+
prev_process = proc
|
147
|
+
|
104
148
|
for p in [diff] + processes:
|
105
149
|
p.wait()
|
106
150
|
|
@@ -112,7 +156,8 @@ def diff_cmds(
|
|
112
156
|
@option('-U', '--unified', type=int, help='Number of lines of context to show (passes through to `diff`)')
|
113
157
|
@option('-v', '--verbose', is_flag=True, help="Log intermediate commands to stderr")
|
114
158
|
@option('-w', '--ignore-whitespace', is_flag=True, help="Ignore whitespace differences (pass `-w` to `diff`)")
|
115
|
-
@
|
159
|
+
@option('-x', '--exec-cmd', 'exec_cmds', multiple=True, help='Command(s) to execute before diffing; alternate syntax to passing commands as positional arguments')
|
160
|
+
@argument('args', metavar='[exec_cmd...] <path>', nargs=-1)
|
116
161
|
def dvc_utils_diff(
|
117
162
|
color: bool,
|
118
163
|
refspec: str | None,
|
@@ -120,6 +165,7 @@ def dvc_utils_diff(
|
|
120
165
|
unified: int | None,
|
121
166
|
verbose: bool,
|
122
167
|
ignore_whitespace: bool,
|
168
|
+
exec_cmds: Tuple[str, ...],
|
123
169
|
args: Tuple[str, ...],
|
124
170
|
):
|
125
171
|
"""Diff a file at two commits (or one commit vs. current worktree), optionally passing both through `cmd` first
|
@@ -134,14 +180,8 @@ def dvc_utils_diff(
|
|
134
180
|
raise click.UsageError('Must specify [cmd...] <path>')
|
135
181
|
|
136
182
|
shell = not no_shell
|
137
|
-
|
138
|
-
|
139
|
-
cmd = shlex.split(cmd)
|
140
|
-
elif len(args) == 1:
|
141
|
-
cmd = None
|
142
|
-
path, = args
|
143
|
-
else:
|
144
|
-
raise click.UsageError('Maximum 2 positional args: [cmd] <path>')
|
183
|
+
*cmds, path = args
|
184
|
+
cmds = list(exec_cmds) + cmds
|
145
185
|
|
146
186
|
path, dvc_path = dvc_paths(path)
|
147
187
|
|
@@ -158,17 +198,27 @@ def dvc_utils_diff(
|
|
158
198
|
before_path = dvc_cache_path(before, dvc_path, log=log)
|
159
199
|
after_path = path if after is None else dvc_cache_path(after, dvc_path, log=log)
|
160
200
|
|
161
|
-
if
|
162
|
-
|
163
|
-
|
164
|
-
|
201
|
+
if cmds:
|
202
|
+
cmd, *sub_cmds = cmds
|
203
|
+
if not shell:
|
204
|
+
sub_cmds = [ shlex.split(c) for c in sub_cmds ]
|
205
|
+
before_cmds = [
|
206
|
+
shlex.split(f'{cmd} {before_path}'),
|
207
|
+
*sub_cmds,
|
208
|
+
]
|
209
|
+
after_cmds = [
|
210
|
+
shlex.split(f'{cmd} {after_path}'),
|
211
|
+
*sub_cmds,
|
212
|
+
]
|
213
|
+
shell_kwargs = {}
|
214
|
+
else:
|
215
|
+
before_cmds = [ f'{cmd} {before_path}', *sub_cmds ]
|
216
|
+
after_cmds = [ f'{cmd} {after_path}', *sub_cmds ]
|
217
|
+
shell_kwargs = dict(shell=shell)
|
165
218
|
|
166
|
-
shell_kwargs = dict(shell=shell) if shell else {}
|
167
|
-
before_cmd = args(before_path)
|
168
|
-
after_cmd = args(after_path)
|
169
219
|
diff_cmds(
|
170
|
-
|
171
|
-
|
220
|
+
before_cmds,
|
221
|
+
after_cmds,
|
172
222
|
verbose=verbose,
|
173
223
|
color=color,
|
174
224
|
unified=unified,
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: dvc-utils
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.6
|
4
4
|
Summary: CLI for diffing DVC files at two commits (or one commit vs. current worktree), optionally passing both through another command first
|
5
5
|
Home-page: https://github.com/runsascoded/dvc-utils
|
6
6
|
Author: Ryan Williams
|
@@ -15,7 +15,7 @@ CLI for diffing [DVC] files, optionally passing both through another command fir
|
|
15
15
|
<!-- toc -->
|
16
16
|
- [Installation](#installation)
|
17
17
|
- [Usage](#usage)
|
18
|
-
- [`dvc-
|
18
|
+
- [`dvc-diff`](#dvc-diff)
|
19
19
|
- [Examples](#examples)
|
20
20
|
- [Parquet file](#parquet-diff)
|
21
21
|
- [Schema diff](#parquet-schema-diff)
|
@@ -42,11 +42,13 @@ dvc-utils --help
|
|
42
42
|
# worktree), optionally passing both through another command first
|
43
43
|
```
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
The single subcommand, `dvc-utils diff`, is also exposed directly as `dvc-dff`:
|
46
|
+
|
47
|
+
### `dvc-diff` <a id="dvc-diff"></a>
|
48
|
+
<!-- `bmdf -- dvc-diff --help` -->
|
47
49
|
```bash
|
48
|
-
dvc-
|
49
|
-
# Usage: dvc-
|
50
|
+
dvc-diff --help
|
51
|
+
# Usage: dvc-diff [OPTIONS] [exec_cmd...] <path>
|
50
52
|
#
|
51
53
|
# Diff a file at two commits (or one commit vs. current worktree), optionally
|
52
54
|
# passing both through `cmd` first
|
@@ -69,6 +71,8 @@ dvc-utils diff --help
|
|
69
71
|
# to `diff`)
|
70
72
|
# -v, --verbose Log intermediate commands to stderr
|
71
73
|
# -w, --ignore-whitespace Ignore whitespace differences (pass `-w` to `diff`)
|
74
|
+
# -x, --exec-cmd TEXT Command(s) to execute before diffing; alternate
|
75
|
+
# syntax to passing commands as positional arguments
|
72
76
|
# --help Show this message and exit.
|
73
77
|
```
|
74
78
|
|
@@ -91,7 +95,7 @@ parquet_schema() {
|
|
91
95
|
parquet2json "$1" schema
|
92
96
|
}
|
93
97
|
export -f parquet_schema
|
94
|
-
dvc-
|
98
|
+
dvc-diff -r $commit^..$commit parquet_schema $path
|
95
99
|
```
|
96
100
|
<details><summary>Output</summary>
|
97
101
|
|
@@ -149,7 +153,7 @@ pretty_print_first_row() {
|
|
149
153
|
parquet2json "$1" cat -l 1 | jq .
|
150
154
|
}
|
151
155
|
export -f pretty_print_first_row
|
152
|
-
dvc-
|
156
|
+
dvc-diff -r $commit^..$commit pretty_print_first_row $path
|
153
157
|
```
|
154
158
|
|
155
159
|
<details><summary>Output</summary>
|
@@ -208,7 +212,7 @@ parquet_row_count() {
|
|
208
212
|
parquet2json "$1" rowcount
|
209
213
|
}
|
210
214
|
export -f parquet_row_count
|
211
|
-
dvc-
|
215
|
+
dvc-diff -r $commit^..$commit parquet_row_count $path
|
212
216
|
```
|
213
217
|
|
214
218
|
This time we get no output; [the given `$commit`][commit] didn't change the row count in the DVC-tracked Parquet file [`$path`][commit path].
|
@@ -2,7 +2,7 @@ from setuptools import setup
|
|
2
2
|
|
3
3
|
setup(
|
4
4
|
name='dvc-utils',
|
5
|
-
version="0.0.
|
5
|
+
version="0.0.6",
|
6
6
|
description="CLI for diffing DVC files at two commits (or one commit vs. current worktree), optionally passing both through another command first",
|
7
7
|
long_description=open("README.md").read(),
|
8
8
|
long_description_content_type="text/markdown",
|
@@ -10,6 +10,7 @@ setup(
|
|
10
10
|
entry_points={
|
11
11
|
'console_scripts': [
|
12
12
|
'dvc-utils = dvc_utils.main:cli',
|
13
|
+
'dvc-diff = dvc_utils.main:dvc_utils_diff',
|
13
14
|
],
|
14
15
|
},
|
15
16
|
license="MIT",
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|