[PATCH v5] nmbug: Translate to Python
On Fri, Oct 03 2014, David Bremner wrote: > "W. Trevor King" writes: > >> This allows us to capture stdout and stderr separately, and do other >> explicit subprocess manipulation without resorting to external >> packages. It should be compatible with Python 2.6 and later >> (including the 3.x series), although with 2.6 you'll need the external >> argparse package. > > As reported on IRC, this version has been working ok for me for a week > or so. I haven't marked it ready to push because iirc, the python 2.6 > support doesn't really work and is doomed to be removed. Maybe just amend to "It is compatible with Python 2.7 and later...", with dropping the comment about external argparse package? Currently also tests don't work with Python 2.6 -- I have a patch that would "fix" this but probably it is just noise at this time (and I'd still need to do the harderst part -- write the commit message). > d Tomi
[PATCH v5] nmbug: Translate to Python
"W. Trevor King" writes: > This allows us to capture stdout and stderr separately, and do other > explicit subprocess manipulation without resorting to external > packages. It should be compatible with Python 2.6 and later > (including the 3.x series), although with 2.6 you'll need the external > argparse package. As reported on IRC, this version has been working ok for me for a week or so. I haven't marked it ready to push because iirc, the python 2.6 support doesn't really work and is doomed to be removed. d
Re: [PATCH v5] nmbug: Translate to Python
On Fri, Oct 03 2014, David Bremner wrote: > "W. Trevor King" writes: > >> This allows us to capture stdout and stderr separately, and do other >> explicit subprocess manipulation without resorting to external >> packages. It should be compatible with Python 2.6 and later >> (including the 3.x series), although with 2.6 you'll need the external >> argparse package. > > As reported on IRC, this version has been working ok for me for a week > or so. I haven't marked it ready to push because iirc, the python 2.6 > support doesn't really work and is doomed to be removed. Maybe just amend to "It is compatible with Python 2.7 and later...", with dropping the comment about external argparse package? Currently also tests don't work with Python 2.6 -- I have a patch that would "fix" this but probably it is just noise at this time (and I'd still need to do the harderst part -- write the commit message). > d Tomi ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
Re: [PATCH v5] nmbug: Translate to Python
"W. Trevor King" writes: > This allows us to capture stdout and stderr separately, and do other > explicit subprocess manipulation without resorting to external > packages. It should be compatible with Python 2.6 and later > (including the 3.x series), although with 2.6 you'll need the external > argparse package. As reported on IRC, this version has been working ok for me for a week or so. I haven't marked it ready to push because iirc, the python 2.6 support doesn't really work and is doomed to be removed. d ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
[PATCH v5] nmbug: Translate to Python
This allows us to capture stdout and stderr separately, and do other explicit subprocess manipulation without resorting to external packages. It should be compatible with Python 2.6 and later (including the 3.x series), although with 2.6 you'll need the external argparse package. Most of the user-facing interface is the same, but there are a few changes, where reproducing the original interface was too difficult or I saw a change to make the underlying Git UI accessible: * 'nmbug help' has been split between the general 'nmbug --help' and the command-specific 'nmbug COMMAND --help'. * Commands are no longer split into "most common", "other useful", and "less common" sets. If we need something like this, I'd prefer workflow examples highlighting common commands in the module docstring (available with 'nmbug --help'). * 'nmbug commit' now only uses a single argument for the optional commit-message text. I wanted to expose more of the underlying 'git commit' UI, since I personally like to write my commit messages in an editor with the notes added by 'git commit -v' to jog my memory. Unfortunately, we're using 'git commit-tree' instead of 'git commit', and commit-tree is too low-level for editor-launching. I'd be interested in rewriting commit() to use 'git commit', but that seemed like it was outside the scope of this rewrite. So I'm not supporting all of Git's commit syntax in this patch, but I can at least match 'git commit -m MESSAGE' in requiring command-line commit messages to be a single argument. * The default repository for 'nmbug push' and 'nmbug fetch' is now the current branch's upstream (branch..remote) instead of 'origin'. When we have to, we extract this remote by hand, but where possible we just call the Git command without a repository argument, and leave it to Git to figure out the default. * 'nmbug push' accepts multiple refspecs if you want to explicitly specify what to push. Otherwise, the refspec(s) pushed depend on push.default. The Perl version hardcoded 'master' as the pushed refspec. * 'nmbug pull' defaults to the current branch's upstream (branch..remote and branch..merge) instead of hardcoding 'origin' and 'master'. It also supports multiple refspecs if for some crazy reason you need an octopus merge (but mostly to avoid breaking consistency with 'git pull'). * 'nmbug log' now execs 'git log', as there's no need to keep the Python process around once we've launched Git there. * 'nmbug status' now catches stderr, and doesn't print errors like: No upstream configured for branch 'master' The Perl implementation had just learned to avoid crashing on that case, but wasn't yet catching the dying subprocess's stderr. * 'nmbug archive' now accepts positional arguments for the tree-ish and additional 'git archive' options. For example, you can run: $ nmbug archive HEAD -- --format tar.gz I wish I could have preserved the argument order from 'git archive' (with the tree-ish at the end), but I'm not sure how to make argparse accept arbitrary possitional arguments (some of which take arguments). Flipping the order to put the tree-ish first seemed easiest. * 'nmbug merge' and 'pull' no longer checkout HEAD before running their command, because blindly clobbering the index seems overly risky. * In order to avoid creating a dirty index, 'nmbug commit' now uses the default index (instead of nmbug.index) for composing the commit. That way the index matches the committed tree. To avoid leaving a broken index after a failed commit, I've wrapped the whole thing in a try/except block that resets the index to match the pre-commit treeish on errors. That means that 'nmbug commit' will ignore anything you've cached in the index via direct Git calls, and you'll either end up with an index matching your notmuch tags and the new HEAD (after a successful commit) or an index matching the original HEAD (after a failed commit). --- Changes since v4 [1]: * Use locale.getpreferredencoding() instead of sys.stdout.encoding to guess the encoding for the input/output streams of spawned processes. In Python 2, sys.stdout.encoding is None when stdout isn't a TTY, so we need to avoid it if we want to redirect logs to files. * Drop _read_tree(), since wrapping two Git calls isn't worth the trouble. * Use the default index (instead of nmbug.index) in commit(). Details in the final list entry of the commit message. This will make it harder to commit non-HEAD branches (because we're clobbering the default index), but I don't see a need to do that anyway (and the nmbug UI has never supported it). Cheers, Trevor [1]: id:e630b6763e9d0771718afee41ea15b29bb4a1de8.1409935538.git.wk...@tremily.us http://article.gmane.org/gmane.mail.notmuch.general/19007 devel/nmbug/nmbug | 1515 - 1 file changed, 807 insertions(+), 708 deletio
[PATCH v5] nmbug: Translate to Python
This allows us to capture stdout and stderr separately, and do other explicit subprocess manipulation without resorting to external packages. It should be compatible with Python 2.6 and later (including the 3.x series), although with 2.6 you'll need the external argparse package. Most of the user-facing interface is the same, but there are a few changes, where reproducing the original interface was too difficult or I saw a change to make the underlying Git UI accessible: * 'nmbug help' has been split between the general 'nmbug --help' and the command-specific 'nmbug COMMAND --help'. * Commands are no longer split into "most common", "other useful", and "less common" sets. If we need something like this, I'd prefer workflow examples highlighting common commands in the module docstring (available with 'nmbug --help'). * 'nmbug commit' now only uses a single argument for the optional commit-message text. I wanted to expose more of the underlying 'git commit' UI, since I personally like to write my commit messages in an editor with the notes added by 'git commit -v' to jog my memory. Unfortunately, we're using 'git commit-tree' instead of 'git commit', and commit-tree is too low-level for editor-launching. I'd be interested in rewriting commit() to use 'git commit', but that seemed like it was outside the scope of this rewrite. So I'm not supporting all of Git's commit syntax in this patch, but I can at least match 'git commit -m MESSAGE' in requiring command-line commit messages to be a single argument. * The default repository for 'nmbug push' and 'nmbug fetch' is now the current branch's upstream (branch..remote) instead of 'origin'. When we have to, we extract this remote by hand, but where possible we just call the Git command without a repository argument, and leave it to Git to figure out the default. * 'nmbug push' accepts multiple refspecs if you want to explicitly specify what to push. Otherwise, the refspec(s) pushed depend on push.default. The Perl version hardcoded 'master' as the pushed refspec. * 'nmbug pull' defaults to the current branch's upstream (branch..remote and branch..merge) instead of hardcoding 'origin' and 'master'. It also supports multiple refspecs if for some crazy reason you need an octopus merge (but mostly to avoid breaking consistency with 'git pull'). * 'nmbug log' now execs 'git log', as there's no need to keep the Python process around once we've launched Git there. * 'nmbug status' now catches stderr, and doesn't print errors like: No upstream configured for branch 'master' The Perl implementation had just learned to avoid crashing on that case, but wasn't yet catching the dying subprocess's stderr. * 'nmbug archive' now accepts positional arguments for the tree-ish and additional 'git archive' options. For example, you can run: $ nmbug archive HEAD -- --format tar.gz I wish I could have preserved the argument order from 'git archive' (with the tree-ish at the end), but I'm not sure how to make argparse accept arbitrary possitional arguments (some of which take arguments). Flipping the order to put the tree-ish first seemed easiest. * 'nmbug merge' and 'pull' no longer checkout HEAD before running their command, because blindly clobbering the index seems overly risky. * In order to avoid creating a dirty index, 'nmbug commit' now uses the default index (instead of nmbug.index) for composing the commit. That way the index matches the committed tree. To avoid leaving a broken index after a failed commit, I've wrapped the whole thing in a try/except block that resets the index to match the pre-commit treeish on errors. That means that 'nmbug commit' will ignore anything you've cached in the index via direct Git calls, and you'll either end up with an index matching your notmuch tags and the new HEAD (after a successful commit) or an index matching the original HEAD (after a failed commit). --- Changes since v4 [1]: * Use locale.getpreferredencoding() instead of sys.stdout.encoding to guess the encoding for the input/output streams of spawned processes. In Python 2, sys.stdout.encoding is None when stdout isn't a TTY, so we need to avoid it if we want to redirect logs to files. * Drop _read_tree(), since wrapping two Git calls isn't worth the trouble. * Use the default index (instead of nmbug.index) in commit(). Details in the final list entry of the commit message. This will make it harder to commit non-HEAD branches (because we're clobbering the default index), but I don't see a need to do that anyway (and the nmbug UI has never supported it). Cheers, Trevor [1]: id:e630b6763e9d0771718afee41ea15b29bb4a1de8.1409935538.git.wking at tremily.us http://article.gmane.org/gmane.mail.notmuch.general/19007 devel/nmbug/nmbug | 1515 - 1 file changed, 807 insertions(+), 708 del