Skip to content

Commit c90b484

Browse files
authored
feat: make python code prettier (#678)
1 parent 7ed8bf4 commit c90b484

File tree

1,295 files changed

+151793
-112346
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,295 files changed

+151793
-112346
lines changed

Makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: clean install analysis test test-install test-docker develop docs docs-install
1+
.PHONY: clean install analysis test test-install test-docker develop docs docs-install prettier prettier-check
22

33
venv:
44
@python --version || (echo "Python is not installed, Python 3.7+"; exit 1);
@@ -22,10 +22,10 @@ analysis:
2222
. venv/bin/activate; flake8 --ignore=E123,E126,E128,E501,W391,W291,W293,F401 tests
2323
. venv/bin/activate; flake8 --ignore=E402,F401,W391,W291,W293 twilio --max-line-length=300
2424

25-
test: analysis
25+
test: analysis prettier-check
2626
. venv/bin/activate; pytest tests --ignore=tests/cluster
2727

28-
test-with-coverage:
28+
test-with-coverage: prettier-check
2929
. venv/bin/activate; \
3030
pytest --cov-config=setup.cfg --cov-report xml --cov=twilio tests --ignore=tests/cluster
3131

@@ -56,6 +56,14 @@ clean:
5656
nopyc:
5757
find . -name \*.pyc -delete
5858

59+
prettier:
60+
. venv/bin/activate; black .
61+
. venv/bin/activate; autoflake --remove-all-unused-imports -i -r --exclude venv .
62+
63+
prettier-check:
64+
. venv/bin/activate; black --check .
65+
. venv/bin/activate; autoflake --check-diff --quiet --remove-all-unused-imports -r --exclude venv .
66+
5967
API_DEFINITIONS_SHA=$(shell git log --oneline | grep Regenerated | head -n1 | cut -d ' ' -f 5)
6068
CURRENT_TAG=$(shell expr "${GITHUB_TAG}" : ".*-rc.*" >/dev/null && echo "rc" || echo "latest")
6169
docker-build:

docs/conf.py

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515
#
1616
import os
1717
import sys
18-
sys.path.insert(0, os.path.abspath('..'))
18+
19+
sys.path.insert(0, os.path.abspath(".."))
1920
from twilio import __version__
2021

2122

2223
# -- Project information -----------------------------------------------------
2324

24-
project = 'twilio-python'
25-
copyright = '2023, Twilio'
26-
author = 'Twilio'
25+
project = "twilio-python"
26+
copyright = "2023, Twilio"
27+
author = "Twilio"
2728

2829
# The short X.Y version
2930
version = __version__
@@ -41,28 +42,28 @@
4142
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
4243
# ones.
4344
extensions = [
44-
'sphinx.ext.autodoc',
45-
'sphinx.ext.doctest',
46-
'sphinx.ext.intersphinx',
47-
'sphinx.ext.coverage',
48-
'sphinx.ext.ifconfig',
49-
'sphinx.ext.viewcode',
50-
'recommonmark'
45+
"sphinx.ext.autodoc",
46+
"sphinx.ext.doctest",
47+
"sphinx.ext.intersphinx",
48+
"sphinx.ext.coverage",
49+
"sphinx.ext.ifconfig",
50+
"sphinx.ext.viewcode",
51+
"recommonmark",
5152
]
5253

5354
# Add any paths that contain templates here, relative to this directory.
54-
templates_path = ['source/_templates']
55+
templates_path = ["source/_templates"]
5556

5657
# The suffix(es) of source filenames.
5758
# You can specify multiple suffix as a list of string:
5859
#
5960
source_suffix = {
60-
'.rst': 'restructuredtext',
61-
'.md': 'markdown',
61+
".rst": "restructuredtext",
62+
".md": "markdown",
6263
}
6364

6465
# The master toctree document.
65-
master_doc = 'index'
66+
master_doc = "index"
6667

6768
# The language for content autogenerated by Sphinx. Refer to documentation
6869
# for a list of supported languages.
@@ -77,23 +78,23 @@
7778
exclude_patterns = []
7879

7980
# The name of the Pygments (syntax highlighting) style to use.
80-
pygments_style = 'sphinx'
81+
pygments_style = "sphinx"
8182

8283

8384
# -- Options for HTML output -------------------------------------------------
8485

8586
# The theme to use for HTML and HTML Help pages. See the documentation for
8687
# a list of builtin themes.
8788
#
88-
html_theme = 'alabaster'
89+
html_theme = "alabaster"
8990

9091
# Theme options are theme-specific and customize the look and feel of a theme
9192
# further. For a list of options available for each theme, see the
9293
# documentation.
9394
#
9495
# html_theme_options = {}
9596

96-
html_static_path = ['source/_static']
97+
html_static_path = ["source/_static"]
9798

9899
# Custom sidebar templates, must be a dictionary that maps document names
99100
# to template names.
@@ -104,15 +105,20 @@
104105
# 'searchbox.html']``.
105106
#
106107
html_sidebars = {
107-
'**': [ 'sidebarintro.html', 'localtoc.html', 'relations.html',
108-
'sourcelink.html', 'searchbox.html']
108+
"**": [
109+
"sidebarintro.html",
110+
"localtoc.html",
111+
"relations.html",
112+
"sourcelink.html",
113+
"searchbox.html",
114+
]
109115
}
110116

111117

112118
# -- Options for HTMLHelp output ---------------------------------------------
113119

114120
# Output file base name for HTML help builder.
115-
htmlhelp_basename = 'twilio-pythondoc'
121+
htmlhelp_basename = "twilio-pythondoc"
116122

117123

118124
# -- Options for LaTeX output ------------------------------------------------
@@ -121,15 +127,12 @@
121127
# The paper size ('letterpaper' or 'a4paper').
122128
#
123129
# 'papersize': 'letterpaper',
124-
125130
# The font size ('10pt', '11pt' or '12pt').
126131
#
127132
# 'pointsize': '10pt',
128-
129133
# Additional stuff for the LaTeX preamble.
130134
#
131135
# 'preamble': '',
132-
133136
# Latex figure (float) alignment
134137
#
135138
# 'figure_align': 'htbp',
@@ -139,19 +142,21 @@
139142
# (source start file, target name, title,
140143
# author, documentclass [howto, manual, or own class]).
141144
latex_documents = [
142-
(master_doc, 'twilio-python.tex', 'twilio-python Documentation',
143-
'Twilio', 'manual'),
145+
(
146+
master_doc,
147+
"twilio-python.tex",
148+
"twilio-python Documentation",
149+
"Twilio",
150+
"manual",
151+
),
144152
]
145153

146154

147155
# -- Options for manual page output ------------------------------------------
148156

149157
# One entry per manual page. List of tuples
150158
# (source start file, name, description, authors, manual section).
151-
man_pages = [
152-
(master_doc, 'twilio-python', 'twilio-python Documentation',
153-
[author], 1)
154-
]
159+
man_pages = [(master_doc, "twilio-python", "twilio-python Documentation", [author], 1)]
155160

156161

157162
# -- Options for Texinfo output ----------------------------------------------
@@ -160,9 +165,15 @@
160165
# (source start file, target name, title, author,
161166
# dir menu entry, description, category)
162167
texinfo_documents = [
163-
(master_doc, 'twilio-python', 'twilio-python Documentation',
164-
author, 'twilio-python', 'One line description of project.',
165-
'Miscellaneous'),
168+
(
169+
master_doc,
170+
"twilio-python",
171+
"twilio-python Documentation",
172+
author,
173+
"twilio-python",
174+
"One line description of project.",
175+
"Miscellaneous",
176+
),
166177
]
167178

168179

@@ -184,12 +195,12 @@
184195
# epub_uid = ''
185196

186197
# A list of files that should not be packed into the epub file.
187-
epub_exclude_files = ['search.html']
198+
epub_exclude_files = ["search.html"]
188199

189200

190201
# -- Extension configuration -------------------------------------------------
191202

192203
# -- Options for intersphinx extension ---------------------------------------
193204

194205
# Example configuration for intersphinx: refer to the Python standard library.
195-
intersphinx_mapping = {'https://docs.python.org/': None}
206+
intersphinx_mapping = {"https://docs.python.org/": None}

examples/basic_usage.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from twilio.rest import Client
44
from twilio.twiml.voice_response import VoiceResponse
55

6-
ACCOUNT_SID = os.environ.get('TWILIO_ACCOUNT_SID')
7-
AUTH_TOKEN = os.environ.get('TWILIO_AUTH_TOKEN')
6+
ACCOUNT_SID = os.environ.get("TWILIO_ACCOUNT_SID")
7+
AUTH_TOKEN = os.environ.get("TWILIO_AUTH_TOKEN")
88

99

1010
def example():
@@ -15,31 +15,31 @@ def example():
1515

1616
# Get all messages
1717
all_messages = client.messages.list()
18-
print('There are {} messages in your account.'.format(len(all_messages)))
18+
print("There are {} messages in your account.".format(len(all_messages)))
1919

2020
# Get only last 10 messages...
2121
some_messages = client.messages.list(limit=10)
22-
print('Here are the last 10 messages in your account:')
22+
print("Here are the last 10 messages in your account:")
2323
for m in some_messages:
2424
print(m)
2525

2626
# Get messages in smaller pages...
2727
all_messages = client.messages.list(page_size=10)
28-
print('There are {} messages in your account.'.format(len(all_messages)))
28+
print("There are {} messages in your account.".format(len(all_messages)))
2929

30-
print('Sending a message...')
31-
new_message = client.messages.create(to='XXXX', from_='YYYY', body='Twilio rocks!')
30+
print("Sending a message...")
31+
new_message = client.messages.create(to="XXXX", from_="YYYY", body="Twilio rocks!")
3232

33-
print('Making a call...')
34-
new_call = client.calls.create(to='XXXX', from_='YYYY', method='GET')
33+
print("Making a call...")
34+
new_call = client.calls.create(to="XXXX", from_="YYYY", method="GET")
3535

36-
print('Serving TwiML')
36+
print("Serving TwiML")
3737
twiml_response = VoiceResponse()
38-
twiml_response.say('Hello!')
38+
twiml_response.say("Hello!")
3939
twiml_response.hangup()
4040
twiml_xml = twiml_response.to_xml()
41-
print('Generated twiml: {}'.format(twiml_xml))
41+
print("Generated twiml: {}".format(twiml_xml))
4242

4343

44-
if __name__ == '__main__':
44+
if __name__ == "__main__":
4545
example()

examples/client_validation.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
Encoding,
77
PublicFormat,
88
PrivateFormat,
9-
NoEncryption
9+
NoEncryption,
1010
)
1111

