Cleanup (#168)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Kalen Michael <kalenmike@gmail.com>
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
# Ultralytics YOLO 🚀, GPL-3.0 license
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
# Ultralytics YOLO 🚀, GPL-3.0 license
|
||||
|
||||
import requests
|
||||
|
||||
from ultralytics.hub.config import HUB_API_ROOT
|
||||
from ultralytics.hub.utils import request_with_credentials
|
||||
from ultralytics.hub.utils import HUB_API_ROOT, request_with_credentials
|
||||
from ultralytics.yolo.utils import is_colab
|
||||
|
||||
API_KEY_PATH = "https://hub.ultralytics.com/settings?tab=api+keys"
|
||||
|
@ -1,12 +0,0 @@
|
||||
import os
|
||||
|
||||
# Global variables
|
||||
REPO_URL = "https://github.com/ultralytics/yolov5.git"
|
||||
REPO_BRANCH = "ultralytics/HUB" # "master"
|
||||
|
||||
ENVIRONMENT = os.environ.get("ULTRALYTICS_ENV", "production")
|
||||
if ENVIRONMENT == 'production':
|
||||
HUB_API_ROOT = "https://api.ultralytics.com"
|
||||
else:
|
||||
HUB_API_ROOT = "http://127.0.0.1:8000"
|
||||
print(f'Connected to development server on {HUB_API_ROOT}')
|
@ -1,3 +1,5 @@
|
||||
# Ultralytics YOLO 🚀, GPL-3.0 license
|
||||
|
||||
import signal
|
||||
import sys
|
||||
from pathlib import Path
|
||||
@ -6,8 +8,7 @@ from time import sleep
|
||||
import requests
|
||||
|
||||
from ultralytics import __version__
|
||||
from ultralytics.hub.config import HUB_API_ROOT
|
||||
from ultralytics.hub.utils import check_dataset_disk_space, smart_request
|
||||
from ultralytics.hub.utils import HUB_API_ROOT, check_dataset_disk_space, smart_request
|
||||
from ultralytics.yolo.utils import LOGGER, is_colab, threaded
|
||||
|
||||
AGENT_NAME = f'python-{__version__}-colab' if is_colab() else f'python-{__version__}-local'
|
||||
|
@ -1,14 +1,17 @@
|
||||
# Ultralytics YOLO 🚀, GPL-3.0 license
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import threading
|
||||
import time
|
||||
|
||||
import requests
|
||||
|
||||
from ultralytics.hub.config import HUB_API_ROOT
|
||||
from ultralytics.yolo.utils import DEFAULT_CONFIG_DICT, LOGGER, RANK, SETTINGS, colorstr, emojis
|
||||
from ultralytics.yolo.utils import DEFAULT_CONFIG_DICT, LOGGER, RANK, SETTINGS, TryExcept, colorstr, emojis
|
||||
|
||||
PREFIX = colorstr('Ultralytics: ')
|
||||
HELP_MSG = 'If this issue persists please visit https://github.com/ultralytics/hub/issues for assistance.'
|
||||
HUB_API_ROOT = os.environ.get("ULTRALYTICS_HUB_API", "https://api.ultralytics.com")
|
||||
|
||||
|
||||
def check_dataset_disk_space(url='https://github.com/ultralytics/yolov5/releases/download/v1.0/coco128.zip', sf=2.0):
|
||||
@ -90,7 +93,6 @@ def smart_request(*args, retry=3, timeout=30, thread=True, code=-1, method="post
|
||||
requests.Response: The HTTP response object. If the request is executed in a separate thread, returns None.
|
||||
"""
|
||||
retry_codes = (408, 500) # retry only these codes
|
||||
methods = {'post': requests.post, 'get': requests.get} # request methods
|
||||
|
||||
def func(*func_args, **func_kwargs):
|
||||
r = None # response
|
||||
@ -98,7 +100,10 @@ def smart_request(*args, retry=3, timeout=30, thread=True, code=-1, method="post
|
||||
for i in range(retry + 1):
|
||||
if (time.time() - t0) > timeout:
|
||||
break
|
||||
r = methods[method](*func_args, **func_kwargs) # i.e. post(url, data, json, files)
|
||||
if method == 'post':
|
||||
r = requests.post(*func_args, **func_kwargs) # i.e. post(url, data, json, files)
|
||||
elif method == 'get':
|
||||
r = requests.get(*func_args, **func_kwargs) # i.e. get(url, data, json, files)
|
||||
if r.status_code == 200:
|
||||
break
|
||||
try:
|
||||
@ -125,7 +130,8 @@ def smart_request(*args, retry=3, timeout=30, thread=True, code=-1, method="post
|
||||
return func(*args, **kwargs)
|
||||
|
||||
|
||||
def sync_analytics(cfg, all_keys=False, enabled=False):
|
||||
@TryExcept()
|
||||
def sync_analytics(cfg, all_keys=False, enabled=True):
|
||||
"""
|
||||
Sync analytics data if enabled in the global settings
|
||||
|
||||
@ -137,8 +143,8 @@ def sync_analytics(cfg, all_keys=False, enabled=False):
|
||||
if SETTINGS['sync'] and RANK in {-1, 0} and enabled:
|
||||
cfg = dict(cfg) # convert type from DictConfig to dict
|
||||
if not all_keys:
|
||||
cfg = {k: v for k, v in cfg.items() if v != DEFAULT_CONFIG_DICT[k]} # retain only non-default values
|
||||
cfg = {k: v for k, v in cfg.items() if v != DEFAULT_CONFIG_DICT.get(k, None)} # retain non-default values
|
||||
cfg['uuid'] = SETTINGS['uuid'] # add the device UUID to the configuration data
|
||||
|
||||
# Send a request to the HUB API to sync the analytics data
|
||||
smart_request(f'{HUB_API_ROOT}/v1/usage/anonymous', data=cfg, headers=None, code=3, retry=0, verbose=False)
|
||||
# Send a request to the HUB API to sync analytics
|
||||
smart_request(f'{HUB_API_ROOT}/v1/usage/anonymous', json=cfg, headers=None, code=3, retry=0, verbose=False)
|
||||
|
Reference in New Issue
Block a user