-
Notifications
You must be signed in to change notification settings - Fork 18
Support python 3.11 #241
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
Merged
Merged
Support python 3.11 #241
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2776194
refactor: undo rename of wrapt
apotterri 646d1bc
refactor: switch to vendoring
apotterri c62e64e
fix: handle 3.11 find_spec implementation
apotterri e00527a
refactor: split appmap.unittest
apotterri bd9598b
fix: update unittest integration for python 3.11
apotterri 15b0ddc
feat: support python 3.11
apotterri affdbda
fix: relax restriction on packaging to >=19.0
apotterri 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +0,0 @@ | ||
| [submodule "extern/wrapt"] | ||
| path = vendor/wrapt | ||
| url = https://github.com/applandinc/wrapt.git | ||
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 |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ os: linux | |
| dist: jammy | ||
| language: python | ||
| python: | ||
| - "3.11" | ||
| - "3.10" | ||
| - "3.9.14" | ||
| - "3.8" | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import sys | ||
| import unittest | ||
| from contextlib import contextmanager | ||
|
|
||
| from _appmap import testing_framework, wrapt | ||
| from _appmap.utils import get_function_location | ||
|
|
||
| _session = testing_framework.session("unittest", "tests") | ||
|
|
||
|
|
||
| def _get_test_location(cls, method_name): | ||
| fn = getattr(cls, method_name) | ||
| return get_function_location(fn) | ||
|
|
||
|
|
||
| if sys.version_info[1] < 8: | ||
| # Prior to 3.8, unittest called the test case's test method directly, which left us without an | ||
| # opportunity to hook it. So, instead, instrument unittest.case._Outcome.testPartExecutor, a | ||
| # method used to run test cases. `isTest` will be True when the part is the actual test method, | ||
| # False when it's setUp or teardown. | ||
| @wrapt.patch_function_wrapper("unittest.case", "_Outcome.testPartExecutor") | ||
| @contextmanager | ||
| def testPartExecutor(wrapped, _, args, kwargs): | ||
| def _args(test_case, *_, isTest=False, **__): | ||
| return (test_case, isTest) | ||
|
|
||
| test_case, is_test = _args(*args, **kwargs) | ||
| already_recording = getattr(test_case, "_appmap_pytest_recording", None) | ||
| # fmt: off | ||
| if ( | ||
| (not is_test) | ||
| or isinstance(test_case, unittest.case._SubTest) # pylint: disable=protected-access | ||
| or already_recording | ||
| ): | ||
| # fmt: on | ||
| with wrapped(*args, **kwargs): | ||
| yield | ||
| return | ||
|
|
||
| method_name = test_case.id().split(".")[-1] | ||
| location = _get_test_location(test_case.__class__, method_name) | ||
| with _session.record( | ||
| test_case.__class__, method_name, location=location | ||
| ) as metadata: | ||
| if metadata: | ||
| with wrapped( | ||
| *args, **kwargs | ||
| ), testing_framework.collect_result_metadata(metadata): | ||
| yield | ||
| else: | ||
| # session.record may return None | ||
| yield | ||
|
|
||
| else: | ||
| # As of 3.8, unittest.case.TestCase now calls the test's method indirectly, through | ||
| # TestCase._callTestMethod. Hook that to manage a recording session. | ||
| @wrapt.patch_function_wrapper("unittest.case", "TestCase._callTestMethod") | ||
| def callTestMethod(wrapped, test_case, args, kwargs): | ||
| already_recording = getattr(test_case, "_appmap_pytest_recording", None) | ||
| if already_recording: | ||
| wrapped(*args, **kwargs) | ||
| return | ||
|
|
||
| method_name = test_case.id().split(".")[-1] | ||
| location = _get_test_location(test_case.__class__, method_name) | ||
| with _session.record(test_case.__class__, method_name, location=location) as metadata: | ||
| if metadata: | ||
| with testing_framework.collect_result_metadata(metadata): | ||
| wrapped(*args, **kwargs) |
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 @@ | ||
| ../vendor/_appmap/wrapt | ||
|
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. This is here to make development easier. It's exclude from the wheel when it gets built: https://github.com/getappmap/appmap-python/pull/241/files#diff-50c86b7ed8ac2cf95bd48334961bf0530cdc77b5a56f852c5c61b89d735fd711R25 |
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,60 +1,7 @@ | ||
| import unittest | ||
| from contextlib import contextmanager | ||
|
|
||
| from _appmap import testing_framework | ||
| from _appmap.env import Env | ||
| from _appmap.utils import get_function_location | ||
| from appmap import wrapt | ||
|
|
||
| logger = Env.current.getLogger(__name__) | ||
|
|
||
|
|
||
| def setup_unittest(): | ||
| session = testing_framework.session("unittest", "tests") | ||
|
|
||
| def get_test_location(cls, method_name): | ||
|
|
||
| fn = getattr(cls, method_name) | ||
| return get_function_location(fn) | ||
|
|
||
| # unittest.case._Outcome.testPartExecutor is used by all supported | ||
| # versions of unittest to run test cases. `isTest` will be True when | ||
| # the part is the actual test method, False when it's setUp or | ||
| # teardown. | ||
| @wrapt.patch_function_wrapper("unittest.case", "_Outcome.testPartExecutor") | ||
| @contextmanager | ||
| def testPartExecutor(wrapped, _, args, kwargs): | ||
| def _args(test_case, *_, isTest=False, **__): | ||
| return (test_case, isTest) | ||
|
|
||
| test_case, is_test = _args(*args, **kwargs) | ||
| already_recording = getattr(test_case, "_appmap_pytest_recording", None) | ||
| # fmt: off | ||
| if ( | ||
| (not is_test) | ||
| or isinstance(test_case, unittest.case._SubTest) # pylint: disable=protected-access | ||
| or already_recording | ||
| ): | ||
| # fmt: on | ||
| with wrapped(*args, **kwargs): | ||
| yield | ||
| return | ||
|
|
||
| method_name = test_case.id().split(".")[-1] | ||
| location = get_test_location(test_case.__class__, method_name) | ||
| with session.record( | ||
| test_case.__class__, method_name, location=location | ||
| ) as metadata: | ||
| if metadata: | ||
| with wrapped( | ||
| *args, **kwargs | ||
| ), testing_framework.collect_result_metadata(metadata): | ||
| yield | ||
| else: | ||
| # session.record may return None | ||
| yield | ||
|
|
||
|
|
||
| if not Env.current.is_appmap_repo and Env.current.enables("unittest"): | ||
| logger.debug("Test recording is enabled (unittest)") | ||
| setup_unittest() | ||
| import _appmap.unittest # pyright: ignore pylint: disable=unused-import |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.