|
19 | 19 | from six.moves.urllib.parse import urljoin |
20 | 20 |
|
21 | 21 | import click |
22 | | -import requests |
23 | 22 | import yaml |
24 | 23 |
|
25 | | -from scrapinghub import Connection, APIError |
26 | | - |
27 | | -try: |
28 | | - from scrapinghub import HubstorageClient |
29 | | -except ImportError: |
30 | | - # scrapinghub < 1.9.0 |
31 | | - from hubstorage import HubstorageClient |
32 | | - |
33 | 24 | import shub |
34 | 25 | from shub.compat import to_native_str |
35 | 26 | from shub.exceptions import (BadParameterException, InvalidAuthException, |
@@ -77,6 +68,7 @@ def create_default_setup_py(**kwargs): |
77 | 68 |
|
78 | 69 |
|
79 | 70 | def make_deploy_request(url, data, files, auth, verbose, keep_log): |
| 71 | + import requests |
80 | 72 | last_logs = deque(maxlen=LAST_N_LOGS) |
81 | 73 | try: |
82 | 74 | rsp = requests.post(url=url, auth=auth, data=data, files=files, |
@@ -400,6 +392,11 @@ def get_job_specs(job): |
400 | 392 |
|
401 | 393 |
|
402 | 394 | def get_job(job): |
| 395 | + try: |
| 396 | + from scrapinghub import HubstorageClient |
| 397 | + except ImportError: |
| 398 | + # scrapinghub < 1.9.0 |
| 399 | + from hubstorage import HubstorageClient |
403 | 400 | jobid, apikey = get_job_specs(job) |
404 | 401 | hsc = HubstorageClient(auth=apikey) |
405 | 402 | job = hsc.get_job(jobid) |
@@ -554,6 +551,7 @@ def latest_github_release(force_update=False, timeout=1., cache=None): |
554 | 551 | # saved |
555 | 552 | if release_data.get('_shub_last_update', 0) == today: |
556 | 553 | return release_data |
| 554 | + import requests |
557 | 555 | release_data = requests.get(REQ_URL, timeout=timeout).json() |
558 | 556 | release_data['_shub_last_update'] = today |
559 | 557 | try: |
@@ -646,6 +644,7 @@ def has_project_access(project, endpoint, apikey): |
646 | 644 | """Check whether an API key has access to a given project. May raise |
647 | 645 | InvalidAuthException if the API key is invalid (but not if it is valid but |
648 | 646 | lacks access to the project)""" |
| 647 | + from scrapinghub import Connection, APIError |
649 | 648 | conn = Connection(apikey, url=endpoint) |
650 | 649 | try: |
651 | 650 | return project in conn.project_ids() |
|
0 commit comments