##// END OF EJS Templates
typing: add type hints to the platform specific scm modules...
Matt Harbison -
r50703:7a414342 default
parent child Browse files
Show More
@@ -4,6 +4,11 b' import fcntl'
4 import os
4 import os
5 import sys
5 import sys
6
6
7 from typing import (
8 List,
9 Tuple,
10 )
11
7 from .pycompat import getattr
12 from .pycompat import getattr
8 from . import (
13 from . import (
9 encoding,
14 encoding,
@@ -11,6 +16,9 b' from . import ('
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
@@ -18,7 +26,7 b' from . import ('
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:
@@ -34,7 +42,7 b' def _rcfiles(path):'
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'
@@ -49,7 +57,7 b' def systemrcpath():'
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:
@@ -65,7 +73,7 b' def userrcpath():'
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
@@ -1,5 +1,10 b''
1 import os
1 import os
2
2
3 from typing import (
4 List,
5 Tuple,
6 )
7
3 from . import (
8 from . import (
4 encoding,
9 encoding,
5 pycompat,
10 pycompat,
@@ -7,6 +12,9 b' from . import ('
7 win32,
12 win32,
8 )
13 )
9
14
15 if pycompat.TYPE_CHECKING:
16 from . import ui as uimod
17
10 try:
18 try:
11 import _winreg as winreg # pytype: disable=import-error
19 import _winreg as winreg # pytype: disable=import-error
12
20
@@ -19,7 +27,7 b' except ImportError:'
19 fallbackpager = b'more'
27 fallbackpager = b'more'
20
28
21
29
22 def systemrcpath():
30 def systemrcpath() -> List[bytes]:
23 '''return default os-specific hgrc search path'''
31 '''return default os-specific hgrc search path'''
24 rcpath = []
32 rcpath = []
25 filename = win32.executablepath()
33 filename = win32.executablepath()
@@ -27,7 +35,7 b' def systemrcpath():'
27 progrc = os.path.join(os.path.dirname(filename), b'mercurial.ini')
35 progrc = os.path.join(os.path.dirname(filename), b'mercurial.ini')
28 rcpath.append(progrc)
36 rcpath.append(progrc)
29
37
30 def _processdir(progrcd):
38 def _processdir(progrcd: bytes) -> None:
31 if os.path.isdir(progrcd):
39 if os.path.isdir(progrcd):
32 for f, kind in sorted(util.listdir(progrcd)):
40 for f, kind in sorted(util.listdir(progrcd)):
33 if f.endswith(b'.rc'):
41 if f.endswith(b'.rc'):
@@ -68,7 +76,7 b' def systemrcpath():'
68 return rcpath
76 return rcpath
69
77
70
78
71 def userrcpath():
79 def userrcpath() -> List[bytes]:
72 '''return os-specific hgrc search path to the user dir'''
80 '''return os-specific hgrc search path to the user dir'''
73 home = _legacy_expanduser(b'~')
81 home = _legacy_expanduser(b'~')
74 path = [os.path.join(home, b'mercurial.ini'), os.path.join(home, b'.hgrc')]
82 path = [os.path.join(home, b'mercurial.ini'), os.path.join(home, b'.hgrc')]
@@ -79,7 +87,7 b' def userrcpath():'
79 return path
87 return path
80
88
81
89
82 def _legacy_expanduser(path):
90 def _legacy_expanduser(path: bytes) -> bytes:
83 """Expand ~ and ~user constructs in the pre 3.8 style"""
91 """Expand ~ and ~user constructs in the pre 3.8 style"""
84
92
85 # Python 3.8+ changed the expansion of '~' from HOME to USERPROFILE. See
93 # Python 3.8+ changed the expansion of '~' from HOME to USERPROFILE. See
@@ -111,5 +119,5 b' def _legacy_expanduser(path):'
111 return userhome + path[i:]
119 return userhome + path[i:]
112
120
113
121
114 def termsize(ui):
122 def termsize(ui: "uimod.ui") -> Tuple[int, int]:
115 return win32.termsize()
123 return win32.termsize()
General Comments 0
You need to be logged in to leave comments. Login now