Skip to content

Commit

Permalink
Update Dependencies. Misc improvements (#130)
Browse files Browse the repository at this point in the history
- Update setup.py version to 0.5.7
- Update dependencies
- Small improvements
  - Reduce default MQTT keep-alive values (see Issue #128)
  - Simplify README
  - Better error message if `cmake` not installed (see [forum issue](https://forums.aws.amazon.com/thread.jspa?threadID=316634&tstart=0))
- CI improvements
  - Set up Github secrets so MQTT tests will run again
  - Alter credentials tests so they can't accidentally leak secrets
  - `ManyLinuxCI` action uses `AWSCrtPython` action.
  • Loading branch information
graebm authored Feb 20, 2020
1 parent f093628 commit e4daed8
Show file tree
Hide file tree
Showing 19 changed files with 143 additions and 149 deletions.
26 changes: 18 additions & 8 deletions .builder/actions/aws_crt_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import sys


class InstallPythonReqs(Builder.Action):
def __init__(self, trust_hosts=False, deps=[], python=sys.executable):
self.trust_hosts = trust_hosts
Expand All @@ -26,21 +27,30 @@ def run(self, env):


class AWSCrtPython(Builder.Action):
def run(self, env):
# Once the virtualenv is set up, we must use that python, so that the venv is used
python = sys.executable
def __init__(self, custom_python=None, name=None):
"""
Prefer the current python3 executable (so that venv is used).
But allow a custom python to be used for installing and testing awscrt on.
"""
self.python3 = sys.executable
self.custom_python = custom_python if custom_python else self.python3
self.name = name if name else 'aws-crt-python'

def run(self, env):
install_options = []
if 'linux' == Builder.Host.current_platform():
install_options = [
'--install-option=--include-dirs={openssl_include}',
'--install-option=--library-dirs={openssl_lib}']

actions = [
InstallPythonReqs(deps=['boto3']),
[python, '-m', 'pip', 'install', '.', '--install-option=--verbose', '--install-option=build_ext', *install_options],
[python, '-m', 'unittest', 'discover', '--verbose'],
[python, 'aws-common-runtime/aws-c-http/integration-testing/http_client_test.py', python, 'elasticurl.py'],
InstallPythonReqs(deps=['boto3'], python=self.custom_python),
[self.custom_python, '-m', 'pip', 'install', '.', '--install-option=--verbose',
'--install-option=build_ext', *install_options],
[self.custom_python, '-m', 'unittest', 'discover', '--verbose'],
# http_client_test.py is python3-only. It launches external processes using the extra args
[self.python3, 'aws-common-runtime/aws-c-http/integration-testing/http_client_test.py',
self.custom_python, 'elasticurl.py'],
]

return Builder.Script(actions, name='aws-crt-python')
return Builder.Script(actions, name=self.name)
25 changes: 4 additions & 21 deletions .builder/actions/manylinux-ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Builder
import os
import sys
from aws_crt_python import InstallPythonReqs
from aws_crt_python import AWSCrtPython, InstallPythonReqs

pythons = (
'cp35-cp35m',
Expand All @@ -17,10 +17,6 @@ def python_path(version):
return '/opt/python/{}/bin/python'.format(version)


def default_python():
return sys.executable


class ManyLinuxPackage(Builder.Action):
def run(self, env):
steps = []
Expand All @@ -38,7 +34,7 @@ def run(self, env):

actions = [
InstallPythonReqs(python=python),
[python,'-m', 'pip', 'install', '.',
[python, '-m', 'pip', 'install', '.',
'--install-option=--verbose',
'--install-option=sdist',
'--install-option=bdist_wheel',
Expand All @@ -60,27 +56,14 @@ def run(self, env):

class ManyLinuxCI(Builder.Action):
def run(self, env):
python3 = default_python()

steps = []
for version in pythons:
python = python_path(version)
if not os.path.isfile(python):
print('Skipping {} as it is not installed'.format(python))
continue

install_options = []
if 'linux' == Builder.Host.current_platform():
install_options = [
'--install-option=--include-dirs={openssl_include}',
'--install-option=--library-dirs={openssl_lib}']

actions = [
InstallPythonReqs(python=python, deps=['boto3'], trust_hosts=True),
[python, '-m', 'pip', 'install', '.',
'--install-option=--verbose', '--install-option=build_ext', *install_options],
[python3, 'aws-common-runtime/aws-c-http/integration-testing/http_client_test.py', python, 'elasticurl.py'],
]
steps.append(Builder.Script(actions, name=python))
# Run the usual AWSCrtPython build and test steps for this python
steps.append(AWSCrtPython(custom_python=python, name=python))

return Builder.Script(steps, name='manylinux-ci')
13 changes: 8 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ env:
PACKAGE_NAME: aws-crt-python
LINUX_BASE_IMAGE: ubuntu-16-x64
RUN: ${{ github.run_id }}-${{ github.run_number }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}

jobs:
linux-compat:
Expand All @@ -30,7 +33,7 @@ jobs:
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin
export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-${{ matrix.image }}:${{ env.BUILDER_VERSION }}
docker pull $DOCKER_IMAGE
docker run --env GITHUB_REF $DOCKER_IMAGE -p ${{ env.PACKAGE_NAME }} run manylinux-ci
docker run --env GITHUB_REF --env AWS_ACCESS_KEY_ID --env AWS_SECRET_ACCESS_KEY --env AWS_DEFAULT_REGION $DOCKER_IMAGE -p ${{ env.PACKAGE_NAME }} run manylinux-ci
al2:
runs-on: ubuntu-latest
Expand All @@ -41,8 +44,8 @@ jobs:
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin
export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-al2-x64:${{ env.BUILDER_VERSION }}
docker pull $DOCKER_IMAGE
docker run --env GITHUB_REF $DOCKER_IMAGE -p ${{ env.PACKAGE_NAME }} run aws-crt-python
docker run --env GITHUB_REF --env AWS_ACCESS_KEY_ID --env AWS_SECRET_ACCESS_KEY --env AWS_DEFAULT_REGION $DOCKER_IMAGE -p ${{ env.PACKAGE_NAME }} run aws-crt-python
clang-compat:
runs-on: ubuntu-latest
strategy:
Expand All @@ -55,7 +58,7 @@ jobs:
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin
export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-${{ env.LINUX_BASE_IMAGE }}:${{ env.BUILDER_VERSION }}
docker pull $DOCKER_IMAGE
docker run --env GITHUB_REF $DOCKER_IMAGE -p ${{ env.PACKAGE_NAME }} run aws-crt-python --compiler=clang-${{ matrix.version }}
docker run --env GITHUB_REF --env AWS_ACCESS_KEY_ID --env AWS_SECRET_ACCESS_KEY --env AWS_DEFAULT_REGION $DOCKER_IMAGE -p ${{ env.PACKAGE_NAME }} run aws-crt-python --compiler=clang-${{ matrix.version }}
gcc-compat:
runs-on: ubuntu-latest
Expand All @@ -69,7 +72,7 @@ jobs:
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin
export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-${{ env.LINUX_BASE_IMAGE }}:${{ env.BUILDER_VERSION }}
docker pull $DOCKER_IMAGE
docker run --env GITHUB_REF $DOCKER_IMAGE -p ${{ env.PACKAGE_NAME }} run aws-crt-python --compiler=gcc-${{ matrix.version }}
docker run --env GITHUB_REF --env AWS_ACCESS_KEY_ID --env AWS_SECRET_ACCESS_KEY --env AWS_DEFAULT_REGION $DOCKER_IMAGE -p ${{ env.PACKAGE_NAME }} run aws-crt-python --compiler=gcc-${{ matrix.version }}
windows:
runs-on: windows-latest
Expand Down
18 changes: 0 additions & 18 deletions .github/workflows/clang-format.yml

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Lint

on: [push]

jobs:
clang-format:

runs-on: ubuntu-latest

steps:
- name: Checkout Sources
uses: actions/checkout@v2

- name: clang-format lint
uses: DoozyX/[email protected]
with:
# List of extensions to check
extensions: c,h

autopep8:
runs-on: ubuntu-latest

steps:
- name: Checkout Source
uses: actions/checkout@v2

- name: Build and Test
run: |
python3 -m pip install --upgrade setuptools
python3 -m pip install --upgrade autopep8
python3 -m autopep8 --exit-code --diff --recursive awscrt test .builder setup.py
59 changes: 11 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,24 @@
## AWS Crt Python
## AWS CRT Python

Python bindings for the AWS Common Runtime

## License

This library is licensed under the Apache 2.0 License.
This library is licensed under the Apache 2.0 License.

## Building the Wheel
## Installation

This builds the wheel itself
To install from pip:
````bash
<path to your python binary> setup.py sdist bdist_wheel
python -m pip install awscrt
````

You'll want to do this for every version of Python:
2.7m, 2.7mu, 3.4m, 3.5m, 3.6m, and 3.7m

Don't worry, it will only do a full build on the first run. All the others will just reuse the artifacts.

### Intel Linux
On linux, assuming you built on an ancient distro (GLIBC is <= 2.5), you'll need to have python inspect the artifact
and ensure it's compatible:

````bash
auditwheel show dist/<your output wheel>
````

If everything is good to go, you'll see a line that says:

following platform tag: "manylinux1_\<arch\>".

One thing to keep in mind, you'll need a version of libcrypto build as a static lib with position independent code (-fPIC).
DO NOT use the shared lib version of libcrypto or the wheel will not pass this test.

Now you'll need to have the wheel renamed to something compatible with pypi:

To install from Github:
````bash
auditwheel repair --plat manylinux1_x86_64 -w dist dist/<your image name>
git clone https://github.com/awslabs/aws-crt-python.git
cd aws-crt-python
git submodule update --init
python -m pip install .
````

After doing this, I like to delete all of the old wheel images for making the next step easier:

### ARM Linux
The process is similar to Intel, but we haven't built the wheels yet. We'll update this document when we finally get that finished.

## Publishing
Upload to pypi:

````bash
<path to your python binary> -m twine upload --repository-url <the repo> dist/*
````

## Using From Your Python Application

Normally, you just declare `aws_crt` as a dependency in your setup.py file.

### Installing from pip
````bash
pip install aws_crt
````
To use from your Python application, declare `awscrt` as a dependency in your `setup.py` file.
2 changes: 1 addition & 1 deletion aws-common-runtime/aws-c-auth
2 changes: 1 addition & 1 deletion aws-common-runtime/aws-c-http
Submodule aws-c-http updated 50 files
+90 −0 .github/workflows/ci.yml
+1 −1 .github/workflows/clang-format.yml
+0 −23 .github/workflows/mac-osx-ci.yml
+1 −0 .gitignore
+5 −8 builder.json
+2 −2 cmake/aws-c-http-config.cmake
+24 −0 include/aws/http/connection.h
+1 −0 include/aws/http/connection_manager.h
+13 −4 include/aws/http/http.h
+19 −19 include/aws/http/private/connection_impl.h
+56 −0 include/aws/http/private/connection_monitor.h
+26 −5 include/aws/http/private/h2_connection.h
+9 −4 include/aws/http/private/h2_decoder.h
+23 −64 include/aws/http/private/h2_frames.h
+14 −5 include/aws/http/private/h2_stream.h
+30 −5 include/aws/http/private/hpack.h
+2 −0 include/aws/http/private/request_response_impl.h
+6 −0 include/aws/http/request_response.h
+63 −0 include/aws/http/statistics.h
+58 −21 source/connection.c
+17 −0 source/connection_manager.c
+222 −0 source/connection_monitor.c
+284 −193 source/h1_connection.c
+1 −2 source/h1_decoder.c
+7 −0 source/h1_stream.c
+375 −36 source/h2_connection.c
+696 −201 source/h2_decoder.c
+95 −750 source/h2_frames.c
+12 −336 source/h2_stream.c
+391 −166 source/hpack.c
+14 −0 source/http.c
+4 −0 source/request_response.c
+34 −0 source/statistics.c
+36 −13 source/websocket_bootstrap.c
+39 −12 tests/CMakeLists.txt
+354 −0 tests/fuzz/fuzz_h2_decoder_correct.c
+4 −3 tests/fuzz/fuzz_h2_decoder_random.c
+0 −112 tests/fuzz/fuzz_h2_frames.c
+4 −2 tests/proxy_test_helper.c
+1,492 −0 tests/test_connection_monitor.c
+66 −115 tests/test_h1_client.c
+15 −27 tests/test_h1_server.c
+104 −0 tests/test_h2_client.c
+363 −0 tests/test_h2_encoder.c
+0 −584 tests/test_h2_frames.c
+155 −151 tests/test_h2_headers.c
+79 −28 tests/test_hpack.c
+6 −18 tests/test_proxy.c
+42 −24 tests/test_websocket_bootstrap.c
+2 −1 tests/test_websocket_handler.c
2 changes: 1 addition & 1 deletion aws-common-runtime/aws-c-io
Submodule aws-c-io updated 48 files
+90 −0 .github/workflows/ci.yml
+26 −0 .github/workflows/clang-tsan.yml
+0 −23 .github/workflows/mac-osx-ci.yml
+0 −23 .travis.yml
+6 −1 CMakeLists.txt
+7 −1 builder.json
+1 −0 cmake/aws-c-io-config.cmake
+97 −0 cmake/modules/FindLibCrypto.cmake
+27 −0 include/aws/io/channel.h
+46 −60 include/aws/io/channel_bootstrap.h
+5 −2 include/aws/io/io.h
+2 −2 include/aws/io/logging.h
+49 −0 include/aws/io/private/tls_channel_handler_shared.h
+1 −0 include/aws/io/socket.h
+88 −0 include/aws/io/statistics.h
+11 −0 include/aws/io/tls_channel_handler.h
+87 −25 include/aws/testing/io_testing_channel.h
+136 −2 source/channel.c
+51 −63 source/channel_bootstrap.c
+12 −1 source/darwin/darwin_pki_utils.c
+29 −1 source/darwin/secure_transport_tls_channel_handler.c
+13 −12 source/host_resolver.c
+4 −1 source/io.c
+44 −7 source/s2n/s2n_tls_channel_handler.c
+38 −3 source/socket_channel_handler.c
+54 −0 source/statistics.c
+4 −0 source/tls_channel_handler.c
+75 −0 source/tls_channel_handler_shared.c
+32 −0 source/windows/secure_channel_tls_handler.c
+5 −0 tests/CMakeLists.txt
+118 −94 tests/channel_test.c
+6 −6 tests/event_loop_test.c
+3 −1 tests/io_testing_channel_test.c
+22 −21 tests/pipe_test.c
+8 −7 tests/read_write_test_handler.c
+51 −0 tests/resources/key_pair0.pem
+51 −0 tests/resources/key_pair1.pem
+51 −0 tests/resources/key_pair2.pem
+51 −0 tests/resources/key_pair3.pem
+51 −0 tests/resources/key_pair4.pem
+51 −0 tests/resources/key_pair5.pem
+51 −0 tests/resources/key_pair6.pem
+51 −0 tests/resources/key_pair7.pem
+1 −0 tests/resources/suppressions.txt
+240 −34 tests/socket_handler_test.c
+122 −0 tests/statistics_handler_test.c
+37 −0 tests/statistics_handler_test.h
+584 −71 tests/tls_handler_test.c
6 changes: 3 additions & 3 deletions awscrt/awsiot_mqtt_connection_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
keep_alive_secs (int): The keep alive value, in seconds, to send in CONNECT packet.
A PING will automatically be sent at this interval.
The server will assume the connection is lost if no PING is received after 1.5X this value.
Default is 3600 (1 hour). This value must be higher than ping_timeout_ms.
Default is 1200sec (20 minutes). This duration must be longer than ping_timeout_ms.
ping_timeout_ms (int): Milliseconds to wait for ping response before client assumes
the connection is invalid and attempts to reconnect.
Default is 3000ms (3 seconds). This value must be less than keep_alive.
Default is 3000ms (3 seconds). This duration must be shorter than keep_alive_secs.
Alternatively, TCP keep-alive may accomplish this in a more efficient (low-power) scenario,
but keep-alive options may not work the same way on every platform and OS version.
Expand Down Expand Up @@ -182,7 +182,7 @@ def _builder(
clean_session=kwargs.get('clean_session', False),
reconnect_min_timeout_secs=kwargs.get('reconnect_min_timeout_secs', 5),
reconnect_max_timeout_secs=kwargs.get('reconnect_max_timeout_secs', 60),
keep_alive_secs=kwargs.get('keep_alive_secs', 3600),
keep_alive_secs=kwargs.get('keep_alive_secs', 1200),
ping_timeout_ms=kwargs.get('ping_timeout_ms', 3000),
will=kwargs.get('will'),
username=username,
Expand Down
9 changes: 6 additions & 3 deletions awscrt/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(self,
on_connection_resumed=None,
reconnect_min_timeout_secs=5,
reconnect_max_timeout_secs=60,
keep_alive_secs=3600,
keep_alive_secs=1200,
ping_timeout_ms=3000,
will=None,
username=None,
Expand Down Expand Up @@ -132,11 +132,11 @@ def __init__(self,
keep_alive_secs (int): The keep alive value, in seconds, to send in CONNECT packet.
A PING will automatically be sent at this interval.
The server will assume the connection is lost if no PING is received after 1.5X this value.
This value must be higher than ping_timeout_ms.
This duration must be longer than ping_timeout_ms.
ping_timeout_ms (int): Milliseconds to wait for ping response before client assumes
the connection is invalid and attempts to reconnect.
This value must be less than keep_alive.
This duration must be shorter than keep_alive_secs.
Alternatively, TCP keep-alive may accomplish this in a more efficient (low-power) scenario,
but keep-alive options may not work the same way on every platform and OS version.
Expand Down Expand Up @@ -173,6 +173,9 @@ def __init__(self,
assert isinstance(websocket_proxy_options, HttpProxyOptions) or websocket_proxy_options is None
assert callable(websocket_handshake_transform) or websocket_handshake_transform is None

if keep_alive_secs * 1000 <= ping_timeout_ms:
raise ValueError("'keep_alive_secs' duration must be longer than 'ping_timeout_ms'")

super(Connection, self).__init__()

# init-only
Expand Down
17 changes: 16 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ def determine_generator_args():
return []


cmake_found = False


def check_cmake_installed():
global cmake_found
if not cmake_found:
try:
subprocess.check_call(['cmake', '--version'])
cmake_found = True
except Exception:
raise Exception("'cmake' not found. cmake must be installed to build from source.")


class AwsLib(object):
def __init__(self, name, extra_cmake_args=[]):
self.name = name
Expand Down Expand Up @@ -110,6 +123,8 @@ def __init__(self, name, extra_cmake_args=[]):

class awscrt_build_ext(setuptools.command.build_ext.build_ext):
def _build_dependency(self, aws_lib):
check_cmake_installed()

prev_cwd = os.getcwd() # restore cwd at end of function
lib_source_dir = os.path.join(PROJECT_DIR, 'aws-common-runtime', aws_lib.name)

Expand Down Expand Up @@ -229,7 +244,7 @@ def awscrt_ext():

setuptools.setup(
name="awscrt",
version="0.5.6",
version="0.5.7",
author="Amazon Web Services, Inc",
author_email="[email protected]",
description="A common runtime for AWS Python projects",
Expand Down
3 changes: 0 additions & 3 deletions test/resources/credentials_test

This file was deleted.

Loading

0 comments on commit e4daed8

Please sign in to comment.