Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-133390: Support basic completion for sqlite3 command-line interface#133393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
tanloong wants to merge40 commits intopython:main
base:main
Choose a base branch
Loading
fromtanloong:sqlite3-cli-completion

Conversation

tanloong
Copy link
Contributor

@tanloongtanloong commentedMay 4, 2025
edited by bedevere-appbot
Loading

This adds tab-completion for the147 SQLite Keywords. A whitespace is appended to completion candidates for users' convenience and to mimic the behavior ofsqlite3 tool.

@python-cla-bot
Copy link

python-cla-botbot commentedMay 4, 2025
edited
Loading

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

Most changes to Pythonrequire a NEWS entry. Add one using theblurb_it web app or theblurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply theskip news label instead.

Copy link
Contributor

@StanFromIrelandStanFromIreland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This needs a whatsnew entry, (maybe a note in the docs?), a NEWS entry and tests.

This is quite limited completion so I guess it could work.

@picnixz
Copy link
Member

I think we need a separate nodule for this because if we want to have a smarter completion later the code is better to be isolated, so something like sqlite3._completer.

If possible, can we have anautogenerated list of keywords? and those keywords could also be stored in a (private) module-level list.

@picnixz
Copy link
Member

Please add tests

@tanloong
Copy link
ContributorAuthor

Yes, tests is coming. I will try to find a way to autogenerate list of keywords.

picnixz reacted with thumbs up emoji

@StanFromIreland
Copy link
Contributor

You can mark the pr as a draft.

@tanloongtanloong marked this pull request as draftMay 4, 2025 21:23
@tanloongtanloongforce-pushed thesqlite3-cli-completion branch 8 times, most recently from782a599 to5005d85CompareMay 5, 2025 04:47
@tanloong
Copy link
ContributorAuthor

tanloong commentedMay 5, 2025
edited
Loading

Added tests and moved keyword list to module level.

Keywords seems not easy to auto-generate, theSQLite document says they can be accessed bysqlite3_keyword_count() andsqlite3_keyword_name() using C, but I am bad at C and didn't figure out how to call these two at Python level. I think these two functions are not exposed to Python?

@tanloongtanloong marked this pull request as ready for reviewMay 5, 2025 05:08
Copy link
Contributor

@StanFromIrelandStanFromIreland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

With#133447 in mind the keywords list would be quite handy (I think hardcoding is fine, it doesn't change often anyway). Maybe it could be moved elsewhere, what do you think Benedikt?

@tanloongtanloongforce-pushed thesqlite3-cli-completion branch from15019ea to22652aeCompareMay 5, 2025 18:20
@tanloong
Copy link
ContributorAuthor

tanloong commentedMay 5, 2025
edited
Loading

Hi@picnixz, as Stan mentioned, beta freeze is around the corner, but I really hope this can be shipped in 3.14, do you think there is a chance to merge it before beta freeze?


@requires_subprocess()
classCompletionTest(unittest.TestCase):
PS1="sqlite> "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is no longer freely customizable by users via sys.ps1 ?

@tanloong
Copy link
ContributorAuthor

On my side it looks great but I'll also want@erlend-aasland to have a look as he's the main maintainer. Maybe he'l ask for some stylistic changes (in which case I'm sorry if I suggested something wrong).

Thank you so much for your review. Really appreciate your guidance!

@tanloong
Copy link
ContributorAuthor

tanloong commentedMay 16, 2025
edited
Loading

Thetest_completion_order() fails. TheSQLITE_KEYWORDS given bysqlite3_keyword_name() andsqlite3_keyword_count() is not in alphabetical order, but GNU Readline always sorts completions before displaying them.

Unfortunately I didn't find adisable-completion-sorting-like option in GNU Readline's document. There is anrl_sort_completion_matches in Readline's source code but it's not exposed as a config flag.

Can we remove thistest_completion_order(), as the order of displayed candidates is controlled by GNU Readline.

@picnixz
Copy link
Member

picnixz commentedMay 16, 2025
edited
Loading

Let's just check that the completion of nothing returns all keywords. You can sort theSQLITE_KEYWORDS list before checking for the equality (I think it's better not to sort it at the C level as it could be helpful in the future for someone interacting with python and C)

gotoerror;
}
}
if (PyModule_Add(module,"SQLITE_KEYWORDS",keywords)<0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

PyModule_Add() "eats" keywords, soPy_XDECREF should not be called after error. Just return -1. Or even return the result ofPyModule_Add().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

cc@encukou who implemented this I believe.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

May I try to update the C code. As this PR is sent from my fork, it would be more convenient that I make the change. I will convert if I mess it up.

Copy link
Member

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM.

@encukouencukou added the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelMay 29, 2025
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by@encukou for commit8d4f659 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F133393%2Fmerge

If you want to schedule another build, you need to add the🔨 test-with-buildbots label again.

@bedevere-botbedevere-bot removed the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelMay 29, 2025
encukou
encukou previously approved these changesMay 29, 2025
Copy link
Member

@encukouencukou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thank you! This looks great.
Let's check the buildbots before merging, as readline can be quirky. (So can the buildbots: not are stable so don't be alarmed if there are failures.)

gpshead reacted with thumbs up emoji
@encukouencukou dismissed theirstale reviewMay 30, 2025 09:45

Buildbot failures

@encukou
Copy link
Member

There are failures on FreeBSD, and onUbuntu and someFedora/RHEL configurations :(
@tanloong, do you want to investigate these?

@tanloong
Copy link
ContributorAuthor

Yes, I will look into it.

Disable coloring in main process to see if it resolves buildbots failures
@tanloong
Copy link
ContributorAuthor

tanloong commentedMay 31, 2025
edited
Loading

FreeBSD: When usingrun_pty() on FreeBSD, thexyzzy\t\t\b\b\b\b\b.quit\n does not quit the session. Instead of doing nothing on\t\t when there are no matching completions, two actual tab characters are inserted. Because of these extra tabs, the five backspaces\b\b\b\b\b delete characters to the left but leave the first two charactersxy intact. This results in the commandxy.quit\n, which is seen not as a dot command (due to not starting with dot) but an incomplete SQLite statement (due to the lack of trailing semicolon),.quit does not take effect and the session hangs.

It is mentioned in other issues as well that therun_pty() has platform specific problems (issue1,issue2). How about we skiptest_nothing_to_complete() on FreeBSD?

Ubuntu and Fedora/RHEL: Could not reproduce on my virtual machines. I suspect that theenv={"NO_COLOR": "1"} may not disable color output on buildbots, so thesqlite> prompt has surrounding control sequences, causingline.startswith(f"{self.PS1}xyzzy") to always returnFalse.

The subprocess created byrun_pty() might inherit some related environment variables from the main process. I want to open a terminal on buildbots for manual debugging but have not found a way to do that yet. I added the@force_not_colorized_test_class decorator to theCompletionTest class to disable coloring in the main process and will see if that helps.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@picnixzpicnixzpicnixz approved these changes

@StanFromIrelandStanFromIrelandStanFromIreland left review comments

@serhiy-storchakaserhiy-storchakaserhiy-storchaka approved these changes

@encukouencukouencukou left review comments

@erlend-aaslanderlend-aaslandAwaiting requested review from erlend-aaslanderlend-aasland is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

7 participants
@tanloong@picnixz@StanFromIreland@bedevere-bot@encukou@serhiy-storchaka@ZeroIntensity

[8]ページ先頭

©2009-2025 Movatter.jp