Skip to content

Commit 7a10e21

Browse files
authored
Merge pull request #2988 from nateprewitt/pre-commit
Add pre-commit config
2 parents 2af248f + bbfbde9 commit 7a10e21

34 files changed

+247
-149
lines changed

.github/workflows/lint.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Lint code
2+
3+
on:
4+
push:
5+
pull_request:
6+
branches-ignore: [ master ]
7+
8+
jobs:
9+
lint:
10+
runs-on: ubuntu-20.04
11+
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Set up Python 3.9
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: 3.9
18+
- name: Run pre-commit
19+
uses: pre-commit/[email protected]

.github/workflows/run-tests.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
name: Run tests
32

43
on:

.pre-commit-config.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
exclude: ^(.github|.changes|docs/|boto3/compat.py|boto3/data)
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v2.3.0
5+
hooks:
6+
- id: check-yaml
7+
- id: end-of-file-fixer
8+
- id: trailing-whitespace
9+
- repo: https://github.com/pycqa/flake8
10+
rev: 3.9.2
11+
hooks:
12+
- id: flake8

CHANGELOG.rst

-1
Original file line numberDiff line numberDiff line change
@@ -8249,4 +8249,3 @@ CHANGELOG
82498249

82508250
* feature:Resources: Supports S3, EC2, SQS, SNS, and IAM resources
82518251
* feature:Clients: Supports low-level clients for most services
8252-

CODE_OF_CONDUCT.md

-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
33
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
44
[email protected] with any additional questions or comments.
5-

README.rst

+3-4
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ Assuming that you have Python and ``virtualenv`` installed, set up your environm
4949
5050
$ python -m pip install boto3
5151
52-
52+
5353
Using Boto3
5454
~~~~~~~~~~~~~~
55-
After installing boto3
55+
After installing boto3
5656

5757
Next, set up credentials (in e.g. ``~/.aws/credentials``):
5858

@@ -68,7 +68,7 @@ Then, set up a default region (in e.g. ``~/.aws/config``):
6868
6969
[default]
7070
region=us-east-1
71-
71+
7272
Other credentials configuration method can be found `here <https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html>`__
7373

7474
Then, from a Python interpreter:
@@ -137,4 +137,3 @@ More Resources
137137
* `NOTICE <https://github.com/boto/boto3/blob/develop/NOTICE>`__
138138
* `Changelog <https://github.com/boto/boto3/blob/develop/CHANGELOG.rst>`__
139139
* `License <https://github.com/boto/boto3/blob/develop/LICENSE>`__
140-

boto3/compat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def _warn_deprecated_python():
7575
'aws-cli-v1/'
7676
}
7777
deprecated_versions = {
78-
(2,7): py_27_params,
78+
(2, 7): py_27_params,
7979
}
8080
py_version = sys.version_info[:2]
8181

boto3/docs/collection.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,13 @@ def document_collection_method(section, resource_name, action_name,
185185
'method_description': (
186186
'Creates an iterable of all %s resources '
187187
'in the collection filtered by kwargs passed to '
188-
'method.' % collection_model.resource.type +
189-
'A %s collection will include all resources by '
188+
'method. A %s collection will include all resources by '
190189
'default if no filters are provided, and extreme '
191190
'caution should be taken when performing actions '
192-
'on all resources.'% collection_model.resource.type),
191+
'on all resources.' % (
192+
collection_model.resource.type,
193+
collection_model.resource.type
194+
)),
193195
'example_prefix': '%s_iterator = %s.%s.filter' % (
194196
xform_name(collection_model.resource.type),
195197
example_resource_name, collection_model.name),

boto3/dynamodb/conditions.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ def __init__(self, *values):
144144
AttributeBase.__init__(self, values[0].name)
145145

146146
def __eq__(self, other):
147-
return ConditionBase.__eq__(self, other) and \
148-
AttributeBase.__eq__(self, other)
147+
return (
148+
ConditionBase.__eq__(self, other) and AttributeBase.__eq__(self, other)
149+
)
149150

150151
def __ne__(self, other):
151152
return not self.__eq__(other)

scripts/ci/run-crt-tests

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def run(command):
2929

3030

3131
try:
32-
import awscrt
32+
import awscrt # noqa
3333
except ImportError:
3434
print("MISSING DEPENDENCY: awscrt must be installed to run the crt tests.")
3535
sys.exit(1)

scripts/new-change

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def replace_issue_references(parsed, repo_name):
135135
'`%s <https://github.com/%s/issues/%s>`__' % (
136136
match.group(), repo_name, number))
137137

138-
new_description = re.sub('#\d+', linkify, description)
138+
new_description = re.sub(r'#\d+', linkify, description)
139139
parsed['description'] = new_description
140140

141141

setup.cfg

+8
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,11 @@ requires_dist =
99