1212
from twilio.http.validation_client import ValidationClient
1313
from twilio.rest import Client
1414

1515

16-
ACCOUNT_SID = os.environ.get('TWILIO_ACCOUNT_SID')
17-
AUTH_TOKEN = os.environ.get('TWILIO_AUTH_TOKEN')
16+
ACCOUNT_SID = os.environ.get("TWILIO_ACCOUNT_SID")
17+
AUTH_TOKEN = os.environ.get("TWILIO_AUTH_TOKEN")
18+
1819

1920
def example():
2021
"""
@@ -28,45 +29,45 @@ def example():
2829

2930
# Using Client Validation requires using API Keys for auth
3031
# First create an API key using the standard account sid, auth token client
31-
print('Creating new api key...')
32-
api_key = client.new_keys.create(friendly_name='ClientValidationApiKey')
32+
print("Creating new api key...")
33+
api_key = client.new_keys.create(friendly_name="ClientValidationApiKey")
3334

3435
# Generate a new RSA Keypair
35-
print('Generating RSA key pair...')
36+
print("Generating RSA key pair...")
3637
key_pair = rsa.generate_private_key(
37-
public_exponent=65537,
38-
key_size=2048,
39-
backend=default_backend()
38+
public_exponent=65537, key_size=2048, backend=default_backend()
39+
)
40+
public_key = key_pair.public_key().public_bytes(
41+
Encoding.PEM, PublicFormat.SubjectPublicKeyInfo
42+
)
43+
private_key = key_pair.private_bytes(
44+
Encoding.PEM, PrivateFormat.PKCS8, NoEncryption()
4045
)
41-
public_key = key_pair.public_key().public_bytes(Encoding.PEM, PublicFormat.SubjectPublicKeyInfo)
42-
private_key = key_pair.private_bytes(Encoding.PEM, PrivateFormat.PKCS8, NoEncryption())
4346

4447
# Register the public key with Twilio
45-
print('Registering public key with Twilio...')
48+
print("Registering public key with Twilio...")
4649
credential = client.accounts.credentials.public_key.create(
47-
public_key,
48-
friendly_name='ClientValidationPublicKey'
50+
public_key, friendly_name="ClientValidationPublicKey"
4951
)
5052

5153
# Create a new ValidationClient with the keys we created
5254
validation_client = ValidationClient(
53-
ACCOUNT_SID,
54-
api_key.sid,
55-
credential.sid,
56-
private_key
55+
ACCOUNT_SID, api_key.sid, credential.sid, private_key
5756
)
5857

5958
# Create a REST Client using the validation_client
60-
client = Client(api_key.sid, api_key.secret, ACCOUNT_SID, http_client=validation_client)
59+
client = Client(
60+
api_key.sid, api_key.secret, ACCOUNT_SID, http_client=validation_client
61+
)
6162

6263
# Use the library as usual
63-
print('Trying out client validation...')
64+
print("Trying out client validation...")
6465
messages = client.messages.list(limit=10)
6566
for m in messages:
66-
print('Message {}'.format(m.sid))
67+
print("Message {}".format(m.sid))
6768

68-
print('Client validation works!')
69+
print("Client validation works!")
6970

7071

71-
if __name__ == '__main__':
72+
if __name__ == "__main__":
7273
example()

setup.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup, find_packages
22

3-
with open('README.md') as f:
3+
with open("README.md") as f:
44
long_description = f.read()
55

66
# To install the twilio-python library, open a Terminal shell, then run this
@@ -19,16 +19,16 @@
1919
author_email="help@twilio.com",
2020
url="https://github.com/twilio/twilio-python/",
2121
keywords=["twilio", "twiml"],
22-
python_requires='>=3.7.0',
22+
python_requires=">=3.7.0",
2323
install_requires=[
2424
"pytz",
2525
"requests >= 2.0.0",
2626
"PyJWT >= 2.0.0, < 3.0.0",
2727
"asyncio>=3.4.3",
2828
"aiohttp>=3.8.4",
29-
"aiohttp-retry>=2.8.3"
29+
"aiohttp-retry>=2.8.3",
3030
],
31-
packages=find_packages(exclude=['tests', 'tests.*']),
31+
packages=find_packages(exclude=["tests", "tests.*"]),
3232
include_package_data=True,
3333
classifiers=[
3434
"Development Status :: 5 - Production/Stable",
@@ -46,5 +46,5 @@
4646
"Topic :: Communications :: Telephony",
4747
],
4848
long_description=long_description,
49-
long_description_content_type='text/markdown'
49+
long_description_content_type="text/markdown",
5050
)

0 commit comments

Comments
 (0)