This repository has been archived by the owner on May 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Python 3.12 and prep v0.2.0. (#35)
Also document how modern Pex can be used instead of Lambdex to pave the way to archiving the project after the 0.2.0 release.
- Loading branch information
Showing
13 changed files
with
178 additions
and
54 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,49 @@ | ||
# Migrating to modern Pex | ||
|
||
Lambdex used to be needed to produce zip files useable in lambda functions, but with modern Pex, | ||
it no longer is. Starting with Pex version 2.1.98 you only need to include `import __pex__` at the | ||
top of your lambda handler entrypoint module and build the PEX with | ||
`--inherit-path {fallback,prefer}`. | ||
|
||
For example, with the following `my_lambda_module.py`: | ||
```python | ||
import __pex__ | ||
|
||
import hashlib | ||
|
||
import requests | ||
|
||
|
||
def handler(event, context): | ||
url = event["url"] | ||
return { | ||
url: hashlib.sha256(requests.get(url).content).hexdigest(), | ||
"requests.__file__": requests.__file__, | ||
} | ||
``` | ||
|
||
You can create a zip that will work[^1] in the Python 3.12 AWS lambda runtime with: | ||
``` | ||
pex \ | ||
--python python3.12 \ | ||
requests \ | ||
--module my_lambda_module \ | ||
--output-file pex_lambda_function.zip \ | ||
--inherit-path=fallback | ||
``` | ||
|
||
With the zip uploaded and the lambda runtime configured to use the `my_lambda_module.handler` | ||
handler, you can post an event with `{"url": "https://example.org"}` to the handler endpoint | ||
and see a response similar to: | ||
```json | ||
{ | ||
"https://example.org": "ea8fac7c65fb589b0d53560f5251f74f9e9b243478dcb6b3ea79b5e36449c8d9", | ||
"requests.__file__": "/var/task/.deps/requests-2.32.3-py3-none-any.whl/requests/__init__.py" | ||
} | ||
``` | ||
|
||
[^1]: In general, you need to either build the PEX in an environment compatible with the Lambda | ||
deployment environment or else use the the Pex [`--complete-platform`]( | ||
https://docs.pex-tool.org/buildingpex.html#complete-platform) option to properly cross-resolve | ||
for the deployement environment. This is no different a requirement than existed when using | ||
Lambdex to transform a PEX into a lambda-compatible zip previously. |
This file contains 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 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 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 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 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 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 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,4 +1,4 @@ | ||
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
__version__ = "0.1.9" | ||
__version__ = "0.2.0" |
This file contains 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 |
---|---|---|
|
@@ -5,8 +5,8 @@ build-backend = "flit_core.buildapi" | |
[tool.flit.metadata] | ||
module = "lambdex" | ||
author = "The Lambdex developers" | ||
author-email = "[email protected]" | ||
home-page = "https://github.com/pantsbuild/lambdex" | ||
author-email = "[email protected]" | ||
home-page = "https://github.com/pex-tool/lambdex" | ||
description-file = "README.md" | ||
classifiers = [ | ||
"Development Status :: 4 - Beta", | ||
|
@@ -25,13 +25,14 @@ classifiers = [ | |
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Programming Language :: Python :: 3.12", | ||
"Topic :: Software Development :: Build Tools", | ||
"Topic :: System :: Archiving :: Packaging", | ||
"Topic :: System :: Software Distribution", | ||
"Topic :: Utilities", | ||
] | ||
requires = ["pex>=1.1.15"] | ||
requires-python = ">=2.7,<3.12,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*" | ||
requires-python = ">=2.7,<3.13,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*" | ||
|
||
[tool.flit.metadata.requires-extra] | ||
test-gcp-http = [ | ||
|
@@ -47,7 +48,7 @@ lambdex = "lambdex.bin.lambdex:main" | |
include = ["CHANGES.md"] | ||
|
||
[tool.flit.metadata.urls] | ||
Changelog = "https://github.com/pantsbuild/lambdex/blob/main/CHANGES.md" | ||
Changelog = "https://github.com/pex-tool/lambdex/blob/main/CHANGES.md" | ||
|
||
[tool.black] | ||
line-length = 100 | ||
|
Oops, something went wrong.