Skip to content

Commit 4654ccc

Browse files
authored
chore: move version to gapic_version.py (#537)
* chore: move version to gapic_version.py * customize testing/constraints-3.7.txt * set coverage level to 98%
1 parent 2ab3fee commit 4654ccc

File tree

14 files changed

+139
-3040
lines changed

14 files changed

+139
-3040
lines changed

packages/google-cloud-bigquery-storage/.github/release-please.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
releaseType: python
22
handleGHRelease: true
3+
manifest: true
34
# NOTE: this section is generated by synthtool.languages.python
45
# See https://github.com/googleapis/synthtool/blob/master/synthtool/languages/python.py
56
branches:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
".": "2.16.2"
3+
}
4+

packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
)
2828

2929
from google.cloud.bigquery_storage_v1 import gapic_types as types
30-
from google.cloud.bigquery_storage_v1 import __version__
3130
from google.cloud.bigquery_storage_v1.types.arrow import ArrowRecordBatch
3231
from google.cloud.bigquery_storage_v1.types.arrow import ArrowSchema
3332
from google.cloud.bigquery_storage_v1.types.arrow import ArrowSerializationOptions

packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage/gapic_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "0.1.0"
16+
__version__ = "2.16.2" # {x-release-please-version}

packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616

1717
from __future__ import absolute_import
1818

19-
import pkg_resources
19+
from google.cloud.bigquery_storage_v1 import gapic_version as package_version
2020

21-
__version__ = pkg_resources.get_distribution(
22-
"google-cloud-bigquery-storage"
23-
).version # noqa
21+
__version__ = package_version.__version__
2422

2523
from google.cloud.bigquery_storage_v1 import client
2624
from google.cloud.bigquery_storage_v1 import types
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2022 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
__version__ = "2.16.2" # {x-release-please-version}

packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1beta2/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616

1717
from __future__ import absolute_import
1818

19-
import pkg_resources
19+
from google.cloud.bigquery_storage_v1beta2 import gapic_version as package_version
2020

21-
__version__ = pkg_resources.get_distribution(
22-
"google-cloud-bigquery-storage"
23-
).version # noqa
21+
__version__ = package_version.__version__
2422

2523
from google.cloud.bigquery_storage_v1beta2 import client
2624
from google.cloud.bigquery_storage_v1beta2 import types
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2022 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
__version__ = "2.16.2" # {x-release-please-version}
Lines changed: 36 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2018 Google LLC
1+
# Copyright 2022 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -12,25 +12,27 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""This script is used to synthesize generated parts of this library."""
15+
import json
16+
from pathlib import Path
17+
import shutil
1618

1719
import synthtool as s
18-
from synthtool import gcp
20+
import synthtool.gcp as gcp
1921
from synthtool.languages import python
2022

21-
common = gcp.CommonTemplates()
23+
# ----------------------------------------------------------------------------
24+
# Copy the generated client from the owl-bot staging directory
25+
# ----------------------------------------------------------------------------
2226

23-
default_version = "v1"
27+
clean_up_generated_samples = True
28+
29+
# Load the default version defined in .repo-metadata.json.
30+
default_version = json.load(open(".repo-metadata.json", "rt")).get("default_version")
2431

2532
for library in s.get_staging_dirs(default_version):
26-
# Work around gapic generator bug https://github.com/googleapis/gapic-generator-python/issues/902
27-
s.replace(
28-
library / f"google/cloud/bigquery_storage_{library.name}/types/arrow.py",
29-
r""".
30-
Attributes:""",
31-
r""".\n
32-
Attributes:""",
33-
)
33+
if clean_up_generated_samples:
34+
shutil.rmtree("samples/generated_samples", ignore_errors=True)
35+
clean_up_generated_samples = False
3436

3537
# We don't want the generated client to be accessible through
3638
# "google.cloud.bigquery_storage", replace it with the hand written client that
@@ -57,30 +59,20 @@
5759
"",
5860
)
5961

60-
# We want types and __version__ to be accessible through the "main" library
61-
# entry point.
62-
s.replace(
63-
library / "google/cloud/bigquery_storage/__init__.py",
64-
f"from google\\.cloud\\.bigquery_storage_{library.name}\\.types\\.arrow import ArrowRecordBatch",
65-
(
66-
f"from google.cloud.bigquery_storage_{library.name} import types\n"
67-
f"from google.cloud.bigquery_storage_{library.name} import __version__\n"
68-
"\\g<0>"
69-
),
70-
)
7162
s.replace(
7263
library / "google/cloud/bigquery_storage/__init__.py",
7364
r"""["']ArrowRecordBatch["']""",
7465
('"__version__",\n' ' "types",\n' " \\g<0>"),
7566
)
7667

77-
# We want to expose all types through "google.cloud.bigquery_storage.types",
78-
# not just the types generated for the BQ Storage library. For example, we also
79-
# want to include common proto types such as Timestamp.
68+
# We want types to be accessible through the "main" library
8069
s.replace(
8170
library / "google/cloud/bigquery_storage/__init__.py",
82-
r"import types",
83-
"import gapic_types as types",
71+
f"from google\\.cloud\\.bigquery_storage_{library.name}\\.types\\.arrow import ArrowRecordBatch",
72+
(
73+
f"from google.cloud.bigquery_storage_{library.name} import gapic_types as types\n"
74+
"\\g<0>"
75+
),
8476
)
8577

8678
# The DataFormat enum is not exposed in bigquery_storage_v1/types, add it there.
@@ -95,59 +87,42 @@
9587
'"DataFormat",\n \\g<0>',
9688
)
9789

98-
# The append_rows method doesn't contain keyword arguments that build request
99-
# objects, so flattened tests are not needed and break with TypeError.
100-
s.replace(
101-
library
102-
/ f"tests/unit/gapic/bigquery_storage_{library.name}*/test_big_query_write.py",
103-
r"(@[a-z.()\n]*\n)?(async )?"
104-
r"def test_append_rows_flattened[_a-z]*\(\):\n"
105-
r"( {4}.*|\n)+",
106-
"\n",
107-
)
108-
10990
s.move(
110-
library,
91+
[library],
11192
excludes=[
112-
"bigquery-storage-*-py.tar.gz",
113-
"docs/conf.py",
114-
"docs/index.rst",
93+
"setup.py",
11594
f"google/cloud/bigquery_storage_{library.name}/__init__.py",
11695
# v1beta2 was first generated after the microgenerator migration.
11796
"scripts/fixup_bigquery_storage_v1beta2_keywords.py",
118-
"README.rst",
119-
"nox*.py",
120-
"setup.py",
121-
"setup.cfg",
97+
"**/gapic_version.py",
98+
"docs/index.rst",
99+
"testing/constraints-3.7.txt",
122100
],
123101
)
124-
125102
s.remove_staging_dirs()
126103

127104
# ----------------------------------------------------------------------------
128105
# Add templated files
129106
# ----------------------------------------------------------------------------
107+
130108
extras = ["fastavro", "pandas", "pyarrow"]
131109
unit_test_extras = ["tests"] + extras
132110

133-
templated_files = common.py_library(
111+
templated_files = gcp.CommonTemplates().py_library(
112+
cov_level=98,
134113
microgenerator=True,
135-
samples=True,
136114
unit_test_extras=unit_test_extras,
137115
system_test_extras=extras,
138116
system_test_external_dependencies=["google-cloud-bigquery"],
139-
cov_level=98,
117+
versions=gcp.common.detect_versions(path="./google", default_first=True),
140118
)
141119
s.move(
142-
templated_files, excludes=[".coveragerc"]
143-
) # microgenerator has a good .coveragerc file
144-
145-
python.configure_previous_major_version_branches()
146-
147-
# ----------------------------------------------------------------------------
148-
# Samples templates
149-
# ----------------------------------------------------------------------------
120+
templated_files,
121+
excludes=[".coveragerc", ".github/release-please.yml", "docs/index.rst"],
122+
)
150123

151124
python.py_samples(skip_readmes=True)
152125

153-
s.shell.run(["nox", "-s", "blacken"], hide_output=False)
126+
# run format session for all directories which have a noxfile
127+
for noxfile in Path(".").glob("**/noxfile.py"):
128+
s.shell.run(["nox", "-s", "blacken"], cwd=noxfile.parent, hide_output=False)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
3+
"packages": {
4+
".": {
5+
"release-type": "python",
6+
"extra-files": [
7+
"google/cloud/bigquery_storage_v1/gapic_version.py",
8+
"google/cloud/bigquery_storage_v1beta2/gapic_version.py",
9+
"google/cloud/bigquery_storage/gapic_version.py",
10+
{
11+
"type": "json",
12+
"path": "samples/generated_samples/snippet_metadata_google.cloud.bigquery.storage.v1.json",
13+
"jsonpath": "$.clientLibrary.version"
14+
},
15+
{
16+
"type": "json",
17+
"path": "samples/generated_samples/snippet_metadata_google.cloud.bigquery.storage.v1beta2.json",
18+
"jsonpath": "$.clientLibrary.version"
19+
}
20+
]
21+
}
22+
},
23+
"release-type": "python",
24+
"plugins": [
25+
{
26+
"type": "sentence-case"
27+
}
28+
],
29+
"initial-version": "0.1.0"
30+
}
31+

0 commit comments

Comments
 (0)