Skip to content

Commit c1dd87e

Browse files
authored
chore(python): configure release-please on previous major versions (#1369)
1 parent 02193e4 commit c1dd87e

File tree

7 files changed

+332
-0
lines changed

7 files changed

+332
-0
lines changed

blargh.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bumpMinorPreMajor: true
2+
handleGHRelease: true
3+
releaseType: java-yoshi
4+
branches:
5+
- handleGHRelease: true
6+
releaseType: python
7+
branch: java7

synthtool/languages/python.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,62 @@ def py_samples(*, root: PathOrStr = None, skip_readmes: bool = False) -> None:
148148
s.copy([result], excludes=excludes)
149149

150150

151+
def configure_previous_major_version_branches() -> None:
152+
"""Configure releases from previous major version branches by editing
153+
`.github/release-please.yml`.
154+
155+
The current library version is obtained from `version.py` in `google/**/version.py`,
156+
or the `setup.py`.
157+
158+
Releases are configured for all previous major versions. For example,
159+
if the library version is currently 3.5.1, the release-please config
160+
will include v2, v1, and v0.
161+
"""
162+
if list(Path(".").glob("google/**/version.py")):
163+
version_file = list(Path(".").glob("google/**/version.py"))[0]
164+
else:
165+
version_file = Path("setup.py")
166+
167+
# In version.py: __version__ = "1.5.2"
168+
# In setup.py: version = "1.5.2"
169+
VERSION_REGEX = (
170+
r"(?:__)?version(?:__)?\s*=\s*[\"'](?P<major_version>\d)\.[\d\.]+[\"']"
171+
)
172+
173+
match = re.search(VERSION_REGEX, Path(version_file).read_text())
174+
175+
if match is not None:
176+
major_version = int(match.group("major_version"))
177+
else:
178+
raise RuntimeError(
179+
"Unable to find library version in {} with regex {}".format(
180+
version_file, VERSION_REGEX
181+
)
182+
)
183+
184+
with open(".github/release-please.yml") as f:
185+
release_please_yml = yaml.load(f, Loader=yaml.SafeLoader)
186+
187+
if major_version > 0 and "branches" not in release_please_yml:
188+
branches = []
189+
for version in range(major_version - 1, -1, -1):
190+
branches.append(
191+
{
192+
"branch": f"v{version}",
193+
"handleGHRelease": True,
194+
"releaseType": "python",
195+
}
196+
)
197+
198+
with open(".github/release-please.yml", "a") as f:
199+
# comments can't be expressed in PyYAML
200+
f.write(
201+
"""# NOTE: this section is generated by synthtool.languages.python
202+
# See https://github.com/googleapis/synthtool/blob/master/synthtool/languages/python.py\n"""
203+
)
204+
f.write(yaml.dump({"branches": branches}))
205+
206+
151207
def owlbot_main() -> None:
152208
"""Copies files from staging and template directories into current working dir.
153209
@@ -202,6 +258,8 @@ def owlbot_main() -> None:
202258
for noxfile in Path(".").glob("**/noxfile.py"):
203259
s.shell.run(["nox", "-s", "blacken"], cwd=noxfile.parent, hide_output=False)
204260

261+
configure_previous_major_version_branches()
262+
205263

206264
if __name__ == "__main__":
207265
owlbot_main()
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# Copyright 2018 Google LLC
15+
#
16+
# Licensed under the Apache License, Version 2.0 (the "License");
17+
# you may not use this file except in compliance with the License.
18+
# You may obtain a copy of the License at
19+
#
20+
# http://www.apache.org/licenses/LICENSE-2.0
21+
#
22+
# Unless required by applicable law or agreed to in writing, software
23+
# distributed under the License is distributed on an "AS IS" BASIS,
24+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25+
# See the License for the specific language governing permissions and
26+
# limitations under the License.
27+
28+
import io
29+
import os
30+
31+
import setuptools
32+
33+
34+
# Package metadata.
35+
36+
name = "google-cloud-texttospeech"
37+
description = "Google Cloud Text-to-Speech API client library"
38+
version = "2.11.0"
39+
# Should be one of:
40+
# 'Development Status :: 3 - Alpha'
41+
# 'Development Status :: 4 - Beta'
42+
# 'Development Status :: 5 - Production/Stable'
43+
release_status = "Development Status :: 5 - Production/Stable"
44+
dependencies = [
45+
# NOTE: Maintainers, please do not require google-api-core>=2.x.x
46+
# Until this issue is closed
47+
# https://github.com/googleapis/google-cloud-python/issues/10566
48+
"google-api-core[grpc] >= 1.31.5, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0",
49+
"proto-plus >= 1.15.0",
50+
]
51+
extras = {}
52+
53+
54+
# Setup boilerplate below this line.
55+
56+
package_root = os.path.abspath(os.path.dirname(__file__))
57+
58+
readme_filename = os.path.join(package_root, "README.rst")
59+
with io.open(readme_filename, encoding="utf-8") as readme_file:
60+
readme = readme_file.read()
61+
62+
# Only include packages under the 'google' namespace. Do not include tests,
63+
# benchmarks, etc.
64+
packages = [
65+
package
66+
for package in setuptools.PEP420PackageFinder.find()
67+
if package.startswith("google")
68+
]
69+
70+
# Determine which namespaces are needed.
71+
namespaces = ["google"]
72+
if "google.cloud" in packages:
73+
namespaces.append("google.cloud")
74+
75+
76+
setuptools.setup(
77+
name=name,
78+
version=version,
79+
description=description,
80+
long_description=readme,
81+
author="Google LLC",
82+
author_email="[email protected]",
83+
license="Apache 2.0",
84+
url="https://github.com/googleapis/python-texttospeech",
85+
classifiers=[
86+
release_status,
87+
"Intended Audience :: Developers",
88+
"License :: OSI Approved :: Apache Software License",
89+
"Programming Language :: Python",
90+
"Programming Language :: Python :: 3",
91+
"Programming Language :: Python :: 3.6",
92+
"Programming Language :: Python :: 3.7",
93+
"Programming Language :: Python :: 3.8",
94+
"Programming Language :: Python :: 3.9",
95+
"Programming Language :: Python :: 3.10",
96+
"Operating System :: OS Independent",
97+
"Topic :: Internet",
98+
],
99+
platforms="Posix; MacOS X; Windows",
100+
packages=packages,
101+
namespace_packages=namespaces,
102+
install_requires=dependencies,
103+
extras_require=extras,
104+
python_requires=">=3.6",
105+
scripts=["scripts/fixup_keywords.py"],
106+
include_package_data=True,
107+
zip_safe=False,
108+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "texttospeech",
3+
"name_pretty": "Google Cloud Text-to-Speech",
4+
"product_documentation": "https://cloud.google.com/text-to-speech",
5+
"client_documentation": "https://googleapis.dev/python/texttospeech/latest",
6+
"issue_tracker": "https://issuetracker.google.com/savedsearches/5235428",
7+
"release_level": "ga",
8+
"language": "python",
9+
"repo": "googleapis/python-texttospeech",
10+
"distribution_name": "google-cloud-texttospeech",
11+
"api_id": "texttospeech.googleapis.com",
12+
"requires_billing": true
13+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "2.11.0"
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# Copyright 2018 Google LLC
15+
#
16+
# Licensed under the Apache License, Version 2.0 (the "License");
17+
# you may not use this file except in compliance with the License.
18+
# You may obtain a copy of the License at
19+
#
20+
# http://www.apache.org/licenses/LICENSE-2.0
21+
#
22+
# Unless required by applicable law or agreed to in writing, software
23+
# distributed under the License is distributed on an "AS IS" BASIS,
24+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25+
# See the License for the specific language governing permissions and
26+
# limitations under the License.
27+
28+
import io
29+
import os
30+
31+
import setuptools
32+
33+
34+
# Package metadata.
35+
36+
name = "google-cloud-texttospeech"
37+
description = "Google Cloud Text-to-Speech API client library"
38+
version = "2.11.0"
39+
# Should be one of:
40+
# 'Development Status :: 3 - Alpha'
41+
# 'Development Status :: 4 - Beta'
42+
# 'Development Status :: 5 - Production/Stable'
43+
release_status = "Development Status :: 5 - Production/Stable"
44+
dependencies = [
45+
# NOTE: Maintainers, please do not require google-api-core>=2.x.x
46+
# Until this issue is closed
47+
# https://github.com/googleapis/google-cloud-python/issues/10566
48+
"google-api-core[grpc] >= 1.31.5, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0",
49+
"proto-plus >= 1.15.0",
50+
]
51+
extras = {}
52+
53+
54+
# Setup boilerplate below this line.
55+
56+
package_root = os.path.abspath(os.path.dirname(__file__))
57+
58+
readme_filename = os.path.join(package_root, "README.rst")
59+
with io.open(readme_filename, encoding="utf-8") as readme_file:
60+
readme = readme_file.read()
61+
62+
# Only include packages under the 'google' namespace. Do not include tests,
63+
# benchmarks, etc.
64+
packages = [
65+
package
66+
for package in setuptools.PEP420PackageFinder.find()
67+
if package.startswith("google")
68+
]
69+
70+
# Determine which namespaces are needed.
71+
namespaces = ["google"]
72+
if "google.cloud" in packages:
73+
namespaces.append("google.cloud")
74+
75+
76+
setuptools.setup(
77+
name=name,
78+
version=version,
79+
description=description,
80+
long_description=readme,
81+
author="Google LLC",
82+
author_email="[email protected]",
83+
license="Apache 2.0",
84+
url="https://github.com/googleapis/python-texttospeech",
85+
classifiers=[
86+
release_status,
87+
"Intended Audience :: Developers",
88+
"License :: OSI Approved :: Apache Software License",
89+
"Programming Language :: Python",
90+
"Programming Language :: Python :: 3",
91+
"Programming Language :: Python :: 3.6",
92+
"Programming Language :: Python :: 3.7",
93+
"Programming Language :: Python :: 3.8",
94+
"Programming Language :: Python :: 3.9",
95+
"Programming Language :: Python :: 3.10",
96+
"Operating System :: OS Independent",
97+
"Topic :: Internet",
98+
],
99+
platforms="Posix; MacOS X; Windows",
100+
packages=packages,
101+
namespace_packages=namespaces,
102+
install_requires=dependencies,
103+
extras_require=extras,
104+
python_requires=">=3.6",
105+
scripts=["scripts/fixup_keywords.py"],
106+
include_package_data=True,
107+
zip_safe=False,
108+
)

tests/test_python_library.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
# limitations under the License.
1414

1515
import os
16+
import shutil
1617
from pathlib import Path
1718

1819
import pytest
1920

2021
from synthtool import gcp
2122
from synthtool.sources import templates
23+
from synthtool.languages import python
2224
from . import util
2325

2426

@@ -126,3 +128,38 @@ def test_split_system_tests():
126128
with open(templated_files / ".kokoro/presubmit/system-3.8.cfg", "r") as f:
127129
contents = f.read()
128130
assert "system-3.8" in contents
131+
132+
133+
@pytest.mark.parametrize(
134+
"fixtures_dir",
135+
[
136+
Path(__file__).parent / "fixtures/python_library", # just setup.py
137+
Path(__file__).parent
138+
/ "fixtures/python_library_w_version_py", # has google/cloud/texttospeech/version.py
139+
],
140+
)
141+
def test_configure_previous_major_version_branches(fixtures_dir):
142+
with util.copied_fixtures_dir(fixtures_dir):
143+
t = templates.Templates(PYTHON_LIBRARY)
144+
result = t.render(".github/release-please.yml")
145+
os.makedirs(".github")
146+
shutil.copy(result, Path(".github/release-please.yml"))
147+
148+
python.configure_previous_major_version_branches()
149+
release_please_yml = Path(".github/release-please.yml").read_text()
150+
151+
assert (
152+
release_please_yml
153+
== """releaseType: python
154+
handleGHRelease: true
155+
# NOTE: this section is generated by synthtool.languages.python
156+
# See https://github.com/googleapis/synthtool/blob/master/synthtool/languages/python.py
157+
branches:
158+
- branch: v1
159+
handleGHRelease: true
160+
releaseType: python
161+
- branch: v0
162+
handleGHRelease: true
163+
releaseType: python
164+
"""
165+
)

0 commit comments

Comments
 (0)