deepspeed
1#!/usr/bin/env python3
2# Copyright (c) Microsoft Corporation.
3# SPDX-License-Identifier: Apache-2.0
4
5# DeepSpeed Team
6
7from __future__ import annotations8'''Copyright The Microsoft DeepSpeed Team'''
9"""
10Checks each file in sys.argv for the string "--extra-index-url".
11Modified from https://github.com/jlebar/pre-commit-hooks/blob/master/check_do_not_submit.py
12"""
13
14import subprocess15import sys16
17
18def err(s: str) -> None:19print(s, file=sys.stderr)20
21
22print(*sys.argv[1:])23
24# There are many ways we could search for the string "--extra-index-url", but `git
25# grep --no-index` is nice because
26# - it's very fast (as compared to iterating over the file in Python)
27# - we can reasonably assume it's available on all machines
28# - unlike plain grep, which is slower and has different flags on MacOS versus
29# Linux, git grep is always the same.
30res = subprocess.run(31["git", "grep", "-Hn", "--no-index", "-e", r"--extra-index-url", *sys.argv[1:]],32capture_output=True,33)
34if res.returncode == 0:35err('Error: The string "--extra-index-url" was found.\nPlease replace all calls to --extra-index-url with "--index-url"'36)37err(res.stdout.decode("utf-8"))38sys.exit(1)39elif res.returncode == 2:40err(f"Error invoking grep on {', '.join(sys.argv[1:])}:")41err(res.stderr.decode("utf-8"))42sys.exit(2)43