Logging: Fix some edge cases when identifying if the logged messages comes from external code or not. #14812
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Link to issue number:
Discussion in #14806
Summary of the issue:
When logging NVDA tries to determine if the logged message comes from its own code or from an add-on. In some cases it does so incorrectly.
Case 1: Directory prepended to
sys.path
by an add-onSome add-ons have to modify
sys.path
to import additional libraries. NVDA'slogHandler
relied on the fact that the first entry in path represents the location of NVDA's source code. While add-on developers should really clean-up after themselves i.e. modify path only for as long as necessary to import additional libraries this is not something we can enforce. Initially observed by @CyrilleB79 for an add-on for ChatGPT.Case 2: Messages logged from add-ons installed in the default config for source copies
By default configuration folder for source copies is placed next to NVDA sources, i.e. in the
source
folder. When determining if the path belongs to NVDA or not we used to check if the given path starts with NVDA's source folder which was true for the plugins in the user config even though the code was not a part of NVDA.Description of user facing changes
This should affect only developers who inspect the log.
Description of development approach
When checking if the path is external or not we no longer rely on
sys.path
- rather the location of thelogHandler
is used to determine the true location of NVDA's source code. In addition if the path is beneath the current NVDA's config it is always marked as external.Testing strategy:
Known issues with pull request:
None known
Change log entries:
For Developers
Code Review Checklist: