annotate hgext/pager.py @ 51928:ad83e4f9b40e

typing: correct pytype mistakes in `mercurial/vfs.py` With the previous changes in this series (prior to merging the *.pyi file), this wasn't too bad- the only definitively wrong things were the `data` argument to `writelines()`, and the return type on `backgroundclosing()` (both of these errors were dropped in the previous commit; for some reason pytype doesn't like `contextlib._GeneratorContextManager`, even though that's what it determined it is): File "/mnt/c/Users/Matt/hg/mercurial/vfs.py", line 411, in abstractvfs: Bad return type 'contextlib._GeneratorContextManager' for generator function abstractvfs.backgroundclosing [bad-yield-annotation] Expected Generator, Iterable or Iterator PyCharm thinks this is `Generator[backgroundfilecloser], Any, None]`, which can be reduced to `Iterator[backgroundfilecloser]`, but pytype flagged the line that calls `yield` without an argument unless it's also `Optional`. PyCharm is happy either way. For some reason, `Iterable` didn't work for pytype: File "/mnt/c/Users/Matt/hg/mercurial/vfs.py", line 390, in abstractvfs: Function contextlib.contextmanager was called with the wrong arguments [wrong-arg-types] Expected: (func: Callable[[Any], Iterator]) Actually passed: (func: Callable[[Any, Any, Any], Iterable[Optional[Any]]]) Attributes of protocol Iterator[_T_co] are not implemented on Iterable[Optional[Any]]: __next__
author Matt Harbison <matt_harbison@yahoo.com>
date Fri, 20 Sep 2024 16:36:28 -0400
parents f4733654f144
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6323
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
1 # pager.py - display output using a pager
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
2 #
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
3 # Copyright 2008 David Soria Parra <dsp@php.net>
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
4 #
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 7995
diff changeset
5 # This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 10112
diff changeset
6 # GNU General Public License version 2 or any later version.
6323
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
7 #
12083
ebfc46929f3e help: refer to user configuration file more consistently
Brodie Rao <brodie@bitheap.org>
parents: 11414
diff changeset
8 # To load the extension, add it to your configuration file:
6323
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
9 #
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
10 # [extension]
10112
703db37d186b hgext: enable extensions without "hgext." prefix in help texts
Martin Geisler <mg@lazybytes.net>
parents: 9841
diff changeset
11 # pager =
6323
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
12 #
29971
bd55d98027ee pager: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 29852
diff changeset
13 # Run 'hg help pager' to get info on configuration.
6462
6c4e12682fb9 pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents: 6457
diff changeset
14
31081
900996da577a pager: move most help to a new help topic and deprecate extension
Augie Fackler <augie@google.com>
parents: 31053
diff changeset
15 '''browse command output with an external pager (DEPRECATED)
6462
6c4e12682fb9 pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents: 6457
diff changeset
16
31081
900996da577a pager: move most help to a new help topic and deprecate extension
Augie Fackler <augie@google.com>
parents: 31053
diff changeset
17 Forcibly enable paging for individual commands that don't typically
900996da577a pager: move most help to a new help topic and deprecate extension
Augie Fackler <augie@google.com>
parents: 31053
diff changeset
18 request pagination with the attend-<command> option. This setting
900996da577a pager: move most help to a new help topic and deprecate extension
Augie Fackler <augie@google.com>
parents: 31053
diff changeset
19 takes precedence over ignore options and defaults::
21281
bcddddcf0b54 pager: add attend-<command> option
Matt Mackall <mpm@selenic.com>
parents: 21280
diff changeset
20
bcddddcf0b54 pager: add attend-<command> option
Matt Mackall <mpm@selenic.com>
parents: 21280
diff changeset
21 [pager]
bcddddcf0b54 pager: add attend-<command> option
Matt Mackall <mpm@selenic.com>
parents: 21280
diff changeset
22 attend-cat = false
6462
6c4e12682fb9 pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents: 6457
diff changeset
23 '''
6323
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
24
51901
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 50825
diff changeset
25 from __future__ import annotations
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 50825
diff changeset
26
28320
63c2864af25f pager: use absolute_import
Augie Fackler <augie@google.com>
parents: 27128
diff changeset
27 from mercurial import (
63c2864af25f pager: use absolute_import
Augie Fackler <augie@google.com>
parents: 27128
diff changeset
28 cmdutil,
63c2864af25f pager: use absolute_import
Augie Fackler <augie@google.com>
parents: 27128
diff changeset
29 commands,
63c2864af25f pager: use absolute_import
Augie Fackler <augie@google.com>
parents: 27128
diff changeset
30 dispatch,
63c2864af25f pager: use absolute_import
Augie Fackler <augie@google.com>
parents: 27128
diff changeset
31 extensions,
34495
6d1b0970f80c configitems: register the 'pager.attend' config
Boris Feld <boris.feld@octobus.net>
parents: 31415
diff changeset
32 registrar,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 34669
diff changeset
33 )
6323
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
34
29852
d5883fd055c6 extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents: 29205
diff changeset
35 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
25186
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 24067
diff changeset
36 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 24067
diff changeset
37 # be specifying the version(s) of Mercurial they are tested with, or
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 24067
diff changeset
38 # leave the attribute unspecified.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
39 testedwith = b'ships-with-hg-core'
16743
38caf405d010 hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents: 16652
diff changeset
40
34495
6d1b0970f80c configitems: register the 'pager.attend' config
Boris Feld <boris.feld@octobus.net>
parents: 31415
diff changeset
41 configtable = {}
6d1b0970f80c configitems: register the 'pager.attend' config
Boris Feld <boris.feld@octobus.net>
parents: 31415
diff changeset
42 configitem = registrar.configitem(configtable)
6d1b0970f80c configitems: register the 'pager.attend' config
Boris Feld <boris.feld@octobus.net>
parents: 31415
diff changeset
43
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 34669
diff changeset
44 configitem(
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43077
diff changeset
45 b'pager',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43077
diff changeset
46 b'attend',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43077
diff changeset
47 default=lambda: attended,
34495
6d1b0970f80c configitems: register the 'pager.attend' config
Boris Feld <boris.feld@octobus.net>
parents: 31415
diff changeset
48 )
6d1b0970f80c configitems: register the 'pager.attend' config
Boris Feld <boris.feld@octobus.net>
parents: 31415
diff changeset
49
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 34669
diff changeset
50
6323
6e1308a09ffd Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff changeset
51 def uisetup(ui):
7216
292fb2ad2846 extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents: 6548
diff changeset
52 def pagecmd(orig, ui, options, cmd, cmdfunc):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
53 auto = options[b'pager'] == b'auto'
31013
9c2977ceaa46 pager: move more behavior into core
Augie Fackler <augie@google.com>
parents: 31012
diff changeset
54 if auto and not ui.pageractive:
21279
19b8cfe4396f pager: break auto out of command check loop
Matt Mackall <mpm@selenic.com>
parents: 21278
diff changeset
55 usepager = False
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
56 attend = ui.configlist(b'pager', b'attend')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
57 ignore = ui.configlist(b'pager', b'ignore')
19940
7d99bff0f77c pager: honour internal aliases
David Soria Parra <dsp@experimentalworks.net>
parents: 18923
diff changeset
58 cmds, _ = cmdutil.findcmd(cmd, commands.table)
7d99bff0f77c pager: honour internal aliases
David Soria Parra <dsp@experimentalworks.net>
parents: 18923
diff changeset
59
7d99bff0f77c pager: honour internal aliases
David Soria Parra <dsp@experimentalworks.net>
parents: 18923
diff changeset
60 for cmd in cmds:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
61 var = b'attend-%s' % cmd
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
62 if ui.config(b'pager', var, None):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
63 usepager = ui.configbool(b'pager', var, True)
21281
bcddddcf0b54 pager: add attend-<command> option
Matt Mackall <mpm@selenic.com>
parents: 21280
diff changeset
64 break
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 34669
diff changeset
65 if cmd in attend or (cmd not in ignore and not attend):
21277
2bc778e2f9b3 pager: break pager invocation out of command check loop
Matt Mackall <mpm@selenic.com>
parents: 20790
diff changeset
66 usepager = True
19940
7d99bff0f77c pager: honour internal aliases
David Soria Parra <dsp@experimentalworks.net>
parents: 18923
diff changeset
67 break
21277
2bc778e2f9b3 pager: break pager invocation out of command check loop
Matt Mackall <mpm@selenic.com>
parents: 20790
diff changeset
68
31013
9c2977ceaa46 pager: move more behavior into core
Augie Fackler <augie@google.com>
parents: 31012
diff changeset
69 if usepager:
31015
5e85bab867a7 ui: add ignore-single-command functionality
Augie Fackler <augie@google.com>
parents: 31013
diff changeset
70 # Slight hack: the attend list is supposed to override
5e85bab867a7 ui: add ignore-single-command functionality
Augie Fackler <augie@google.com>
parents: 31013
diff changeset
71 # the ignore list for the pager extension, but the
5e85bab867a7 ui: add ignore-single-command functionality
Augie Fackler <augie@google.com>
parents: 31013
diff changeset
72 # core code doesn't know about attend, so we have to
5e85bab867a7 ui: add ignore-single-command functionality
Augie Fackler <augie@google.com>
parents: 31013
diff changeset
73 # lobotomize the ignore list so that the extension's
5e85bab867a7 ui: add ignore-single-command functionality
Augie Fackler <augie@google.com>
parents: 31013
diff changeset
74 # behavior is preserved.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
75 ui.setconfig(b'pager', b'ignore', b'', b'pager')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
76 ui.pager(b'extension-via-attend-' + cmd)
31415
e83302d43748 pager: if old pager extensions is enabled, respect pager.attend
Martin von Zweigbergk <martinvonz@google.com>
parents: 31137
diff changeset
77 else:
e83302d43748 pager: if old pager extensions is enabled, respect pager.attend
Martin von Zweigbergk <martinvonz@google.com>
parents: 31137
diff changeset
78 ui.disablepager()
7216
292fb2ad2846 extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents: 6548
diff changeset
79 return orig(ui, options, cmd, cmdfunc)
6417
13fafd8cc4a1 pager: Add a configuration to enable/disable the pager for certain commands
David Soria Parra <dsp <at> php.net>
parents: 6324
diff changeset
80
50825
05430a06a2eb wrapfunction: use sysstr instead of bytes as argument in "pager"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48966
diff changeset
81 extensions.wrapfunction(dispatch, '_runcommand', pagecmd)
9841
7cd6dee6fe37 pager: provide a default attend list
Brodie Rao <me+hg@dackz.net>
parents: 9267
diff changeset
82
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 34669
diff changeset
83
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
84 attended = [b'annotate', b'cat', b'diff', b'export', b'glog', b'log', b'qdiff']