|
29 | 29 |
|
30 | 30 | import nox |
31 | 31 |
|
32 | | -import os |
33 | | -import subprocess |
34 | | - |
35 | | -import os |
36 | | -import subprocess |
37 | | - |
38 | | -def _provision_kokoro_secrets(): |
39 | | - """Downloads CI secrets directly from GCS and formats them for the tests.""" |
40 | | - if not os.environ.get("KOKORO_GFILE_DIR"): |
41 | | - return # We are not running in Kokoro, skip. |
42 | | - |
43 | | - dest_dir = os.path.join(os.path.dirname(__file__), "data") |
44 | | - os.makedirs(dest_dir, exist_ok=True) |
45 | | - |
46 | | - print("\n--- DEBUG: Fetching secrets from GCS ---") |
47 | | - try: |
48 | | - subprocess.run( |
49 | | - ["gsutil", "cp", "gs://cloud-devrel-kokoro-resources/google-auth-library-python/*", dest_dir], |
50 | | - check=True, |
51 | | - capture_output=True, |
52 | | - text=True |
53 | | - ) |
54 | | - |
55 | | - # 1. Rename the hyphen file to an underscore |
56 | | - downloaded_sa = os.path.join(dest_dir, "service-account.json") |
57 | | - expected_sa = os.path.join(dest_dir, "service_account.json") |
58 | | - if os.path.exists(downloaded_sa): |
59 | | - os.rename(downloaded_sa, expected_sa) |
60 | | - |
61 | | - # 2. Fake the authorized_user file if it's missing (using the service account) |
62 | | - expected_au = os.path.join(dest_dir, "authorized_user.json") |
63 | | - if os.path.exists(expected_sa) and not os.path.exists(expected_au): |
64 | | - import shutil |
65 | | - shutil.copy(expected_sa, expected_au) |
66 | | - |
67 | | - print("--- DEBUG: Successfully downloaded and formatted secrets. ---") |
68 | | - print(f"--- DEBUG: Final files ready for testing: {os.listdir(dest_dir)} ---") |
69 | | - |
70 | | - except subprocess.CalledProcessError as e: |
71 | | - print(f"--- DEBUG: Failed to download from GCS. stderr: {e.stderr} ---") |
72 | | - except FileNotFoundError: |
73 | | - print("--- DEBUG: gsutil not found in path ---") |
74 | | - |
75 | | - print("-" * 40 + "\n") |
76 | | - |
77 | | -# Execute this immediately when Nox loads the file |
78 | | -_provision_kokoro_secrets() |
79 | | - |
80 | | - |
81 | 32 | HERE = os.path.abspath(os.path.dirname(__file__)) |
82 | 33 | LIBRARY_DIR = os.path.abspath(os.path.dirname(HERE)) |
83 | 34 | DATA_DIR = os.path.join(HERE, "data") |
@@ -320,7 +271,7 @@ def compute_engine(session): |
320 | 271 | session.install(*TEST_DEPENDENCIES_SYNC) |
321 | 272 | # unset Application Default Credentials so |
322 | 273 | # credentials are detected from environment |
323 | | - session.virtualenv.env.pop("GOOGLE_APPLICATION_CREDENTIALS", None) |
| 274 | + del session.virtualenv.env["GOOGLE_APPLICATION_CREDENTIALS"] |
324 | 275 | session.install(LIBRARY_DIR) |
325 | 276 | default( |
326 | 277 | session, |
|
0 commit comments