Skip to content

Commit 6702a34

Browse files
authored
chore(python): remove configure_previous_major_version_branches (#2137)
chore(python): remove configure_previous_major_version_branches from python post processor
1 parent 5865ee7 commit 6702a34

2 files changed

Lines changed: 0 additions & 98 deletions

File tree

synthtool/languages/python.py

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import re
1615
import sys
1716

1817
import json
@@ -129,64 +128,6 @@ def py_samples(
129128
s.copy([result], excludes=excludes)
130129

131130

132-
def configure_previous_major_version_branches() -> None:
133-
"""Configure releases from previous major version branches by editing
134-
`.github/release-please.yml`.
135-
136-
The current library version is obtained from `version.py` in `google/**/version.py`,
137-
or the `setup.py`.
138-
139-
Releases are configured for all previous major versions. For example,
140-
if the library version is currently 3.5.1, the release-please config
141-
will include v2, v1, and v0.
142-
"""
143-
144-
# In version.py: __version__ = "1.5.2"
145-
# In setup.py: version = "1.5.2"
146-
VERSION_REGEX = (
147-
r"(?:__)?version(?:__)?\s*=\s*[\"'](?P<major_version>\d)\.[\d\.]+[\"']"
148-
)
149-
version_paths = list(Path(".").glob("google/**/version.py")) + [Path("setup.py")]
150-
151-
major_version = None
152-
153-
for p in version_paths:
154-
match = re.search(VERSION_REGEX, Path(p).read_text())
155-
156-
if match is not None:
157-
major_version = int(match.group("major_version"))
158-
break
159-
160-
if major_version is None:
161-
raise RuntimeError(
162-
"Unable to find library version in files {} with regex {}".format(
163-
version_paths, VERSION_REGEX
164-
)
165-
)
166-
167-
with open(".github/release-please.yml") as f:
168-
release_please_yml = yaml.load(f, Loader=yaml.SafeLoader)
169-
170-
if major_version > 0 and "branches" not in release_please_yml:
171-
branches = []
172-
for version in range(major_version - 1, -1, -1):
173-
branches.append(
174-
{
175-
"branch": f"v{version}",
176-
"handleGHRelease": True,
177-
"releaseType": "python",
178-
}
179-
)
180-
181-
with open(".github/release-please.yml", "a") as f:
182-
# comments can't be expressed in PyYAML
183-
f.write(
184-
"""# NOTE: this section is generated by synthtool.languages.python
185-
# See https://github.com/googleapis/synthtool/blob/master/synthtool/languages/python.py\n"""
186-
)
187-
f.write(yaml.dump({"branches": branches}))
188-
189-
190131
def owlbot_main() -> None:
191132
"""Copies files from staging and template directories into current working dir.
192133
@@ -241,8 +182,6 @@ def owlbot_main() -> None:
241182
for noxfile in Path(".").glob("**/noxfile.py"):
242183
s.shell.run(["nox", "-s", "format"], cwd=noxfile.parent, hide_output=False)
243184

244-
configure_previous_major_version_branches()
245-
246185

247186
if __name__ == "__main__":
248187
owlbot_main()

tests/test_python_library.py

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

1515
import os
16-
import shutil
1716
from pathlib import Path
1817
import yaml
1918

2019
import pytest
2120

2221
from synthtool import gcp
2322
from synthtool.sources import templates
24-
from synthtool.languages import python
2523
from . import util
2624

2725

@@ -140,38 +138,3 @@ def test_split_system_tests():
140138
with open(templated_files / ".kokoro/presubmit/system-3.8.cfg", "r") as f:
141139
contents = f.read()
142140
assert "system-3.8" in contents
143-
144-
145-
@pytest.mark.parametrize(
146-
"fixtures_dir",
147-
[
148-
Path(__file__).parent / "fixtures/python_library", # just setup.py
149-
Path(__file__).parent
150-
/ "fixtures/python_library_w_version_py", # has google/cloud/texttospeech/version.py
151-
],
152-
)
153-
def test_configure_previous_major_version_branches(fixtures_dir):
154-
with util.copied_fixtures_dir(fixtures_dir):
155-
t = templates.Templates(PYTHON_LIBRARY)
156-
result = t.render(".github/release-please.yml")
157-
os.makedirs(".github")
158-
shutil.copy(result, Path(".github/release-please.yml"))
159-
160-
python.configure_previous_major_version_branches()
161-
release_please_yml = Path(".github/release-please.yml").read_text()
162-
163-
assert (
164-
release_please_yml
165-
== """releaseType: python
166-
handleGHRelease: true
167-
# NOTE: this section is generated by synthtool.languages.python
168-
# See https://github.com/googleapis/synthtool/blob/master/synthtool/languages/python.py
169-
branches:
170-
- branch: v1
171-
handleGHRelease: true
172-
releaseType: python
173-
- branch: v0
174-
handleGHRelease: true
175-
releaseType: python
176-
"""
177-
)

0 commit comments

Comments
 (0)