tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

check_install.py (2298B)


      1 # This Source Code Form is subject to the terms of the Mozilla Public
      2 # License, v. 2.0. If a copy of the MPL was not distributed with this
      3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
      4 """Installs dependencies at runtime to simplify deployment.
      5 
      6 This module tries to make sure we have all dependencies installed on
      7 all our environments.
      8 """
      9 
     10 import os
     11 import subprocess
     12 import sys
     13 
     14 PY3 = sys.version_info.major == 3
     15 TOPDIR = os.path.join(os.path.dirname(__file__), "..")
     16 
     17 
     18 def install_reqs():
     19    """We install requirements one by one, with no cache, and in isolated mode."""
     20    try:
     21        import yaml  # NOQA
     22 
     23        return False
     24    except Exception:
     25        # we're detecting here that this is running in Taskcluster
     26        # by checking for the presence of the mozfile directory
     27        # that was decompressed from target.condprof.tests.tar.zst
     28        run_in_ci = os.path.exists(os.path.join(TOPDIR, "mozfile"))
     29 
     30        # On Python 2 we only install what's required for condprof.client
     31        # On Python 3 it's the full thing
     32        if not run_in_ci:
     33            req_files = PY3 and ["base.txt", "local.txt"] or ["local-client.txt"]
     34        else:
     35            req_files = PY3 and ["base.txt", "ci.txt"] or ["ci-client.txt"]
     36 
     37        for req_file in req_files:
     38            req_file = os.path.join(TOPDIR, "requirements", req_file)
     39 
     40            with open(req_file) as f:
     41                reqs = [
     42                    req
     43                    for req in f.read().split("\n")
     44                    if req.strip() != "" and not req.startswith("#")
     45                ]
     46                for req in reqs:
     47                    subprocess.check_call([
     48                        sys.executable,
     49                        "-m",
     50                        "pip",
     51                        "install",
     52                        "--no-cache-dir",
     53                        "--isolated",
     54                        "--find-links",
     55                        "https://pypi.pub.build.mozilla.org/pub/",
     56                        req,
     57                    ])
     58 
     59        return True
     60 
     61 
     62 def check():
     63    """Called by the runner.
     64 
     65    The check function will restart the app after
     66    all deps have been installed.
     67    """
     68    if install_reqs():
     69        os.execl(sys.executable, sys.executable, *sys.argv)
     70        os._exit(0)