-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[libclang/python] Add LIBCLANG_LIBRARY_PATH and LIBCLANG_LIBRARY_FILE #170201
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
TApplencourt
wants to merge
8
commits into
llvm:main
Choose a base branch
from
TApplencourt:env_cindex
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+76
−49
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
53ff625
Add LIBCLANG_LIBRARY_PATH and LIBCLANG_LIBRARY_FILE
TApplencourt 8de9e2d
Update clang/docs/ReleaseNotes.rst
TApplencourt 45478df
Move too LIBCLANG_LIBRARY_PATH
TApplencourt b13a58b
update error message
TApplencourt 2b52da5
Apply darker sugestion
TApplencourt 8417da5
Merge branch 'main' into env_cindex
TApplencourt 0ff4d95
Fix negative tests...
TApplencourt d124b43
One more set of fix
TApplencourt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
clang/bindings/python/tests/cindex/test_environment_variable.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,63 @@ | ||||||
| import unittest | ||||||
| import unittest.mock | ||||||
| import sys | ||||||
| import os | ||||||
|
|
||||||
|
|
||||||
| def reset_import_and_get_frech_config(): | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| # Reloads the clang.cindex module to reset any class-level state in Config. | ||||||
| sys.modules.pop("clang.cindex", None) | ||||||
| sys.modules.pop("clang", None) | ||||||
| from clang.cindex import Config | ||||||
|
|
||||||
| return Config() | ||||||
|
|
||||||
|
|
||||||
| class TestEnvironementVariable(unittest.TestCase): | ||||||
| def test_working_libclang_library_file(self): | ||||||
| ref_libclang_library_file = reset_import_and_get_frech_config().get_filename() | ||||||
| with unittest.mock.patch.dict( | ||||||
| os.environ, {"LIBCLANG_LIBRARY_FILE": ref_libclang_library_file} | ||||||
| ): | ||||||
| reset_import_and_get_frech_config().lib | ||||||
|
|
||||||
| @unittest.mock.patch.dict("os.environ", {"LIBCLANG_LIBRARY_FILE": "/dev/null"}) | ||||||
| def test_non_working_libclang_library_file(self): | ||||||
| config = reset_import_and_get_frech_config() | ||||||
| import clang.cindex | ||||||
|
|
||||||
| with self.assertRaises(clang.cindex.LibclangError): | ||||||
| config.lib | ||||||
|
|
||||||
| def test_working_libclang_library_path(self): | ||||||
| # Get adequate libclang path | ||||||
| ref_libclang_library_file = reset_import_and_get_frech_config().get_filename() | ||||||
| ref_libclang_library_path, filename = os.path.split(ref_libclang_library_file) | ||||||
| filename_root, filename_ext = os.path.splitext(filename) | ||||||
|
|
||||||
| # Config only recognizes the default libclang filename. | ||||||
| # If LIBCLANG_LIBRARY_FILE points to a non-standard name, skip this test. | ||||||
|
|
||||||
| if not ( | ||||||
| filename_root == "libclang" and filename_ext in (".so", ".dll", ".dylib") | ||||||
| ): | ||||||
| self.skipTest(f"Skipping because {filename} is not a default libclang name") | ||||||
|
|
||||||
| with unittest.mock.patch.dict( | ||||||
| os.environ, {"LIBCLANG_LIBRARY_PATH": ref_libclang_library_path} | ||||||
| ): | ||||||
| # Remove LIBCLANG_LIBRARY_FILE to avoid it taking precedence if set by the user | ||||||
| # Need to be in the mocked environement | ||||||
| os.environ.pop("LIBCLANG_LIBRARY_FILE", None) | ||||||
| reset_import_and_get_frech_config().lib | ||||||
|
|
||||||
| @unittest.mock.patch.dict("os.environ", {"LIBCLANG_LIBRARY_PATH": "not_a_real_dir"}) | ||||||
| def test_non_working_libclang_library_path(self): | ||||||
| # Remove LIBCLANG_LIBRARY_FILE to avoid it taking precedence if set by the user | ||||||
| os.environ.pop("LIBCLANG_LIBRARY_FILE", None) | ||||||
|
|
||||||
| config = reset_import_and_get_frech_config() | ||||||
| import clang.cindex | ||||||
|
|
||||||
| with self.assertRaises(clang.cindex.LibclangError): | ||||||
| config.lib | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Configshould now be unused in most (all?) test files, so you can remove the import as well