Coverage for /builds/kinetik161/ase/ase/cli/complete.py: 18.87%

53 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-12-10 11:04 +0000

1#!/usr/bin/env python3 

2"""Bash completion for ase. 

3 

4Put this in your .bashrc:: 

5 

6 complete -o default -C /path/to/ase/cli/complete.py ase 

7 

8or run:: 

9 

10 $ ase completion 

11 

12""" 

13 

14import os 

15import sys 

16from glob import glob 

17 

18 

19def match(word, *suffixes): 

20 return [w for w in glob(word + '*') 

21 if any(w.endswith(suffix) for suffix in suffixes)] 

22 

23 

24# Beginning of computer generated data: 

25commands = { 

26 'band-structure': 

27 ['-o', '--output', '-r', '--range'], 

28 'build': 

29 ['-M', '--magnetic-moment', '--modify', '-V', '--vacuum', '-v', 

30 '--vacuum0', '--unit-cell', '--bond-length', '-x', 

31 '--crystal-structure', '-a', '--lattice-constant', 

32 '--orthorhombic', '--cubic', '-r', '--repeat', '-g', 

33 '--gui', '--periodic'], 

34 'completion': 

35 [], 

36 'convert': 

37 ['-v', '--verbose', '-i', '--input-format', '-o', 

38 '--output-format', '-f', '--force', '-n', 

39 '--image-number', '-e', '--exec-code', '-E', 

40 '--exec-file', '-a', '--arrays', '-I', '--info', '-s', 

41 '--split-output', '--read-args', '--write-args'], 

42 'db': 

43 ['-v', '--verbose', '-q', '--quiet', '-n', '--count', '-l', 

44 '--long', '-i', '--insert-into', '-a', 

45 '--add-from-file', '-k', '--add-key-value-pairs', '-L', 

46 '--limit', '--offset', '--delete', '--delete-keys', 

47 '-y', '--yes', '--explain', '-c', '--columns', '-s', 

48 '--sort', '--cut', '-p', '--plot', '--csv', '-w', 

49 '--open-web-browser', '--no-lock-file', '--analyse', 

50 '-j', '--json', '-m', '--show-metadata', 

51 '--set-metadata', '--strip-data', '--progress-bar', 

52 '--show-keys', '--show-values'], 

53 'diff': 

54 ['-r', '--rank-order', '-c', '--calculator-outputs', 

55 '--max-lines', '-t', '--template', '--template-help', 

56 '-s', '--summary-functions', '--log-file', '--as-csv', 

57 '--precision'], 

58 'dimensionality': 

59 ['--display-all', '--no-merge'], 

60 'eos': 

61 ['-p', '--plot', '-t', '--type'], 

62 'exec': 

63 ['-e', '--exec-code', '-E', '--exec-file', '-i', '--input-format', 

64 '-n', '--image-number', '--read-args'], 

65 'find': 

66 ['-v', '--verbose', '-l', '--long', '-i', '--include', '-x', 

67 '--exclude'], 

68 'gui': 

69 ['-n', '--image-number', '-r', '--repeat', '-R', '--rotations', 

70 '-o', '--output', '-g', '--graph', '-t', '--terminal', 

71 '--interpolate', '-b', '--bonds', '-s', '--scale'], 

72 'info': 

73 ['-v', '--verbose', '--formats', '--config', '--calculators'], 

74 'nebplot': 

75 ['--nimages', '--share-x', '--share-y'], 

76 'nomad-get': 

77 [], 

78 'nomad-upload': 

79 ['-t', '--token', '-n', '--no-save-token', '-0', '--dry-run'], 

80 'reciprocal': 

81 [], 

82 'run': 

83 ['-p', '--parameters', '-t', '--tag', '--properties', '-f', 

84 '--maximum-force', '--constrain-tags', '-s', 

85 '--maximum-stress', '-E', '--equation-of-state', 

86 '--eos-type', '-o', '--output', '--modify', '--after'], 

87 'test': 

88 ['-c', '--calculators', '--help-calculators', '--list', 

89 '--list-calculators', '-j', '--jobs', '-v', '--verbose', 

90 '--strict', '--fast', '--coverage', '--nogui', 

91 '--pytest'], 

92 'ulm': 

93 ['-n', '--index', '-d', '--delete', '-v', '--verbose']} 

94# End of computer generated data 

95 

96 

97def complete(word, previous, line, point): 

98 for w in line[:point - len(word)].strip().split()[1:]: 

99 if w[0].isalpha(): 

100 if w in commands: 

101 command = w 

102 break 

103 else: 

104 if word[:1] == '-': 

105 return ['-h', '--help', '--version'] 

106 return list(commands.keys()) + ['-h', '--help', '--verbose'] 

107 

108 if word[:1] == '-': 

109 return commands[command] 

110 

111 words = [] 

112 

113 if command == 'db': 

114 if previous == 'db': 

115 words = match(word, '.db', '.json') 

116 

117 elif command == 'run': 

118 if previous == 'run': 

119 from ase.calculators.calculator import names as words 

120 

121 elif command == 'build': 

122 if previous in ['-x', '--crystal-structure']: 

123 words = ['sc', 'fcc', 'bcc', 'hcp', 'diamond', 'zincblende', 

124 'rocksalt', 'cesiumchloride', 'fluorite', 'wurtzite'] 

125 

126 elif command == 'test': 

127 if previous in ['-c', '--calculators']: 

128 from ase.calculators.calculator import names as words 

129 elif not word.startswith('-'): 

130 from ase.test.testsuite import all_test_modules_and_groups 

131 words = [] 

132 for path in all_test_modules_and_groups(): 

133 path = str(path) 

134 if not path.endswith('.py'): 

135 path += '/' 

136 words.append(path) 

137 

138 return words 

139 

140 

141if sys.version_info[0] == 2: 

142 import warnings 

143 warnings.warn('Command-line completion running with python2. ' 

144 'Your ASE autocompletion setup is probably outdated. ' 

145 'Please consider rerunning \'ase completion\'.') 

146 

147 

148def main(): 

149 word, previous = sys.argv[2:] 

150 line = os.environ['COMP_LINE'] 

151 point = int(os.environ['COMP_POINT']) 

152 words = complete(word, previous, line, point) 

153 for w in words: 

154 if w.startswith(word): 

155 print(w) 

156 

157 

158if __name__ == '__main__': 

159 main()