From e942e294f0a700cdc2f94bb7f967c2e9bcb1a271 Mon Sep 17 00:00:00 2001 From: "Colin P. Mccabe" Date: Mon, 4 Feb 2019 14:27:50 -0800 Subject: [PATCH] MINOR: release.py: fix some compatibility problems. Rather than using sed, use built-in Python regular expressions to strip the SNAPSHOT expression from the pom.xml files. Sed has different flags on different platforms, such as Linux. Using Python directly here is more compatible, as well as being more efficient, and not requiring an rm command afterwards. When running release_notes.py, use the current Python interpreter. This is needed to prevent attempting to run release_notes.py with Python 3 on some systems. release_notes.py will not (yet) work with Python 3. Author: Colin P. Mccabe Reviewers: Magnus Edenhill , David Arthur , Manikumar Reddy Closes #6198 from cmccabe/release_py --- release.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/release.py b/release.py index eecbebeba82..b22597640cd 100755 --- a/release.py +++ b/release.py @@ -141,6 +141,16 @@ def replace(path, pattern, replacement): for line in updated: f.write(line) +def regexReplace(path, pattern, replacement): + updated = [] + with open(path, 'r') as f: + for line in f: + updated.append(re.sub(pattern, replacement, line)) + + with open(path, 'w') as f: + for line in updated: + f.write(line) + def user_ok(msg): ok = raw_input(msg) return ok.lower() == 'y' @@ -522,12 +532,17 @@ cmd("Checking out current development branch", "git checkout -b %s %s" % (releas print("Updating version numbers") replace("gradle.properties", "version", "version=%s" % release_version) replace("tests/kafkatest/__init__.py", "__version__", "__version__ = '%s'" % release_version) -cmd("update streams quickstart pom", ["sed", "-i", ".orig"," s/-SNAPSHOT//", "streams/quickstart/pom.xml"]) -cmd("update streams quickstart java pom", ["sed", "-i", ".orig", "s/-SNAPSHOT//", "streams/quickstart/java/pom.xml"]) -cmd("update streams quickstart java pom", ["sed", "-i", ".orig", "s/-SNAPSHOT//", "streams/quickstart/java/src/main/resources/archetype-resources/pom.xml"]) -cmd("remove backup pom.xml", "rm streams/quickstart/pom.xml.orig") -cmd("remove backup java pom.xml", "rm streams/quickstart/java/pom.xml.orig") -cmd("remove backup java pom.xml", "rm streams/quickstart/java/src/main/resources/archetype-resources/pom.xml.orig") +print("updating streams quickstart pom") +regexReplace("streams/quickstart/pom.xml", "-SNAPSHOT", "") +print("updating streams quickstart java pom") +regexReplace("streams/quickstart/java/pom.xml", "-SNAPSHOT", "") +print("updating streams quickstart archetype pom") +regexReplace("streams/quickstart/java/src/main/resources/archetype-resources/pom.xml", "-SNAPSHOT", "") +print("updating ducktape version.py") +regexReplace("./tests/kafkatest/version.py", "^DEV_VERSION =.*", + "DEV_VERSION = KafkaVersion(\"%s-SNAPSHOT\")" % release_version) +print("updating ducktape __init__.py") +regexReplace("./tests/kafkatest/__init__.py", ".dev.*", "") # Command in explicit list due to messages with spaces cmd("Committing version number updates", ["git", "commit", "-a", "-m", "Bump version to %s" % release_version]) # Command in explicit list due to messages with spaces @@ -555,7 +570,7 @@ cmd("Verifying the correct year in NOTICE", "grep %s NOTICE" % current_year, cwd with open(os.path.join(artifacts_dir, "RELEASE_NOTES.html"), 'w') as f: print("Generating release notes") try: - subprocess.check_call(["./release_notes.py", release_version], stdout=f) + subprocess.check_call([sys.executable, "./release_notes.py", release_version], stdout=f) except subprocess.CalledProcessError as e: print_output(e.output)