diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..a04c33e --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,6 @@ +repos: +- repo: https://github.com/psf/black + rev: 22.10.0 + hooks: + - id: black + language_version: python3.8 \ No newline at end of file diff --git a/fhirpy/base/lib.py b/fhirpy/base/lib.py index a8a8142..c418768 100644 --- a/fhirpy/base/lib.py +++ b/fhirpy/base/lib.py @@ -108,7 +108,9 @@ def _build_request_url(self, path, params): class AsyncClient(AbstractClient, ABC): aiohttp_config = None - def __init__(self, url, authorization=None, extra_headers=None, aiohttp_config=None): + def __init__( + self, url, authorization=None, extra_headers=None, aiohttp_config=None + ): self.aiohttp_config = aiohttp_config or {} super().__init__(url, authorization, extra_headers) @@ -125,8 +127,7 @@ async def _do_request(self, method, path, data=None, params=None): ) as r: if 200 <= r.status < 300: data = await r.text() - return (json.loads(data, object_hook=AttrDict) - if data else None) + return json.loads(data, object_hook=AttrDict) if data else None if r.status == 404 or r.status == 410: raise ResourceNotFound(await r.text()) @@ -147,7 +148,9 @@ async def _fetch_resource(self, path, params=None): class SyncClient(AbstractClient, ABC): requests_config = None - def __init__(self, url, authorization=None, extra_headers=None, requests_config=None): + def __init__( + self, url, authorization=None, extra_headers=None, requests_config=None + ): self.requests_config = requests_config or {} super().__init__(url, authorization, extra_headers) @@ -158,7 +161,9 @@ def execute(self, path, method="post", **kwargs): def _do_request(self, method, path, data=None, params=None): headers = self._build_request_headers() url = self._build_request_url(path, params) - r = requests.request(method, url, json=data, headers=headers, **self.requests_config) + r = requests.request( + method, url, json=data, headers=headers, **self.requests_config + ) if 200 <= r.status_code < 300: return ( diff --git a/requirements.txt b/requirements.txt index bce38b7..aed3f10 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,5 +4,6 @@ pytest-cov==2.12.0 aiohttp==3.7.4 pytest-asyncio==0.15.1 responses==0.13.3 -yapf==0.31.0 -pytz==2021.1 \ No newline at end of file +pytz==2021.1 +black==22.10.0 +pre-commit==2.20.0 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index d628318..20450ab 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,3 @@ [metadata] license_file = LICENSE.md description-file = README.md - -[yapf] -based_on_style = facebook diff --git a/tests/test_lib_async.py b/tests/test_lib_async.py index a74661a..fc748b1 100644 --- a/tests/test_lib_async.py +++ b/tests/test_lib_async.py @@ -597,27 +597,19 @@ async def test_aiohttp_config(): client = AsyncFHIRClient( FHIR_SERVER_URL, authorization=FHIR_SERVER_AUTHORIZATION, - aiohttp_config={ - "ssl": False, - "proxy": "http://example.com" - } + aiohttp_config={"ssl": False, "proxy": "http://example.com"}, ) resp = MockAiohttpResponse( bytes( json.dumps( - { - 'resourceType': 'Bundle', - 'type': 'searchset', - 'total': 0, - 'entry': [] - } - ), 'utf-8' - ), 200 + {"resourceType": "Bundle", "type": "searchset", "total": 0, "entry": []} + ), + "utf-8", + ), + 200, ) - with patch( - "aiohttp.ClientSession.request", return_value=resp - ) as patched_request: - await client.resources('Patient').first() + with patch("aiohttp.ClientSession.request", return_value=resp) as patched_request: + await client.resources("Patient").first() patched_request.assert_called_with( - ANY, ANY, json=None, ssl=False, proxy='http://example.com' + ANY, ANY, json=None, ssl=False, proxy="http://example.com" ) diff --git a/tests/test_lib_sync.py b/tests/test_lib_sync.py index f42df04..86f3825 100644 --- a/tests/test_lib_sync.py +++ b/tests/test_lib_sync.py @@ -541,22 +541,14 @@ def test_requests_config(): client = SyncFHIRClient( FHIR_SERVER_URL, authorization=FHIR_SERVER_AUTHORIZATION, - requests_config={ - "verify": False, - "cert": "some_cert" - } + requests_config={"verify": False, "cert": "some_cert"}, ) json_resp_str = json.dumps( - { - 'resourceType': 'Bundle', - 'type': 'searchset', - 'total': 0, - 'entry': [] - } + {"resourceType": "Bundle", "type": "searchset", "total": 0, "entry": []} ) - resp = MockRequestsResponse(bytes(json_resp_str, 'utf-8'), 200) + resp = MockRequestsResponse(bytes(json_resp_str, "utf-8"), 200) with patch("requests.request", return_value=resp) as patched_request: - client.resources('Patient').first() + client.resources("Patient").first() patched_request.assert_called_with( - ANY, ANY, json=ANY, headers=ANY, verify=False, cert='some_cert' + ANY, ANY, json=ANY, headers=ANY, verify=False, cert="some_cert" )