|
52 | 52 | "ensure_dir", |
53 | 53 | "remove_auth_from_url", |
54 | 54 | "check_externally_managed", |
| 55 | + "looks_like_ci", |
55 | 56 | "ConfiguredBuildBackendHookCaller", |
56 | 57 | ] |
57 | 58 |
|
|
65 | 66 | OnErr = Callable[[FunctionType, Path, ExcInfo], Any] |
66 | 67 |
|
67 | 68 | FILE_CHUNK_SIZE = 1024 * 1024 |
| 69 | +# These are environment variables present when running under various |
| 70 | +# CI systems. For each variable, some CI systems that use the variable |
| 71 | +# are indicated. The collection was chosen so that for each of a number |
| 72 | +# of popular systems, at least one of the environment variables is used. |
| 73 | +# This list is used to provide some indication of and lower bound for |
| 74 | +# CI traffic to PyPI. Thus, it is okay if the list is not comprehensive. |
| 75 | +# For more background, see: https://github.com/pypa/pip/issues/5499 |
| 76 | +CI_ENVIRONMENT_VARIABLES = ( |
| 77 | + # Azure Pipelines |
| 78 | + "BUILD_BUILDID", |
| 79 | + # Jenkins |
| 80 | + "BUILD_ID", |
| 81 | + # AppVeyor, CircleCI, Codeship, Gitlab CI, Shippable, Travis CI |
| 82 | + "CI", |
| 83 | + # Explicit environment variable. |
| 84 | + "PIP_IS_CI", |
| 85 | +) |
68 | 86 |
|
69 | 87 |
|
70 | 88 | def get_pip_version() -> str: |
@@ -785,3 +803,13 @@ def warn_if_run_as_root() -> None: |
785 | 803 | "Use the --root-user-action option if you know what you are doing and " |
786 | 804 | "want to suppress this warning." |
787 | 805 | ) |
| 806 | + |
| 807 | + |
| 808 | +def looks_like_ci() -> bool: |
| 809 | + """ |
| 810 | + Return whether it looks like pip is running under CI. |
| 811 | + """ |
| 812 | + # We don't use the method of checking for a tty (e.g. using isatty()) |
| 813 | + # because some CI systems mimic a tty (e.g. Travis CI). Thus that |
| 814 | + # method doesn't provide definitive information in either direction. |
| 815 | + return any(name in os.environ for name in CI_ENVIRONMENT_VARIABLES) |
0 commit comments