dvc-utils 0.0.3__tar.gz → 0.0.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dvc-utils
3
- Version: 0.0.3
3
+ Version: 0.0.4
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
@@ -29,6 +29,7 @@ pip install dvc-utils
29
29
  ```
30
30
 
31
31
  ## Usage <a id="usage"></a>
32
+ <!-- `bmdf -- dvc-utils --help` -->
32
33
  ```bash
33
34
  dvc-utils --help
34
35
  # Usage: dvc-utils [OPTIONS] COMMAND [ARGS]...
@@ -42,6 +43,7 @@ dvc-utils --help
42
43
  ```
43
44
 
44
45
  ### `dvc-utils diff` <a id="dvc-utils-diff"></a>
46
+ <!-- `bmdf -- dvc-utils diff --help` -->
45
47
  ```bash
46
48
  dvc-utils diff --help
47
49
  # Usage: dvc-utils diff [OPTIONS] [cmd...] <path>
@@ -59,11 +61,15 @@ dvc-utils diff --help
59
61
  # optional) at HEAD (last committed value) vs. the current worktree content.
60
62
  #
61
63
  # Options:
62
- # -r, --refspec TEXT <commit 1>..<commit 2> (compare two commits) or <commit>
63
- # (compare <commit> to the worktree)
64
- # -S, --no-shell Don't pass `shell=True` to Python `subprocess`es
65
- # -v, --verbose Log intermediate commands to stderr
66
- # --help Show this message and exit.
64
+ # -c, --color Colorize the output
65
+ # -r, --refspec TEXT <commit 1>..<commit 2> (compare two commits) or
66
+ # <commit> (compare <commit> to the worktree)
67
+ # -S, --no-shell Don't pass `shell=True` to Python `subprocess`es
68
+ # -U, --unified INTEGER Number of lines of context to show (passes through
69
+ # to `diff`)
70
+ # -v, --verbose Log intermediate commands to stderr
71
+ # -w, --ignore-whitespace Ignore whitespace differences (pass `-w` to `diff`)
72
+ # --help Show this message and exit.
67
73
  ```
68
74
 
69
75
  ## Examples <a id="examples"></a>
@@ -18,6 +18,7 @@ pip install dvc-utils
18
18
  ```
19
19
 
20
20
  ## Usage <a id="usage"></a>
21
+ <!-- `bmdf -- dvc-utils --help` -->
21
22
  ```bash
22
23
  dvc-utils --help
23
24
  # Usage: dvc-utils [OPTIONS] COMMAND [ARGS]...
@@ -31,6 +32,7 @@ dvc-utils --help
31
32
  ```
32
33
 
33
34
  ### `dvc-utils diff` <a id="dvc-utils-diff"></a>
35
+ <!-- `bmdf -- dvc-utils diff --help` -->
34
36
  ```bash
35
37
  dvc-utils diff --help
36
38
  # Usage: dvc-utils diff [OPTIONS] [cmd...] <path>
@@ -48,11 +50,15 @@ dvc-utils diff --help
48
50
  # optional) at HEAD (last committed value) vs. the current worktree content.
49
51
  #
50
52
  # Options:
51
- # -r, --refspec TEXT <commit 1>..<commit 2> (compare two commits) or <commit>
52
- # (compare <commit> to the worktree)
53
- # -S, --no-shell Don't pass `shell=True` to Python `subprocess`es
54
- # -v, --verbose Log intermediate commands to stderr
55
- # --help Show this message and exit.
53
+ # -c, --color Colorize the output
54
+ # -r, --refspec TEXT <commit 1>..<commit 2> (compare two commits) or
55
+ # <commit> (compare <commit> to the worktree)
56
+ # -S, --no-shell Don't pass `shell=True` to Python `subprocess`es
57
+ # -U, --unified INTEGER Number of lines of context to show (passes through
58
+ # to `diff`)
59
+ # -v, --verbose Log intermediate commands to stderr
60
+ # -w, --ignore-whitespace Ignore whitespace differences (pass `-w` to `diff`)
61
+ # --help Show this message and exit.
56
62
  ```
57
63
 
58
64
  ## Examples <a id="examples"></a>
@@ -72,13 +72,29 @@ def dvc_cache_path(ref: str, dvc_path: Optional[str] = None, log: bool = False)
72
72
  return join(dvc_cache_dir(log=log), 'files', 'md5', dirname, basename)
73
73
 
74
74
 
75
- def diff_cmds(cmd1: str, cmd2: str, verbose: bool = False, **kwargs):
75
+ def diff_cmds(
76
+ cmd1: str,
77
+ cmd2: str,
78
+ verbose: bool = False,
79
+ color: bool = False,
80
+ unified: int | None = None,
81
+ ignore_whitespace: bool = False,
82
+ **kwargs,
83
+ ):
76
84
  """Run two commands and diff their output.
77
85
 
78
86
  Adapted from https://stackoverflow.com/a/28840955"""
79
87
  with named_pipes(n=2) as pipes:
80
88
  (pipe1, pipe2) = pipes
