comparison mercurial/scmposix.py @ 49808:7a4143428db7

typing: add type hints to the platform specific scm modules Surprisingly, pytype struggled to figure out the return types in the posix functions.
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 15 Dec 2022 15:41:59 -0500
parents a87338fe8cfa
children 18c8c18993f0
comparison
equal deleted inserted replaced
49807:c5a06cc37401 49808:7a4143428db7
1 import array 1 import array
2 import errno 2 import errno
3 import fcntl 3 import fcntl
4 import os 4 import os
5 import sys 5 import sys
6
7 from typing import (
8 List,
9 Tuple,
10 )
6 11
7 from .pycompat import getattr 12 from .pycompat import getattr
8 from . import ( 13 from . import (
9 encoding, 14 encoding,
10 pycompat, 15 pycompat,
11 util, 16 util,
12 ) 17 )
13 18
19 if pycompat.TYPE_CHECKING:
20 from . import ui as uimod
21
14 # BSD 'more' escapes ANSI color sequences by default. This can be disabled by 22 # BSD 'more' escapes ANSI color sequences by default. This can be disabled by
15 # $MORE variable, but there's no compatible option with Linux 'more'. Given 23 # $MORE variable, but there's no compatible option with Linux 'more'. Given
16 # OS X is widely used and most modern Unix systems would have 'less', setting 24 # OS X is widely used and most modern Unix systems would have 'less', setting
17 # 'less' as the default seems reasonable. 25 # 'less' as the default seems reasonable.
18 fallbackpager = b'less' 26 fallbackpager = b'less'
19 27
20 28
21 def _rcfiles(path): 29 def _rcfiles(path: bytes) -> List[bytes]:
22 rcs = [os.path.join(path, b'hgrc')] 30 rcs = [os.path.join(path, b'hgrc')]
23 rcdir = os.path.join(path, b'hgrc.d') 31 rcdir = os.path.join(path, b'hgrc.d')
24 try: 32 try:
25 rcs.extend( 33 rcs.extend(
26 [ 34 [
32 except OSError: 40 except OSError:
33 pass 41 pass
34 return rcs 42 return rcs
35 43
36 44
37 def systemrcpath(): 45 def systemrcpath() -> List[bytes]:
38 path = [] 46 path = []
39 if pycompat.sysplatform == b'plan9': 47 if pycompat.sysplatform == b'plan9':
40 root = b'lib/mercurial' 48 root = b'lib/mercurial'
41 else: 49 else:
42 root = b'etc/mercurial' 50 root = b'etc/mercurial'
47 path.extend(_rcfiles(os.path.join(p, root))) 55 path.extend(_rcfiles(os.path.join(p, root)))
48 path.extend(_rcfiles(b'/' + root)) 56 path.extend(_rcfiles(b'/' + root))
49 return path 57 return path
50 58
51 59
52 def userrcpath(): 60 def userrcpath() -> List[bytes]:
53 if pycompat.sysplatform == b'plan9': 61 if pycompat.sysplatform == b'plan9':
54 return [encoding.environ[b'home'] + b'/lib/hgrc'] 62 return [encoding.environ[b'home'] + b'/lib/hgrc']
55 elif pycompat.isdarwin: 63 elif pycompat.isdarwin:
56 return [os.path.expanduser(b'~/.hgrc')] 64 return [os.path.expanduser(b'~/.hgrc')]
57 else: 65 else:
63 os.path.expanduser(b'~/.hgrc'), 71 os.path.expanduser(b'~/.hgrc'),
64 os.path.join(confighome, b'hg', b'hgrc'), 72 os.path.join(confighome, b'hg', b'hgrc'),
65 ] 73 ]
66 74
67 75
68 def termsize(ui): 76 def termsize(ui: "uimod.ui") -> Tuple[int, int]:
69 try: 77 try:
70 import termios 78 import termios
71 79
72 TIOCGWINSZ = termios.TIOCGWINSZ # unavailable on IRIX (issue3449) 80 TIOCGWINSZ = termios.TIOCGWINSZ # unavailable on IRIX (issue3449)
73 except (AttributeError, ImportError): 81 except (AttributeError, ImportError):