dwave-cloud-client 0.11.0.dev0__tar.gz → 0.11.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dwave-cloud-client-0.11.0.dev0/dwave_cloud_client.egg-info → dwave-cloud-client-0.11.2}/PKG-INFO +3 -9
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/README.rst +1 -5
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/auth/flows.py +59 -6
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/auth/server.py +56 -10
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/cli.py +66 -31
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/client/base.py +2 -2
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/package_info.py +1 -1
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/utils.py +50 -3
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2/dwave_cloud_client.egg-info}/PKG-INFO +3 -9
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave_cloud_client.egg-info/entry_points.txt +0 -1
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave_cloud_client.egg-info/requires.txt +1 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/setup.py +2 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/LICENSE +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/__init__.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/__init__.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/api/__init__.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/api/client.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/api/constants.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/api/exceptions.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/api/models.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/api/resources.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/auth/__init__.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/auth/_creds.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/auth/config.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/auth/creds.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/client/__init__.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/client/hybrid.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/client/qpu.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/client/sw.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/coders.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/computation.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/concurrency.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/config/__init__.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/config/loaders.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/config/models.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/events.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/exceptions.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/regions.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/solver.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/testing/__init__.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/testing/mocks.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/upload.py +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave_cloud_client.egg-info/SOURCES.txt +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave_cloud_client.egg-info/dependency_links.txt +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave_cloud_client.egg-info/not-zip-safe +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave_cloud_client.egg-info/top_level.txt +0 -0
- {dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/setup.cfg +0 -0
{dwave-cloud-client-0.11.0.dev0/dwave_cloud_client.egg-info → dwave-cloud-client-0.11.2}/PKG-INFO
RENAMED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: dwave-cloud-client
|
|
3
|
-
Version: 0.11.
|
|
3
|
+
Version: 0.11.2
|
|
4
4
|
Summary: A minimal client for interacting with D-Wave cloud resources.
|
|
5
5
|
Home-page: https://github.com/dwavesystems/dwave-cloud-client
|
|
6
6
|
Author: D-Wave Systems Inc.
|
|
7
7
|
License: Apache 2.0
|
|
8
|
-
Platform: UNKNOWN
|
|
9
8
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
9
|
Classifier: Operating System :: OS Independent
|
|
11
10
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -13,6 +12,7 @@ Classifier: Programming Language :: Python :: 3.8
|
|
|
13
12
|
Classifier: Programming Language :: Python :: 3.9
|
|
14
13
|
Classifier: Programming Language :: Python :: 3.10
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
16
|
Requires-Python: >=3.8
|
|
17
17
|
Provides-Extra: test
|
|
18
18
|
Provides-Extra: bqm
|
|
@@ -35,10 +35,6 @@ License-File: LICENSE
|
|
|
35
35
|
:target: https://codecov.io/gh/dwavesystems/dwave-cloud-client
|
|
36
36
|
:alt: Coverage report
|
|
37
37
|
|
|
38
|
-
.. image:: https://readthedocs.com/projects/d-wave-systems-dwave-cloud-client/badge/?version=latest
|
|
39
|
-
:target: https://docs.ocean.dwavesys.com/projects/cloud-client/en/latest/?badge=latest
|
|
40
|
-
:alt: Documentation Status
|
|
41
|
-
|
|
42
38
|
.. index-start-marker
|
|
43
39
|
|
|
44
40
|
==================
|
|
@@ -86,7 +82,7 @@ Installation
|
|
|
86
82
|
|
|
87
83
|
.. installation-start-marker
|
|
88
84
|
|
|
89
|
-
Requires Python 3.
|
|
85
|
+
Requires Python 3.8+:
|
|
90
86
|
|
|
91
87
|
.. code-block:: bash
|
|
92
88
|
|
|
@@ -135,5 +131,3 @@ Commit the file along with your changes.
|
|
|
135
131
|
|
|
136
132
|
See reno's `user guide <https://docs.openstack.org/reno/latest/user/usage.html>`_
|
|
137
133
|
for details.
|
|
138
|
-
|
|
139
|
-
|
|
@@ -10,10 +10,6 @@
|
|
|
10
10
|
:target: https://codecov.io/gh/dwavesystems/dwave-cloud-client
|
|
11
11
|
:alt: Coverage report
|
|
12
12
|
|
|
13
|
-
.. image:: https://readthedocs.com/projects/d-wave-systems-dwave-cloud-client/badge/?version=latest
|
|
14
|
-
:target: https://docs.ocean.dwavesys.com/projects/cloud-client/en/latest/?badge=latest
|
|
15
|
-
:alt: Documentation Status
|
|
16
|
-
|
|
17
13
|
.. index-start-marker
|
|
18
14
|
|
|
19
15
|
==================
|
|
@@ -61,7 +57,7 @@ Installation
|
|
|
61
57
|
|
|
62
58
|
.. installation-start-marker
|
|
63
59
|
|
|
64
|
-
Requires Python 3.
|
|
60
|
+
Requires Python 3.8+:
|
|
65
61
|
|
|
66
62
|
.. code-block:: bash
|
|
67
63
|
|
|
@@ -19,16 +19,17 @@ import time
|
|
|
19
19
|
import webbrowser
|
|
20
20
|
from operator import sub
|
|
21
21
|
from typing import Any, Callable, Dict, Optional, Union, Sequence
|
|
22
|
-
from urllib.parse import urljoin
|
|
22
|
+
from urllib.parse import urljoin
|
|
23
23
|
|
|
24
24
|
import click
|
|
25
25
|
from authlib.integrations.requests_client import OAuth2Session, OAuthError
|
|
26
26
|
from authlib.oauth2.rfc6749 import OAuth2Token
|
|
27
27
|
from authlib.common.security import generate_token
|
|
28
|
+
from authlib.common.urls import add_params_to_uri
|
|
28
29
|
|
|
29
30
|
from dwave.cloud.auth.config import OCEAN_SDK_CLIENT_ID, OCEAN_SDK_SCOPES
|
|
30
31
|
from dwave.cloud.auth.creds import Credentials
|
|
31
|
-
from dwave.cloud.auth.server import SingleRequestAppServer,
|
|
32
|
+
from dwave.cloud.auth.server import SingleRequestAppServer, RequestCaptureAndRedirectApp
|
|
32
33
|
from dwave.cloud.config.models import ClientConfig
|
|
33
34
|
from dwave.cloud.regions import resolve_endpoints
|
|
34
35
|
from dwave.cloud.utils import pretty_argvalues
|
|
@@ -201,7 +202,9 @@ class AuthFlow:
|
|
|
201
202
|
return token
|
|
202
203
|
|
|
203
204
|
def ensure_active_token(self):
|
|
204
|
-
|
|
205
|
+
if not self.token:
|
|
206
|
+
return False
|
|
207
|
+
is_active = self.session.ensure_active_token(token=self.token)
|
|
205
208
|
self._save_token_to_creds(self.token)
|
|
206
209
|
return is_active
|
|
207
210
|
|
|
@@ -252,6 +255,14 @@ class LeapAuthFlow(AuthFlow):
|
|
|
252
255
|
def _infer_token_endpoint(leap_api_endpoint: str) -> str:
|
|
253
256
|
return urljoin(leap_api_endpoint, '/leap/openid/token')
|
|
254
257
|
|
|
258
|
+
@staticmethod
|
|
259
|
+
def _infer_leap_success_uri(leap_api_endpoint: str) -> str:
|
|
260
|
+
return urljoin(leap_api_endpoint, '/leap/openid/success')
|
|
261
|
+
|
|
262
|
+
@staticmethod
|
|
263
|
+
def _infer_leap_error_uri(leap_api_endpoint: str) -> str:
|
|
264
|
+
return urljoin(leap_api_endpoint, '/leap/openid/error')
|
|
265
|
+
|
|
255
266
|
@classmethod
|
|
256
267
|
def from_config_model(cls, config: ClientConfig, **kwargs) -> LeapAuthFlow:
|
|
257
268
|
"""Construct a :class:`.LeapAuthModel` initialized with Ocean SDK's
|
|
@@ -353,7 +364,47 @@ class LeapAuthFlow(AuthFlow):
|
|
|
353
364
|
flow.run_redirect_flow(open_browser=True)
|
|
354
365
|
|
|
355
366
|
"""
|
|
356
|
-
|
|
367
|
+
error_uri = self._infer_leap_error_uri(self.leap_api_endpoint)
|
|
368
|
+
success_uri = self._infer_leap_success_uri(self.leap_api_endpoint)
|
|
369
|
+
|
|
370
|
+
def exchange_code(app: RequestCaptureAndRedirectApp) -> str:
|
|
371
|
+
# error responses redirect immediately
|
|
372
|
+
if 'error' in app.query:
|
|
373
|
+
app.set_exception(
|
|
374
|
+
OAuthError(error=app.query['error'],
|
|
375
|
+
description=app.query.get('error_description')))
|
|
376
|
+
return add_params_to_uri(error_uri, app.query)
|
|
377
|
+
|
|
378
|
+
# when code received, exchange it for token
|
|
379
|
+
try:
|
|
380
|
+
self.fetch_token(code=app.query.get('code'), state=app.query.get('state'))
|
|
381
|
+
|
|
382
|
+
except OAuthError as exc:
|
|
383
|
+
# store for main thread
|
|
384
|
+
app.set_exception(exc)
|
|
385
|
+
|
|
386
|
+
# redirect to leap error page
|
|
387
|
+
query = dict(error=exc.error, error_description=exc.description,
|
|
388
|
+
state=app.query.get('state'))
|
|
389
|
+
return add_params_to_uri(error_uri, query)
|
|
390
|
+
|
|
391
|
+
except Exception as exc:
|
|
392
|
+
# store for main thread
|
|
393
|
+
app.set_exception(exc)
|
|
394
|
+
|
|
395
|
+
# redirect to leap error page
|
|
396
|
+
query = dict(error=type(exc).__name__, error_description=str(exc),
|
|
397
|
+
state=app.query.get('state'))
|
|
398
|
+
return add_params_to_uri(error_uri, query)
|
|
399
|
+
|
|
400
|
+
# redirect to leap success page
|
|
401
|
+
return add_params_to_uri(success_uri, app.query)
|
|
402
|
+
|
|
403
|
+
app = RequestCaptureAndRedirectApp(
|
|
404
|
+
message=self._REDIRECT_DONE_MSG,
|
|
405
|
+
redirect_uri=exchange_code,
|
|
406
|
+
include_query=False)
|
|
407
|
+
|
|
357
408
|
srv = SingleRequestAppServer(
|
|
358
409
|
host=self._REDIRECT_HOST,
|
|
359
410
|
base_port=self._REDIRECT_PORT_RANGE[0],
|
|
@@ -380,5 +431,7 @@ class LeapAuthFlow(AuthFlow):
|
|
|
380
431
|
print(self._AUTH_TIMEOUT_MSG)
|
|
381
432
|
return
|
|
382
433
|
|
|
383
|
-
|
|
384
|
-
|
|
434
|
+
# now raise auth exception if set by the app during code exchange
|
|
435
|
+
app.exception()
|
|
436
|
+
|
|
437
|
+
return self.token
|
|
@@ -18,8 +18,8 @@ import sys
|
|
|
18
18
|
import threading
|
|
19
19
|
import traceback
|
|
20
20
|
from socketserver import ThreadingMixIn
|
|
21
|
-
from typing import
|
|
22
|
-
from urllib.parse import urlsplit
|
|
21
|
+
from typing import Callable, Iterator, Optional, Union
|
|
22
|
+
from urllib.parse import urljoin, urlsplit, parse_qsl, SplitResult
|
|
23
23
|
from wsgiref.simple_server import make_server, WSGIRequestHandler, WSGIServer
|
|
24
24
|
from wsgiref.util import request_uri
|
|
25
25
|
|
|
@@ -250,10 +250,11 @@ class SingleRequestAppServer(BackgroundAppServer):
|
|
|
250
250
|
app = kwargs.pop('app')
|
|
251
251
|
|
|
252
252
|
def single_request_app(*args, **kwargs):
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
253
|
+
try:
|
|
254
|
+
return app(*args, **kwargs)
|
|
255
|
+
finally:
|
|
256
|
+
# we're done after the first request
|
|
257
|
+
self.server.shutdown()
|
|
257
258
|
|
|
258
259
|
super().__init__(app=single_request_app, **kwargs)
|
|
259
260
|
|
|
@@ -265,15 +266,60 @@ class RequestCaptureApp:
|
|
|
265
266
|
|
|
266
267
|
def __init__(self, message: str):
|
|
267
268
|
self.message = message
|
|
268
|
-
self.uri = None
|
|
269
|
-
self.
|
|
269
|
+
self.uri: str = None
|
|
270
|
+
self.parts: SplitResult = None
|
|
271
|
+
self.query: dict = None
|
|
270
272
|
|
|
271
|
-
def
|
|
273
|
+
def store_request(self, environ: dict):
|
|
272
274
|
# store the URI accessed
|
|
273
275
|
self.uri = request_uri(environ, include_query=True)
|
|
274
|
-
self.
|
|
276
|
+
self.parts = urlsplit(self.uri)
|
|
277
|
+
self.query = dict(parse_qsl(self.parts.query))
|
|
275
278
|
# in the future, we might also store: method, body data, headers, etc,
|
|
276
279
|
# but we don't need that for now
|
|
277
280
|
|
|
281
|
+
def set_exception(self, exc):
|
|
282
|
+
self._exc = exc
|
|
283
|
+
|
|
284
|
+
def exception(self):
|
|
285
|
+
if hasattr(self, '_exc') and self._exc:
|
|
286
|
+
raise self._exc
|
|
287
|
+
|
|
288
|
+
def __call__(self, environ: dict, start_response: Callable):
|
|
289
|
+
self.store_request(environ)
|
|
290
|
+
|
|
278
291
|
start_response("200 OK", [('Content-Type', 'text/plain; charset=utf-8')])
|
|
279
292
|
return [self.message.encode('utf-8')]
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
class RequestCaptureAndRedirectApp(RequestCaptureApp):
|
|
296
|
+
"""A simple WSGI application that stores request data (currently only URL),
|
|
297
|
+
and redirects to `redirect_uri`, possibly dynamically generated.
|
|
298
|
+
"""
|
|
299
|
+
|
|
300
|
+
def __init__(self, message: str,
|
|
301
|
+
redirect_uri: Union[str, Callable],
|
|
302
|
+
include_query: bool = True):
|
|
303
|
+
super().__init__(message)
|
|
304
|
+
|
|
305
|
+
self.redirect_uri = redirect_uri
|
|
306
|
+
self.include_query = include_query
|
|
307
|
+
|
|
308
|
+
def __call__(self, environ: dict, start_response: Callable):
|
|
309
|
+
self.store_request(environ)
|
|
310
|
+
|
|
311
|
+
if callable(self.redirect_uri):
|
|
312
|
+
uri = self.redirect_uri(self)
|
|
313
|
+
else:
|
|
314
|
+
uri = self.redirect_uri
|
|
315
|
+
|
|
316
|
+
if self.include_query:
|
|
317
|
+
uri = urljoin(uri, f'?{self.parts.query}')
|
|
318
|
+
|
|
319
|
+
start_response('302 Found', [
|
|
320
|
+
('Content-Type', 'text/plain; charset=utf-8'),
|
|
321
|
+
('Location', uri),
|
|
322
|
+
])
|
|
323
|
+
|
|
324
|
+
# just in case, include the message in body
|
|
325
|
+
return [self.message.encode('utf-8')]
|
|
@@ -17,7 +17,6 @@ import sys
|
|
|
17
17
|
import ast
|
|
18
18
|
import json
|
|
19
19
|
import subprocess
|
|
20
|
-
import pkg_resources
|
|
21
20
|
from collections.abc import Sequence
|
|
22
21
|
from configparser import ConfigParser
|
|
23
22
|
from datetime import datetime
|
|
@@ -35,7 +34,8 @@ from dwave.cloud.solver import StructuredSolver, BaseUnstructuredSolver
|
|
|
35
34
|
from dwave.cloud.utils import (
|
|
36
35
|
default_text_input, generate_random_ising_problem,
|
|
37
36
|
datetime_to_timestamp, utcnow, strtrunc, CLIError, set_loglevel,
|
|
38
|
-
get_contrib_packages, user_agent, epochnow
|
|
37
|
+
get_contrib_packages, user_agent, epochnow,
|
|
38
|
+
get_distribution, PackageNotFoundError, VersionNotFoundError)
|
|
39
39
|
from dwave.cloud.coders import bqm_as_file
|
|
40
40
|
from dwave.cloud.package_info import __title__, __version__
|
|
41
41
|
from dwave.cloud.exceptions import (
|
|
@@ -483,11 +483,18 @@ def ping(*, config_file, profile, endpoint, region, client_type, solver_def,
|
|
|
483
483
|
if label:
|
|
484
484
|
params.update(label=label)
|
|
485
485
|
|
|
486
|
+
# gently prefer the least busy QPU
|
|
487
|
+
def order_by(solver):
|
|
488
|
+
category = solver.properties.get('category')
|
|
489
|
+
avg_load = solver.properties.get('avg_load')
|
|
490
|
+
return (0 if category == 'qpu' else 1, avg_load)
|
|
491
|
+
|
|
486
492
|
config = dict(
|
|
487
493
|
config_file=config_file, profile=profile,
|
|
488
494
|
endpoint=endpoint, region=region,
|
|
489
495
|
client=client_type, solver=solver_def,
|
|
490
|
-
request_timeout=request_timeout, polling_timeout=polling_timeout
|
|
496
|
+
request_timeout=request_timeout, polling_timeout=polling_timeout,
|
|
497
|
+
defaults=dict(solver=dict(order_by=order_by)))
|
|
491
498
|
|
|
492
499
|
t0 = timer()
|
|
493
500
|
client, solver = _get_client_solver(config, output)
|
|
@@ -799,15 +806,7 @@ def install(list_all, install_all, update_all, accept_license, verbose, packages
|
|
|
799
806
|
_install_contrib_package(pkg, verbose=verbose, prompt=not accept_license)
|
|
800
807
|
|
|
801
808
|
|
|
802
|
-
def
|
|
803
|
-
"""Returns `pkg_resources.Distribution` object for matching `dist_spec`,
|
|
804
|
-
which can be given as `pkg_resources.Requirement`, or an unparsed string
|
|
805
|
-
requirement.
|
|
806
|
-
"""
|
|
807
|
-
return pkg_resources.get_distribution(dist_spec)
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
def _contrib_package_maybe_installed(name):
|
|
809
|
+
def _contrib_package_maybe_installed(name: str) -> bool:
|
|
811
810
|
"""Check if contrib package `name` is installed (even partially)."""
|
|
812
811
|
|
|
813
812
|
contrib = get_contrib_packages()
|
|
@@ -816,12 +815,12 @@ def _contrib_package_maybe_installed(name):
|
|
|
816
815
|
maybe_installed = False
|
|
817
816
|
for req in pkg['requirements']:
|
|
818
817
|
try:
|
|
819
|
-
|
|
818
|
+
get_distribution(req)
|
|
820
819
|
maybe_installed = True
|
|
821
|
-
except
|
|
820
|
+
except VersionNotFoundError:
|
|
822
821
|
# dependency installed, but wrong version
|
|
823
822
|
maybe_installed = True
|
|
824
|
-
except
|
|
823
|
+
except PackageNotFoundError:
|
|
825
824
|
# dependency not installed
|
|
826
825
|
pass
|
|
827
826
|
|
|
@@ -843,13 +842,13 @@ def _install_contrib_package(name, verbose=0, prompt=True):
|
|
|
843
842
|
# requirements are installed
|
|
844
843
|
reinstall = False
|
|
845
844
|
try:
|
|
846
|
-
if all(
|
|
845
|
+
if all(get_distribution(req) for req in pkg['requirements']):
|
|
847
846
|
click.echo("{} installed and up to date.\n".format(title))
|
|
848
847
|
return
|
|
849
|
-
except
|
|
848
|
+
except VersionNotFoundError:
|
|
850
849
|
click.echo("{} dependency version mismatch.\n".format(title))
|
|
851
850
|
reinstall = True
|
|
852
|
-
except
|
|
851
|
+
except PackageNotFoundError:
|
|
853
852
|
pass # dependency not installed, proceed with install
|
|
854
853
|
|
|
855
854
|
action = 'Reinstall' if reinstall else 'Install'
|
|
@@ -897,15 +896,26 @@ def _install_contrib_package(name, verbose=0, prompt=True):
|
|
|
897
896
|
@click.option('--install-all', '--all', '-a', default=False, is_flag=True,
|
|
898
897
|
help='Install all non-open-source packages '\
|
|
899
898
|
'available and accept licenses without prompting')
|
|
899
|
+
@click.option('--auth', default=False, is_flag=True,
|
|
900
|
+
help="Authorize Ocean to access Leap API on user's behalf. "
|
|
901
|
+
"Implies --auto-token during 'dwave config create' and it's "
|
|
902
|
+
"mutually exclusive with --full.")
|
|
903
|
+
@click.option('--project', 'project', default=None,
|
|
904
|
+
help='Leap project for which SAPI token is retrieved. Defaults to active project.')
|
|
905
|
+
@click.option('--oob', default=False, is_flag=True,
|
|
906
|
+
help="Same as '--auth', but using OAuth out-of-band flow. "
|
|
907
|
+
"Use when 'localhost' is not available in your browser.")
|
|
900
908
|
@click.option('--full', 'ask_full', default=False, is_flag=True,
|
|
901
|
-
help='
|
|
909
|
+
help='Manually configure non-essential options such as endpoint and solver.')
|
|
902
910
|
@click.option('--verbose', '-v', count=True,
|
|
903
911
|
help='Increase output verbosity (additive, up to 4 times)')
|
|
904
|
-
|
|
912
|
+
@standardized_output
|
|
913
|
+
def setup(install_all, auth, project, oob, ask_full, verbose, output):
|
|
905
914
|
"""Setup optional Ocean packages and configuration file(s).
|
|
906
915
|
|
|
907
916
|
Equivalent to running `dwave install [--all]`, followed by
|
|
908
|
-
`dwave
|
|
917
|
+
an optional `dwave auth login --skip-valid [--oob]` and then by
|
|
918
|
+
`dwave config create [--full] [--auto-token]`.
|
|
909
919
|
"""
|
|
910
920
|
|
|
911
921
|
contrib = get_contrib_packages()
|
|
@@ -921,17 +931,32 @@ def setup(install_all, ask_full, verbose):
|
|
|
921
931
|
# and `dwave setup` ran without `--all` flag.
|
|
922
932
|
click.echo("Optionally install non-open-source packages and "
|
|
923
933
|
"configure your environment.\n")
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
934
|
+
|
|
935
|
+
# Skip the prompt if all contrib packages already installed
|
|
936
|
+
if all(_contrib_package_maybe_installed(name) for name in contrib):
|
|
937
|
+
click.echo("All optional packages already installed.")
|
|
938
|
+
install = False
|
|
939
|
+
else:
|
|
940
|
+
prompt = "Do you want to select non-open-source packages to install (y/n)?"
|
|
941
|
+
val = default_text_input(prompt, default='y')
|
|
942
|
+
install = val.lower() == 'y'
|
|
927
943
|
click.echo()
|
|
928
944
|
|
|
929
945
|
if install:
|
|
930
946
|
for pkg in packages:
|
|
931
947
|
_install_contrib_package(pkg, verbose=verbose, prompt=not install_all)
|
|
932
948
|
|
|
933
|
-
|
|
934
|
-
|
|
949
|
+
auto_token = False
|
|
950
|
+
if auth or oob:
|
|
951
|
+
click.echo("Authorizing Leap access.\n")
|
|
952
|
+
_login(config_file=None, profile=None, oob=oob, skip_valid=True, output=output)
|
|
953
|
+
click.echo()
|
|
954
|
+
auto_token = True
|
|
955
|
+
ask_full = False
|
|
956
|
+
|
|
957
|
+
click.echo("Creating the D-Wave configuration file.\n")
|
|
958
|
+
return _config_create(config_file=None, profile=None, ask_full=ask_full,
|
|
959
|
+
auto_token=auto_token, project=project)
|
|
935
960
|
|
|
936
961
|
|
|
937
962
|
@cli.group()
|
|
@@ -943,22 +968,32 @@ def auth():
|
|
|
943
968
|
@click.option('--oob', is_flag=True,
|
|
944
969
|
help='Run OAuth 2.0 Authorization Code flow out-of-band, '
|
|
945
970
|
'without the use of locally hosted redirect URL.')
|
|
971
|
+
@click.option('--skip-valid', is_flag=True,
|
|
972
|
+
help='Skip authorization if access token is valid, or it '
|
|
973
|
+
'can be refreshed.')
|
|
946
974
|
@standardized_output
|
|
947
|
-
def login(*, config_file, profile, oob, output):
|
|
975
|
+
def login(*, config_file, profile, oob, skip_valid, output):
|
|
948
976
|
"""Authorize Ocean to access Leap API on user's behalf."""
|
|
949
977
|
|
|
978
|
+
return _login(config_file=config_file, profile=profile, oob=oob,
|
|
979
|
+
skip_valid=skip_valid, output=output)
|
|
980
|
+
|
|
981
|
+
def _login(*, config_file, profile, oob, skip_valid, output):
|
|
950
982
|
config = validate_config_v1(load_config(config_file=config_file, profile=profile))
|
|
951
983
|
flow = LeapAuthFlow.from_config_model(config)
|
|
952
984
|
|
|
985
|
+
if skip_valid:
|
|
986
|
+
if flow.ensure_active_token():
|
|
987
|
+
output('Valid token found, skipping authorization.')
|
|
988
|
+
return
|
|
989
|
+
|
|
953
990
|
if oob:
|
|
954
|
-
# XXX: until the standard OOB URI is supported on Leap
|
|
955
|
-
flow._OOB_REDIRECT_URI = 'oob'
|
|
956
991
|
flow.run_oob_flow(open_browser=True)
|
|
957
992
|
else:
|
|
958
993
|
flow.run_redirect_flow(open_browser=True)
|
|
959
994
|
|
|
960
|
-
|
|
961
|
-
|
|
995
|
+
output('Authorization completed successfully. '
|
|
996
|
+
'You can now use "dwave auth get" to fetch your token.')
|
|
962
997
|
|
|
963
998
|
|
|
964
999
|
@auth.command()
|
|
@@ -1682,8 +1682,8 @@ class Client(object):
|
|
|
1682
1682
|
raise
|
|
1683
1683
|
|
|
1684
1684
|
# parse response
|
|
1685
|
-
logger.trace("[%s] response: (code=%r, body=%r)",
|
|
1686
|
-
caller, response.status_code, response.text)
|
|
1685
|
+
logger.trace("[%s] response: (code=%r, body=%r, headers=%r)",
|
|
1686
|
+
caller, response.status_code, response.text, response.headers)
|
|
1687
1687
|
|
|
1688
1688
|
# workaround for charset_normalizer episode in requests>=2.26.0,
|
|
1689
1689
|
# where decoding of an empty json object '{}' fails.
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
__packagename__ = 'dwave-cloud-client'
|
|
16
16
|
__title__ = 'D-Wave Cloud Client'
|
|
17
|
-
__version__ = '0.11.
|
|
17
|
+
__version__ = '0.11.2'
|
|
18
18
|
__author__ = 'D-Wave Systems Inc.'
|
|
19
19
|
__description__ = 'A minimal client for interacting with D-Wave cloud resources.'
|
|
20
20
|
__url__ = 'https://github.com/dwavesystems/dwave-cloud-client'
|
|
@@ -29,13 +29,15 @@ from urllib.parse import urljoin
|
|
|
29
29
|
from datetime import datetime, timedelta
|
|
30
30
|
from dateutil.tz import UTC
|
|
31
31
|
from functools import partial, wraps
|
|
32
|
-
from
|
|
32
|
+
from importlib.metadata import Distribution, PackageNotFoundError
|
|
33
33
|
from secrets import token_hex
|
|
34
34
|
from typing import Any, Optional, Union, List, Dict, Mapping, Sequence
|
|
35
35
|
from unittest import mock
|
|
36
36
|
|
|
37
37
|
import requests
|
|
38
38
|
import diskcache
|
|
39
|
+
from importlib_metadata import entry_points
|
|
40
|
+
from packaging.requirements import Requirement
|
|
39
41
|
|
|
40
42
|
# Use numpy if available for fast decoding
|
|
41
43
|
try:
|
|
@@ -49,6 +51,7 @@ __all__ = ['evaluate_ising', 'uniform_iterator', 'uniform_get',
|
|
|
49
51
|
'datetime_to_timestamp', 'utcnow', 'epochnow', 'tictoc',
|
|
50
52
|
'hasinstance', 'exception_chain', 'is_caused_by',
|
|
51
53
|
'NumpyEncoder', 'coerce_numpy_to_python',
|
|
54
|
+
'get_distribution', 'PackageNotFoundError', 'VersionNotFoundError',
|
|
52
55
|
]
|
|
53
56
|
|
|
54
57
|
logger = logging.getLogger(__name__)
|
|
@@ -845,7 +848,10 @@ def pretty_argvalues():
|
|
|
845
848
|
def get_contrib_config():
|
|
846
849
|
"""Return all registered contrib (non-open-source) Ocean packages."""
|
|
847
850
|
|
|
848
|
-
|
|
851
|
+
# Note: we use `entry_points` from `importlib_metadata` to simplify access
|
|
852
|
+
# and use py312 semantics. See "compatibility note" in `importlib.metadata`
|
|
853
|
+
# docs for entry points.
|
|
854
|
+
contrib = [ep.load() for ep in entry_points(group='dwave_contrib')]
|
|
849
855
|
return contrib
|
|
850
856
|
|
|
851
857
|
|
|
@@ -867,11 +873,52 @@ def get_contrib_packages():
|
|
|
867
873
|
def get_platform_tags():
|
|
868
874
|
"""Return a list of platform tags generated from registered entry points."""
|
|
869
875
|
|
|
870
|
-
fs = [ep.load() for ep in
|
|
876
|
+
fs = [ep.load() for ep in entry_points(group='dwave.common.platform.tags')]
|
|
871
877
|
tags = list(filter(None, [f() for f in fs]))
|
|
872
878
|
return tags
|
|
873
879
|
|
|
874
880
|
|
|
881
|
+
class VersionNotFoundError(Exception):
|
|
882
|
+
"""Package version requirement not satisfied."""
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
def get_distribution(requirement: Union[str, Requirement],
|
|
886
|
+
prereleases: bool = True) -> Distribution:
|
|
887
|
+
"""Returns :class:`~importlib.metadata.Distribution` for a matching
|
|
888
|
+
`requirement` specification.
|
|
889
|
+
|
|
890
|
+
Note: this function re-implements :func:`pkg_resources.get_distribution`
|
|
891
|
+
functionality for py38+ (including py312, where setuptools/pkg_resources
|
|
892
|
+
is not available by default).
|
|
893
|
+
|
|
894
|
+
Args:
|
|
895
|
+
requirement:
|
|
896
|
+
Package dependency requirement according to PEP-508, given as string,
|
|
897
|
+
or :class:`~packaging.requirements.Requirement`.
|
|
898
|
+
prereleases:
|
|
899
|
+
Boolean flag to control if installed prereleases are allowed.
|
|
900
|
+
|
|
901
|
+
Raises:
|
|
902
|
+
:class:`~importlib.metadata.PackageNotFoundError`:
|
|
903
|
+
Package by name not found.
|
|
904
|
+
:class:`~dwave.cloud.utils.VersionNotFoundError`:
|
|
905
|
+
Version of the package found (distribution) does not match the
|
|
906
|
+
requirement.
|
|
907
|
+
"""
|
|
908
|
+
|
|
909
|
+
if not isinstance(requirement, Requirement):
|
|
910
|
+
requirement = Requirement(requirement)
|
|
911
|
+
|
|
912
|
+
dist = Distribution.from_name(requirement.name)
|
|
913
|
+
|
|
914
|
+
if not requirement.specifier.contains(dist.version, prereleases=prereleases):
|
|
915
|
+
raise VersionNotFoundError(
|
|
916
|
+
f"Package {dist.name!r} version {dist.version} "
|
|
917
|
+
f"does not match {requirement.specifier!s}")
|
|
918
|
+
|
|
919
|
+
return dist
|
|
920
|
+
|
|
921
|
+
|
|
875
922
|
class aliasdict(dict):
|
|
876
923
|
"""A dict subclass with support for item aliasing -- when you want to allow
|
|
877
924
|
explicit access to some keys, but not to store them in the dict.
|
{dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2/dwave_cloud_client.egg-info}/PKG-INFO
RENAMED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: dwave-cloud-client
|
|
3
|
-
Version: 0.11.
|
|
3
|
+
Version: 0.11.2
|
|
4
4
|
Summary: A minimal client for interacting with D-Wave cloud resources.
|
|
5
5
|
Home-page: https://github.com/dwavesystems/dwave-cloud-client
|
|
6
6
|
Author: D-Wave Systems Inc.
|
|
7
7
|
License: Apache 2.0
|
|
8
|
-
Platform: UNKNOWN
|
|
9
8
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
9
|
Classifier: Operating System :: OS Independent
|
|
11
10
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -13,6 +12,7 @@ Classifier: Programming Language :: Python :: 3.8
|
|
|
13
12
|
Classifier: Programming Language :: Python :: 3.9
|
|
14
13
|
Classifier: Programming Language :: Python :: 3.10
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
16
|
Requires-Python: >=3.8
|
|
17
17
|
Provides-Extra: test
|
|
18
18
|
Provides-Extra: bqm
|
|
@@ -35,10 +35,6 @@ License-File: LICENSE
|
|
|
35
35
|
:target: https://codecov.io/gh/dwavesystems/dwave-cloud-client
|
|
36
36
|
:alt: Coverage report
|
|
37
37
|
|
|
38
|
-
.. image:: https://readthedocs.com/projects/d-wave-systems-dwave-cloud-client/badge/?version=latest
|
|
39
|
-
:target: https://docs.ocean.dwavesys.com/projects/cloud-client/en/latest/?badge=latest
|
|
40
|
-
:alt: Documentation Status
|
|
41
|
-
|
|
42
38
|
.. index-start-marker
|
|
43
39
|
|
|
44
40
|
==================
|
|
@@ -86,7 +82,7 @@ Installation
|
|
|
86
82
|
|
|
87
83
|
.. installation-start-marker
|
|
88
84
|
|
|
89
|
-
Requires Python 3.
|
|
85
|
+
Requires Python 3.8+:
|
|
90
86
|
|
|
91
87
|
.. code-block:: bash
|
|
92
88
|
|
|
@@ -135,5 +131,3 @@ Commit the file along with your changes.
|
|
|
135
131
|
|
|
136
132
|
See reno's `user guide <https://docs.openstack.org/reno/latest/user/usage.html>`_
|
|
137
133
|
for details.
|
|
138
|
-
|
|
139
|
-
|
|
@@ -17,6 +17,7 @@ install_requires = ['requests[socks]>=2.18', 'pydantic>=2,<3', 'homebase>=1.0',
|
|
|
17
17
|
'click>=7.0', 'python-dateutil>=2.7', 'plucky>=0.4.3',
|
|
18
18
|
'diskcache>=5.2.1', 'packaging>=19', 'werkzeug>=2.2',
|
|
19
19
|
'typing-extensions>=4.5.0', 'authlib>=1.2,<2',
|
|
20
|
+
'importlib_metadata>=5.0.0', # can be dropped in py312+
|
|
20
21
|
]
|
|
21
22
|
|
|
22
23
|
# Package extras requirements
|
|
@@ -50,6 +51,7 @@ classifiers = [
|
|
|
50
51
|
'Programming Language :: Python :: 3.9',
|
|
51
52
|
'Programming Language :: Python :: 3.10',
|
|
52
53
|
'Programming Language :: Python :: 3.11',
|
|
54
|
+
'Programming Language :: Python :: 3.12',
|
|
53
55
|
]
|
|
54
56
|
|
|
55
57
|
setup(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave/cloud/testing/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dwave-cloud-client-0.11.0.dev0 → dwave-cloud-client-0.11.2}/dwave_cloud_client.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|