diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 19237e55..4ca2fe69 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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: @@ -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 \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..e0286062 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,5 @@ +[tool.black] +color = true +line-length = 100 +target-version = ['py311'] +skip-string-normalization = true \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 45444f0b..a8c354a5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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: diff --git a/src/vonage/client.py b/src/vonage/client.py index 6aa43d62..e6a72499 100644 --- a/src/vonage/client.py +++ b/src/vonage/client.py @@ -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: @@ -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) @@ -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) @@ -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() @@ -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: @@ -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, ), ) @@ -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: @@ -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, ), ) @@ -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): @@ -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}" @@ -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, ), )