Repository navigation
Add Python 3.15 support #146
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
mbUSC
wants to merge
3
commits into
singlestore-labs:main
Choose a base branch
from
mbUSC:python-3.15-support
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.
Open
Changes from all commits
Commits
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 |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ jobs: | |
| - "3.12" | ||
| - "3.13" | ||
| - "3.14" | ||
| - "3.15" | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v7 | ||
|
|
||
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,91 @@ | ||
| """Tests for loading a zipped environment file through ``asgi.main()``.""" | ||
| import os | ||
| import sys | ||
| import tempfile | ||
| import textwrap | ||
| import unittest | ||
| import uuid | ||
| import zipfile | ||
| from types import ModuleType | ||
| from typing import Optional | ||
| from unittest.mock import MagicMock | ||
| from unittest.mock import patch | ||
|
|
||
| from ..functions.ext import asgi | ||
|
|
||
|
|
||
| GOOD_MODULE = textwrap.dedent(''' | ||
| from singlestoredb.functions import udf | ||
|
|
||
| @udf | ||
| def env_file_double(x: int) -> int: | ||
| return x * 2 | ||
| ''') | ||
|
|
||
| FAILING_MODULE = textwrap.dedent(''' | ||
| raise RuntimeError('environment init failed') | ||
| ''') | ||
|
|
||
|
|
||
| class TestEnvironmentFile(unittest.TestCase): | ||
| """``main()`` imports the module inside a zip passed as the function source. | ||
|
|
||
| Python 3.15 removed ``zipimporter.load_module()``, which this path used | ||
| to rely on. uvicorn is mocked out, so no server is started. | ||
| """ | ||
|
|
||
| def setUp(self) -> None: | ||
| self.tmpdir = tempfile.TemporaryDirectory() | ||
| self.addCleanup(self.tmpdir.cleanup) | ||
| # A unique name per test, so no module cached in sys.modules from | ||
| # an earlier test can satisfy the import | ||
| self.modname = f'envfile_{uuid.uuid4().hex}' | ||
| self.addCleanup(sys.modules.pop, self.modname, None) | ||
| self.cached_module: Optional[ModuleType] = None | ||
|
|
||
| def _make_env(self, source: str) -> str: | ||
| path = os.path.join(self.tmpdir.name, f'{self.modname}.zip') | ||
| with zipfile.ZipFile(path, 'w') as zf: | ||
| zf.writestr(f'{self.modname}/__init__.py', source) | ||
| return path | ||
|
|
||
| def _run_main(self, env_path: str) -> MagicMock: | ||
| """Run ``main()`` on the environment file and return the mocked uvicorn. | ||
|
|
||
| What ``sys.modules`` holds for the environment module is saved to | ||
| ``self.cached_module`` before ``patch.dict`` exits, since restoring | ||
| ``sys.modules`` would otherwise drop the entry. It is saved even when | ||
| ``main()`` raises. | ||
|
|
||
| """ | ||
| uvicorn = MagicMock() | ||
| with patch.dict(sys.modules, {'uvicorn': uvicorn}): | ||
| try: | ||
| # An empty --db skips registering the functions with a database | ||
| asgi.main(['--db', '', env_path]) | ||
| finally: | ||
| self.cached_module = sys.modules.get(self.modname) | ||
| return uvicorn | ||
|
|
||
| def test_module_is_loaded_and_functions_found(self) -> None: | ||
| uvicorn = self._run_main(self._make_env(GOOD_MODULE)) | ||
|
|
||
| uvicorn.run.assert_called_once() | ||
| app = uvicorn.run.call_args.args[0] | ||
| names = [info['signature']['name'] for _, info in app.endpoints.values()] | ||
| self.assertEqual(names, ['env_file_double']) | ||
|
|
||
| mod = self.cached_module | ||
| assert mod is not None | ||
| self.assertEqual(mod.env_file_double(21), 42) | ||
| self.assertTrue(str(mod.__file__).startswith(self.tmpdir.name)) | ||
|
|
||
| def test_failed_import_is_not_cached(self) -> None: | ||
| with self.assertRaisesRegex(RuntimeError, 'environment init failed'): | ||
| self._run_main(self._make_env(FAILING_MODULE)) | ||
|
|
||
| self.assertIsNone(self.cached_module) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() |
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.
We have another PR that is going to refactor this part of the code, so I'm holding off on approving this PR until that is done.
get_event_loopis no longer used in the refactored code.