code-loader 1.0.115__py3-none-any.whl → 1.0.117__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.
code_loader/__init__.py CHANGED
@@ -2,3 +2,9 @@ from code_loader.leaploader import LeapLoader
2
2
  from code_loader.inner_leap_binder import global_leap_binder as leap_binder
3
3
  from code_loader.experiment_api.experiment import init_experiment
4
4
  from code_loader.experiment_api.client import Client
5
+
6
+ try:
7
+ from code_loader.mixpanel_tracker import track_code_loader_loaded
8
+ track_code_loader_loaded({'event_type': 'module_import'})
9
+ except Exception:
10
+ pass
code_loader/leaploader.py CHANGED
@@ -34,6 +34,16 @@ class LeapLoader(LeapLoaderBase):
34
34
  super().__init__(code_path, code_entry_name)
35
35
 
36
36
  self._preprocess_result_cached = None
37
+
38
+ try:
39
+ from code_loader.mixpanel_tracker import track_code_loader_loaded
40
+ track_code_loader_loaded({
41
+ 'event_type': 'leap_loader_instantiated',
42
+ 'code_path': code_path,
43
+ 'code_entry_name': code_entry_name
44
+ })
45
+ except Exception:
46
+ pass
37
47
 
38
48
  @lru_cache()
39
49
  def exec_script(self) -> None:
@@ -0,0 +1,134 @@
1
+ """
2
+ Mixpanel tracking utilities for code-loader.
3
+ """
4
+ import os
5
+ import sys
6
+ import getpass
7
+ import uuid
8
+ from typing import Optional, Dict, Any
9
+ import mixpanel # type: ignore[import]
10
+
11
+
12
+ class MixpanelTracker:
13
+ """Handles Mixpanel event tracking for code-loader."""
14
+
15
+ def __init__(self, token: str = "f1bf46fb339d8c2930cde8c1acf65491"):
16
+ self.token = token
17
+ self.mp = mixpanel.Mixpanel(token)
18
+ self._user_id: Optional[str] = None
19
+
20
+ def _get_whoami(self) -> str:
21
+ """Get the current system username (whoami) for device identification.
22
+
23
+ Returns:
24
+ str: The system username, with fallbacks to environment variables or 'unknown'
25
+ """
26
+ if self._user_id is None:
27
+ try:
28
+ self._user_id = getpass.getuser()
29
+ except Exception:
30
+ # Fallback to environment variables or default
31
+ self._user_id = os.environ.get('USER', os.environ.get('USERNAME', 'unknown'))
32
+ return self._user_id or 'unknown'
33
+
34
+
35
+ def _get_tensorleap_user_id(self) -> Optional[str]:
36
+ """Get the TensorLeap user ID from ~/.tensorleap/user_id if it exists."""
37
+ try:
38
+ user_id_path = os.path.expanduser("~/.tensorleap/user_id")
39
+ if os.path.exists(user_id_path):
40
+ with open(user_id_path, 'r') as f:
41
+ user_id = f.read().strip()
42
+ if user_id:
43
+ return user_id
44
+ except Exception:
45
+ pass
46
+ return None
47
+
48
+ def _get_or_create_device_id(self) -> str:
49
+ """Get or create a device ID from ~/.tensorleap/device_id file.
50
+
51
+ If the file doesn't exist, creates it with a new UUID.
52
+
53
+ Returns:
54
+ str: The device ID (UUID string)
55
+ """
56
+ try:
57
+ device_id_path = os.path.expanduser("~/.tensorleap/device_id")
58
+
59
+ # Create directory if it doesn't exist
60
+ os.makedirs(os.path.dirname(device_id_path), exist_ok=True)
61
+
62
+ if os.path.exists(device_id_path):
63
+ with open(device_id_path, 'r') as f:
64
+ device_id = f.read().strip()
65
+ if device_id:
66
+ return device_id
67
+
68
+ # Generate new device ID and save it
69
+ device_id = str(uuid.uuid4())
70
+ with open(device_id_path, 'w') as f:
71
+ f.write(device_id)
72
+
73
+ return device_id
74
+ except Exception:
75
+ # Fallback to generating a new UUID if file operations fail
76
+ return str(uuid.uuid4())
77
+
78
+ def _get_distinct_id(self) -> str:
79
+ """Get the distinct ID for Mixpanel tracking.
80
+
81
+ Priority order:
82
+ 1. TensorLeap user ID (from ~/.tensorleap/user_id)
83
+ 2. Device ID (from ~/.tensorleap/device_id, generated if not exists)
84
+ """
85
+ tensorleap_user_id = self._get_tensorleap_user_id()
86
+ if tensorleap_user_id:
87
+ return tensorleap_user_id
88
+
89
+ return self._get_or_create_device_id()
90
+
91
+ def track_code_loader_loaded(self, event_properties: Optional[Dict[str, Any]] = None) -> None:
92
+ """Track code loader loaded event with device identification.
93
+
94
+ Args:
95
+ event_properties: Optional additional properties to include in the event
96
+ """
97
+ try:
98
+ distinct_id = self._get_distinct_id()
99
+
100
+ tensorleap_user_id = self._get_tensorleap_user_id()
101
+ whoami = self._get_whoami()
102
+ device_id = self._get_or_create_device_id()
103
+
104
+ properties = {
105
+ 'whoami': whoami,
106
+ '$device_id': device_id, # Always use device_id for $device_id
107
+ 'python_version': f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
108
+ 'platform': os.name,
109
+ }
110
+
111
+ if tensorleap_user_id:
112
+ properties['user_id'] = tensorleap_user_id
113
+
114
+ if event_properties:
115
+ properties.update(event_properties)
116
+
117
+ self.mp.track(distinct_id, 'code_loader_loaded', properties)
118
+ except Exception as e:
119
+ pass
120
+
121
+
122
+ # Global tracker instance
123
+ _tracker = None
124
+
125
+
126
+ def get_tracker() -> MixpanelTracker:
127
+ global _tracker
128
+ if _tracker is None:
129
+ _tracker = MixpanelTracker()
130
+ return _tracker
131
+
132
+
133
+ def track_code_loader_loaded(event_properties: Optional[Dict[str, Any]] = None) -> None:
134
+ get_tracker().track_code_loader_loaded(event_properties)
@@ -1,8 +1,7 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: code-loader
3
- Version: 1.0.115
3
+ Version: 1.0.117
4
4
  Summary:
