python: Use universal_newlines to get str from subprocess.

We can replace ‘universal_newlines’ with ‘text’ when we bump our
minimum Python version to 3.7.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2020-10-29 17:36:18 -07:00
committed by Tim Abbott
parent 9281dccae4
commit aaa7b766d8
12 changed files with 35 additions and 38 deletions

View File

@@ -2,9 +2,10 @@ import hashlib
import json
import os
import shutil
import subprocess
from typing import List, Optional
from scripts.lib.zulip_tools import run, subprocess_text_output
from scripts.lib.zulip_tools import run
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
ZULIP_SRV_PATH = "/srv"
@@ -30,14 +31,16 @@ def generate_sha1sum_node_modules(
PACKAGE_JSON_FILE_PATH = os.path.join(setup_dir, 'package.json')
YARN_LOCK_FILE_PATH = os.path.join(setup_dir, 'yarn.lock')
sha1sum = hashlib.sha1()
sha1sum.update(subprocess_text_output(['cat', PACKAGE_JSON_FILE_PATH]).encode('utf8'))
with open(PACKAGE_JSON_FILE_PATH, "rb") as fb:
sha1sum.update(fb.read().strip())
if os.path.exists(YARN_LOCK_FILE_PATH):
# For backwards compatibility, we can't assume yarn.lock exists
sha1sum.update(subprocess_text_output(['cat', YARN_LOCK_FILE_PATH]).encode('utf8'))
with open(YARN_LOCK_FILE_PATH, "rb") as fb:
sha1sum.update(fb.read().strip())
with open(YARN_PACKAGE_JSON) as f:
yarn_version = json.load(f)['version']
sha1sum.update(yarn_version.encode("utf8"))
sha1sum.update(subprocess_text_output(['node', '--version']).encode('utf8'))
sha1sum.update(subprocess.check_output(['node', '--version']).strip())
yarn_args = get_yarn_args(production=production)
sha1sum.update(''.join(sorted(yarn_args)).encode('utf8'))
return sha1sum.hexdigest()