1010
[options.extras_require]
1111
crt = botocore[crt]>=1.21.0,<2.0a0
12+
13+
[flake8]
14+
ignore = E203,E501,W503,W504
15+
exclude =
16+
docs,
17+
boto3/compat.py,
18+
boto3/data,
19+
.changes

tests/__init__.py

-12
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,12 @@
1212
# language governing permissions and limitations under the License.
1313

1414
import random
15-
import sys
1615
import time
1716

18-
from botocore.compat import six
19-
20-
2117
import unittest
2218
from unittest import mock
2319

2420

25-
# In python 3, order matters when calling assertEqual to
26-
# compare lists and dictionaries with lists. Therefore,
27-
# assertItemsEqual needs to be used but it is renamed to
28-
# assertCountEqual in python 3.
29-
if six.PY2:
30-
unittest.TestCase.assertCountEqual = unittest.TestCase.assertItemsEqual
31-
32-
3321
def unique_id(name):
3422
"""
3523
Generate a unique ID that includes the given name,

tests/functional/docs/test_ec2.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,23 @@
1919
class TestInstanceDeleteTags(BaseDocsFunctionalTests):
2020
def setUp(self):
2121
self.documenter = ServiceDocumenter(
22-
'ec2', session=Session(region_name='us-east-1'))
22+
'ec2', session=Session(region_name='us-east-1')
23+
)
2324
self.generated_contents = self.documenter.document_service()
2425
self.generated_contents = self.generated_contents.decode('utf-8')
2526

2627
def test_delete_tags_method_is_documented(self):
2728
contents = self.get_class_document_block(
28-
'EC2.Instance', self.generated_contents)
29+
'EC2.Instance', self.generated_contents
30+
)
2931
method_contents = self.get_method_document_block(
30-
'delete_tags', contents)
31-
self.assert_contains_lines_in_order([
32-
'response = instance.delete_tags(',
33-
'DryRun=True|False,',
34-
'Tags=[',
35-
], method_contents)
32+
'delete_tags', contents
33+
)
34+
self.assert_contains_lines_in_order(
35+
[
36+
'response = instance.delete_tags(',
37+
'DryRun=True|False,',
38+
'Tags=[',
39+
],
40+
method_contents
41+
)

tests/functional/docs/test_smoke.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
def botocore_session():
2424
return botocore.session.get_session()
2525

26+
2627
@pytest.fixture
2728
def boto3_session():
2829
return boto3.Session(region_name='us-east-1')
2930

31+
3032
def all_services():
31-
botocore_session = botocore.session.get_session()
3233
session = boto3.Session(region_name='us-east-1')
3334
for service_name in session.get_available_services():
3435
yield service_name
@@ -52,32 +53,28 @@ def test_documentation(
5253
# Check that all of the services have the appropriate title
5354
_assert_has_title(generated_docs, client)
5455

55-
5656
# Check that all services have the client documented.
5757
_assert_has_client_documentation(generated_docs, service_name, client)
5858

59-
60-
#If the service has resources, make sure the service resource
61-
#is at least documented.
59+
# If the service has resources, make sure the service resource
60+
# is at least documented.
6261
if service_name in available_resources:
63-
62+
6463
resource = boto3.resource(service_name, 'us-east-1')
6564
_assert_has_resource_documentation(
6665
generated_docs, service_name, resource
6766
)
6867

6968
# If the client can paginate, make sure the paginators are documented.
7069
try:
71-
paginator_model = botocore_session.get_paginator_model(
72-
service_name)
70+
paginator_model = botocore_session.get_paginator_model(service_name)
7371
_assert_has_paginator_documentation(
7472
generated_docs, service_name, client,
7573
sorted(paginator_model._paginator_config)
7674
)
7775
except DataNotFoundError:
7876
pass
7977

80-
8178
# If the client has waiters, make sure the waiters are documented.
8279
if client.waiter_names:
8380
waiter_model = botocore_session.get_waiter_model(service_name)

tests/functional/dynamodb/test_stubber_conditions.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ def test_table_query_can_be_stubbed_with_expressions(self):
3131
)
3232

3333
stubber = Stubber(table.meta.client)
34-
stubber.add_response('query', dict(Items=list()), expected_params=dict(
34+
stubber.add_response(
35+
'query',
36+
dict(Items=list()),
37+
expected_params=dict(
3538
TableName='mytable',
3639
KeyConditionExpression=key_expr,
3740
FilterExpression=filter_expr
38-
))
41+
)
42+
)
3943

4044
with stubber:
4145
response = table.query(KeyConditionExpression=key_expr,
@@ -46,15 +50,20 @@ def test_table_query_can_be_stubbed_with_expressions(self):
4650

4751
def test_table_scan_can_be_stubbed_with_expressions(self):
4852
table = self.resource.Table('mytable')
49-
filter_expr = Attr('myattr').eq('foo') & (
50-
Attr('myattr2').lte('buzz') | Attr('myattr2').gte('fizz')
53+
filter_expr = (
54+
Attr('myattr').eq('foo') &
55+
(Attr('myattr2').lte('buzz') | Attr('myattr2').gte('fizz'))
5156
)
5257

5358
stubber = Stubber(table.meta.client)
54-
stubber.add_response('scan', dict(Items=list()), expected_params=dict(
59+
stubber.add_response(
60+
'scan',
61+
dict(Items=list()),
62+
expected_params=dict(
5563
TableName='mytable',
5664
FilterExpression=filter_expr
57-
))
65+
)
66+
)
5867

5968
with stubber:
6069
response = table.scan(FilterExpression=filter_expr)

tests/functional/dynamodb/test_table.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
from tests import unittest, mock
13+
from tests import unittest
1414

1515
import boto3
1616
from botocore.stub import Stubber

tests/functional/test_s3.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def stub_get_object(self, full_contents, start_byte=0, end_byte=None):
377377
# If this is a ranged get, ContentRange needs to be returned,
378378
# contents needs to be pruned, and Range needs to be an expected param.
379379
if end_byte is not None:
380-
contents = full_contents[start_byte:end_byte+1]
380+
contents = full_contents[start_byte:end_byte + 1]
381381
part_range = 'bytes=%s-%s' % (start_byte, end_byte_range)
382382
content_range = 'bytes=%s-%s/%s' % (
383383
start_byte, end_byte, len(full_contents))

tests/functional/test_smoke.py

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
boto3_session = None
1919

20+
2021
def create_session():
2122
global boto3_session
2223
if boto3_session is None:
@@ -28,6 +29,7 @@ def create_session():
2829

2930
return boto3_session
3031

32+
3133
def _all_resources():
3234
session = create_session()
3335
for service_name in session.get_available_resources():

tests/integration/test_dynamodb.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,20 @@ def test_condition_attribute_type(self):
171171

172172
def test_condition_and(self):
173173
r = self.scan(
174-
filter_expression=(Attr('MyHashKey').eq('mykey') &
175-
Attr('MyString').eq('mystring')))
174+
filter_expression=(
175+
Attr('MyHashKey').eq('mykey') & Attr('MyString').eq('mystring')
176+
)
177+
)
176178
item = r['Items'][0]
177179
self.assertTrue(
178180
item['MyHashKey'] == 'mykey' and item['MyString'] == 'mystring')
179181

180182
def test_condition_or(self):
181183
r = self.scan(
182-
filter_expression=(Attr('MyHashKey').eq('mykey2') |
183-
Attr('MyString').eq('mystring')))
184+
filter_expression=(
185+
Attr('MyHashKey').eq('mykey2') | Attr('MyString').eq('mystring')
186+
)
187+
)
184188
item = r['Items'][0]
185189
self.assertTrue(
186190
item['MyHashKey'] == 'mykey2' or item['MyString'] == 'mystring')

tests/integration/test_s3.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ def test_callback_called_once_with_sigv4(self):
472472
# twice when using signature version 4.
473473
self.amount_seen = 0
474474
lock = threading.Lock()
475+
475476
def progress_callback(amount):
476477
with lock:
477478
self.amount_seen += amount
@@ -593,9 +594,11 @@ def test_download_above_threshold(self):
593594

594595
def test_download_file_with_directory_not_exist(self):
595596
transfer = self.create_s3_transfer()
596-
self.client.put_object(Bucket=self.bucket_name,
597-
Key='foo.txt',
598-
Body=b'foo')
597+
self.client.put_object(
598+
Bucket=self.bucket_name,
599+
Key='foo.txt',
600+
Body=b'foo'
601+
)
599602
self.addCleanup(self.delete_object, 'foo.txt')
600603
download_path = os.path.join(self.files.rootdir, 'a', 'b', 'c',
601604
'downloaded.txt')
@@ -667,7 +670,7 @@ def test_transfer_methods_through_bucket(self):
667670
# This is just a sanity check to ensure that the bucket interface work.
668671
key = 'bucket.txt'
669672
bucket = self.session.resource('s3').Bucket(self.bucket_name)
670-
filename = self.files.create_file_with_size(key, 1024*1024)
673+
filename = self.files.create_file_with_size(key, 1024 * 1024)
671674
bucket.upload_file(Filename=filename, Key=key)
672675
self.addCleanup(self.delete_object, key)
673676
download_path = os.path.join(self.files.rootdir, unique_id('foo'))
@@ -678,7 +681,7 @@ def test_transfer_methods_through_object(self):
678681
# This is just a sanity check to ensure that the object interface work.
679682
key = 'object.txt'
680683
obj = self.session.resource('s3').Object(self.bucket_name, key)
681-
filename = self.files.create_file_with_size(key, 1024*1024)
684+
filename = self.files.create_file_with_size(key, 1024 * 1024)
682685
obj.upload_file(Filename=filename)
683686
self.addCleanup(self.delete_object, key)
684687
download_path = os.path.join(self.files.rootdir, unique_id('foo'))

0 commit comments

Comments
 (0)