From 975eaa6b6b55fa01db2f2a8d9d5bc33a80082043 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 27 Sep 2024 03:19:02 -0400 Subject: [PATCH] Remove usage of a separate `python.json` environment. (#35802) * Remove usage of a separate `python.json` environment. We instead now pull the python according to pigweed setup (so that version is maintained and uniform). This moves windows to also use python 3.11 (because 3.9 will not work) and removes the arm64 pull of a python3.9 as that is redundant. * Some debugging * Fix typo * Fix indent * make logging work * Also remove one package that does not seem exactly used * Restyle * More debug * Fix nargs handling * Add comment * Fix comment * Restyled by autopep8 --------- Co-authored-by: Andrei Litvin Co-authored-by: Restyled.io --- scripts/setup/bootstrap.sh | 3 ++- scripts/setup/environment.json | 1 - scripts/setup/gen_pigweed_cipd_json.py | 22 +++++++++++++++++++--- scripts/setup/python.json | 9 --------- 4 files changed, 21 insertions(+), 14 deletions(-) delete mode 100644 scripts/setup/python.json diff --git a/scripts/setup/bootstrap.sh b/scripts/setup/bootstrap.sh index ce3ab42dd56c79..f7e733da6b84b4 100644 --- a/scripts/setup/bootstrap.sh +++ b/scripts/setup/bootstrap.sh @@ -141,7 +141,8 @@ _bootstrap_or_activate() { $_CHIP_ROOT/scripts/setup/gen_pigweed_cipd_json.py \ -i $_PIGWEED_CIPD_JSON \ -o $_GENERATED_PIGWEED_CIPD_JSON \ - -e darwin:$_PYTHON_CIPD_JSON + -e darwin:$_PYTHON_CIPD_JSON \ + -e windows:$_PYTHON_CIPD_JSON if test -n "$GITHUB_ACTION"; then tee <"${_PW_ACTUAL_ENVIRONMENT_ROOT}/pip.conf" diff --git a/scripts/setup/environment.json b/scripts/setup/environment.json index fc9ace2b99b11c..09e31468771cd1 100644 --- a/scripts/setup/environment.json +++ b/scripts/setup/environment.json @@ -1,7 +1,6 @@ { "cipd_package_files": [ "third_party/pigweed/repo/pw_env_setup/py/pw_env_setup/cipd_setup/arm.json", - "scripts/setup/python.json", "scripts/setup/zap.json" ], "virtualenv": { diff --git a/scripts/setup/gen_pigweed_cipd_json.py b/scripts/setup/gen_pigweed_cipd_json.py index d1a47fe2cef7be..4fe77aaf09dce4 100755 --- a/scripts/setup/gen_pigweed_cipd_json.py +++ b/scripts/setup/gen_pigweed_cipd_json.py @@ -15,10 +15,15 @@ # limitations under the License. import argparse +import itertools import json +import logging import platform -_LIST_OF_PACKAGES_TO_EXCLUDE = ['fuchsia/third_party/rust/'] +_LIST_OF_PACKAGES_TO_EXCLUDE = { + 'fuchsia/third_party/rust/', + 'infra/3pp/tools/renode', +} def include_package(package: dict) -> bool: @@ -43,12 +48,20 @@ def generate_new_cipd_package_json(input, output, extra): # Extra is a list of platform:json. # Filter it for the given platform and append any resulting packages my_platform = platform.system().lower() - for item in extra: + + logging.info("Loading extra packages for %s", my_platform) + + # Extra chain because extra is a list of lists like: + # [['darwin:path1'], ['windows:path2']] + for item in itertools.chain.from_iterable(extra): inject_platform, path = item.split(':', 1) if inject_platform.lower() != my_platform: + logging.info("Skipping: %s (i.e. %s)", inject_platform.lower(), path) continue + logging.info("Appending: %s for this platform", path) + with open(path) as ins: for package in json.load(ins).get('packages'): new_file_packages.append(package) @@ -57,6 +70,8 @@ def generate_new_cipd_package_json(input, output, extra): with open(output, 'w') as f: json.dump(new_packages, f, indent=2) + logging.debug("PACKAGES:\n%s\n", json.dumps(new_packages, indent=2)) + def main(): parser = argparse.ArgumentParser( @@ -70,10 +85,11 @@ def main(): '--output', '-o', required=True ) parser.add_argument( - '--extra', '-e', nargs='*', default=[], + '--extra', '-e', nargs='*', action="append", default=[], help="Inject extra packages for specific platforms. Format is :" ) + logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO) generate_new_cipd_package_json(**vars(parser.parse_args())) diff --git a/scripts/setup/python.json b/scripts/setup/python.json deleted file mode 100644 index 0df6cc494ab40a..00000000000000 --- a/scripts/setup/python.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "packages": [ - { - "path": "infra/3pp/tools/cpython3/${platform}", - "platforms": ["mac-amd64", "windows-amd64"], - "tags": ["version:2@3.9.5.chromium.19"] - } - ] -}