Skip to content

Commit 729947a

Browse files
committed
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@gentoo.org>
1 parent 640c78d commit 729947a

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

src/pkgdev/scripts/pkgdev_commit.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,16 +443,19 @@ def modify(self):
443443
watch_vars = {'HOMEPAGE', 'DESCRIPTION', 'LICENSE', 'SRC_URI'}
444444
array_targets = {'PYTHON_COMPAT', 'LUA_COMPAT'}
445445
string_targets = {'USE_RUBY'}
446+
use_expand_mapping = {'PYTHON_COMPAT': 'python_targets', 'LUA_COMPAT': 'lua_targets', 'USE_RUBY': 'ruby_targets'}
446447
targets = array_targets | string_targets
447448

448449
updated_vars = drop.keys() & add.keys()
449450
if updated := sorted(watch_vars & updated_vars):
450451
return f"update {', '.join(updated)}"
451452
elif (target := targets & updated_vars) and len(target) == 1:
452453
target = next(iter(target))
454+
py_re = lambda x: re.sub(r'^python(\d+)_(\d+)$', r'py\1.\2', x)
455+
use_expand = {py_re(use[len(target)+2:])
456+
for use, _ in self.repo.use_expand_desc[use_expand_mapping[target]]}
453457
if target in array_targets:
454458
array_re = re.compile(r'\[\d+\]="(?P<val>.+?)"')
455-
py_re = lambda x: re.sub(r'^python(\d+)_(\d+)$', r'py\1.\2', x)
456459
old = {py_re(m.group('val')) for m in re.finditer(array_re, drop[target])}
457460
new = {py_re(m.group('val')) for m in re.finditer(array_re, add[target])}
458461
else:
@@ -462,8 +465,9 @@ def modify(self):
462465
msg = []
463466
if added := sorted(new - old):
464467
msg.append(f"enable {', '.join(added)}")
465-
if dropped := sorted(old - new):
466-
msg.append(f"disable {', '.join(dropped)}")
468+
if dropped := old - new:
469+
if not msg or (dropped := dropped.intersection(use_expand)):
470+
msg.append(f"disable {', '.join(sorted(dropped))}")
467471
msg = ' and '.join(msg)
468472
if len(msg) <= 50:
469473
return msg

tests/scripts/test_pkgdev_commit.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,9 @@ def commit():
479479
assert commit() == 'cat/pkg: update DESCRIPTION, HOMEPAGE'
480480

481481
# update string_targets (USE_RUBY)
482+
os.mkdir(pjoin(repo.location, 'profiles', 'desc'))
483+
with open(pjoin(repo.path, 'profiles', 'desc', 'ruby_targets.desc'), 'w') as file:
484+
file.write('\n'.join(f'ruby{ver} - stub' for ver in range(27, 40)))
482485
repo.create_ebuild('cat/pkg-8', use_ruby='ruby27')
483486
git_repo.add_all('cat/pkg-8')
484487
repo.create_ebuild('cat/pkg-8', use_ruby='ruby27 ruby30')
@@ -489,12 +492,16 @@ def commit():
489492
assert commit() == 'cat/pkg: update USE_RUBY support'
490493

491494
# update array_targets (PYTHON_COMPAT)
492-
repo.create_ebuild('cat/pkg-9', data='PYTHON_COMPAT=( python3_9 )')
495+
with open(pjoin(repo.path, 'profiles', 'desc', 'python_targets.desc'), 'w') as file:
496+
file.write('\n'.join(f'python3_{ver} - stub' for ver in (10, 11)))
497+
repo.create_ebuild('cat/pkg-9', data='PYTHON_COMPAT=( python3_8 python3_9 )')
493498
git_repo.add_all('cat/pkg-9')
494-
repo.create_ebuild('cat/pkg-9', data='PYTHON_COMPAT=( python3_{9..10} )')
499+
repo.create_ebuild('cat/pkg-9', data='PYTHON_COMPAT=( python3_{8..10} )')
495500
assert commit() == 'cat/pkg: enable py3.10'
496-
repo.create_ebuild('cat/pkg-9', data='PYTHON_COMPAT=( python3_10 )')
497-
assert commit() == 'cat/pkg: disable py3.9'
501+
repo.create_ebuild('cat/pkg-9', data='PYTHON_COMPAT=( python3_{9..10} )')
502+
assert commit() == 'cat/pkg: disable py3.8'
503+
repo.create_ebuild('cat/pkg-9', data='PYTHON_COMPAT=( python3_{10..11} )')
504+
assert commit() == 'cat/pkg: enable py3.11'
498505

499506

500507
# multiple ebuild modifications don't get a generated summary
@@ -508,12 +515,12 @@ def commit():
508515
assert commit() == 'cat/pkg: add versions'
509516

510517
# create Manifest
511-
with open(pjoin(git_repo.path, 'cat/pkg/Manifest'), 'w') as f:
512-
f.write('DIST pkg-3.tar.gz 101 BLAKE2B deadbeef SHA512 deadbeef\n')
518+
with open(pjoin(git_repo.path, 'cat/pkg/Manifest'), 'w') as file:
519+
file.write('DIST pkg-3.tar.gz 101 BLAKE2B deadbeef SHA512 deadbeef\n')
513520
assert commit() == 'cat/pkg: update Manifest'
514521
# update Manifest
515-
with open(pjoin(git_repo.path, 'cat/pkg/Manifest'), 'a+') as f:
516-
f.write('DIST pkg-2.tar.gz 101 BLAKE2B deadbeef SHA512 deadbeef\n')
522+
with open(pjoin(git_repo.path, 'cat/pkg/Manifest'), 'a+') as file:
523+
file.write('DIST pkg-2.tar.gz 101 BLAKE2B deadbeef SHA512 deadbeef\n')
517524
assert commit() == 'cat/pkg: update Manifest'
518525
# remove Manifest
519526
os.remove(pjoin(git_repo.path, 'cat/pkg/Manifest'))

0 commit comments

Comments
 (0)