Skip to content

Commit

Permalink
fix: get_staging_dirs default_version should be optional (#1045)
Browse files Browse the repository at this point in the history
  • Loading branch information
chingor13 authored Apr 14, 2021
1 parent 721339a commit 14111b3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
10 changes: 6 additions & 4 deletions synthtool/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from pathlib import Path
import shutil
from typing import Callable, Iterable, Union, List
from typing import Callable, Iterable, Union, List, Optional
import os
import re
import sys
Expand Down Expand Up @@ -277,13 +277,13 @@ def replace(
return count_replaced


def get_staging_dirs(default_version: str) -> List[Path]:
def get_staging_dirs(default_version: Optional[str] = None) -> List[Path]:
"""Returns the list of directories, one per version, copied from
https://github.com/googleapis/googleapis-gen.
Args:
default_version: the default version of the API. The directory for this version
will be the last item in the returned list.
will be the last item in the returned list if specified.
Returns: the empty list if no file were copied.
"""
Expand All @@ -293,7 +293,9 @@ def get_staging_dirs(default_version: str) -> List[Path]:
# Collect the subdirectories of the staging directory.
versions = [v.name for v in staging.iterdir() if v.is_dir()]
# Reorder the versions so the default version always comes last.
versions = [v for v in versions if v != default_version] + [default_version]
versions = [v for v in versions if v != default_version]
if default_version is not None:
versions += [default_version]
dirs = [staging / v for v in versions]
for dir in dirs:
_tracked_paths.add(dir)
Expand Down
Empty file.
Empty file.
14 changes: 14 additions & 0 deletions tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,17 @@ def test_copy_with_merge_file_permissions(expand_path_fixtures):

# ensure that the destination existing file now has the correct file permissions
assert os.stat(destination_file).st_mode == os.stat(template).st_mode


@pytest.fixture(scope="function")
def change_test_dir():
cur = os.curdir
os.chdir(Path(__file__).parent / "fixtures/staging_dirs")
yield
os.chdir(cur)


def test_get_staging_dirs(change_test_dir):
assert [path.name for path in transforms.get_staging_dirs("v1")] == ["v2", "v1"]
assert [path.name for path in transforms.get_staging_dirs("v2")] == ["v1", "v2"]
assert [path.name for path in transforms.get_staging_dirs()] == ["v1", "v2"]

0 comments on commit 14111b3

Please sign in to comment.