Skip to content

Commit 355401a

Browse files
committed
Update get_target_packages to account for CIRCLE_TAG.
1 parent 87d63c0 commit 355401a

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

test_utils/scripts/get_target_packages.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@
1515
"""Print a list of packages which require testing."""
1616

1717
import os
18+
import re
1819
import subprocess
1920
import warnings
2021

2122

2223
CURRENT_DIR = os.path.realpath(os.path.dirname(__file__))
2324
BASE_DIR = os.path.realpath(os.path.join(CURRENT_DIR, '..', '..'))
2425
GITHUB_REPO = os.environ.get('GITHUB_REPO', 'google-cloud-python')
26+
CIRCLE_TAG = os.environ.get('CIRCLE_TAG')
27+
# NOTE: This reg-ex is copied from ``get_tagged_packages``.
28+
TAG_RE = re.compile(r"""
29+
^
30+
(?P<pkg>
31+
(([a-z]+)-)*) # pkg-name-with-hyphens- (empty allowed)
32+
([0-9]+)\.([0-9]+)\.([0-9]+) # Version x.y.z (x, y, z all ints)
33+
$
34+
""", re.VERBOSE)
2535

2636
# This is the current set of dependencies by package.
2737
# As of this writing, the only "real" dependency is that of error_reporting
@@ -143,7 +153,42 @@ def get_changed_packages(file_list):
143153
return answer
144154

145155

156+
def get_tagged_package():
157+
"""Return the package corresponding to the current tag.
158+
159+
If there is not tag, will return :data:`None`.
160+
"""
161+
if CIRCLE_TAG is None:
162+
return
163+
164+
match = TAG_RE.match(CIRCLE_TAG)
165+
if match is None:
166+
return
167+
168+
pkg_name = match.group('pkg')
169+
if pkg_name == '':
170+
# NOTE: This corresponds to the "umbrella" tag.
171+
return
172+
173+
return pkg_name.rstrip('-').replace('-', '_')
174+
175+
176+
def get_target_packages():
177+
"""Return a list of target packages to be run in the current build.
178+
179+
If in a tag build, will run only the package(s) that are tagged, otherwise
180+
will run the packages that have file changes in them (or packages that
181+
depend on those).
182+
"""
183+
tagged_package = get_tagged_package()
184+
if tagged_package is None:
185+
file_list = get_changed_files()
186+
for package in sorted(get_changed_packages(file_list)):
187+
yield package
188+
else:
189+
yield tagged_package
190+
191+
146192
if __name__ == '__main__':
147-
file_list = get_changed_files()
148-
for package in sorted(get_changed_packages(file_list)):
193+
for package in get_target_packages():
149194
print(package)

0 commit comments

Comments
 (0)