Bug 1455143 - Make hashlib required; r=ted
authorGregory Szorc <gps@mozilla.com>
Wed, 18 Apr 2018 15:31:11 -0700
changeset 468151 4c987b999ff1123be2596d1eed4d790bb3c57b8f
parent 468150 f9f1ea8029d2812486db444e42c5735a7dc11c30
child 468152 37fec60424380f4a64d2f568d644e26679a2f99f
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs1455143
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1455143 - Make hashlib required; r=ted A missing or unimportable hashlib is only possible on very old or very busted Pythons. Remove code for conditionally handling a failure to import it. MozReview-Commit-ID: EXVlmttcwUa
build/checksums.py
--- a/build/checksums.py
+++ b/build/checksums.py
@@ -1,52 +1,44 @@
 #!/usr/bin/python
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import with_statement
 
 from optparse import OptionParser
+import hashlib
 import logging
 import os
-try:
-    import hashlib
-except ImportError:
-    hashlib = None
 
 
 def digest_file(filename, digest, chunk_size=1024):
     '''Produce a checksum for the file specified by 'filename'.  'filename'
     is a string path to a file that is opened and read in this function.  The
     checksum algorithm is specified by 'digest' and is a valid OpenSSL
     algorithm.  If the digest used is not valid or Python's hashlib doesn't
     work, the None object will be returned instead.  The size of blocks
     that this function will read from the file object it opens based on
     'filename' can be specified by 'chunk_size', which defaults to 1K'''
     assert not os.path.isdir(filename), 'this function only works with files'
     logger = logging.getLogger('checksums.py')
-    if hashlib is not None:
-        logger.debug('Creating new %s object' % digest)
-        h = hashlib.new(digest)
-        with open(filename, 'rb') as f:
-            while True:
-                data = f.read(chunk_size)
-                if not data:
-                    logger.debug('Finished reading in file')
-                    break
-                h.update(data)
-        hash = h.hexdigest()
-        logger.debug('Hash for %s is %s' % (filename, hash))
-        return hash
-    else:
-        # In this case we could subprocess.Popen and .communicate with
-        # sha1sum or md5sum
-        logger.warn('The python module for hashlib is missing!')
-        return None
+
+    logger.debug('Creating new %s object' % digest)
+    h = hashlib.new(digest)
+    with open(filename, 'rb') as f:
+        while True:
+            data = f.read(chunk_size)
+            if not data:
+                logger.debug('Finished reading in file')
+                break
+            h.update(data)
+    hash = h.hexdigest()
+    logger.debug('Hash for %s is %s' % (filename, hash))
+    return hash
 
 
 def process_files(files, output_filename, digests, strip):
     '''This function takes a list of file names, 'files'.  It will then
     compute the checksum for each of the files by opening the files.
     Once each file is read and its checksum is computed, this function
     will write the information to the file specified by 'output_filename'.
     The path written in the output file will have anything specified by 'strip'