1#!/usr/bin/env python3 2# Copyright 2023 The ChromiumOS Authors 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6""" 7Run first before executing any python developer tool to ensure the environment is set up correctly. 8""" 9 10import sys 11from typing import List 12 13 14def ensure_packages_exist(*packages: str): 15 """ 16 Exits if one of the listed packages does not exist. 17 18 TODO(b/270708102): Automate venv installation of the packages 19 """ 20 missing_packages: List[str] = [] 21 22 for package in packages: 23 try: 24 __import__(package) 25 except ImportError: 26 missing_packages.append(package) 27 28 if missing_packages: 29 debian_packages = [f"python3-{p}" for p in missing_packages] 30 package_list = " ".join(debian_packages) 31 print("Missing python dependencies. Please re-run ./tools/install-deps") 32 print(f"Or `sudo apt install {package_list}`") 33 sys.exit(1) 34 35 36# Note: These packages need to be provided as CIPD packages for vpython in Luci CI. 37# See tools/.vpython3 for how to add them. 38ensure_packages_exist("argh", "rich") 39