|
41 | 41 | def _find_pyproject() -> Path: |
42 | 42 | """Locates pyproject.toml by walking up from this file's directory. |
43 | 43 |
|
44 | | - Works in both layouts: |
45 | | - * Open-source: pyproject.toml lives at the repo root. |
46 | | - * google3: pyproject.toml lives under open_source_workspace/ and tests/ is |
47 | | - a symlink into the package root, so .resolve() lands in the wrong place. |
| 44 | + Handles layouts where pyproject.toml is at an ancestor directory as well as |
| 45 | + layouts where it lives in a sibling build directory next to the package. The |
| 46 | + test tree may be symlinked, so the walk avoids ``.resolve()``. |
48 | 47 | """ |
49 | 48 | start = Path(__file__).parent |
50 | 49 | for candidate in [start, *start.parents]: |
51 | 50 | direct = candidate / 'pyproject.toml' |
52 | 51 | if direct.is_file(): |
53 | 52 | return direct |
54 | | - sibling = candidate / 'open_source_workspace' / 'pyproject.toml' |
55 | | - if sibling.is_file(): |
56 | | - return sibling |
| 53 | + try: |
| 54 | + children = sorted(p for p in candidate.iterdir() if p.is_dir()) |
| 55 | + except OSError: |
| 56 | + continue |
| 57 | + for child in children: |
| 58 | + sibling = child / 'pyproject.toml' |
| 59 | + if sibling.is_file(): |
| 60 | + return sibling |
57 | 61 | raise FileNotFoundError( |
58 | 62 | f'Could not find pyproject.toml walking up from {start}.' |
59 | 63 | ) |
@@ -105,8 +109,8 @@ def test_environment_simulation_config_imports_validation_error_from_pydantic() |
105 | 109 | pydantic-core is undeclared; importing from it directly is fragile. pydantic |
106 | 110 | re-exports ValidationError, so use that. |
107 | 111 | """ |
108 | | - # Use importlib to locate the source file so the test works in both the |
109 | | - # open-source layout (src/google/adk/...) and inside google3 (flat layout). |
| 112 | + # Use importlib to locate the source file so the test is independent of the |
| 113 | + # on-disk package layout. |
110 | 114 | spec = importlib.util.find_spec( |
111 | 115 | 'google.adk.tools.environment_simulation.environment_simulation_config' |
112 | 116 | ) |
|
0 commit comments