commit: 729947acaa9bb071936c4d68fa1dfe86628f2d26
Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Sun Oct 16 17:27:36 2022 +0000
Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Sun Oct 16 17:27:36 2022 +0000
URL:
https://gitweb.gentoo.org/proj/pkgcore/pkgdev.git/commit/?id=729947ac
commit: don't show disable for targets that are no-op
For PYTHON_COMPAT, LUA_COMPAT and USE_RUBY, show the "disable" target
after "enable" only if this target exists. For example, if I enable
py3.11 and disable py3.7 (which is no-op), it will show only "enable
py3.11". If there is no "enable", it will still show "disable py3.7".
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>
src/pkgdev/scripts/pkgdev_commit.py | 10 +++++++---
tests/scripts/test_pkgdev_commit.py | 23 +++++++++++++++--------
2 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/src/pkgdev/scripts/pkgdev_commit.py
b/src/pkgdev/scripts/pkgdev_commit.py
index 20fd471..0cdf232 100644
--- a/src/pkgdev/scripts/pkgdev_commit.py
+++ b/src/pkgdev/scripts/pkgdev_commit.py
@@ -443,6 +443,7 @@ class PkgSummary(ChangeSummary):
watch_vars = {'HOMEPAGE', 'DESCRIPTION', 'LICENSE', 'SRC_URI'}
array_targets = {'PYTHON_COMPAT', 'LUA_COMPAT'}
string_targets = {'USE_RUBY'}
+ use_expand_mapping = {'PYTHON_COMPAT': 'python_targets',
'LUA_COMPAT': 'lua_targets', 'USE_RUBY': 'ruby_targets'}
targets = array_targets | string_targets
updated_vars = drop.keys() & add.keys()
@@ -450,9 +451,11 @@ class PkgSummary(ChangeSummary):
return f"update {', '.join(updated)}"
elif (target := targets & updated_vars) and len(target) == 1:
target = next(iter(target))
+ py_re = lambda x: re.sub(r'^python(\d+)_(\d+)$',
r'py\1.\2', x)
+ use_expand = {py_re(use[len(target)+2:])
+ for use, _ in
self.repo.use_expand_desc[use_expand_mapping[target]]}
if target in array_targets:
array_re = re.compile(r'\[\d+\]="(?P<val>.+?)"')
- py_re = lambda x: re.sub(r'^python(\d+)_(\d+)$',
r'py\1.\2', x)
old = {py_re(m.group('val')) for m in
re.finditer(array_re, drop[target])}
new = {py_re(m.group('val')) for m in
re.finditer(array_re, add[target])}
else:
@@ -462,8 +465,9 @@ class PkgSummary(ChangeSummary):
msg = []
if added := sorted(new - old):
msg.append(f"enable {', '.join(added)}")
- if dropped := sorted(old - new):
- msg.append(f"disable {', '.join(dropped)}")
+ if dropped := old - new:
+ if not msg or (dropped :=
dropped.intersection(use_expand)):
+ msg.append(f"disable {', '.join(sorted(dropped))}")
msg = ' and '.join(msg)
if len(msg) <= 50:
return msg
diff --git a/tests/scripts/test_pkgdev_commit.py
b/tests/scripts/test_pkgdev_commit.py
index f920054..efc9491 100644
--- a/tests/scripts/test_pkgdev_commit.py
+++ b/tests/scripts/test_pkgdev_commit.py
@@ -479,6 +479,9 @@ class TestPkgdevCommit:
assert commit() == 'cat/pkg: update DESCRIPTION, HOMEPAGE'
# update string_targets (USE_RUBY)
+ os.mkdir(pjoin(repo.location, 'profiles', 'desc'))
+ with open(pjoin(repo.path, 'profiles', 'desc', 'ruby_targets.desc'),
'w') as file:
+ file.write('\n'.join(f'ruby{ver} - stub' for ver in range(27, 40)))
repo.create_ebuild('cat/pkg-8', use_ruby='ruby27')
git_repo.add_all('cat/pkg-8')
repo.create_ebuild('cat/pkg-8', use_ruby='ruby27 ruby30')
@@ -489,12 +492,16 @@ class TestPkgdevCommit:
assert commit() == 'cat/pkg: update USE_RUBY support'
# update array_targets (PYTHON_COMPAT)
- repo.create_ebuild('cat/pkg-9', data='PYTHON_COMPAT=( python3_9 )')
+ with open(pjoin(repo.path, 'profiles', 'desc', 'python_targets.desc'),
'w') as file:
+ file.write('\n'.join(f'python3_{ver} - stub' for ver in (10, 11)))
+ repo.create_ebuild('cat/pkg-9', data='PYTHON_COMPAT=( python3_8
python3_9 )')
git_repo.add_all('cat/pkg-9')
- repo.create_ebuild('cat/pkg-9', data='PYTHON_COMPAT=( python3_{9..10}
)')
+ repo.create_ebuild('cat/pkg-9', data='PYTHON_COMPAT=( python3_{8..10}
)')
assert commit() == 'cat/pkg: enable py3.10'
- repo.create_ebuild('cat/pkg-9', data='PYTHON_COMPAT=( python3_10 )')
- assert commit() == 'cat/pkg: disable py3.9'
+ repo.create_ebuild('cat/pkg-9', data='PYTHON_COMPAT=( python3_{9..10}
)')
+ assert commit() == 'cat/pkg: disable py3.8'
+ repo.create_ebuild('cat/pkg-9', data='PYTHON_COMPAT=( python3_{10..11}
)')
+ assert commit() == 'cat/pkg: enable py3.11'
# multiple ebuild modifications don't get a generated summary
@@ -508,12 +515,12 @@ class TestPkgdevCommit:
assert commit() == 'cat/pkg: add versions'
# create Manifest
- with open(pjoin(git_repo.path, 'cat/pkg/Manifest'), 'w') as f:
- f.write('DIST pkg-3.tar.gz 101 BLAKE2B deadbeef SHA512 deadbeef\n')
+ with open(pjoin(git_repo.path, 'cat/pkg/Manifest'), 'w') as file:
+ file.write('DIST pkg-3.tar.gz 101 BLAKE2B deadbeef SHA512
deadbeef\n')
assert commit() == 'cat/pkg: update Manifest'
# update Manifest
- with open(pjoin(git_repo.path, 'cat/pkg/Manifest'), 'a+') as f:
- f.write('DIST pkg-2.tar.gz 101 BLAKE2B deadbeef SHA512 deadbeef\n')
+ with open(pjoin(git_repo.path, 'cat/pkg/Manifest'), 'a+') as file:
+ file.write('DIST pkg-2.tar.gz 101 BLAKE2B deadbeef SHA512
deadbeef\n')
assert commit() == 'cat/pkg: update Manifest'
# remove Manifest
os.remove(pjoin(git_repo.path, 'cat/pkg/Manifest'))