2323
2424common = gcp .CommonTemplates ()
2525
26- # This is a customized version of the s.get_staging_dirs() function from synthtool to
27- # cater for copying 3 different folders from googleapis-gen
28- # which are spanner, spanner/admin/instance and spanner/admin/database.
29- # Source https://github.com/googleapis/synthtool/blob/master/synthtool/transforms.py#L280
26+
3027def get_staging_dirs (
31- default_version : Optional [str ] = None , sub_directory : Optional [str ] = None
28+ # This is a customized version of the s.get_staging_dirs() function
29+ # from synthtool to # cater for copying 3 different folders from
30+ # googleapis-gen:
31+ # spanner, spanner/admin/instance and spanner/admin/database.
32+ # Source:
33+ # https://github.com/googleapis/synthtool/blob/master/synthtool/transforms.py#L280
34+ default_version : Optional [str ] = None ,
35+ sub_directory : Optional [str ] = None ,
3236) -> List [Path ]:
3337 """Returns the list of directories, one per version, copied from
3438 https://github.com/googleapis/googleapis-gen. Will return in lexical sorting
@@ -63,46 +67,69 @@ def get_staging_dirs(
6367 else :
6468 return []
6569
70+
6671spanner_default_version = "v1"
6772spanner_admin_instance_default_version = "v1"
6873spanner_admin_database_default_version = "v1"
6974
7075for library in get_staging_dirs (spanner_default_version , "spanner" ):
7176 # Work around gapic generator bug https://github.com/googleapis/gapic-generator-python/issues/902
72- s .replace (library / f"google/cloud/spanner_{ library .name } /types/transaction.py" ,
73- r""".
77+ s .replace (
78+ library / f"google/cloud/spanner_{ library .name } /types/transaction.py" ,
79+ r""".
7480 Attributes:""" ,
75- r""".\n
81+ r""".\n
7682 Attributes:""" ,
7783 )
7884
7985 # Work around gapic generator bug https://github.com/googleapis/gapic-generator-python/issues/902
80- s .replace (library / f"google/cloud/spanner_{ library .name } /types/transaction.py" ,
81- r""".
86+ s .replace (
87+ library / f"google/cloud/spanner_{ library .name } /types/transaction.py" ,
88+ r""".
8289 Attributes:""" ,
83- r""".\n
90+ r""".\n
8491 Attributes:""" ,
8592 )
8693
8794 # Remove headings from docstring. Requested change upstream in cl/377290854 due to https://google.aip.dev/192#formatting.
88- s .replace (library / f"google/cloud/spanner_{ library .name } /types/transaction.py" ,
95+ s .replace (
96+ library / f"google/cloud/spanner_{ library .name } /types/transaction.py" ,
8997 """\n ==.*?==\n """ ,
9098 ":" ,
9199 )
92100
93101 # Remove headings from docstring. Requested change upstream in cl/377290854 due to https://google.aip.dev/192#formatting.
94- s .replace (library / f"google/cloud/spanner_{ library .name } /types/transaction.py" ,
102+ s .replace (
103+ library / f"google/cloud/spanner_{ library .name } /types/transaction.py" ,
95104 """\n --.*?--\n """ ,
96105 ":" ,
97106 )
98107
99- s .move (library , excludes = ["google/cloud/spanner/**" , "*.*" , "docs/index.rst" , "google/cloud/spanner_v1/__init__.py" ])
108+ s .move (
109+ library ,
110+ excludes = [
111+ "google/cloud/spanner/**" ,
112+ "*.*" ,
113+ "docs/index.rst" ,
114+ "google/cloud/spanner_v1/__init__.py" ,
115+ ],
116+ )
100117
101- for library in get_staging_dirs (spanner_admin_instance_default_version , "spanner_admin_instance" ):
102- s .move (library , excludes = ["google/cloud/spanner_admin_instance/**" , "*.*" , "docs/index.rst" ])
118+ for library in get_staging_dirs (
119+ spanner_admin_instance_default_version , "spanner_admin_instance"
120+ ):
121+ s .move (
122+ library ,
123+ excludes = ["google/cloud/spanner_admin_instance/**" , "*.*" , "docs/index.rst" ],
124+ )
103125
104- for library in get_staging_dirs (spanner_admin_database_default_version , "spanner_admin_database" ):
105- s .move (library , excludes = ["google/cloud/spanner_admin_database/**" , "*.*" , "docs/index.rst" ])
126+ for library in get_staging_dirs (
127+ spanner_admin_database_default_version , "spanner_admin_database"
128+ ):
129+ s .move (
130+ library ,
131+ excludes = ["google/cloud/spanner_admin_database/**" , "*.*" , "docs/index.rst" ],
132+ )
106133
107134s .remove_staging_dirs ()
108135
@@ -116,9 +143,11 @@ def get_staging_dirs(
116143s .replace (
117144 ".kokoro/build.sh" ,
118145 "# Remove old nox" ,
119- "# Set up creating a new instance for each system test run\n "
120- "export GOOGLE_CLOUD_TESTS_CREATE_SPANNER_INSTANCE=true\n "
121- "\n \g<0>" ,
146+ """\
147+ # Set up creating a new instance for each system test run
148+ export GOOGLE_CLOUD_TESTS_CREATE_SPANNER_INSTANCE=true
149+
150+ # Remove old nox""" ,
122151)
123152
124153# Update samples folder in CONTRIBUTING.rst
@@ -134,15 +163,21 @@ def get_staging_dirs(
134163# Customize noxfile.py
135164# ----------------------------------------------------------------------------
136165
166+
137167def place_before (path , text , * before_text , escape = None ):
138168 replacement = "\n " .join (before_text ) + "\n " + text
139169 if escape :
140170 for c in escape :
141- text = text .replace (c , ' \\ ' + c )
171+ text = text .replace (c , " \\ " + c )
142172 s .replace ([path ], text , replacement )
143173
174+
144175open_telemetry_test = """
176+ # XXX Work around Kokoro image's older pip, which borks the OT install.
177+ session.run("pip", "install", "--upgrade", "pip")
145178 session.install("-e", ".[tracing]", "-c", constraints_path)
179+ # XXX: Dump installed versions to debug OT issue
180+ session.run("pip", "list")
146181
147182 # Run py.test against the unit tests with OpenTelemetry.
148183 session.run(
@@ -164,10 +199,10 @@ def place_before(path, text, *before_text, escape=None):
164199 "noxfile.py" ,
165200 "@nox.session(python=UNIT_TEST_PYTHON_VERSIONS)" ,
166201 open_telemetry_test ,
167- escape = "()"
202+ escape = "()" ,
168203)
169204
170- skip_tests_if_env_var_not_set = """# Sanity check: Only run tests if the environment variable is set.
205+ skip_tests_if_env_var_not_set = """# Sanity check: Only run tests if the environment variable is set.
171206 if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", "") and not os.environ.get(
172207 "SPANNER_EMULATOR_HOST", ""
173208 ):
@@ -180,7 +215,7 @@ def place_before(path, text, *before_text, escape=None):
180215 "noxfile.py" ,
181216 "# Install pyopenssl for mTLS testing." ,
182217 skip_tests_if_env_var_not_set ,
183- escape = "()"
218+ escape = "()" ,
184219)
185220
186221s .replace (
@@ -190,25 +225,25 @@ def place_before(path, text, *before_text, escape=None):
190225 "--cov=tests/unit",""" ,
191226 """\" --cov=google.cloud.spanner",
192227 "--cov=google.cloud",
193- "--cov=tests.unit","""
228+ "--cov=tests.unit",""" ,
194229)
195230
196231s .replace (
197232 "noxfile.py" ,
198- """session.install\("-e", "."\)""" ,
199- """session.install("-e", ".[tracing]")"""
233+ r """session.install\("-e", "."\)""" ,
234+ """session.install("-e", ".[tracing]")""" ,
200235)
201236
202237s .replace (
203238 "noxfile.py" ,
204- """# Install all test dependencies, then install this package into the
239+ r """# Install all test dependencies, then install this package into the
205240 # virtualenv's dist-packages.
206241 session.install\("mock", "pytest", "google-cloud-testutils", "-c", constraints_path\)
207242 session.install\("-e", ".", "-c", constraints_path\)""" ,
208243 """# Install all test dependencies, then install this package into the
209244 # virtualenv's dist-packages.
210245 session.install("mock", "pytest", "google-cloud-testutils", "-c", constraints_path)
211- session.install("-e", ".[tracing]", "-c", constraints_path)"""
246+ session.install("-e", ".[tracing]", "-c", constraints_path)""" ,
212247)
213248
214249s .shell .run (["nox" , "-s" , "blacken" ], hide_output = False )
0 commit comments