From 0474f313d120bb24baa0bb94e9ac0b85c5e61963 Mon Sep 17 00:00:00 2001 From: Stuart Campbell Date: Thu, 16 Jan 2025 12:44:01 -0500 Subject: [PATCH 1/3] Add auth for httpx client --- src/nsls2api/services/helpers.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/nsls2api/services/helpers.py b/src/nsls2api/services/helpers.py index ce5eca7..67bd109 100644 --- a/src/nsls2api/services/helpers.py +++ b/src/nsls2api/services/helpers.py @@ -36,6 +36,7 @@ def __call__(self): async def _call_async_webservice( url: str, + auth: tuple = None, headers: dict = None, ) -> Response: transport = None @@ -47,6 +48,8 @@ async def _call_async_webservice( timeout=httpx.Timeout(None, connect=30.0), transport=transport, limits=httpx.Limits(max_keepalive_connections=5, max_connections=5), + auth=auth, + headers=headers, ) as client: logger.logger(f"Calling {url} using unshared client.") resp: Response = await client.get(url) @@ -58,13 +61,13 @@ async def _call_async_webservice( async def _call_async_webservice_with_client( - url: str, headers: dict = None, client: httpx.AsyncClient = None + url: str, auth: tuple = None, headers: dict = None, client: httpx.AsyncClient = None ) -> Response: if client is None: # Then just use the general method that creates a client each time - return await _call_async_webservice(url, headers) + return await _call_async_webservice(url, auth, headers) else: - resp: Response = await client.get(url, timeout=90.0) + resp: Response = await client.get(url, timeout=90.0, auth=auth, headers=headers) resp.raise_for_status() results = resp.json() return results From e5097d2bee607bbf5bd80c49961d80fdfbe44570 Mon Sep 17 00:00:00 2001 From: Stuart Campbell Date: Thu, 16 Jan 2025 12:44:25 -0500 Subject: [PATCH 2/3] code formatting --- src/nsls2api/services/sync_service.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/nsls2api/services/sync_service.py b/src/nsls2api/services/sync_service.py index ebcb286..7d76329 100644 --- a/src/nsls2api/services/sync_service.py +++ b/src/nsls2api/services/sync_service.py @@ -202,20 +202,26 @@ async def worker_synchronize_proposal_types_from_pass( ) -async def synchronize_proposal_from_pass(proposal_id: str, facility_name: FacilityName = FacilityName.nsls2) -> None: +async def synchronize_proposal_from_pass( + proposal_id: str, facility_name: FacilityName = FacilityName.nsls2 +) -> None: beamline_list = [] user_list = [] saf_list = [] try: - pass_proposal: PassProposal = await pass_service.get_proposal(proposal_id, facility_name) + pass_proposal: PassProposal = await pass_service.get_proposal( + proposal_id, facility_name + ) except pass_service.PassException as error: error_message = f"Error retrieving proposal {proposal_id} from PASS" logger.exception(error_message) raise Exception(error_message) from error # Get the SAFs for this proposal - pass_saf_list: list[PassSaf] = await pass_service.get_saf_from_proposal(proposal_id, facility_name) + pass_saf_list: list[PassSaf] = await pass_service.get_saf_from_proposal( + proposal_id, facility_name + ) for saf in pass_saf_list: saf_beamline_list = [] for resource in saf.Resources: @@ -351,7 +357,9 @@ async def update_proposals_with_cycle( logger.warning(error) -async def worker_synchronize_proposal_from_pass(proposal_id: str, facility: FacilityName = FacilityName.nsls2) -> None: +async def worker_synchronize_proposal_from_pass( + proposal_id: str, facility: FacilityName = FacilityName.nsls2 +) -> None: start_time = datetime.datetime.now() await synchronize_proposal_from_pass(proposal_id, facility) From 1c807bc4ea5bdf52c3fb647507c70ffb9db8f97d Mon Sep 17 00:00:00 2001 From: Stuart Campbell Date: Thu, 16 Jan 2025 12:47:57 -0500 Subject: [PATCH 3/3] Add note about formatting and linting --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index e60cba8..4369b02 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,20 @@ directory as the json files). 3. Ensure that you have the `bnlroot.crt` file (which is deployed to all BNL managed machines) in the location specified within the `.env` file. +### Code Style + +This project uses `ruff` to format the code - in order to run the formatter simply type: +```bash + uvx ruff format +``` +### Code Linting + +This project uses `ruff` to check the code - in order to run the linter simply type: +```bash + uvx ruff check +``` + + ### Updating Dependencies The project uses `uv pip compile` to manage the `requirements.txt` and `requirements-dev.txt` files.