Skip to content

Commit

Permalink
Merge branch 'develop' into electron_pow
Browse files Browse the repository at this point in the history
  • Loading branch information
kessler-frost authored Oct 19, 2023
2 parents 59ce1ee + 1995292 commit d9d9256
Show file tree
Hide file tree
Showing 135 changed files with 9,219 additions and 4,652 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ jobs:
run: python -m pip install pip-check-reqs

- name: Check extra core requirements
run: pip-extra-reqs -r werkzeug covalent covalent_dispatcher covalent_ui --ignore-requirement=qiskit --ignore-requirement=qiskit-ibm-provider --ignore-requirement=amazon-braket-pennylane-plugin
run: pip-extra-reqs -r werkzeug -r python-multipart covalent covalent_dispatcher covalent_ui --ignore-requirement=qiskit --ignore-requirement=qiskit-ibm-provider --ignore-requirement=amazon-braket-pennylane-plugin

- name: Check missing SDK requirements
run: >
pip-missing-reqs
--ignore-module=covalent_ui.*
--ignore-module=covalent.*
--ignore-module=urllib3.*
--ignore-module=pkg_resources
--ignore-module=covalent/_dispatcher_plugins
--ignore-module=covalent/_shared_files
--ignore-file=covalent/executor/**
--ignore-file=covalent/triggers/**
--ignore-file=covalent/cloud_resource_manager/**
Expand All @@ -58,7 +61,7 @@ jobs:
pip-missing-reqs
--ignore-module=covalent_ui.*
--ignore-module=covalent.*
--ignore-module=covalent_dispatcher
--ignore-module=covalent_dispatcher.*
--ignore-module=distributed.*
covalent_dispatcher
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ jobs:
if: >
steps.modified-files.outputs.sdk == 'true'
|| env.BUILD_AND_RUN_ALL
run: PYTHONPATH=$PWD/ pytest -vvs --reruns=5 tests/covalent_tests --cov=covalent --cov-config=.coveragerc
run: PYTHONPATH=$PWD/ pytest -vvs --reruns=5 tests/covalent_tests --cov=covalent --cov-config=.coveragerc

- name: Generate SDK coverage report
id: sdk-coverage
Expand All @@ -248,7 +248,7 @@ jobs:
if: >
steps.modified-files.outputs.dispatcher == 'true'
|| env.BUILD_AND_RUN_ALL
run: PYTHONPATH=$PWD/ pytest -vvs --reruns=5 tests/covalent_dispatcher_tests --cov=covalent_dispatcher --cov-config=.coveragerc
run: PYTHONPATH=$PWD/ pytest -vvs --reruns=5 tests/covalent_dispatcher_tests --cov=covalent_dispatcher --cov-config=.coveragerc

- name: Generate dispatcher coverage report
id: dispatcher-coverage
Expand All @@ -260,7 +260,7 @@ jobs:
if: >
steps.modified-files.outputs.ui_backend == 'true'
|| env.BUILD_AND_RUN_ALL
run: PYTHONPATH=$PWD/ pytest -vvs --reruns=5 tests/covalent_ui_backend_tests --cov=covalent_ui --cov-config=.coveragerc
run: PYTHONPATH=$PWD/ pytest -vvs --reruns=5 tests/covalent_ui_backend_tests --cov=covalent_ui --cov-config=.coveragerc

- name: Generate UI backend coverage report
id: ui-backend-coverage
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Removed strict version pins on `lmdbm`, `mpire`, `orjson`, and `pennylane`
- Changed license to Apache
- Improved error handling in generate_docs.py
- [Significant Changes] Migrated core server-side code to new data access layer.

### Added

Expand Down Expand Up @@ -73,6 +74,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Rsync command fixed to recursively copy files when using SSH
- Removed accidentally added migrations build files
- Updated migration script to add a default value for `qelectron_data_exists` in the `electrons` table since it cannot be nullable
- Reduced server memory consumption during workflow processing

### Changed

Expand Down
6 changes: 5 additions & 1 deletion covalent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
from ._dispatcher_plugins import local_redispatch as redispatch # nopycln: import
from ._dispatcher_plugins import stop_triggers # nopycln: import
from ._file_transfer import strategies as fs_strategies # nopycln: import
from ._results_manager.results_manager import cancel, get_result, sync # nopycln: import
from ._results_manager.results_manager import ( # nopycln: import
cancel,
get_result,
get_result_manager,
)
from ._shared_files.config import get_config, reload_config, set_config # nopycln: import
from ._shared_files.util_classes import RESULT_STATUS as status # nopycln: import
from ._workflow import ( # nopycln: import
Expand Down
15 changes: 15 additions & 0 deletions covalent/_api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2023 Agnostiq Inc.
#
# This file is part of Covalent.
#
# Licensed under the Apache License 2.0 (the "License"). A copy of the
# License may be obtained with this software package or at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Use of this file is prohibited except in compliance with the License.
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
128 changes: 128 additions & 0 deletions covalent/_api/apiclient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Copyright 2023 Agnostiq Inc.
#
# This file is part of Covalent.
#
# Licensed under the Apache License 2.0 (the "License"). A copy of the
# License may be obtained with this software package or at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Use of this file is prohibited except in compliance with the License.
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


"""API client"""

import json
import os
from typing import Dict

import requests
from requests.adapters import HTTPAdapter


class CovalentAPIClient:
"""Thin wrapper around Requests to centralize error handling."""

def __init__(self, dispatcher_addr: str, adapter: HTTPAdapter = None, auto_raise: bool = True):
self.dispatcher_addr = dispatcher_addr
self.adapter = adapter
self.auto_raise = auto_raise

def prepare_headers(self, **kwargs):
extra_headers = CovalentAPIClient.get_extra_headers()
headers = kwargs.get("headers", {})
if headers:
kwargs.pop("headers")

Check warning on line 40 in covalent/_api/apiclient.py

View check run for this annotation

Codecov / codecov/patch

covalent/_api/apiclient.py#L40

Added line #L40 was not covered by tests
headers.update(extra_headers)
return headers

def get(self, endpoint: str, **kwargs):
headers = self.prepare_headers(**kwargs)
url = self.dispatcher_addr + endpoint
try:
with requests.Session() as session:
if self.adapter:
session.mount("http://", self.adapter)

r = session.get(url, headers=headers, **kwargs)

if self.auto_raise:
r.raise_for_status()

Check warning on line 55 in covalent/_api/apiclient.py

View check run for this annotation

Codecov / codecov/patch

covalent/_api/apiclient.py#L55

Added line #L55 was not covered by tests

except requests.exceptions.ConnectionError:
message = f"The Covalent server cannot be reached at {url}. Local servers can be started using `covalent start` in the terminal. If you are using a remote Covalent server, contact your systems administrator to report an outage."
print(message)
raise

Check warning on line 60 in covalent/_api/apiclient.py

View check run for this annotation

Codecov / codecov/patch

covalent/_api/apiclient.py#L57-L60

Added lines #L57 - L60 were not covered by tests

return r

def put(self, endpoint: str, **kwargs):
headers = self.prepare_headers()
url = self.dispatcher_addr + endpoint
try:
with requests.Session() as session:
if self.adapter:
session.mount("http://", self.adapter)

Check warning on line 70 in covalent/_api/apiclient.py

View check run for this annotation

Codecov / codecov/patch

covalent/_api/apiclient.py#L70

Added line #L70 was not covered by tests

r = session.put(url, headers=headers, **kwargs)

if self.auto_raise:
r.raise_for_status()
except requests.exceptions.ConnectionError:
message = f"The Covalent server cannot be reached at {url}. Local servers can be started using `covalent start` in the terminal. If you are using a remote Covalent server, contact your systems administrator to report an outage."
print(message)
raise

Check warning on line 79 in covalent/_api/apiclient.py

View check run for this annotation

Codecov / codecov/patch

covalent/_api/apiclient.py#L77-L79

Added lines #L77 - L79 were not covered by tests

return r

def post(self, endpoint: str, **kwargs):
headers = self.prepare_headers()
url = self.dispatcher_addr + endpoint
try:
with requests.Session() as session:
if self.adapter:
session.mount("http://", self.adapter)

Check warning on line 89 in covalent/_api/apiclient.py

View check run for this annotation

Codecov / codecov/patch

covalent/_api/apiclient.py#L89

Added line #L89 was not covered by tests

r = session.post(url, headers=headers, **kwargs)

if self.auto_raise:
r.raise_for_status()
except requests.exceptions.ConnectionError:
message = f"The Covalent server cannot be reached at {url}. Local servers can be started using `covalent start` in the terminal. If you are using a remote Covalent server, contact your systems administrator to report an outage."
print(message)
raise

return r

def delete(self, endpoint: str, **kwargs):
headers = self.prepare_headers()
url = self.dispatcher_addr + endpoint
try:
with requests.Session() as session:
if self.adapter:
session.mount("http://", self.adapter)

Check warning on line 108 in covalent/_api/apiclient.py

View check run for this annotation

Codecov / codecov/patch

covalent/_api/apiclient.py#L103-L108

Added lines #L103 - L108 were not covered by tests

r = session.delete(url, headers=headers, **kwargs)

Check warning on line 110 in covalent/_api/apiclient.py

View check run for this annotation

Codecov / codecov/patch

covalent/_api/apiclient.py#L110

Added line #L110 was not covered by tests

if self.auto_raise:
r.raise_for_status()
except requests.exceptions.ConnectionError:
message = f"The Covalent server cannot be reached at {url}. Local servers can be started using `covalent start` in the terminal. If you are using a remote Covalent server, contact your systems administrator to report an outage."
print(message)
raise

Check warning on line 117 in covalent/_api/apiclient.py

View check run for this annotation

Codecov / codecov/patch

covalent/_api/apiclient.py#L112-L117

Added lines #L112 - L117 were not covered by tests

return r

Check warning on line 119 in covalent/_api/apiclient.py

View check run for this annotation

Codecov / codecov/patch

covalent/_api/apiclient.py#L119

Added line #L119 was not covered by tests

@classmethod
def get_extra_headers(headers: Dict) -> Dict:
# This is expected to be a JSONified dictionary
data = os.environ.get("COVALENT_EXTRA_HEADERS")
if data:
return json.loads(data)

Check warning on line 126 in covalent/_api/apiclient.py

View check run for this annotation

Codecov / codecov/patch

covalent/_api/apiclient.py#L126

Added line #L126 was not covered by tests
else:
return {}
Loading

0 comments on commit d9d9256

Please sign in to comment.