Skip to content

Commit

Permalink
Merge pull request #17 from iqm-finland/fix-ci
Browse files Browse the repository at this point in the history
Add MyPy support
  • Loading branch information
kukushechkin authored Aug 30, 2022
2 parents 15074f8 + f940943 commit 42d0e39
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 14 deletions.
10 changes: 10 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[mypy]

[mypy-mockito.*]
ignore_missing_imports = True

[mypy-cirq_iqm.*]
ignore_missing_imports = True

[mypy-daemon.*]
ignore_missing_imports = True
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
Changelog
=========

Version 0.9
===========

* Enable mypy checks. `#17 <https://github.com/iqm-finland/cortex-cli/pull/17>`_
* Update source code according to new checks in pylint v2.15.0. `#17 <https://github.com/iqm-finland/cortex-cli/pull/17>`_

Version 0.8
===========

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ testing =
pytest-mypy == 0.9.1
pytest-pylint == 0.18.0
mockito == 1.2.2
types-requests == 2.28.9
docs =
sphinx == 4.5.0
sphinx-book-theme == 0.3.3
Expand Down
7 changes: 4 additions & 3 deletions src/cortex_cli/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from pydantic import BaseModel, Field

REFRESH_MARGIN_SECONDS = 15
AUTH_REQUESTS_TIMEOUT = 20


class ClientAuthenticationError(RuntimeError):
Expand Down Expand Up @@ -83,7 +84,7 @@ def login_request(url: str, realm: str, client_id: str, username: str, password:
)

request_url = f'{url}/realms/{realm}/protocol/openid-connect/token'
result = requests.post(request_url, data=data.dict(exclude_none=True))
result = requests.post(request_url, data=data.dict(exclude_none=True), timeout=AUTH_REQUESTS_TIMEOUT)
if result.status_code != 200:
raise ClientAuthenticationError(f'Failed to authenticate, {result.text}')
tokens = result.json()
Expand Down Expand Up @@ -111,7 +112,7 @@ def refresh_request(url: str, realm: str, client_id: str, refresh_token: str) ->
)

request_url = f'{url}/realms/{realm}/protocol/openid-connect/token'
result = requests.post(request_url, data=data.dict(exclude_none=True))
result = requests.post(request_url, data=data.dict(exclude_none=True), timeout=AUTH_REQUESTS_TIMEOUT)
if result.status_code != 200:
raise ClientAuthenticationError(f'Failed to update tokens, {result.text}')
tokens = result.json()
Expand All @@ -132,7 +133,7 @@ def logout_request(url: str, realm: str, client_id: str, refresh_token: str) ->
refresh_token=refresh_token
)
request_url = f'{url}/realms/{realm}/protocol/openid-connect/logout'
result = requests.post(request_url, data=data.dict(exclude_none=True))
result = requests.post(request_url, data=data.dict(exclude_none=True), timeout=AUTH_REQUESTS_TIMEOUT)

if result.status_code != 204:
raise ClientAuthenticationError(f'Failed to logout, {result.text}')
Expand Down
12 changes: 7 additions & 5 deletions src/cortex_cli/cortex_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _set_log_level_by_verbosity(verbose: bool) -> int:
return logging.INFO


def _validate_path(ctx: click.Context, param: object, path: str) -> str:
def _validate_path(ctx: click.Context, param: click.Path, path: str) -> str:
"""Callback for CLI prompt. If needed, confirmation to overwrite is prompted.
Args:
Expand Down Expand Up @@ -506,11 +506,13 @@ def run( #pylint: disable=too-many-arguments, too-many-locals, import-outside-t

logger.debug('\nInput circuit:\n%s', input_circuit)

parsed_qubit_mapping = None
if qubit_mapping is not None:
qubit_mapping = json.load(qubit_mapping)
parsed_qubit_mapping = json.load(qubit_mapping)

parsed_settings = None
if settings is not None:
settings = json.load(settings)
parsed_settings = json.load(settings)

# run the circuit on the backend
if no_auth:
Expand All @@ -519,9 +521,9 @@ def run( #pylint: disable=too-many-arguments, too-many-locals, import-outside-t
iqm_client = IQMClient(url, tokens_file=tokens_file)
job_id = iqm_client.submit_circuits(
[input_circuit],
qubit_mapping=qubit_mapping,
qubit_mapping=parsed_qubit_mapping,
shots=shots,
settings=settings,
settings=parsed_settings,
calibration_set_id=calibration_set_id
)
results = iqm_client.wait_for_results(job_id)
Expand Down
Empty file added src/cortex_cli/py.typed
Empty file.
7 changes: 5 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from cortex_cli.cortex_cli import CLIENT_ID, REALM_NAME

existing_run = UUID('3c3fcda3-e860-46bf-92a4-bcc59fa76ce9')
AUTH_REQUESTS_TIMEOUT = 20


def resources_path():
Expand Down Expand Up @@ -151,7 +152,8 @@ def prepare_tokens(
}
when(requests).post(
f'{credentials["base_url"]}/realms/{REALM_NAME}/protocol/openid-connect/token',
data=request_data.dict(exclude_none=True)
data=request_data.dict(exclude_none=True),
timeout=AUTH_REQUESTS_TIMEOUT
).thenReturn(MockJsonResponse(status_code, tokens))

return tokens
Expand All @@ -174,7 +176,8 @@ def expect_logout(
request_data = AuthRequest(client_id=client_id, refresh_token=refresh_token)
expect(requests, times=1).post(
f'{base_url}/realms/{realm}/protocol/openid-connect/logout',
data=request_data.dict(exclude_none=True)
data=request_data.dict(exclude_none=True),
timeout=AUTH_REQUESTS_TIMEOUT
).thenReturn(
mock({'status_code': status_code, 'text': '{}'})
)
Expand Down
6 changes: 2 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ extras =
commands =
python --version
python -m pip --version
pytest tests --verbose --cov --cov-report=term-missing --junitxml=test_report.xml --doctest-modules src
pytest --pylint src
pytest --pylint --pylint-rcfile=tests/.pylintrc tests
pytest --isort --verbose tests src
pytest --verbose --isort --mypy --pylint-rcfile=tests/.pylintrc --pylint --cov --cov-report term-missing --junitxml=test_report.xml tests/
pytest --verbose --isort --mypy --doctest-modules --pylint src/

[testenv:docs]
description =
Expand Down

0 comments on commit 42d0e39

Please sign in to comment.