def setup_node_modules(npm_args=None, stdout=None, stderr=None, copy_modules=False): # type: (Optional[List[str]], Optional[IO], Optional[IO], Optional[bool]) -> None sha1sum = hashlib.sha1() sha1sum.update(subprocess_text_output(["cat", "package.json"]).encode("utf8")) sha1sum.update(subprocess_text_output(["npm", "--version"]).encode("utf8")) sha1sum.update(subprocess_text_output(["node", "--version"]).encode("utf8")) if npm_args is not None: sha1sum.update("".join(sorted(npm_args)).encode("utf8")) npm_cache = os.path.join(NPM_CACHE_PATH, sha1sum.hexdigest()) cached_node_modules = os.path.join(npm_cache, "node_modules") success_stamp = os.path.join(cached_node_modules, ".success-stamp") # Check if a cached version already exists if not os.path.exists(success_stamp): do_npm_install( npm_cache, npm_args or [], stdout=stdout, stderr=stderr, success_stamp=success_stamp, copy_modules=copy_modules, ) print("Using cached node modules from %s" % (cached_node_modules,)) cmds = [["rm", "-rf", "node_modules"], ["ln", "-nsf", cached_node_modules, "node_modules"]] for cmd in cmds: run(cmd, stdout=stdout, stderr=stderr)
def setup_node_modules(npm_args=None, stdout=None, stderr=None, copy_modules=False): # type: (Optional[List[str]], Optional[str], Optional[str], Optional[bool]) -> None sha1sum = hashlib.sha1() sha1sum.update( subprocess_text_output(['cat', 'package.json']).encode('utf8')) sha1sum.update(subprocess_text_output(['npm', '--version']).encode('utf8')) sha1sum.update( subprocess_text_output(['node', '--version']).encode('utf8')) if npm_args is not None: sha1sum.update(''.join(sorted(npm_args)).encode('utf8')) npm_cache = os.path.join(NPM_CACHE_PATH, sha1sum.hexdigest()) cached_node_modules = os.path.join(npm_cache, 'node_modules') success_stamp = os.path.join(cached_node_modules, '.success-stamp') # Check if a cached version already exists if not os.path.exists(success_stamp): do_npm_install(npm_cache, npm_args or [], stdout, stderr, copy_modules) print("Using cached node modules from %s" % (cached_node_modules, )) cmds = [ ['rm', '-rf', 'node_modules'], ["ln", "-nsf", cached_node_modules, 'node_modules'], ['touch', success_stamp], ] for cmd in cmds: run(cmd, stdout=stdout, stderr=stderr)
def generate_sha1sum_node_modules(npm_args=None): # type: (Optional[List[str]]) -> str sha1sum = hashlib.sha1() sha1sum.update(subprocess_text_output(['cat', 'package.json']).encode('utf8')) sha1sum.update(subprocess_text_output(['npm', '--version']).encode('utf8')) sha1sum.update(subprocess_text_output(['node', '--version']).encode('utf8')) if npm_args is not None: sha1sum.update(''.join(sorted(npm_args)).encode('utf8')) return sha1sum.hexdigest()
def generate_sha1sum_node_modules(production=DEFAULT_PRODUCTION): # type: (bool) -> str sha1sum = hashlib.sha1() sha1sum.update(subprocess_text_output(['cat', 'package.json']).encode('utf8')) sha1sum.update(subprocess_text_output(['cat', 'yarn.lock']).encode('utf8')) sha1sum.update(subprocess_text_output([YARN_BIN, '--version']).encode('utf8')) sha1sum.update(subprocess_text_output(['node', '--version']).encode('utf8')) yarn_args = get_yarn_args(production=production) sha1sum.update(''.join(sorted(yarn_args)).encode('utf8')) return sha1sum.hexdigest()
def generate_sha1sum_node_modules(npm_args=None): # type: (Optional[List[str]]) -> str sha1sum = hashlib.sha1() sha1sum.update( subprocess_text_output(['cat', 'package.json']).encode('utf8')) sha1sum.update(subprocess_text_output(['npm', '--version']).encode('utf8')) sha1sum.update( subprocess_text_output(['node', '--version']).encode('utf8')) if npm_args is not None: sha1sum.update(''.join(sorted(npm_args)).encode('utf8')) return sha1sum.hexdigest()
def main() -> None: # Get the correct Python interpreter. If we don't do this and use # `virtualenv -p python3` to create the venv in Travis, the venv # starts referring to the system Python interpreter. python_interpreter = subprocess_text_output(['which', 'python3']) setup_virtualenv(VENV_PATH, DEV_REQS_FILE, patch_activate_script=True, virtualenv_args=['-p', python_interpreter])
def generate_sha1sum_node_modules(setup_dir=None, production=DEFAULT_PRODUCTION): # type: (Optional[Text], bool) -> str if setup_dir is None: setup_dir = os.path.realpath(os.getcwd()) 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')) 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')) sha1sum.update(subprocess_text_output([YARN_BIN, '--version']).encode('utf8')) sha1sum.update(subprocess_text_output(['node', '--version']).encode('utf8')) yarn_args = get_yarn_args(production=production) sha1sum.update(''.join(sorted(yarn_args)).encode('utf8')) return sha1sum.hexdigest()
def main() -> None: # Get the correct Python interpreter. If we don't do this and use # `virtualenv -p python3` to create the venv in Travis, the venv # starts referring to the system Python interpreter. python_interpreter = subprocess_text_output(['which', 'python3']) setup_virtualenv("/srv/zulip-thumbor-venv", THUMBOR_REQS_FILE, patch_activate_script=True, virtualenv_args=['-p', 'python2.7']) cached_venv_path = setup_virtualenv( VENV_PATH, DEV_REQS_FILE, patch_activate_script=True, virtualenv_args=['-p', python_interpreter]) overwrite_symlink(cached_venv_path, os.path.join(ZULIP_PATH, "zulip-py3-venv"))
def install_npm(): # type: () -> None if not TRAVIS: if subprocess_text_output(['npm', '--version']) != NPM_VERSION: run(["sudo", "npm", "install", "-g", "npm@{}".format(NPM_VERSION)]) return run(['mkdir', '-p', TRAVIS_NODE_PATH]) npm_exe = os.path.join(TRAVIS_NODE_PATH, 'bin', 'npm') travis_npm = subprocess_text_output(['which', 'npm']) if os.path.exists(npm_exe): run(['sudo', 'ln', '-sf', npm_exe, travis_npm]) version = subprocess_text_output(['npm', '--version']) if os.path.exists(npm_exe) and version == NPM_VERSION: print("Using cached npm") return run(["npm", "install", "-g", "--prefix", TRAVIS_NODE_PATH, "npm@{}".format(NPM_VERSION)]) run(['sudo', 'ln', '-sf', npm_exe, travis_npm])
def main(is_travis=False): # type: (bool) -> None # Get the correct Python interpreter. If we don't do this and use # `virtualenv -p python3` to create the venv in Travis, the venv # starts referring to the system Python interpreter. python_interpreter = subprocess_text_output(['which', 'python3']) if is_travis: setup_virtualenv(VENV_PATH, DEV_REQS_FILE, patch_activate_script=True, virtualenv_args=['-p', python_interpreter]) else: run(['sudo', 'rm', '-f', OLD_VENV_PATH]) setup_virtualenv(VENV_PATH, DEV_REQS_FILE, patch_activate_script=True, virtualenv_args=['-p', python_interpreter])
def setup_node_modules(npm_args=None, stdout=None, stderr=None, copy_modules=False): # type: (Optional[List[str]], Optional[str], Optional[str], Optional[bool]) -> None sha1sum = hashlib.sha1() sha1sum.update(subprocess_text_output(['cat', 'package.json']).encode('utf8')) sha1sum.update(subprocess_text_output(['npm', '--version']).encode('utf8')) sha1sum.update(subprocess_text_output(['node', '--version']).encode('utf8')) if npm_args is not None: sha1sum.update(''.join(sorted(npm_args)).encode('utf8')) npm_cache = os.path.join(NPM_CACHE_PATH, sha1sum.hexdigest()) cached_node_modules = os.path.join(npm_cache, 'node_modules') success_stamp = os.path.join(cached_node_modules, '.success-stamp') # Check if a cached version already exists if not os.path.exists(success_stamp): do_npm_install(npm_cache, npm_args or [], stdout, stderr, copy_modules) print("Using cached node modules from %s" % (cached_node_modules,)) cmds = [ ['rm', '-rf', 'node_modules'], ["ln", "-nsf", cached_node_modules, 'node_modules'], ['touch', success_stamp], ] for cmd in cmds: run(cmd, stdout=stdout, stderr=stderr)
if platform.architecture()[0] == '64bit': arch = 'amd64' elif platform.architecture()[0] == '32bit': arch = "i386" else: logging.critical("Only x86 is supported;" "ping [email protected] if you want another architecture.") sys.exit(1) # Ideally we wouldn't need to install a dependency here, before we # know the codename. if not os.path.exists("/usr/bin/lsb_release"): subprocess.check_call(["sudo", "apt-get", "install", "-y", "lsb-release"]) vendor = subprocess_text_output(["lsb_release", "-is"]) codename = subprocess_text_output(["lsb_release", "-cs"]) if not (vendor in SUPPORTED_PLATFORMS and codename in SUPPORTED_PLATFORMS[vendor]): logging.critical("Unsupported platform: {} {}".format(vendor, codename)) sys.exit(1) POSTGRES_VERSION_MAP = { "stretch": "9.6", "trusty": "9.3", "xenial": "9.5", "bionic": "10", } POSTGRES_VERSION = POSTGRES_VERSION_MAP[codename] UBUNTU_COMMON_APT_DEPENDENCIES = [ "closure-compiler",