diff --git a/changelog.md b/changelog.md index 0f1f3ce8..fe98e172 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,7 @@ Features * Continue to expand TIPS. * Make `--progress` and `--checkpoint` strictly by statement. * Allow more characters in passwords read from a file. +* Show sponsors and contributors separately in startup messages. Bug Fixes diff --git a/mycli/main_modes/repl.py b/mycli/main_modes/repl.py index 17edcd19..9d20f1d4 100644 --- a/mycli/main_modes/repl.py +++ b/mycli/main_modes/repl.py @@ -135,8 +135,10 @@ def _show_startup_banner( print(sqlexecute.server_info) print('mycli', mycli_package.__version__) print(SUPPORT_INFO) - if random.random() <= 0.5: - print('Thanks to the contributor —', _thanks_picker()) + if random.random() <= 0.25: + print('Thanks to the sponsor —', _sponsors_picker()) + elif random.random() <= 0.5: + print('Thanks to the contributor —', _contributors_picker()) else: print('Tip —', _tips_picker()) @@ -700,7 +702,7 @@ def _one_iteration( mycli.query_history.append(query) -def _thanks_picker() -> str: +def _contributors_picker() -> str: lines: str = "" try: @@ -709,6 +711,16 @@ def _thanks_picker() -> str: except FileNotFoundError: pass + contents = [] + for line in lines.split("\n"): + if m := re.match(r"^ *\* (.*)", line): + contents.append(m.group(1)) + return random.choice(contents) if contents else 'our contributors' + + +def _sponsors_picker() -> str: + lines: str = "" + try: with resources.files(mycli_package).joinpath("SPONSORS").open('r') as f: lines += f.read() diff --git a/test/pytests/test_main_modes_repl.py b/test/pytests/test_main_modes_repl.py index 919aa575..f67867cc 100644 --- a/test/pytests/test_main_modes_repl.py +++ b/test/pytests/test_main_modes_repl.py @@ -304,11 +304,13 @@ def test_repl_picker_helpers_cover_present_and_missing_resources(monkeypatch: py } monkeypatch.setattr(repl_mode.resources, 'files', lambda package: FakeResourceTree(files)) monkeypatch.setattr(repl_mode.random, 'choice', lambda seq: seq[0]) - assert repl_mode._thanks_picker() == 'Alice' + assert repl_mode._contributors_picker() == 'Alice' + assert repl_mode._sponsors_picker() == 'Carol' assert repl_mode._tips_picker() == 'Tip 1' monkeypatch.setattr(repl_mode.resources, 'files', lambda package: FakeResourceTree({})) - assert repl_mode._thanks_picker() == 'our sponsors' + assert repl_mode._contributors_picker() == 'our contributors' + assert repl_mode._sponsors_picker() == 'our sponsors' assert repl_mode._tips_picker() == r'\? or "help" for help!' @@ -317,7 +319,8 @@ def test_repl_show_startup_banner_and_prompt_helpers(monkeypatch: pytest.MonkeyP printed: list[str] = [] monkeypatch.setattr(builtins, 'print', lambda *args, **kwargs: printed.append(' '.join(str(x) for x in args))) monkeypatch.setattr(repl_mode.random, 'random', lambda: 0.4) - monkeypatch.setattr(repl_mode, '_thanks_picker', lambda: 'Alice') + monkeypatch.setattr(repl_mode, '_contributors_picker', lambda: 'Alice') + monkeypatch.setattr(repl_mode, '_sponsors_picker', lambda: 'Carol') monkeypatch.setattr(repl_mode, '_tips_picker', lambda: 'Tip') cli.less_chatty = False