dvc-utils 0.0.6__tar.gz → 0.0.8__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.6
3
+ Version: 0.0.8
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
@@ -63,17 +63,22 @@ dvc-diff --help
63
63
  # optional) at HEAD (last committed value) vs. the current worktree content.
64
64
  #
65
65
  # Options:
66
- # -c, --color Colorize the output
67
- # -r, --refspec TEXT <commit 1>..<commit 2> (compare two commits) or
68
- # <commit> (compare <commit> to the worktree)
69
- # -S, --no-shell Don't pass `shell=True` to Python `subprocess`es
70
- # -U, --unified INTEGER Number of lines of context to show (passes through
71
- # to `diff`)
72
- # -v, --verbose Log intermediate commands to stderr
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
76
- # --help Show this message and exit.
66
+ # -c, --color Colorize the output
67
+ # -r, --refspec TEXT <commit 1>..<commit 2> (compare two commits) or
68
+ # <commit> (compare <commit> to the worktree)
69
+ # -s, --shell-executable TEXT Shell to use for executing commands; defaults
70
+ # to $SHELL (/bin/bash)
71
+ # -S, --no-shell Don't pass `shell=True` to Python
72
+ # `subprocess`es
73
+ # -U, --unified INTEGER Number of lines of context to show (passes
74
+ # through to `diff`)
75
+ # -v, --verbose Log intermediate commands to stderr
76
+ # -w, --ignore-whitespace Ignore whitespace differences (pass `-w` to
77
+ # `diff`)
78
+ # -x, --exec-cmd TEXT Command(s) to execute before diffing; alternate
79
+ # syntax to passing commands as positional
80
+ # arguments
81
+ # --help Show this message and exit.
77
82
  ```
78
83
 
79
84
  ## Examples <a id="examples"></a>
@@ -52,17 +52,22 @@ dvc-diff --help
52
52
  # optional) at HEAD (last committed value) vs. the current worktree content.
53
53
  #
54
54
  # Options:
55
- # -c, --color Colorize the output
56
- # -r, --refspec TEXT <commit 1>..<commit 2> (compare two commits) or
57
- # <commit> (compare <commit> to the worktree)
58
- # -S, --no-shell Don't pass `shell=True` to Python `subprocess`es
59
- # -U, --unified INTEGER Number of lines of context to show (passes through
60
- # to `diff`)
61
- # -v, --verbose Log intermediate commands to stderr
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
65
- # --help Show this message and exit.
55
+ # -c, --color Colorize the output
56
+ # -r, --refspec TEXT <commit 1>..<commit 2> (compare two commits) or
57
+ # <commit> (compare <commit> to the worktree)
58
+ # -s, --shell-executable TEXT Shell to use for executing commands; defaults
59
+ # to $SHELL (/bin/bash)
60
+ # -S, --no-shell Don't pass `shell=True` to Python
61
+ # `subprocess`es
62
+ # -U, --unified INTEGER Number of lines of context to show (passes
63
+ # through to `diff`)
64
+ # -v, --verbose Log intermediate commands to stderr
65
+ # -w, --ignore-whitespace Ignore whitespace differences (pass `-w` to
66
+ # `diff`)
67
+ # -x, --exec-cmd TEXT Command(s) to execute before diffing; alternate
68
+ # syntax to passing commands as positional
69
+ # arguments
70
+ # --help Show this message and exit.
66
71
  ```
67
72
 
68
73
  ## Examples <a id="examples"></a>
@@ -2,15 +2,12 @@ from functools import cache
2
2
  from os import environ as env, getcwd
3
3
  from os.path import join, relpath
4
4
  import shlex
5
- from subprocess import Popen, PIPE
6
5
  from typing import Optional, Tuple
7
6
 
8
7
  from click import option, argument, group
9
8
  import click
10
9
  import yaml
11
- from utz import process, singleton, err
12
-
13
- from dvc_utils.named_pipes import named_pipes
10
+ from utz import diff_cmds, process, err, singleton
14
11
 
15
12
 
16
13
  @group()
@@ -69,89 +66,10 @@ def dvc_cache_path(ref: str, dvc_path: Optional[str] = None, log: bool = False)
69
66
  return join(dvc_cache_dir(log=log), 'files', 'md5', dirname, basename)
70
67
 
71
68
 
72
- def diff_cmds(
73
- cmds1: list[str],
74
- cmds2: list[str],
75
- verbose: bool = False,
76
- color: bool = False,
77
- unified: int | None = None,
78
- ignore_whitespace: bool = False,
79
- **kwargs,
80
- ):
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.
95
-
96
- Adapted from https://stackoverflow.com/a/28840955"""
97
- with named_pipes(n=2) as pipes:
98
- (pipe1, pipe2) = pipes
99
- diff_cmd = [
100
- 'diff',
101
- *(['-w'] if ignore_whitespace else []),
102
- *(['-U', str(unified)] if unified is not None else []),
103
- *(['--color=always'] if color else []),
104
- pipe1,
105
- pipe2,
106
- ]
107
- diff = Popen(diff_cmd)
108
- processes = []
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
-
148
- for p in [diff] + processes:
149
- p.wait()
150
-
151
-
152
69
  @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')
