ml-dash 0.6.2rc1__py3-none-any.whl → 0.6.4__py3-none-any.whl

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.
ml_dash/config.py CHANGED
@@ -1,132 +1,132 @@
1
1
  """Configuration file management for ML-Dash CLI."""
2
2
 
3
- from pathlib import Path
4
3
  import json
5
- from typing import Optional, Dict, Any
4
+ from pathlib import Path
5
+ from typing import Any, Dict, Optional
6
6
 
7
7
 
8
8
  class Config:
9
+ """
10
+ Manages ML-Dash CLI configuration file.
11
+
12
+ Configuration is stored in ~/.dash/config.json with structure:
13
+ {
14
+ "remote_url": "https://api.dash.ml",
15
+ "api_key": "token",
16
+ "default_batch_size": 100
17
+ }
18
+ """
19
+
20
+ DEFAULT_CONFIG_DIR = Path.home() / ".dash"
21
+ CONFIG_FILE = "config.json"
22
+
23
+ def __init__(self, config_dir: Optional[Path] = None):
9
24
  """
10
- Manages ML-Dash CLI configuration file.
11
-
12
- Configuration is stored in ~/.ml-dash/config.json with structure:
13
- {
14
- "remote_url": "https://api.dash.ml",
15
- "api_key": "token",
16
- "default_batch_size": 100
17
- }
18
- """
25
+ Initialize config manager.
19
26
 
20
- DEFAULT_CONFIG_DIR = Path.home() / ".ml-dash"
21
- CONFIG_FILE = "config.json"
22
-
23
- def __init__(self, config_dir: Optional[Path] = None):
24
- """
25
- Initialize config manager.
26
-
27
- Args:
28
- config_dir: Config directory path (defaults to ~/.ml-dash)
29
- """
30
- self.config_dir = config_dir or self.DEFAULT_CONFIG_DIR
31
- self.config_path = self.config_dir / self.CONFIG_FILE
32
- self._data = self._load()
33
-
34
- def _load(self) -> Dict[str, Any]:
35
- """Load config from file."""
36
- if self.config_path.exists():
37
- try:
38
- with open(self.config_path, "r") as f:
39
- return json.load(f)
40
- except (json.JSONDecodeError, IOError):
41
- # If config is corrupted, return empty dict
42
- return {}
27
+ Args:
28
+ config_dir: Config directory path (defaults to ~/.dash)
29
+ """
30
+ self.config_dir = config_dir or self.DEFAULT_CONFIG_DIR
31
+ self.config_path = self.config_dir / self.CONFIG_FILE
32
+ self._data = self._load()
33
+
34
+ def _load(self) -> Dict[str, Any]:
35
+ """Load config from file."""
36
+ if self.config_path.exists():
37
+ try:
38
+ with open(self.config_path, "r") as f:
39
+ return json.load(f)
40
+ except (json.JSONDecodeError, IOError):
41
+ # If config is corrupted, return empty dict
43
42
  return {}
43
+ return {}
44
+
45
+ def save(self):
46
+ """Save config to file."""
47
+ self.config_dir.mkdir(parents=True, exist_ok=True)
48
+ with open(self.config_path, "w") as f:
49
+ json.dump(self._data, f, indent=2)
50
+
51
+ def get(self, key: str, default: Any = None) -> Any:
52
+ """
53
+ Get config value.
44
54
 
