This is an automated email from the ASF dual-hosted git repository. aw pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/yetus.git
The following commit(s) were added to refs/heads/main by this push: new d036f2ae YETUS-777. --version is broken in python programs (#277) d036f2ae is described below commit d036f2aeb166acfd0d97e0c1913ea3f445c345c8 Author: Allen Wittenauer <a...@apache.org> AuthorDate: Fri May 6 22:39:33 2022 -0700 YETUS-777. --version is broken in python programs (#277) --- precommit/src/main/python/jenkins-admin.py | 15 +++++++--- .../src/main/python/releasedocmaker/__init__.py | 11 +++++-- shelldocs/src/main/python/shelldocs.py | 35 +++++++++++++++++----- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/precommit/src/main/python/jenkins-admin.py b/precommit/src/main/python/jenkins-admin.py index f193adfe..dbe261a2 100755 --- a/precommit/src/main/python/jenkins-admin.py +++ b/precommit/src/main/python/jenkins-admin.py @@ -29,6 +29,7 @@ from argparse import ArgumentParser from tempfile import NamedTemporaryFile from xml.etree import ElementTree import os +import pathlib import re import sys import requests @@ -160,10 +161,16 @@ def main(): #pylint: disable=too-many-branches, too-many-statements, too-many-l # Handle the version string right away and exit if options.release_version: - with open( - os.path.join(os.path.dirname(__file__), "..", "..", - "VERSION")) as ver_file: - print(ver_file.read()) + execname = pathlib.Path(__file__) + binversion = execname.joinpath("..", "..", "VERSION").resolve() + mvnversion = execname.joinpath("..", "..", "..", "..", "..", ".mvn", + "maven.config").resolve() + if binversion.exists(): + with open(binversion, encoding='utf-8') as ver_file: + print(ver_file.read().strip()) + elif mvnversion.exists(): + with open(mvnversion, encoding='utf-8') as ver_file: + print(ver_file.read().split('=')[1].strip()) sys.exit(0) token_frag = '' diff --git a/releasedocmaker/src/main/python/releasedocmaker/__init__.py b/releasedocmaker/src/main/python/releasedocmaker/__init__.py index 588400f0..0a5043ec 100755 --- a/releasedocmaker/src/main/python/releasedocmaker/__init__.py +++ b/releasedocmaker/src/main/python/releasedocmaker/__init__.py @@ -112,12 +112,19 @@ def buildreadme(title, asf_license): def getversion(): """ print the version file""" basepath = pathlib.Path(__file__).parent.resolve() - for versionfile in [basepath.resolve().joinpath('VERSION'), - basepath.parent.parent.resolve().joinpath('VERSION')]: + for versionfile in [ + basepath.resolve().joinpath('VERSION'), + basepath.parent.parent.resolve().joinpath('VERSION') + ]: if versionfile.exists(): with open(versionfile, encoding='utf-8') as ver_file: version = ver_file.read() return version + mvnversion = basepath.parent.parent.parent.parent.parent.resolve( + ).joinpath('.mvn', 'maven.config') + if mvnversion.exists(): + with open(mvnversion, encoding='utf-8') as ver_file: + return ver_file.read().split('=')[1].strip() return 'Unknown' diff --git a/shelldocs/src/main/python/shelldocs.py b/shelldocs/src/main/python/shelldocs.py index 8bd9b3d0..0b8bfbe3 100755 --- a/shelldocs/src/main/python/shelldocs.py +++ b/shelldocs/src/main/python/shelldocs.py @@ -51,6 +51,7 @@ ASFLICENSE = ''' class ShellFunction: # pylint: disable=too-many-instance-attributes """a shell function""" + def __init__(self, filename='Unknown'): '''Initializer''' self.audience = '' @@ -128,8 +129,7 @@ class ShellFunction: # pylint: disable=too-many-instance-attributes elif value not in attrvalues: if attribute == 'replacerawtext' and value == '': continue - validvalue = "|".join(v.lower() - for v in attrvalues) + validvalue = "|".join(v.lower() for v in attrvalues) logging.error( "%s:%d:ERROR: function %s has invalid value (%s) for @%s (%s)", self.filename, self.linenum, self.name, value.lower(), @@ -162,7 +162,7 @@ class ProcessFile: Comparison is case sensitive and the comment must be in UPPERCASE. """ - with open(self.filename) as input_file: #pylint: disable=unspecified-encoding + with open(self.filename) as input_file: #pylint: disable=unspecified-encoding for line in input_file: if line.startswith( "#") and line[1:].strip() == "SHELLDOC-IGNORE": @@ -249,7 +249,7 @@ class ProcessFile: return try: - with open(self.filename, "r") as shellcode: #pylint: disable=unspecified-encoding + with open(self.filename, "r") as shellcode: #pylint: disable=unspecified-encoding # if the file contains a comment containing # only "SHELLDOC-IGNORE" then skip that file @@ -282,6 +282,7 @@ class ProcessFile: class MarkdownReport: ''' generate a markdown report ''' + def __init__(self, functions, filename=None): self.filename = filename self.filepath = pathlib.Path(self.filename) @@ -320,6 +321,7 @@ class MarkdownReport: def process_input(inputlist, skipprnorep): """ take the input and loop around it """ + def call_process_file(filename, skipsuperprivate): ''' handle building a ProcessFile ''' fileprocessor = ProcessFile(filename=filename, @@ -347,6 +349,26 @@ def process_input(inputlist, skipprnorep): return allfuncs +def getversion(): + """ print the version file""" + basepath = pathlib.Path(__file__).parent.resolve() + for versionfile in [ + basepath.resolve().joinpath('VERSION'), + basepath.parent.resolve().joinpath('VERSION') + ]: + if versionfile.exists(): + with open(versionfile, encoding='utf-8') as ver_file: + version = ver_file.read() + return version + mvnversion = basepath.parent.parent.parent.parent.resolve().joinpath( + '.mvn', 'maven.config') + if mvnversion.exists(): + with open(mvnversion, encoding='utf-8') as ver_file: + return ver_file.read().split('=')[1].strip() + + return 'Unknown' + + def process_arguments(): ''' deal with parameters ''' parser = ArgumentParser( @@ -387,9 +409,7 @@ def process_arguments(): options = parser.parse_args() if options.release_version: - verfile = pathlib.Path(__file__).parent.joinpath('VERSION') - with open(verfile, encoding='utf-8') as ver_file: - print(ver_file.read()) + print(getversion()) sys.exit(0) if options.infile is None: @@ -400,6 +420,7 @@ def process_arguments(): return options + def main(): '''main entry point''' logging.basicConfig(format='%(message)s')