-
Notifications
You must be signed in to change notification settings - Fork 25
feat: bundle local (non-pip) modules for serverless endpoints #352
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
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
fdff4c6
feat: add local-module resolution and payload-size exceptions
deanq bce768a
feat: add additive modules map to FunctionRequest protocol
deanq e503def
feat: add local-module classification primitives
deanq a922b9c
feat: resolve transitive local-import closure for endpoints
deanq ee53cd7
fix: resolve names in bare relative imports; cover outside-root branch
deanq 3b2f2f7
fix: preserve package-init resolution for bare star relative imports
deanq 85e3c60
feat: materialize inline local modules before LB exec
deanq 331273d
feat: ship local module closure inline for live serverless
deanq 47b9b9d
feat: ship local module closure inline for LB-live execution
deanq 1aec81d
feat: force-include and validate local modules in build tarball
deanq b161672
fix: keep local modules on sys.path through LB function call
deanq 0443369
fix: scope build-time local-module strictness to endpoint files
deanq 0c8c90c
docs: note parent-dir import and sys.path concurrency constraints
deanq a662964
fix: harden local-module bundling per PR #352 review
deanq 7272691
fix: refuse ignore-excluded imports, bundle pkg submodules
deanq 2fa6db4
refactor(build): move defines_endpoint into scanner module
deanq 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| """Materialize inline local-module source onto the worker's import path. | ||
|
|
||
| The live-serverless path ships local module files in ``FunctionRequest.modules``. | ||
| Before the worker ``exec``s the function code, those files must exist on disk and | ||
| be importable. This context manager writes them to a temp dir, prepends it to | ||
| ``sys.path``, and cleans up afterward. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| import sys | ||
| import tempfile | ||
| from collections.abc import Iterator | ||
| from contextlib import contextmanager | ||
| from pathlib import Path | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| @contextmanager | ||
| def materialized_modules(modules: dict[str, str]) -> Iterator[str | None]: | ||
| """Write *modules* to a temp dir on ``sys.path`` for the duration of the block. | ||
|
|
||
| Args: | ||
| modules: POSIX relative path -> module source text. Empty means no-op. | ||
|
|
||
| Yields: | ||
| The temp dir path added to ``sys.path``, or ``None`` when *modules* is empty. | ||
|
|
||
| Concurrency note: this mutates the process-global ``sys.path``. It assumes one | ||
| function executes at a time per worker process (the current worker model). If a | ||
| worker runs multiple handler invocations concurrently (e.g. async concurrency > | ||
| 1), the inserted temp dir is visible to other in-flight invocations and cleanup | ||
| on exit could remove files mid-import. Isolating sys.path per invocation is a | ||
| follow-up if concurrent execution is enabled. | ||
| """ | ||
| if not modules: | ||
| yield None | ||
| return | ||
|
|
||
| tmpdir = tempfile.mkdtemp(prefix="flash_modules_") | ||
| root = Path(tmpdir) | ||
| for rel_path, source in modules.items(): | ||
| dest = root / rel_path | ||
| dest.parent.mkdir(parents=True, exist_ok=True) | ||
| dest.write_text(source, encoding="utf-8") | ||
|
deanq marked this conversation as resolved.
Outdated
|
||
|
|
||
| sys.path.insert(0, tmpdir) | ||
| try: | ||
| yield tmpdir | ||
| finally: | ||
| try: | ||
| sys.path.remove(tmpdir) | ||
| except ValueError: | ||
| log.warning( | ||
| "flash module temp dir %s already removed from sys.path", tmpdir | ||
| ) | ||
| import shutil | ||
|
|
||
| shutil.rmtree(tmpdir, ignore_errors=True) | ||
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.
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.