MCPcopy Index your code
hub / github.com/ampproject/amphtml / CheckPrereqs

Function CheckPrereqs

validator/build.py:42–100  ·  view source on GitHub ↗

Checks that various prerequisites for this script are satisfied.

()

Source from the content-addressed store, hash-verified

40
41
42def CheckPrereqs():
43 """Checks that various prerequisites for this script are satisfied."""
44 logging.info('entering ...')
45
46 if platform.system() != 'Linux' and platform.system() != 'Darwin':
47 Die('Sorry, this script assumes Linux or Mac OS X thus far. '
48 'Please feel free to edit the source and fix it to your needs.')
49
50 # Ensure source files are available.
51 for f in [
52 'validator-main.protoascii', 'validator.proto', 'validator_gen_js.py',
53 'package.json', 'js/engine/validator.js', 'js/engine/validator_test.js',
54 'js/engine/validator-in-browser.js', 'js/engine/tokenize-css.js',
55 'js/engine/definitions.js', 'js/engine/parse-css.js',
56 'js/engine/parse-srcset.js', 'js/engine/parse-url.js'
57 ]:
58 if not os.path.exists(f):
59 Die('%s not found. Must run in amp_validator source directory.' % f)
60
61 # Ensure protoc is available.
62 try:
63 libprotoc_version = subprocess.check_output(['protoc', '--version'])
64 except (subprocess.CalledProcessError, OSError):
65 Die('Protobuf compiler not found. Try "apt-get install protobuf-compiler" '
66 'or follow the install instructions at '
67 'https://github.com/ampproject/amphtml/blob/main/validator/README.md#installation.'
68 )
69
70 # Ensure 'libprotoc 2.5.0' or newer.
71 m = re.search(b'^(\\w+) (\\d+)\\.(\\d+)\\.(\\d+)', libprotoc_version)
72 if (m.group(1) != b'libprotoc' or
73 (int(m.group(2)), int(m.group(3)), int(m.group(4))) < (2, 5, 0)):
74 Die('Expected libprotoc 2.5.0 or newer, saw: %s' % libprotoc_version)
75
76 # Ensure that the Python protobuf package is installed.
77 for m in ['descriptor', 'text_format', 'json_format']:
78 module = 'google.protobuf.%s' % m
79 try:
80 __import__(module)
81 except ImportError:
82 # Python3 needs pip3. Python 2 needs pip.
83 if sys.version_info < (3, 0):
84 Die('%s not found. Try "pip install protobuf" or follow the install '
85 'instructions at https://github.com/ampproject/amphtml/blob/main/'
86 'validator/README.md#installation' % module)
87 else:
88 Die('%s not found. Try "pip3 install protobuf" or follow the install '
89 'instructions at https://github.com/ampproject/amphtml/blob/main/'
90 'validator/README.md#installation' % module)
91
92 # Ensure JVM installed. TODO: Check for version?
93 try:
94 subprocess.check_output(['java', '-version'], stderr=subprocess.STDOUT)
95 except (subprocess.CalledProcessError, OSError):
96 Die('Java missing. Try "apt-get install openjdk-7-jre" or follow the'
97 'install instructions at'
98 'https://github.com/ampproject/amphtml/blob/main/validator/README.md#installation'
99 )

Callers 1

MainFunction · 0.70

Calls 3

infoMethod · 0.80
groupMethod · 0.80
DieFunction · 0.70

Tested by

no test coverage detected