81
- diff = Popen(['diff'] + pipes)
89
+ diff_cmd = [
90
+ 'diff',
91
+ *(['-w'] if ignore_whitespace else []),
92
+ *(['-U', str(unified)] if unified is not None else []),
93
+ *(['--color=always'] if color else []),
94
+ pipe1,
95
+ pipe2,
96
+ ]
97
+ diff = Popen(diff_cmd)
82
98
  processes = []
83
99
  for path, cmd in ((pipe1, cmd1), (pipe2, cmd2)):
84
100
  with open(path, 'wb', 0) as pipe:
@@ -90,11 +106,22 @@ def diff_cmds(cmd1: str, cmd2: str, verbose: bool = False, **kwargs):
90
106
 
91
107
 
92
108
  @cli.command('diff', short_help='Diff a DVC-tracked file at two commits (or one commit vs. current worktree), optionally passing both through another command first')
109
+ @option('-c', '--color', is_flag=True, help='Colorize the output')
93
110
  @option('-r', '--refspec', default='HEAD', help='<commit 1>..<commit 2> (compare two commits) or <commit> (compare <commit> to the worktree)')
94
111
  @option('-S', '--no-shell', is_flag=True, help="Don't pass `shell=True` to Python `subprocess`es")
112
+ @option('-U', '--unified', type=int, help='Number of lines of context to show (passes through to `diff`)')
95
113
  @option('-v', '--verbose', is_flag=True, help="Log intermediate commands to stderr")
114
+ @option('-w', '--ignore-whitespace', is_flag=True, help="Ignore whitespace differences (pass `-w` to `diff`)")
96
115
  @argument('args', metavar='[cmd...] <path>', nargs=-1)
97
- def dvc_utils_diff(refspec, no_shell, verbose, args):
116
+ def dvc_utils_diff(
117
+ color: bool,
118
+ refspec: str | None,
119
+ no_shell: bool,
120
+ unified: int | None,
121
+ verbose: bool,
122
+ ignore_whitespace: bool,
123
+ args: Tuple[str, ...],
124
+ ):
98
125
  """Diff a file at two commits (or one commit vs. current worktree), optionally passing both through `cmd` first
99
126
 
100
127
  Examples:
@@ -139,7 +166,15 @@ def dvc_utils_diff(refspec, no_shell, verbose, args):
139
166
  shell_kwargs = dict(shell=shell) if shell else {}
140
167
  before_cmd = args(before_path)
141
168
  after_cmd = args(after_path)
142
- diff_cmds(before_cmd, after_cmd, verbose=verbose, **shell_kwargs)
169
+ diff_cmds(
170
+ before_cmd,
171
+ after_cmd,
172
+ verbose=verbose,
173
+ color=color,
174
+ unified=unified,
175
+ ignore_whitespace=ignore_whitespace,
176
+ **shell_kwargs,
177
+ )
143
178
  else:
144
179
  process.run('diff', before_path, after_path, log=log)
145
180
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dvc-utils
3
- Version: 0.0.3
3
+ Version: 0.0.4
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
@@ -29,6 +29,7 @@ pip install dvc-utils
29
29
  ```
30
30
 
31
31
  ## Usage <a id="usage"></a>
32
+ <!-- `bmdf -- dvc-utils --help` -->
32
33
  ```bash
33
34
  dvc-utils --help
34
35
  # Usage: dvc-utils [OPTIONS] COMMAND [ARGS]...
@@ -42,6 +43,7 @@ dvc-utils --help
42
43
  ```
43
44
 
44
45
  ### `dvc-utils diff` <a id="dvc-utils-diff"></a>
46
+ <!-- `bmdf -- dvc-utils diff --help` -->
45
47
  ```bash
46
48
  dvc-utils diff --help
47
49
  # Usage: dvc-utils diff [OPTIONS] [cmd...] <path>
@@ -59,11 +61,15 @@ dvc-utils diff --help
59
61
  # optional) at HEAD (last committed value) vs. the current worktree content.
60
62
  #
61
63
  # Options:
62
- # -r, --refspec TEXT <commit 1>..<commit 2> (compare two commits) or <commit>
63
- # (compare <commit> to the worktree)
64
- # -S, --no-shell Don't pass `shell=True` to Python `subprocess`es
65
- # -v, --verbose Log intermediate commands to stderr
66
- # --help Show this message and exit.
64
+ # -c, --color Colorize the output
65
+ # -r, --refspec TEXT <commit 1>..<commit 2> (compare two commits) or
66
+ # <commit> (compare <commit> to the worktree)
67
+ # -S, --no-shell Don't pass `shell=True` to Python `subprocess`es
68
+ # -U, --unified INTEGER Number of lines of context to show (passes through
69
+ # to `diff`)
70
+ # -v, --verbose Log intermediate commands to stderr
71
+ # -w, --ignore-whitespace Ignore whitespace differences (pass `-w` to `diff`)
72
+ # --help Show this message and exit.
67
73
  ```
68
74
 
69
75
  ## Examples <a id="examples"></a>
@@ -2,7 +2,7 @@ from setuptools import setup
2
2
 
3
3
  setup(
4
4
  name='dvc-utils',
5
- version="0.0.3",
5
+ version="0.0.4",
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",
File without changes
File without changes