|
3 | 3 | import sys
|
4 | 4 | import time
|
5 | 5 | from getpass import getpass
|
| 6 | +from pathlib import Path |
6 | 7 | from urllib.parse import urlparse
|
7 | 8 |
|
8 | 9 | import requests
|
@@ -59,20 +60,23 @@ def check_key(api_key, model, notebook, num_retries=0):
|
59 | 60 | return "onboarding"
|
60 | 61 |
|
61 | 62 |
|
| 63 | +def auth(api_key): |
| 64 | + r = check_key(api_key) |
| 65 | + w = r["workspace"] |
| 66 | + |
| 67 | + return Roboflow(api_key, w) |
| 68 | + |
| 69 | + |
62 | 70 | def login(workspace=None, force=False):
|
63 | 71 | os_name = os.name
|
64 | 72 |
|
65 | 73 | if os_name == "nt":
|
66 |
| - default_path = os.path.join(os.getenv("USERPROFILE", ""), "roboflow/config.json") |
| 74 | + default_path = str(Path.home() / "roboflow" / "config.json") |
67 | 75 | else:
|
68 |
| - default_path = os.path.join(os.getenv("HOME", ""), ".config/roboflow/config.json") |
| 76 | + default_path = str(Path.home() / ".config" / "roboflow" / "config.json") |
69 | 77 |
|
70 | 78 | # default configuration location
|
71 |
| - conf_location = os.getenv( |
72 |
| - "ROBOFLOW_CONFIG_DIR", |
73 |
| - default=default_path, |
74 |
| - ) |
75 |
| - |
| 79 | + conf_location = os.getenv("ROBOFLOW_CONFIG_DIR", default=default_path) |
76 | 80 | if os.path.isfile(conf_location) and not force:
|
77 | 81 | write_line("You are already logged into Roboflow. To make a different login," "run roboflow.login(force=True).")
|
78 | 82 | return None
|
@@ -134,10 +138,7 @@ def initialize_roboflow(the_workspace=None):
|
134 | 138 |
|
135 | 139 | global active_workspace
|
136 | 140 |
|
137 |
| - conf_location = os.getenv( |
138 |
| - "ROBOFLOW_CONFIG_DIR", |
139 |
| - default=os.getenv("HOME", "") + "/.config/roboflow/config.json", |
140 |
| - ) |
| 141 | + conf_location = os.getenv("ROBOFLOW_CONFIG_DIR", default=str(Path.home() / ".config" / "roboflow" / "config.json")) |
141 | 142 |
|
142 | 143 | if not os.path.isfile(conf_location):
|
143 | 144 | raise RuntimeError("To use this method, you must first login - run roboflow.login()")
|
@@ -275,7 +276,7 @@ def project(self, project_name, the_workspace=None):
|
275 | 276 |
|
276 | 277 | dataset_info = dataset_info.json()["project"]
|
277 | 278 |
|
278 |
| - return Project(self.api_key or "", dataset_info) |
| 279 | + return Project(self.api_key, dataset_info) |
279 | 280 |
|
280 | 281 | def __str__(self):
|
281 | 282 | """to string function"""
|
|
0 commit comments