Skip to content

gh-89520: IDLE - Make extentions use user's keys, not all defaults #28713

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 40 commits into
base: main
Choose a base branch
from

Conversation

CoolCat467
Copy link

@CoolCat467 CoolCat467 commented Oct 3, 2021

I was trying to write an extension for Idle, and was noticing extension keys defined in ~/.idlerc weren't being used, so I looked into it and found that in idlelib.config.idleConf, GetExtensionKeys, __GetRawExtensionKeys, and GetKeyBinding would never check for user keys, always assuming default keys have everything. This is not always true. In a system with multiple users, you would not want to modify the default config file for a custom extension, as that is used for everyone. This pull request is changing aforementioned functions to also check user config files, and overwrite values acquired from the default config file if the user config redefined one.

Edit:
The especially interesting part is that extensions are loaded anyways if they have an entry in the user's IDLE configuration file, but their keybinds are only loaded properly if they are defined in the root configuration file at the moment. This pull request is fixing this difference and allows extension keybinds to be loaded from the user's IDLE configuration file, making user extensions work just as well as root extensions.

I was trying to write an extension for Idle, and was noticing extension keys defined in ~/.idlerc weren't being used, so I looked into it and found `GetExtensionKeys`, `__GetRawExtensionKeys`, and `GetKeyBinding` would never check for user keys, always assuming default keys have everything. This is not always true. In a system with multiple users, you would not want to modify the default config file for a custom extension, as that is used for everyone. This pull request is changing aforementioned functions to also check user config files, and overwrite values acquired from the default config file if the user config redefined one.
blurb-it bot and others added 3 commits October 3, 2021 21:55
CoolCat467 and others added 3 commits February 1, 2022 14:57
@terryjreedy terryjreedy changed the title bpo-45357: Make extentions use user's keys, not all defaults bpo-45357: IDLE - Make extentions use user's keys, not all defaults Nov 2, 2022
@terryjreedy terryjreedy self-assigned this Nov 2, 2022
@terryjreedy terryjreedy changed the title bpo-45357: IDLE - Make extentions use user's keys, not all defaults gh-89520: IDLE - Make extentions use user's keys, not all defaults Nov 2, 2022
@python python deleted a comment from the-knights-who-say-ni Nov 2, 2022
@CoolCat467
Copy link
Author

Some tests are failing; please fix those.

Fixed failing tests as of 016ce89

@JelleZijlstra
Copy link
Member

As mentioned above, I'm not able to provide a full review on this PR.

@JelleZijlstra JelleZijlstra removed their request for review March 11, 2024 03:23
@CoolCat467
Copy link
Author

@terryjreedy Ping, it's been 3 years and I think my newest approach will work well. I've been testing a version of what this PR does as it's own module that has to do some nasty monkeypatching stuff, but it allows IDLE to successfully load extensions from user configuration files, and I would like to see this become something standard.

Copy link
Member

@terryjreedy terryjreedy left a comment

Choose a reason for hiding this comment

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

These comments are very preliminary. And when I wrote the first 2, I had forgotten that this PR intentionally changes a config rule. But its late, so I am submitting them as they are to give you some feedback.

I am a bit more favorable toward this than I was on the issue, but no promises yet.

If I were to approve, new tests would be needed, modeled on existing tests that avoid reading/writing the user files on disk by loading the in-memory config dicts. zzdummy.py, or a copy in idle_test, might be usable.

Comment on lines +795 to +796
for key in self.userCfg:
self.userCfg[key].Load()
Copy link
Member

Choose a reason for hiding this comment

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

This change looks wrong, as it would load any garbage that users add to the user file. Since it affects all confit files, not obvious related to this PR.

Copy link
Author

Choose a reason for hiding this comment

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

This change allows keys that are not in the default configuration to be loaded from user configuration. This means sections like extensions that might not be in the default config can be loaded.

@CoolCat467
Copy link
Author

These comments are very preliminary. And when I wrote the first 2, I had forgotten that this PR intentionally changes a config rule. But its late, so I am submitting them as they are to give you some feedback.

If I were to approve, new tests would be needed, modeled on existing tests that avoid reading/writing the user files on disk by loading the in-memory config dicts. zzdummy.py, or a copy in idle_test, might be usable.

@terryjreedy Ping, I have reviewed your feedback and have made noted changes, and I've added a few tests that try to capture the fact that and extension that is not enabled will not have it's keybinds bound but that one that is enabled will, as well as making sure extensions that are enabled entirely from user configuration files will have their keybinds found successfully. To do this I made a copy of test_zzdummy (test_zzdummy_user) and changed both of them to test aforementioned behavior.

@CoolCat467 CoolCat467 requested a review from terryjreedy March 29, 2024 02:01
@python-cla-bot
Copy link

python-cla-bot bot commented Apr 18, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants