Skip to content

Commit

Permalink
Remove support for python 2 (#105)
Browse files Browse the repository at this point in the history
Python 2's end-of-life date was Jan 1 2020.
  • Loading branch information
graebm authored Sep 10, 2020
1 parent 88908b5 commit 4c66229
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 70 deletions.
4 changes: 2 additions & 2 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
AWS IoT SDK for Python v2
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
AWS IoT Device SDK v2 for Python
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# AWS IoT Device SDK for Python v2
This document provides information about the AWS IoT device SDK for Python V2.
# AWS IoT Device SDK v2 for Python
This document provides information about the AWS IoT Device SDK v2 for Python.

If you have any issues or feature requests, please file an issue or pull request.

Expand Down Expand Up @@ -35,26 +35,25 @@ to Python by the `awscrt` package ([PyPI](https://pypi.org/project/awscrt/)) ([G

### Install from PyPI
```
pip install awsiotsdk
python3 -m pip install awsiotsdk
```

### Install from source
```
pip install ./aws-iot-device-sdk-python-v2
git clone https://github.com/aws/aws-iot-device-sdk-python-v2.git
python3 -m pip install ./aws-iot-device-sdk-python-v2
```

### Installation Issues

`awsiotsdk` depends on [awscrt](https://github.com/awslabs/aws-crt-python), which makes use of C extensions. Precompiled wheels are downloaded when installing on major platforms (Mac, Windows, Linux, Raspbian (python3 only)). If wheels are unavailable for your platform (ex: Raspbian with python2.7), your machine must compile some C libraries. If you encounter issues, install the following and try again:
`awsiotsdk` depends on [awscrt](https://github.com/awslabs/aws-crt-python), which makes use of C extensions. Precompiled wheels are downloaded when installing on major platforms (Mac, Windows, Linux, Raspbian. If wheels are unavailable for your platform, your machine must compile some C libraries. If you encounter issues, install the following and try again:

```
sudo apt-get update
sudo apt-get install cmake
sudo apt-get install libssl-dev
```



## Mac-Only TLS Behavior

Please note that on Mac, once a private key is used with a certificate, that certificate-key pair is imported into the Mac Keychain. All subsequent uses of that certificate will use the stored private key and ignore anything passed in programmatically. Beginning in v1.3.2, when a stored private key from the Keychain is used, the following will be logged at the "info" log level:
Expand Down
4 changes: 2 additions & 2 deletions awsiot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
PayloadObj = Dict[str, Any]
PayloadToClassFn = Callable[[PayloadObj], T]

class MqttServiceClient(object):
class MqttServiceClient:
"""
Base class for an AWS MQTT Service Client
"""
Expand Down Expand Up @@ -153,7 +153,7 @@ def callback_wrapper(topic, payload, **kwargs):

return future, topic

class ModeledClass(object):
class ModeledClass:
"""
Base for input/output classes generated from an AWS service model.
"""
Expand Down
4 changes: 2 additions & 2 deletions awsiot/greengrass_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from concurrent.futures import Future
import json

class DiscoveryClient(object):
class DiscoveryClient:
__slots__ = ['_bootstrap', '_tls_context', '_socket_options', '_region', '_tls_connection_options', '_gg_server_name', 'gg_url', 'port']

def __init__(self, bootstrap, socket_options, tls_context, region):
Expand Down Expand Up @@ -63,7 +63,7 @@ def on_connection_completed(conn_future):
http_stream = connection.request(
request=request,
on_body=on_incoming_body)

http_stream.activate()
http_stream.completion_future.add_done_callback(on_request_complete)

Expand Down
22 changes: 6 additions & 16 deletions builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
},
"manylinux": {
"post_build_steps": [
["echo", "------ Python 3.7 ------"],
["/opt/python/cp37-cp37m/bin/python", "-m", "pip", "install", "--upgrade", "pip", "setuptools"],
["/opt/python/cp37-cp37m/bin/python", "-m", "pip", "install", ".", "--verbose"],
["/opt/python/cp37-cp37m/bin/python", "-m", "pip", "install", "boto3", "autopep8"],
["/opt/python/cp37-cp37m/bin/python", "-m", "unittest", "discover", "--verbose"],
["echo", "------ Python 3.6 ------"],
["/opt/python/cp36-cp36m/bin/python", "-m", "pip", "install", "--upgrade", "pip", "setuptools"],
["/opt/python/cp36-cp36m/bin/python", "-m", "pip", "install", ".", "--verbose"],
Expand All @@ -32,22 +37,7 @@
["/opt/python/cp35-cp35m/bin/python", "-m", "pip", "install", "--upgrade", "pip", "setuptools"],
["/opt/python/cp35-cp35m/bin/python", "-m", "pip", "install", ".", "--verbose"],
["/opt/python/cp35-cp35m/bin/python", "-m", "pip", "install", "boto3", "autopep8"],
["/opt/python/cp35-cp35m/bin/python", "-m", "unittest", "discover", "--verbose"],
["echo", "------ Python 3.4 ------"],
["/opt/python/cp34-cp34m/bin/python", "-m", "pip", "install", "--upgrade", "pip", "setuptools"],
["/opt/python/cp34-cp34m/bin/python", "-m", "pip", "install", ".", "--verbose"],
["/opt/python/cp34-cp34m/bin/python", "-m", "pip", "install", "boto3", "autopep8"],
["/opt/python/cp34-cp34m/bin/python", "-m", "unittest", "discover", "--verbose"],
["echo", "------ Python 2.7 narrow-unicode ------"],
["/opt/python/cp27-cp27m/bin/python", "-m", "pip", "install", "--upgrade", "pip", "setuptools"],
["/opt/python/cp27-cp27m/bin/python", "-m", "pip", "install", ".", "--verbose"],
["/opt/python/cp27-cp27m/bin/python", "-m", "pip", "install", "boto3", "autopep8"],
["/opt/python/cp27-cp27m/bin/python", "-m", "unittest", "discover", "--verbose"],
["echo", "------ Python 2.7 wide-unicode ------"],
["/opt/python/cp27-cp27mu/bin/python", "-m", "pip", "install", "--upgrade", "pip", "setuptools"],
["/opt/python/cp27-cp27mu/bin/python", "-m", "pip", "install", ".", "--verbose"],
["/opt/python/cp27-cp27mu/bin/python", "-m", "pip", "install", "boto3", "autopep8"],
["/opt/python/cp27-cp27mu/bin/python", "-m", "unittest", "discover", "--verbose"]
["/opt/python/cp35-cp35m/bin/python", "-m", "unittest", "discover", "--verbose"]
],
"run_tests": false,
"_comment": "manylinux has all its own build steps, turn off 'tests' which is where normal build steps are declared. using data to program sucks"
Expand Down
2 changes: 1 addition & 1 deletion docsrc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

# -- Project information -----------------------------------------------------

project = 'AWS IoT Device SDK Python v2'
project = 'AWS IoT Device SDK v2 for Python'
copyright = '%s, Amazon Web Services, Inc' % datetime.now().year
author = 'Amazon Web Services, Inc'

Expand Down
8 changes: 4 additions & 4 deletions docsrc/index.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.. AWS IoT Device SDK Python v2 documentation master file, created by
.. AWS IoT Device SDK v2 for Python documentation master file, created by
sphinx-quickstart on Mon Aug 17 14:57:36 2020.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
AWS IoT Device SDK Python v2
============================
AWS IoT Device SDK v2 for Python
================================

Python bindings for the AWS IoT Device API.

Expand All @@ -18,7 +18,7 @@ API Reference
-------------
.. toctree::
:maxdepth: 2

awsiot/greengrass_discovery
awsiot/iotidentity
awsiot/iotjobs
Expand Down
20 changes: 10 additions & 10 deletions samples/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sample apps for the AWS IoT Device SDK for Python v2
# Sample apps for the AWS IoT Device SDK v2 for Python

* [pubsub](#pubsub)
* [shadow](#shadow)
Expand All @@ -19,7 +19,7 @@ Source: `samples/pubsub.py`

Run the sample like this:
```
python pubsub.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file>
python3 pubsub.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file>
```

Your Thing's
Expand Down Expand Up @@ -90,7 +90,7 @@ Source: `samples/shadow.py`

Run the sample like this:
```
python shadow.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file> --thing-name <name>
python3 shadow.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file> --thing-name <name>
```

Your Thing's
Expand Down Expand Up @@ -176,7 +176,7 @@ Source: `samples/jobs.py`

Run the sample like this:
```
python jobs.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file> --thing-name <name>
python3 jobs.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file> --thing-name <name>
```

Your Thing's
Expand Down Expand Up @@ -248,12 +248,12 @@ Source: `samples/fleetprovisioning.py`

Run the sample using createKeysAndCertificate:
```
python fleetprovisioning.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file> --templateName <name> --templateParameters <parameters>
python3 fleetprovisioning.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file> --templateName <name> --templateParameters <parameters>
```

Run the sample using createCertificateFromCsr:
```
python fleetprovisioning.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file> --templateName <name> --templateParameters <parameters> --csr <csr file>
python3 fleetprovisioning.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file> --templateName <name> --templateParameters <parameters> --csr <csr file>
```

Your Thing's
Expand Down Expand Up @@ -353,15 +353,15 @@ you'll need to substitute the name of the template you previously created, and o

(Optional) Create a temporary provisioning claim certificate set:
<pre>
aws iot create-provisioning-claim --template-name [TemplateName] | python ../utils/parse_cert_set_result.py --path /tmp --filename provision
aws iot create-provisioning-claim --template-name [TemplateName] | python3 ../utils/parse_cert_set_result.py --path /tmp --filename provision
</pre>

The provisioning claim's cert and key set have been written to `/tmp/provision*`. Now you can use these temporary keys
to perform the actual provisioning. If you are not using the temporary provisioning certificate, replace the paths for `--cert`
and `--key` appropriately:

<pre>
python fleetprovisioning.py --endpoint [your endpoint]-ats.iot.[region].amazonaws.com --root-ca [pathToRootCA] --cert /tmp/provision.cert.pem --key /tmp/provision.private.key --templateName [TemplateName]--templateParameters "{\"SerialNumber\":\"1\",\"DeviceLocation\":\"Seattle\"}"
python3 fleetprovisioning.py --endpoint [your endpoint]-ats.iot.[region].amazonaws.com --root-ca [pathToRootCA] --cert /tmp/provision.cert.pem --key /tmp/provision.private.key --templateName [TemplateName]--templateParameters "{\"SerialNumber\":\"1\",\"DeviceLocation\":\"Seattle\"}"
</pre>

Notice that we provided substitution values for the two parameters in the template body, `DeviceLocation` and `SerialNumber`.
Expand All @@ -383,13 +383,13 @@ openssl req -new -key /tmp/deviceCert.key -out /tmp/deviceCert.csr
be skipped if you're using a certificate set capable of provisioning the device:

<pre>
aws iot create-provisioning-claim --template-name [TemplateName] | python ../utils/parse_cert_set_result.py --path /tmp --filename provision
aws iot create-provisioning-claim --template-name [TemplateName] | python3 ../utils/parse_cert_set_result.py --path /tmp --filename provision
</pre>

Finally, supply the certificate signing request while invoking the provisioning sample. As with the previous workflow, if
using a permanent certificate set, replace the paths specified in the `--cert` and `--key` arguments:
<pre>
python fleetprovisioning.py --endpoint [your endpoint]-ats.iot.[region].amazonaws.com --root-ca [pathToRootCA] --cert /tmp/provision.cert.pem --key /tmp/provision.private.key --templateName [TemplateName]--templateParameters "{\"SerialNumber\":\"1\",\"DeviceLocation\":\"Seattle\"}" --csr /tmp/deviceCert.csr
python3 fleetprovisioning.py --endpoint [your endpoint]-ats.iot.[region].amazonaws.com --root-ca [pathToRootCA] --cert /tmp/provision.cert.pem --key /tmp/provision.private.key --templateName [TemplateName]--templateParameters "{\"SerialNumber\":\"1\",\"DeviceLocation\":\"Seattle\"}" --csr /tmp/deviceCert.csr
</pre>

## basic discovery
Expand Down
4 changes: 1 addition & 3 deletions samples/fleetprovisioning.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0.

from __future__ import absolute_import
from __future__ import print_function
import argparse
from awscrt import auth, http, io, mqtt
from awsiot import iotidentity
Expand Down Expand Up @@ -63,7 +61,7 @@
createCertificateFromCsrResponse = None
registerThingResponse = None

class LockedData(object):
class LockedData:
def __init__(self):
self.lock = threading.Lock()
self.disconnect_called = False
Expand Down
4 changes: 1 addition & 3 deletions samples/jobs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0.

from __future__ import absolute_import
from __future__ import print_function
import argparse
from awscrt import auth, http, io, mqtt
from awsiot import iotjobs
Expand Down Expand Up @@ -64,7 +62,7 @@
jobs_client = None
thing_name = ""

class LockedData(object):
class LockedData:
def __init__(self):
self.lock = threading.Lock()
self.disconnect_called = False
Expand Down
2 changes: 0 additions & 2 deletions samples/pubsub.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0.

from __future__ import absolute_import
from __future__ import print_function
import argparse
from awscrt import io, mqtt, auth, http
from awsiot import mqtt_connection_builder
Expand Down
9 changes: 2 additions & 7 deletions samples/shadow.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0.

from __future__ import absolute_import
from __future__ import print_function
import argparse
from awscrt import auth, io, mqtt, http
from awsiot import iotshadow
Expand Down Expand Up @@ -64,7 +62,7 @@

SHADOW_VALUE_DEFAULT = "off"

class LockedData(object):
class LockedData:
def __init__(self):
self.lock = threading.Lock()
self.shadow_value = None
Expand Down Expand Up @@ -207,10 +205,7 @@ def user_input_thread_fn():
while True:
try:
# Read user input
try:
new_value = raw_input() # python 2 only
except NameError:
new_value = input() # python 3 only
new_value = input()

# If user wants to quit sample, then quit.
# Otherwise change the shadow value.
Expand Down
8 changes: 3 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
description='AWS IoT SDK based on the AWS Common Runtime',
author='AWS SDK Common Runtime Team',
url='https://github.com/aws/aws-iot-device-sdk-python-v2',
packages = ['awsiot'],
packages=['awsiot'],
install_requires=[
'awscrt==0.8.0',
'futures;python_version<"3.2"',
'typing;python_version<"3.5"',
'awscrt==0.9.0',
],
python_requires='>=2.7',
python_requires='>=3.5',
)
6 changes: 1 addition & 5 deletions test/test_samples.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0.
from __future__ import absolute_import, print_function
import awsiot
import boto3
import botocore.exceptions
Expand Down Expand Up @@ -43,10 +42,7 @@ def get():

# boto3 caches the HTTPS connection for the API calls, which appears to the unit test
# framework as a leak, so ignore it, that's not what we're testing here
try:
warnings.simplefilter('ignore', ResourceWarning)
except NameError: # Python 2 has no ResourceWarning
pass
warnings.simplefilter('ignore', ResourceWarning)

try:
secrets = boto3.client('secretsmanager')
Expand Down
2 changes: 1 addition & 1 deletion utils/parse_cert_set_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Example usage:
aws iot create-provisioning-claim --template-name <TemplateName> | python parse_cert_set_result.py --path <PathToOutputtedCerts> --filename <Filename>
aws iot create-provisioning-claim --template-name <TemplateName> | python3 parse_cert_set_result.py --path <PathToOutputtedCerts> --filename <Filename>
"""

Expand Down

0 comments on commit 4c66229

Please sign in to comment.