153
70
  @option('-c', '--color', is_flag=True, help='Colorize the output')
154
71
  @option('-r', '--refspec', default='HEAD', help='<commit 1>..<commit 2> (compare two commits) or <commit> (compare <commit> to the worktree)')
72
+ @option('-s', '--shell-executable', help=f'Shell to use for executing commands; defaults to $SHELL ({env.get("SHELL")})')
155
73
  @option('-S', '--no-shell', is_flag=True, help="Don't pass `shell=True` to Python `subprocess`es")
156
74
  @option('-U', '--unified', type=int, help='Number of lines of context to show (passes through to `diff`)')
157
75
  @option('-v', '--verbose', is_flag=True, help="Log intermediate commands to stderr")
@@ -161,6 +79,7 @@ def diff_cmds(
161
79
  def dvc_utils_diff(
162
80
  color: bool,
163
81
  refspec: str | None,
82
+ shell_executable: str | None,
164
83
  no_shell: bool,
165
84
  unified: int | None,
166
85
  verbose: bool,
@@ -223,6 +142,7 @@ def dvc_utils_diff(
223
142
  color=color,
224
143
  unified=unified,
225
144
  ignore_whitespace=ignore_whitespace,
145
+ shell_executable=shell_executable,
226
146
  **shell_kwargs,
227
147
  )
228
148
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dvc-utils
3
- Version: 0.0.6
3
+ Version: 0.0.8
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
@@ -63,17 +63,22 @@ dvc-diff --help
63
63
  # optional) at HEAD (last committed value) vs. the current worktree content.
64
64
  #
65
65
  # Options:
66
- # -c, --color Colorize the output
67
- # -r, --refspec TEXT <commit 1>..<commit 2> (compare two commits) or
68
- # <commit> (compare <commit> to the worktree)
69
- # -S, --no-shell Don't pass `shell=True` to Python `subprocess`es
70
- # -U, --unified INTEGER Number of lines of context to show (passes through
71
- # to `diff`)
72
- # -v, --verbose Log intermediate commands to stderr
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
76
- # --help Show this message and exit.
66
+ # -c, --color Colorize the output
67
+ # -r, --refspec TEXT <commit 1>..<commit 2> (compare two commits) or
68
+ # <commit> (compare <commit> to the worktree)
69
+ # -s, --shell-executable TEXT Shell to use for executing commands; defaults
70
+ # to $SHELL (/bin/bash)
71
+ # -S, --no-shell Don't pass `shell=True` to Python
72
+ # `subprocess`es
73
+ # -U, --unified INTEGER Number of lines of context to show (passes
74
+ # through to `diff`)
75
+ # -v, --verbose Log intermediate commands to stderr
76
+ # -w, --ignore-whitespace Ignore whitespace differences (pass `-w` to
77
+ # `diff`)
78
+ # -x, --exec-cmd TEXT Command(s) to execute before diffing; alternate
79
+ # syntax to passing commands as positional
80
+ # arguments
81
+ # --help Show this message and exit.
77
82
  ```
78
83
 
79
84
  ## Examples <a id="examples"></a>
@@ -3,7 +3,6 @@ README.md
3
3
  setup.py
4
4
  dvc_utils/__init__.py
5
5
  dvc_utils/main.py
6
- dvc_utils/named_pipes.py
7
6
  dvc_utils.egg-info/PKG-INFO
8
7
  dvc_utils.egg-info/SOURCES.txt
9
8
  dvc_utils.egg-info/dependency_links.txt
@@ -2,7 +2,7 @@ from setuptools import setup
2
2
 
3
3
  setup(
4
4
  name='dvc-utils',
5
- version="0.0.6",
5
+ version="0.0.8",
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",
@@ -1,19 +0,0 @@
1
- import os
2
- import shutil
3
- import tempfile
4
- from contextlib import contextmanager
5
-
6
-
7
- @contextmanager
8
- def named_pipes(n: int = 1):
9
- """Yield a list of paths to named pipes that are created and destroyed
10
-
11
- From https://stackoverflow.com/a/28840955"""
12
- dirname = tempfile.mkdtemp()
13
- try:
14
- paths = [os.path.join(dirname, 'named_pipe' + str(i)) for i in range(n)]
15
- for path in paths:
16
- os.mkfifo(path)
17
- yield paths
18
- finally:
19
- shutil.rmtree(dirname)
File without changes
File without changes