Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 15 additions & 3 deletions mycli/main_modes/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down Expand Up @@ -700,7 +702,7 @@ def _one_iteration(
mycli.query_history.append(query)


def _thanks_picker() -> str:
def _contributors_picker() -> str:
lines: str = ""

try:
Expand All @@ -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()
Expand Down
9 changes: 6 additions & 3 deletions test/pytests/test_main_modes_repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!'


Expand All @@ -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
Expand Down
Loading