Skip to content

Commit

Permalink
Reduce imports processed by python stubs.
Browse files Browse the repository at this point in the history
There are several import statements in the python wrapper stub used by
`py_binary` and `py_test` rules which are only used when running from a
zip archive.  Processing these imports is a waste of time in the common
case where they aren't going to  be used.  They also might not be
present at all in some stripped-down python environments (e.g. the
Debian `python3-minimal` package), which might be the only python
available on a remote builder when using a hermetic python toolchain
(even when using a hermetic python toolchain, the wrapper is executed
using the system python environment).

Closes #15571

Closes #15572.

PiperOrigin-RevId: 462362750
Change-Id: I561fde110c8b176e2f616ab9a0469b6c50c6986b
  • Loading branch information
adam-azarchs authored and copybara-github committed Jul 21, 2022
1 parent f99cebe commit c33e44c
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ import sys
del sys.path[0]

import os
import re
import shutil
import subprocess
import tempfile
import zipfile

def IsRunningFromZip():
return %is_zipfile%

if IsRunningFromZip():
import shutil
import tempfile
import zipfile
else:
import re

# Return True if running on Windows
def IsWindows():
Expand Down Expand Up @@ -71,9 +77,6 @@ def SearchPath(name):
return path
return None

def IsRunningFromZip():
return %is_zipfile%

def FindPythonBinary(module_space):
"""Finds the real Python binary if it's not a normal absolute path."""
if PYTHON_BINARY.startswith('//'):
Expand Down

0 comments on commit c33e44c

Please sign in to comment.