-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add a mode to allow crt to either be used as a default dependency wit… #505
Changes from all commits
b160841
e8f08b2
adfc3c2
e25f26f
d151f5a
ca34baf
6156ead
592cc93
aa8c1b8
69e198a
bc6033e
1104cd6
12bc7ba
c625d3e
19d272d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -531,3 +531,4 @@ deps/ | |
|
||
# API docs are updated automatically by .github/workflows/docs.yml | ||
docs/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,5 +67,13 @@ Please note that on Mac, once a private key is used with a certificate, that cer | |
static: certificate has an existing certificate-key pair that was previously imported into the Keychain. Using key from Keychain instead of the one provided. | ||
``` | ||
|
||
## Using With a System-Level Installation of the _awscrt Module or as an Optional Dependency | ||
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. I don't know much about package managers, but I can't imagine one vending Just FYI, here's what's in the Amazon Linux 2023 package:
|
||
|
||
By default, upon installation if both the wheel is unavailable from PyPi and setup.py cannot build the _awscrt module, installation will still succeed. This is intended to allow the crt to be installed into other libraries or applications as a library without failing its install step if a compiler or any other required build tool is not available. This also allows _awscrt to be loaded at the system level via. operating system package managers as this will cause the loader to look at the system path when it can't find the locally installed module. | ||
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. Ask our Python folks if this is a good approach. Failing at run time instead of install time is a pretty radical change. I want to be sure we have buy-in from people who know the community best |
||
|
||
````awscrt.crt_wheel_installed()```` will always return without throwing an Exception even if the build itself failed. If this function returns true, the rest of the modules in this package may be used. | ||
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. pedantic: A "wheel" is whole installable package, not just the C-extension. Even packages without C-extensions, or anything platform specific, still have wheels in PyPI. For example: Maybe name it: |
||
|
||
To disable this behavior at build time, set ```AWS_CRT_BUILD_STRICT_MODE=ON``` which will cause the install to abort if an error occurs building the wheel. | ||
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. trivial: we have a few on/off env variables already, and they all use |
||
|
||
## Crash Handler | ||
You can enable the crash handler by setting the environment variable `AWS_CRT_CRASH_HANDLER=1`. This will print the callstack to `stderr` in the event of a fatal error. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
# SPDX-License-Identifier: Apache-2.0. | ||
|
||
from weakref import WeakSet | ||
from .config import crt_wheel_installed | ||
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. trivial: I would just put the function here in or name the other file |
||
|
||
__all__ = [ | ||
'auth', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
Config module which can always be checked regardless of if the CRT was successfully built, installed on system, or not. | ||
""" | ||
|
||
""" | ||
Returns True if either _awscrt was installed in the local environment or loaded from the system. | ||
Otherwise returns False indicating that any other functions or modules in this library will also fail. | ||
""" | ||
|
||
|
||
def crt_wheel_installed(): | ||
try: | ||
import _awscrt | ||
return True | ||
except Exception: | ||
return False |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0. | ||
|
||
import awscrt | ||
|
||
print('Is CRT wheel installed? {}', awscrt.crt_wheel_installed()) | ||
## this had better be False since the caller sabotaged the build in some way. | ||
assert(awscrt.crt_wheel_installed() == False) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
set -euxo pipefail | ||
|
||
# intentionally not pulling the submodules to make the build fail cleanly. | ||
# git submodule update --init | ||
|
||
export AWS_CRT_BUILD_STRICT_MODE=OFF | ||
python -m venv ./crt-build | ||
source ./crt-build/bin/activate | ||
pip install setuptools wheel --upgrade | ||
pip install -v ./ | ||
python codebuild/test-config-on-failure.py |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,12 @@ def using_system_libcrypto(): | |
return os.getenv('AWS_CRT_BUILD_USE_SYSTEM_LIBCRYPTO') == '1' | ||
|
||
|
||
def strict_build_success_mode(): | ||
strict_mode = os.getenv('AWS_CRT_BUILD_STRICT_MODE') | ||
print("Strict-Mode is set to: {}".format(strict_mode)) | ||
return strict_mode is not None and strict_mode.strip().lower() != 'off' | ||
|
||
|
||
class AwsLib: | ||
def __init__(self, name, extra_cmake_args=[], libname=None): | ||
self.name = name | ||
|
@@ -391,25 +397,52 @@ def _load_version(): | |
return VERSION_RE.match(fp.read()).group(1) | ||
|
||
|
||
setuptools.setup( | ||
name="awscrt", | ||
version=_load_version(), | ||
license="Apache 2.0", | ||
author="Amazon Web Services, Inc", | ||
author_email="[email protected]", | ||
description="A common runtime for AWS Python projects", | ||
long_description=_load_readme(), | ||
long_description_content_type='text/markdown', | ||
url="https://github.com/awslabs/aws-crt-python", | ||
# Note: find_packages() without extra args will end up installing test/ | ||
packages=setuptools.find_packages(include=['awscrt*']), | ||
classifiers=[ | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: Apache Software License", | ||
"Operating System :: OS Independent", | ||
], | ||
python_requires='>=3.7', | ||
ext_modules=[awscrt_ext()], | ||
cmdclass={'build_ext': awscrt_build_ext, "bdist_wheel": bdist_wheel_abi3}, | ||
test_suite='test', | ||
) | ||
try: | ||
setuptools.setup( | ||
name="awscrt", | ||
version=_load_version(), | ||
license="Apache 2.0", | ||
author="Amazon Web Services, Inc", | ||
author_email="[email protected]", | ||
description="A common runtime for AWS Python projects", | ||
long_description=_load_readme(), | ||
long_description_content_type='text/markdown', | ||
url="https://github.com/awslabs/aws-crt-python", | ||
# Note: find_packages() without extra args will end up installing test/ | ||
packages=setuptools.find_packages(include=['awscrt*']), | ||
classifiers=[ | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: Apache Software License", | ||
"Operating System :: OS Independent", | ||
], | ||
python_requires='>=3.7', | ||
ext_modules=[awscrt_ext()], | ||
cmdclass={'build_ext': awscrt_build_ext, "bdist_wheel": bdist_wheel_abi3}, | ||
test_suite='test', | ||
) | ||
|
||
except (SystemExit, Exception) as e: | ||
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. did you really encounter I asked BingGPT if setuptools.setup() could return SystemExit and it said that's what happens if someone calls your setup.py directly and doesn't pass the correct args, like: |
||
if (strict_build_success_mode()): | ||
raise e | ||
|
||
# build without the c extension, and allow the system loader to pick it up if/when it's available. | ||
# The config module will provide users with a way to check. | ||
setuptools.setup( | ||
name="awscrt", | ||
version=_load_version(), | ||
license="Apache 2.0", | ||
author="Amazon Web Services, Inc", | ||
author_email="[email protected]", | ||
description="A common runtime for AWS Python projects", | ||
long_description=_load_readme(), | ||
long_description_content_type='text/markdown', | ||
url="https://github.com/awslabs/aws-crt-python", | ||
# Note: find_packages() without extra args will end up installing test/ | ||
packages=setuptools.find_packages(include=['awscrt*']), | ||
classifiers=[ | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: Apache Software License", | ||
"Operating System :: OS Independent", | ||
], | ||
python_requires='>=3.7', | ||
) | ||
Comment on lines
+430
to
+448
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 very copy/pasty. It's very hard to tell what's different, and it's likely someone makes a mistake one day and updates 1 block and not the other. Maybe break this into a function:
|
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.
trivial: Just enter the shell commands here. It's simpler