From 1f0fb13fb93be65df274d9d20ace7a4403acc978 Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Fri, 30 Sep 2022 16:13:21 +0100 Subject: [PATCH 1/4] lisa._git: Avoid warning when git notes are not available FIX Avoid showing warnings when git notes are not available. --- lisa/_git.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lisa/_git.py b/lisa/_git.py index 10ad927a6..4fc0f8c84 100644 --- a/lisa/_git.py +++ b/lisa/_git.py @@ -79,8 +79,10 @@ def get_commit_message(repo, ref='HEAD', notes_ref='refs/notes/commits', format= :param notes_ref: Git notes reference to be displayed (if ``%N`` is in ``format``). :type notes_ref: str """ + notes = [f'--notes={notes_ref}'] if check_ref(repo, notes_ref) else [] + # pylint: disable=redefined-builtin - return git(repo, 'show', '--notes=' + notes_ref, '--format=' + format, '-s', ref) + return git(repo, 'show', *notes, '--format=' + format, '-s', ref) def find_commits(repo, ref='HEAD', notes_ref='refs/notes/commits', grep=None, regex=False): """ @@ -105,7 +107,8 @@ def find_commits(repo, ref='HEAD', notes_ref='refs/notes/commits', grep=None, re '-E' if regex else '-F' ] - commits = git(repo, 'log', '--notes=' + notes_ref, '--format=%H', *opts, ref, '--') + notes = [f'--notes={notes_ref}'] if check_ref(repo, notes_ref) else [] + commits = git(repo, 'log', *notes, '--format=%H', *opts, ref, '--') return commits.splitlines() def log(repo, ref='HEAD', format=None, commits_nr=1): @@ -143,4 +146,15 @@ def find_root(repo): """ root = git(repo, 'rev-parse', '--show-toplevel') return Path(root.strip()).resolve() + +def check_ref(repo, ref): + """ + Check if a given reference exists. + """ + try: + git(repo, 'rev-parse', '--quiet', '--verify', ref) + except subprocess.CalledProcessError: + return False + else: + return True # vim :set tabstop=4 shiftwidth=4 expandtab textwidth=80 -- GitLab From a56849d0e34898bc87b7cc49cc23d2711f0f2244 Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Fri, 30 Sep 2022 15:32:06 +0100 Subject: [PATCH 2/4] tools/check-setuppy: Watch git hooks FIX Also watch for new git hooks to install. --- tools/check-setuppy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/check-setuppy b/tools/check-setuppy index c55fdc1d4..36a016ac2 100755 --- a/tools/check-setuppy +++ b/tools/check-setuppy @@ -70,7 +70,7 @@ def main(): parser.add_argument('--filename-pattern', nargs='*', - default=['*setup.py', *tools_path], + default=['*setup.py', *tools_path, os.path.join(LISA_HOME, 'tools', 'git-hooks')], help='git rev-list filename pattern to check' ) @@ -109,7 +109,7 @@ def main(): f'{pattern}: {commit}' for pattern, commit in commits ) - print(f'Files have been modified in the following commits, re-run lisa-install to update dependencies and install new CLI tools:{sep}{commits}') + print(f'Files have been modified in the following commits, re-run lisa-install to update dependencies and install new CLI tools or git hooks:{sep}{commits}') print('THIS WILL RESET YOUR VENV !') return 1 else: -- GitLab From 6753114ca18f5fb679390366a56b53f2f9ab67e0 Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Fri, 30 Sep 2022 16:00:51 +0100 Subject: [PATCH 3/4] tools/check-setuppy: Fix CLI path detection FIX Avoid error if lisa package cannot be imported (e.g. if source init_env has not been done) --- tools/check-setuppy | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/check-setuppy b/tools/check-setuppy index 36a016ac2..abee711fe 100755 --- a/tools/check-setuppy +++ b/tools/check-setuppy @@ -64,13 +64,17 @@ def main(): ) - import lisa._cli_tools - tools_path = lisa._cli_tools.__path__ - tools_path = tools_path if tools_path else [] + try: + import lisa._cli_tools + except ImportError: + cli_path = [] + else: + cli_path = lisa._cli_tools.__path__ + cli_path = cli_path if cli_path else [] parser.add_argument('--filename-pattern', nargs='*', - default=['*setup.py', *tools_path, os.path.join(LISA_HOME, 'tools', 'git-hooks')], + default=['*setup.py', *cli_path, os.path.join(LISA_HOME, 'tools', 'git-hooks')], help='git rev-list filename pattern to check' ) -- GitLab From e92374aa13e795c73b537765b7c5a4e1e6a8fb8b Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Fri, 30 Sep 2022 15:31:39 +0100 Subject: [PATCH 4/4] tools/lisa-whatsnew: Add lisa-whatsnew FEATURE Add a new tool that displays the changes since a given git ref. Also call this tool automatically after a git pull. --- lisa/_doc/helpers.py | 23 ++++++++++--- tools/git-hooks/post-merge | 29 +++++++++++++++++ tools/lisa-whatsnew | 66 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 5 deletions(-) create mode 100755 tools/git-hooks/post-merge create mode 100755 tools/lisa-whatsnew diff --git a/lisa/_doc/helpers.py b/lisa/_doc/helpers.py index 3356cbb62..baa3a10d3 100644 --- a/lisa/_doc/helpers.py +++ b/lisa/_doc/helpers.py @@ -595,7 +595,7 @@ def get_subclasses_bullets(cls, abbrev=True, style=None, only_leaves=False): ) -def make_changelog(repo): +def make_changelog(repo, since=None, head_release_name='Next release', fmt='rst'): """ Generate a reStructuredText changelog to be included in the documentation. @@ -607,12 +607,25 @@ def make_changelog(repo): up changelog entries if markers were forgotten without rewriting the history. """ + + if fmt == 'rst': + escape_fmt = escape_rst + else: + escape_fmt = lambda x: x + + notes_ref = 'refs/notes/changelog' - release_refs = ['HEAD'] + lisa._git.find_tags(repo, 'v*') + release_refs = ( + ['HEAD'] + ( + [since] + if since else + lisa._git.find_tags(repo, 'v*') + ) + ) def update_release_name(name): if name == 'HEAD': - return 'Next release' + return head_release_name else: return name @@ -701,7 +714,7 @@ def make_changelog(repo): return f'{title}\n{body}' def format_msg(msg): - subject = escape(msg.splitlines()[0].strip()) + subject = escape_fmt(msg.splitlines()[0].strip()) return f'- {subject}' rst = '\n\n'.join( @@ -719,7 +732,7 @@ class PlaceHolderRef: documentable. """ -def escape(s): +def escape_rst(s): """ Escape the string so that it's considered plain reStructuredText input, without any markup even if it contains some. This avoids having to use a diff --git a/tools/git-hooks/post-merge b/tools/git-hooks/post-merge new file mode 100755 index 000000000..f3ea28125 --- /dev/null +++ b/tools/git-hooks/post-merge @@ -0,0 +1,29 @@ +#! /bin/sh +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright (C) 2022, Arm Limited and contributors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# DO NOT REMOVE THIS COMMENT: LISA-HOOK + +# Git post-merge hook that displays what is new since the last git pull. + +if which lisa-whatsnew >/dev/null 2>&1; then + printf "\n" + lisa-whatsnew --since ORIG_HEAD + printf "\n" +fi + +exit 0 diff --git a/tools/lisa-whatsnew b/tools/lisa-whatsnew new file mode 100755 index 000000000..42d8646de --- /dev/null +++ b/tools/lisa-whatsnew @@ -0,0 +1,66 @@ +#! /usr/bin/env python3 +# +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright (C) 2018, Arm Limited and contributors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import argparse +import sys + +def main(): + try: + from lisa.utils import LISA_HOME + import lisa._git as git + from lisa._doc.helpers import make_changelog + except ImportError: + print("Cannot import lisa, LISA news skipped") + return 0 + else: + parser = argparse.ArgumentParser(description=''' + Show noteworthy news since last git pull + ''' + ) + + parser.add_argument('--since', + required=True, + help='Show what is new since the given git ref', + ) + + parser.add_argument('--repo', + default=LISA_HOME, + help='Path to LISA git repo', + ) + + args = parser.parse_args() + repo = args.repo + since = args.since + + since_date = git.git(repo, 'show', '-s', '--format=%ci', since).strip() + since_date_rel = git.git(repo, 'show', '-s', '--format=%cr', since).strip() + + changelog = make_changelog( + repo, + since=since, + head_release_name=f'Changes since {since_date_rel} ({since_date})', + fmt='txt', + ) + print(changelog) + return 0 + +if __name__ == '__main__': + sys.exit(main()) + +# vim :set tabstop=4 shiftwidth=4 textwidth=80 expandtab -- GitLab