5
- Home-page: https://github.com/tensorleap/code-loader
6
5
  License: MIT
7
6
  Author: dorhar
8
7
  Author-email: doron.harnoy@tensorleap.ai
@@ -14,11 +13,13 @@ Classifier: Programming Language :: Python :: 3.9
14
13
  Classifier: Programming Language :: Python :: 3.10
15
14
  Classifier: Programming Language :: Python :: 3.11
16
15
  Classifier: Programming Language :: Python :: 3.12
16
+ Requires-Dist: mixpanel (>=4.10.0,<5.0.0)
17
17
  Requires-Dist: numpy (>=1.22.3,<2.0.0) ; python_version >= "3.8" and python_version < "3.11"
18
18
  Requires-Dist: numpy (>=2.3.2,<3.0.0) ; python_version >= "3.11" and python_version < "3.13"
19
19
  Requires-Dist: psutil (>=5.9.5,<6.0.0)
20
20
  Requires-Dist: pyyaml (>=6.0.2,<7.0.0)
21
21
  Requires-Dist: requests (>=2.32.3,<3.0.0)
22
+ Project-URL: Homepage, https://github.com/tensorleap/code-loader
22
23
  Project-URL: Repository, https://github.com/tensorleap/code-loader
23
24
  Description-Content-Type: text/markdown
24
25
 
@@ -1,5 +1,4 @@
1
- LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
2
- code_loader/__init__.py,sha256=6MMWr0ObOU7hkqQKgOqp4Zp3I28L7joGC9iCbQYtAJg,241
1
+ code_loader/__init__.py,sha256=outxRQ0M-zMfV0QGVJmAed5qWfRmyD0TV6-goEGAzBw,406
3
2
  code_loader/contract/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
3
  code_loader/contract/datasetclasses.py,sha256=gJsXu4zVAaiBlq6GJwPxfTD2e0gICTtI_6Ir61MRL48,8838
5
4
  code_loader/contract/enums.py,sha256=GEFkvUMXnCNt-GOoz7NJ9ecQZ2PPDettJNOsxsiM0wk,1622
@@ -22,15 +21,16 @@ code_loader/experiment_api/workingspace_config_utils.py,sha256=DLzXQCg4dgTV_YgaS
22
21
  code_loader/inner_leap_binder/__init__.py,sha256=koOlJyMNYzGbEsoIbXathSmQ-L38N_pEXH_HvL7beXU,99
23
22
  code_loader/inner_leap_binder/leapbinder.py,sha256=0iHVHxC2NjfH7F0vQFVGy1e0llgKEyUHUHh3DdtqL70,32602
24
23
  code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=wjtk3TflrjJ8Y-OeuedVBD-09ZuOjIKGUjL7sMBU0fQ,41017
25
- code_loader/leaploader.py,sha256=fxf2CrWPeWfJYVoNg-Lue7RSvosuZO35FjRrDfrny5I,29363
24
+ code_loader/leaploader.py,sha256=rQRK1lyUPSpZiRs6lKUUxVJBCe3grEY_UxEMxSIpuxI,29709
26
25
  code_loader/leaploaderbase.py,sha256=lKdw2pd6H9hFsxVmc7jJMoZd_vlG5He1ooqT-cR_yq8,4496
26
+ code_loader/mixpanel_tracker.py,sha256=U20vQXH8G7XIVXxcpQcVEZSuIwwGnyH5RMHXWZZG8HI,4639
27
27
  code_loader/plot_functions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
28
  code_loader/plot_functions/plot_functions.py,sha256=xg6Gi4myTN9crq6JtyrhYI38HLXjPVJcbnI7CIy8f7w,14625
29
29
  code_loader/plot_functions/visualize.py,sha256=gsBAYYkwMh7jIpJeDMPS8G4CW-pxwx6LznoQIvi4vpo,657
30
30
  code_loader/utils.py,sha256=_j8b60pimoNAvWMRj7hEkkT6C76qES6cZoBFHpXHMxA,2698
31
31
  code_loader/visualizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
32
32
  code_loader/visualizers/default_visualizers.py,sha256=onRnLE_TXfgLN4o52hQIOOhUcFexGlqJ3xSpQDVLuZM,2604
33
- code_loader-1.0.115.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
34
- code_loader-1.0.115.dist-info/METADATA,sha256=gG-J8pjjV6uGDL4pQ9eBNJ8qPISDUDxMNAaH2Mx4kN4,1048
35
- code_loader-1.0.115.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
36
- code_loader-1.0.115.dist-info/RECORD,,
33
+ code_loader-1.0.117.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
34
+ code_loader-1.0.117.dist-info/METADATA,sha256=du8-T5bFdFlkZj7rC-z9ZczxH_fCPrKjQCAjfKs3QGU,1102
35
+ code_loader-1.0.117.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
36
+ code_loader-1.0.117.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.9.0
2
+ Generator: poetry-core 2.1.3
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 TensorLeap
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
File without changes