Skip to content

Commit

Permalink
add new blackening step to github actions workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkahan committed Aug 24, 2023
1 parent 29e1d8a commit dfeb751
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 14 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
matrix:
python: ["3.8", "3.9", "3.10", "3.11"]
os: ["ubuntu-latest", "macos-latest"]

steps:
- uses: actions/setup-python@v4
with:
Expand All @@ -36,3 +35,9 @@ jobs:
run: make coverage
- name: Run codecov
uses: codecov/codecov-action@v3

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: psf/black@stable
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[tool.black]
color = true
line-length = 100
target-version = ['py311']
skip-string-normalization = true
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ addopts=--tb=short -p no:doctest
norecursedirs = bin dist docs htmlcov .* {args}

[pycodestyle]
max-line-length=120
max-line-length=100

[coverage:run]
# TODO: Change this to True:
Expand Down
69 changes: 57 additions & 12 deletions src/vonage/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ def __init__(
self.signature_secret = signature_secret or os.environ.get("VONAGE_SIGNATURE_SECRET", None)
self.signature_method = signature_method or os.environ.get("VONAGE_SIGNATURE_METHOD", None)

if self.signature_method in {"md5", "sha1", "sha256", "sha512"}:
if self.signature_method in {
"md5",
"sha1",
"sha256",
"sha512",
}:
self.signature_method = getattr(hashlib, signature_method)

if private_key is not None and application_id is not None:
Expand All @@ -111,7 +116,10 @@ def __init__(
if app_name and app_version:
user_agent += f" {app_name}/{app_version}"

self.headers = {"User-Agent": user_agent, "Accept": "application/json"}
self.headers = {
"User-Agent": user_agent,
"Accept": "application/json",
}

self.account = Account(self)
self.application = Application(self)
Expand All @@ -132,7 +140,9 @@ def __init__(
self.timeout = timeout
self.session = Session()
self.adapter = HTTPAdapter(
pool_connections=pool_connections, pool_maxsize=pool_maxsize, max_retries=max_retries
pool_connections=pool_connections,
pool_maxsize=pool_maxsize,
max_retries=max_retries,
)
self.session.mount("https://", self.adapter)

Expand Down Expand Up @@ -173,7 +183,10 @@ def check_signature(self, params):

def signature(self, params):
if self.signature_method:
hasher = hmac.new(self.signature_secret.encode(), digestmod=self.signature_method)
hasher = hmac.new(
self.signature_secret.encode(),
digestmod=self.signature_method,
)
else:
hasher = hashlib.md5()

Expand Down Expand Up @@ -201,7 +214,11 @@ def get(self, host, request_uri, params=None, auth_type=None):
if auth_type == 'jwt':
self._request_headers['Authorization'] = self._create_jwt_auth_string()
elif auth_type == 'params':
params = dict(params or {}, api_key=self.api_key, api_secret=self.api_secret)
params = dict(
params or {},
api_key=self.api_key,
api_secret=self.api_secret,
)
elif auth_type == 'header':
self._request_headers['Authorization'] = self._create_header_auth_string()
else:
Expand All @@ -215,7 +232,10 @@ def get(self, host, request_uri, params=None, auth_type=None):
return self.parse(
host,
self.session.get(
uri, params=params, headers=self._request_headers, timeout=self.timeout
uri,
params=params,
headers=self._request_headers,
timeout=self.timeout,
),
)

Expand Down Expand Up @@ -245,7 +265,11 @@ def post(
elif auth_type == 'jwt':
self._request_headers['Authorization'] = self._create_jwt_auth_string()
elif auth_type == 'params':
params = dict(params, api_key=self.api_key, api_secret=self.api_secret)
params = dict(
params,
api_key=self.api_key,
api_secret=self.api_secret,
)
elif auth_type == 'header':
self._request_headers['Authorization'] = self._create_header_auth_string()
else:
Expand All @@ -260,14 +284,20 @@ def post(
return self.parse(
host,
self.session.post(
uri, json=params, headers=self._request_headers, timeout=self.timeout
uri,
json=params,
headers=self._request_headers,
timeout=self.timeout,
),
)
else:
return self.parse(
host,
self.session.post(
uri, data=params, headers=self._request_headers, timeout=self.timeout
uri,
data=params,
headers=self._request_headers,
timeout=self.timeout,
),
)

Expand All @@ -290,7 +320,12 @@ def put(self, host, request_uri, params, auth_type=None):
# All APIs that currently use put methods require a json-formatted body so don't need to check this
return self.parse(
host,
self.session.put(uri, json=params, headers=self._request_headers, timeout=self.timeout),
self.session.put(
uri,
json=params,
headers=self._request_headers,
timeout=self.timeout,
),
)

def patch(self, host, request_uri, params, auth_type=None):
Expand All @@ -308,7 +343,14 @@ def patch(self, host, request_uri, params, auth_type=None):
f"PATCH to {repr(uri)} with params {repr(params)}, headers {repr(self._request_headers)}"
)
# Only newer APIs (that expect json-bodies) currently use this method, so we will always send a json-formatted body
return self.parse(host, self.session.patch(uri, json=params, headers=self._request_headers))
return self.parse(
host,
self.session.patch(
uri,
json=params,
headers=self._request_headers,
),
)

def delete(self, host, request_uri, params=None, auth_type=None):
uri = f"https://{host}{request_uri}"
Expand All @@ -329,7 +371,10 @@ def delete(self, host, request_uri, params=None, auth_type=None):
return self.parse(
host,
self.session.delete(
uri, headers=self._request_headers, timeout=self.timeout, params=params
uri,
headers=self._request_headers,
timeout=self.timeout,
params=params,
),
)

Expand Down

0 comments on commit dfeb751

Please sign in to comment.