Coverage for /builds/kinetik161/ase/ase/cli/info.py: 86.11%
72 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-12-10 11:04 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-12-10 11:04 +0000
1# Note:
2# Try to avoid module level import statements here to reduce
3# import time during CLI execution
6class CLICommand:
7 """Print information about files or system.
9 Without any filename(s), informations about the ASE installation will be
10 shown (Python version, library versions, ...).
12 With filename(s), the file format will be determined for each file.
13 """
15 @staticmethod
16 def add_arguments(parser):
17 parser.add_argument('filename', nargs='*',
18 help='Name of file to determine format for.')
19 parser.add_argument('-v', '--verbose', action='store_true',
20 help='Show more information about files.')
21 parser.add_argument('--formats', action='store_true',
22 help='List file formats known to ASE.')
23 parser.add_argument('--config', action='store_true',
24 help='List configured calculators')
25 parser.add_argument('--calculators', action='store_true',
26 help='List all calculators known to ASE '
27 'and whether/how each is installed. Also, '
28 'attempt to determine version numbers by '
29 'running binaries or importing packages as '
30 'appropriate.')
32 @staticmethod
33 def run(args):
34 from ase.io.bundletrajectory import print_bundletrajectory_info
35 from ase.io.formats import UnknownFileTypeError, filetype, ioformats
36 from ase.io.ulm import print_ulm_info
38 from ase.config import cfg
39 if not args.filename:
40 print_info()
41 if args.formats:
42 print()
43 print_formats()
44 if args.config:
45 print()
46 cfg.print_everything()
47 if args.calculators:
48 print()
49 cfg.check_calculators()
50 # print()
51 # from ase.calculators.autodetect import (detect_calculators,
52 # format_configs)
53 # configs = detect_calculators()
54 # print('Calculators:')
55 # for message in format_configs(configs):
56 # print(' {}'.format(message))
57 # print()
58 # print('Available: {}'.format(','.join(sorted(configs))))
59 return
61 n = max(len(filename) for filename in args.filename) + 2
62 nfiles_not_found = 0
63 for filename in args.filename:
64 try:
65 format = filetype(filename)
66 except FileNotFoundError:
67 format = '?'
68 description = 'No such file'
69 nfiles_not_found += 1
70 except UnknownFileTypeError:
71 format = '?'
72 description = '?'
73 else:
74 if format in ioformats:
75 description = ioformats[format].description
76 else:
77 description = '?'
79 print('{:{}}{} ({})'.format(filename + ':', n,
80 description, format))
81 if args.verbose:
82 if format == 'traj':
83 print_ulm_info(filename)
84 elif format == 'bundletrajectory':
85 print_bundletrajectory_info(filename)
87 raise SystemExit(nfiles_not_found)
90def print_info():
91 import platform
92 import sys
94 from ase.dependencies import all_dependencies
96 versions = [('platform', platform.platform()),
97 ('python-' + sys.version.split()[0], sys.executable)]
99 for name, path in versions + all_dependencies():
100 print(f'{name:24} {path}')
103def print_formats():
104 from ase.io.formats import ioformats
106 print('Supported formats:')
107 for fmtname in sorted(ioformats):
108 fmt = ioformats[fmtname]
110 infos = [fmt.modes, 'single' if fmt.single else 'multi']
111 if fmt.isbinary:
112 infos.append('binary')
113 if fmt.encoding is not None:
114 infos.append(fmt.encoding)
115 infostring = '/'.join(infos)
117 moreinfo = [infostring]
118 if fmt.extensions:
119 moreinfo.append('ext={}'.format('|'.join(fmt.extensions)))
120 if fmt.globs:
121 moreinfo.append('glob={}'.format('|'.join(fmt.globs)))
123 print(' {} [{}]: {}'.format(fmt.name,
124 ', '.join(moreinfo),
125 fmt.description))