Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions synthtool/gcp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,13 @@ def detect_versions(
except FileNotFoundError:
pass

# Sort the sub directories alphabetically.
sub_dirs = sorted([p.name for p in Path(path).rglob("*v[1-9]*") if p.is_dir()])
# Detect versions up to a depth of 4 in directory hierarchy
for level in ("*v[1-9]*", "*/*v[1-9]*", "*/*/*v[1-9]*", "*/*/*/*v[1-9]*"):
# Sort the sub directories alphabetically.
sub_dirs = sorted([p.name for p in Path(path).glob(level) if p.is_dir()])
# Don't proceed to the next level if we've detected versions in this depth level
if sub_dirs:
break

if sub_dirs:
# if `default_version` is not specified, return the sorted directories.
Expand Down
2 changes: 1 addition & 1 deletion synthtool/languages/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def owlbot_main() -> None:

templated_files = CommonTemplates().py_library(
microgenerator=True,
versions=detect_versions(path="./google/cloud", default_first=True),
versions=detect_versions(path="./google", default_first=True),
)
s.move(
[templated_files], excludes=[".coveragerc"]
Expand Down
4 changes: 3 additions & 1 deletion tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,12 @@ def test_detect_versions_with_default_version_from_metadata():

def test_detect_versions_nested_directory():
temp_dir = Path(tempfile.mkdtemp())
src_dir = temp_dir / "src" / "src2" / "src3"
src_dir = temp_dir / "src" / "src2" / "src3" / "src4"
vs = ("v1", "v2", "v3")
for v in vs:
os.makedirs(src_dir / v)
# this folder should be ignored
os.makedirs(src_dir / v / "some_other_service_v1_beta")

with util.chdir(temp_dir):
versions = detect_versions(default_version="v1")
Expand Down