code-loader 1.0.115__py3-none-any.whl → 1.0.116__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.

Potentially problematic release.


This version of code-loader might be problematic. Click here for more details.

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,95 @@
1
+ """
2
+ Mixpanel tracking utilities for code-loader.
3
+ """
4
+ import os
5
+ import sys
6
+ import getpass
7
+ from typing import Optional, Dict, Any
8
+ import mixpanel
9
+
10
+
11
+ class MixpanelTracker:
12
+ """Handles Mixpanel event tracking for code-loader."""
13
+
14
+ def __init__(self, token: str = "f1bf46fb339d8c2930cde8c1acf65491"):
15
+ self.token = token
16
+ self.mp = mixpanel.Mixpanel(token)
17
+ self._user_id: Optional[str] = None
18
+
19
+ def _get_user_id(self) -> str:
20
+ if self._user_id is None:
21
+ try:
22
+ self._user_id = getpass.getuser()
23
+ except Exception:
24
+ # Fallback to environment variables or default
25
+ self._user_id = os.environ.get('USER', os.environ.get('USERNAME', 'unknown'))
26
+ return self._user_id or 'unknown'
27
+
28
+ def _get_tensorleap_user_id(self) -> Optional[str]:
29
+ """Get the TensorLeap user ID from ~/.tensorleap/user_id if it exists."""
30
+ try:
31
+ user_id_path = os.path.expanduser("~/.tensorleap/user_id")
32
+ if os.path.exists(user_id_path):
33
+ with open(user_id_path, 'r') as f:
34
+ user_id = f.read().strip()
35
+ if user_id:
36
+ return user_id
37
+ except Exception:
38
+ pass
39
+ return None
40
+
41
+ def _get_distinct_id(self) -> str:
42
+ """Get the distinct ID for Mixpanel tracking.
43
+
44
+ Priority order:
45
+ 1. TensorLeap user ID (from ~/.tensorleap/user_id)
46
+ 2. System username (whoami)
47
+ 3. 'unknown' as fallback
48
+ """
49
+ tensorleap_user_id = self._get_tensorleap_user_id()
50
+ if tensorleap_user_id:
51
+ return tensorleap_user_id
52
+
53
+ try:
54
+ return getpass.getuser()
55
+ except Exception:
56
+ # Final fallback
57
+ return os.environ.get('USER', os.environ.get('USERNAME', 'unknown'))
58
+
59
+ def track_code_loader_loaded(self, event_properties: Optional[Dict[str, Any]] = None) -> None:
60
+ try:
61
+ distinct_id = self._get_distinct_id()
62
+
63
+ tensorleap_user_id = self._get_tensorleap_user_id()
64
+ whoami = self._get_user_id()
65
+
66
+ properties = {
67
+ 'whoami': whoami,
68
+ 'python_version': f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
69
+ 'platform': os.name,
70
+ }
71
+
72
+ if tensorleap_user_id:
73
+ properties['user_id'] = tensorleap_user_id
74
+
75
+ if event_properties:
76
+ properties.update(event_properties)
77
+
78
+ self.mp.track(distinct_id, 'code_loader_loaded', properties)
79
+ except Exception as e:
80
+ pass
81
+
82
+
83
+ # Global tracker instance
84
+ _tracker = None
85
+
86
+
87
+ def get_tracker() -> MixpanelTracker:
88
+ global _tracker
89
+ if _tracker is None:
90
+ _tracker = MixpanelTracker()
91
+ return _tracker
92
+
93
+
94
+ def track_code_loader_loaded(event_properties: Optional[Dict[str, Any]] = None) -> None:
95
+ 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.116
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=dxVgMug5sE99DkRonlY-Pg0l1asFH7ZtHZK_fKpk1k0,3089
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.116.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
34
+ code_loader-1.0.116.dist-info/METADATA,sha256=WiSm72MyFj2xP8DsMmhBN5IzzHVvYk7YVvE5KZGHs0I,1102
35
+ code_loader-1.0.116.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
36
+ code_loader-1.0.116.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