45
- def save(self):
46
- """Save config to file."""
47
- self.config_dir.mkdir(parents=True, exist_ok=True)
48
- with open(self.config_path, "w") as f:
49
- json.dump(self._data, f, indent=2)
50
-
51
- def get(self, key: str, default: Any = None) -> Any:
52
- """
53
- Get config value.
54
-
55
- Args:
56
- key: Config key
57
- default: Default value if key not found
58
-
59
- Returns:
60
- Config value or default
61
- """
62
- return self._data.get(key, default)
63
-
64
- def set(self, key: str, value: Any):
65
- """
66
- Set config value and save.
67
-
68
- Args:
69
- key: Config key
70
- value: Config value
71
- """
72
- self._data[key] = value
73
- self.save()
74
-
75
- def delete(self, key: str):
76
- """
77
- Delete config key and save.
78
-
79
- Args:
80
- key: Config key to delete
81
- """
82
- if key in self._data:
83
- del self._data[key]
84
- self.save()
85
-
86
- def clear(self):
87
- """Clear all config and save."""
88
- self._data = {}
89
- self.save()
90
-
91
- @property
92
- def remote_url(self) -> Optional[str]:
93
- """Get default remote URL."""
94
- return self.get("remote_url", "https://api.dash.ml")
95
-
96
- @remote_url.setter
97
- def remote_url(self, url: str):
98
- """Set default remote URL."""
99
- self.set("remote_url", url)
100
-
101
- @property
102
- def api_key(self) -> Optional[str]:
103
- """Get default API key."""
104
- return self.get("api_key")
105
-
106
- @api_key.setter
107
- def api_key(self, key: str):
108
- """Set default API key."""
109
- self.set("api_key", key)
110
-
111
- @property
112
- def batch_size(self) -> int:
113
- """Get default batch size for uploads."""
114
- return self.get("default_batch_size", 100)
115
-
116
- @batch_size.setter
117
- def batch_size(self, size: int):
118
- """Set default batch size."""
119
- self.set("default_batch_size", size)
120
-
121
- @property
122
- def device_secret(self) -> Optional[str]:
123
- """Get device secret for OAuth device flow."""
124
- return self.get("device_secret")
125
-
126
- @device_secret.setter
127
- def device_secret(self, secret: str):
128
- """Set device secret."""
129
- self.set("device_secret", secret)
55
+ Args:
56
+ key: Config key
57
+ default: Default value if key not found
58
+
59
+ Returns:
60
+ Config value or default
61
+ """
62
+ return self._data.get(key, default)
63
+
64
+ def set(self, key: str, value: Any):
65
+ """
66
+ Set config value and save.
67
+
68
+ Args:
69
+ key: Config key
70
+ value: Config value
71
+ """
72
+ self._data[key] = value
73
+ self.save()
74
+
75
+ def delete(self, key: str):
76
+ """
77
+ Delete config key and save.
78
+
79
+ Args:
80
+ key: Config key to delete
81
+ """
82
+ if key in self._data:
83
+ del self._data[key]
84
+ self.save()
85
+
86
+ def clear(self):
87
+ """Clear all config and save."""
88
+ self._data = {}
89
+ self.save()
90
+
91
+ @property
92
+ def remote_url(self) -> Optional[str]:
93
+ """Get default remote URL."""
94
+ return self.get("remote_url", "https://api.dash.ml")
95
+
96
+ @remote_url.setter
97
+ def remote_url(self, url: str):
98
+ """Set default remote URL."""
99
+ self.set("remote_url", url)
100
+
101
+ @property
102
+ def api_key(self) -> Optional[str]:
103
+ """Get default API key."""
104
+ return self.get("api_key")
105
+
106
+ @api_key.setter
107
+ def api_key(self, key: str):
108
+ """Set default API key."""
109
+ self.set("api_key", key)
110
+
111
+ @property
112
+ def batch_size(self) -> int:
113
+ """Get default batch size for uploads."""
114
+ return self.get("default_batch_size", 100)
115
+
116
+ @batch_size.setter
117
+ def batch_size(self, size: int):
118
+ """Set default batch size."""
119
+ self.set("default_batch_size", size)
120
+
121
+ @property
122
+ def device_secret(self) -> Optional[str]:
123
+ """Get device secret for OAuth device flow."""
124
+ return self.get("device_secret")
125
+
126
+ @device_secret.setter
127
+ def device_secret(self, secret: str):
128
+ """Set device secret."""
129
+ self.set("device_secret", secret)
130
130
 
131
131
 
132
132
  # Global config instance