commons-metrics 0.0.22__tar.gz → 0.0.24__tar.gz

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.
Files changed (23) hide show
  1. {commons_metrics-0.0.22 → commons_metrics-0.0.24}/PKG-INFO +1 -1
  2. {commons_metrics-0.0.22 → commons_metrics-0.0.24}/commons_metrics/__init__.py +1 -1
  3. {commons_metrics-0.0.22 → commons_metrics-0.0.24}/commons_metrics/azure_devops_client.py +3 -3
  4. {commons_metrics-0.0.22 → commons_metrics-0.0.24}/commons_metrics/github_api_client.py +53 -5
  5. {commons_metrics-0.0.22 → commons_metrics-0.0.24}/commons_metrics.egg-info/PKG-INFO +1 -1
  6. {commons_metrics-0.0.22 → commons_metrics-0.0.24}/setup.py +1 -1
  7. {commons_metrics-0.0.22 → commons_metrics-0.0.24}/LICENSE +0 -0
  8. {commons_metrics-0.0.22 → commons_metrics-0.0.24}/README.md +0 -0
  9. {commons_metrics-0.0.22 → commons_metrics-0.0.24}/commons_metrics/cache_manager.py +0 -0
  10. {commons_metrics-0.0.22 → commons_metrics-0.0.24}/commons_metrics/commons_repos_client.py +0 -0
  11. {commons_metrics-0.0.22 → commons_metrics-0.0.24}/commons_metrics/database.py +0 -0
  12. {commons_metrics-0.0.22 → commons_metrics-0.0.24}/commons_metrics/date_utils.py +0 -0
  13. {commons_metrics-0.0.22 → commons_metrics-0.0.24}/commons_metrics/repositories.py +0 -0
  14. {commons_metrics-0.0.22 → commons_metrics-0.0.24}/commons_metrics/s3_file_manager.py +0 -0
  15. {commons_metrics-0.0.22 → commons_metrics-0.0.24}/commons_metrics/text_simplifier.py +0 -0
  16. {commons_metrics-0.0.22 → commons_metrics-0.0.24}/commons_metrics/update_design_components.py +0 -0
  17. {commons_metrics-0.0.22 → commons_metrics-0.0.24}/commons_metrics/util.py +0 -0
  18. {commons_metrics-0.0.22 → commons_metrics-0.0.24}/commons_metrics/variable_finder.py +0 -0
  19. {commons_metrics-0.0.22 → commons_metrics-0.0.24}/commons_metrics.egg-info/SOURCES.txt +0 -0
  20. {commons_metrics-0.0.22 → commons_metrics-0.0.24}/commons_metrics.egg-info/dependency_links.txt +0 -0
  21. {commons_metrics-0.0.22 → commons_metrics-0.0.24}/commons_metrics.egg-info/requires.txt +0 -0
  22. {commons_metrics-0.0.22 → commons_metrics-0.0.24}/commons_metrics.egg-info/top_level.txt +0 -0
  23. {commons_metrics-0.0.22 → commons_metrics-0.0.24}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: commons_metrics
3
- Version: 0.0.22
3
+ Version: 0.0.24
4
4
  Summary: A simple library for basic statistical calculations
5
5
  Author: Bancolombia
6
6
  Author-email: omar.david.pino@email.com
@@ -12,4 +12,4 @@ from .text_simplifier import TextSimplifier
12
12
  from .variable_finder import VariableFinder
13
13
 
14
14
  __all__ = ['Util', 'DatabaseConnection', 'ComponentRepository', 'UpdateDesignSystemComponents', 'GitHubAPIClient', 'AzureDevOpsClient', 'S3FileManager', 'CacheManager', 'CommonsReposClient', 'DateUtils', 'TextSimplifier', 'VariableFinder']
15
- __version__ = '0.0.22'
15
+ __version__ = '0.0.24'
@@ -5,7 +5,7 @@ import re
5
5
  from typing import List, Dict, Optional
6
6
  from requests.exceptions import HTTPError, Timeout, ConnectionError
7
7
  import urllib3
8
- from .commons_repos_client import extract_package_version_from_pubspec, extract_package_version_from_package_json
8
+ from .commons_repos_client import CommonsReposClient
9
9
 
10
10
  # Suprimir warnings de SSL para Azure DevOps con certificados corporativos
11
11
  urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
@@ -383,11 +383,11 @@ class AzureDevOpsClient:
383
383
  if platform == 'mobile':
384
384
  config_file = 'pubspec.yaml'
385
385
  default_package_name = 'bds_mobile'
386
- extract_version_method = extract_package_version_from_pubspec
386
+ extract_version_method = CommonsReposClient.extract_package_version_from_pubspec
387
387
  else: # web
388
388
  config_file = 'package.json'
389
389
  default_package_name = '@bancolombia/design-system-web'
390
- extract_version_method = extract_package_version_from_package_json
390
+ extract_version_method = CommonsReposClient.extract_package_version_from_package_json
391
391
 
392
392
  # Usar nombre de paquete por defecto si no se proporciona
393
393
  package_name = design_system_name or default_package_name
@@ -1,15 +1,46 @@
1
1
  import requests
2
2
  import base64
3
+ import time
4
+ from threading import Lock
3
5
  from typing import List, Dict, Optional
4
6
  import os
5
- from .commons_repos_client import extract_package_version_from_pubspec, extract_package_version_from_package_json
7
+ from .commons_repos_client import CommonsReposClient
8
+
9
+
10
+ class RateLimiter:
11
+ """
12
+ Controla el rate limiting para respetar los límites de API de GitHub.
13
+ GitHub permite 5000 requests/hora autenticados = ~1.4 TPS.
14
+ Usamos 720ms entre requests (1.39 TPS) para estar seguros.
15
+ """
16
+ def __init__(self, delay: float = 0.72):
17
+ self.delay = delay
18
+ self.last_request_time = 0
19
+ self.lock = Lock()
20
+
21
+ def wait(self):
22
+ """Espera el tiempo necesario antes de hacer el siguiente request"""
23
+ with self.lock:
24
+ current_time = time.time()
25
+ time_since_last_request = current_time - self.last_request_time
26
+
27
+ if time_since_last_request < self.delay:
28
+ sleep_time = self.delay - time_since_last_request
29
+ time.sleep(sleep_time)
30
+
31
+ self.last_request_time = time.time()
32
+
6
33
 
7
34
  class GitHubAPIClient:
8
35
  """
9
- Cliente para interactuar con la API de GitHub
36
+ Cliente para interactuar con la API de GitHub con rate limiting integrado.
37
+ Controla automáticamente el TPS para no exceder los límites de GitHub (5000 req/hora).
10
38
  """
11
39
 
12
- def __init__(self, token: str, owner: str = None, repo: str = None):
40
+ # Rate limiter compartido entre todas las instancias
41
+ _rate_limiter = RateLimiter(delay=0.72) # 720ms entre requests = 1.39 TPS
42
+
43
+ def __init__(self, token: str, owner: str = None, repo: str = None, enable_rate_limit: bool = True):
13
44
  """
14
45
  Inicializa el cliente de GitHub API
15
46
 
@@ -17,10 +48,12 @@ class GitHubAPIClient:
17
48
  token: Personal Access Token de GitHub
18
49
  owner: Dueño del repositorio (ej: 'grupobancolombia-innersource') - Opcional
19
50
  repo: Nombre del repositorio (ej: 'NU0066001_BDS_MOBILE_Lib') - Opcional
51
+ enable_rate_limit: Si True, aplica rate limiting automático (por defecto True)
20
52
  """
21
53
  self.token = token
22
54
  self.owner = owner
23
55
  self.repo = repo
56
+ self.enable_rate_limit = enable_rate_limit
24
57
  self.base_url = f"https://api.github.com/repos/{owner}/{repo}" if owner and repo else "https://api.github.com"
25
58
  self.headers = {
26
59
  "Authorization": f"token {token}",
@@ -37,6 +70,9 @@ class GitHubAPIClient:
37
70
  Returns:
38
71
  Lista de diccionarios con información de archivos/carpetas
39
72
  """
73
+ if self.enable_rate_limit:
74
+ self._rate_limiter.wait()
75
+
40
76
  url = f"{self.base_url}/contents/{path}"
41
77
  response = requests.get(url, headers=self.headers)
42
78
 
@@ -57,6 +93,9 @@ class GitHubAPIClient:
57
93
  Returns:
58
94
  Contenido del archivo como string, o None si no existe
59
95
  """
96
+ if self.enable_rate_limit:
97
+ self._rate_limiter.wait()
98
+
60
99
  url = f"{self.base_url}/contents/{path}"
61
100
  response = requests.get(url, headers=self.headers)
62
101
 
@@ -150,6 +189,9 @@ class GitHubAPIClient:
150
189
  page = 1
151
190
 
152
191
  while True:
192
+ if self.enable_rate_limit:
193
+ self._rate_limiter.wait()
194
+
153
195
  url = "https://api.github.com/search/code"
154
196
  params = {
155
197
  'q': query,
@@ -207,11 +249,11 @@ class GitHubAPIClient:
207
249
  if platform == 'mobile':
208
250
  config_file = 'pubspec.yaml'
209
251
  default_package_name = 'bds_mobile'
210
- extract_version_method = extract_package_version_from_pubspec
252
+ extract_version_method = CommonsReposClient.extract_package_version_from_pubspec
211
253
  else: # web
212
254
  config_file = 'package.json'
213
255
  default_package_name = '@bancolombia/design-system-web'
214
- extract_version_method = extract_package_version_from_package_json
256
+ extract_version_method = CommonsReposClient.extract_package_version_from_package_json
215
257
 
216
258
  # Usar nombre de paquete por defecto si no se proporciona
217
259
  package_name = design_system_name or default_package_name
@@ -255,6 +297,9 @@ class GitHubAPIClient:
255
297
  search_url = "https://api.github.com/search/repositories"
256
298
 
257
299
  while True:
300
+ if self.enable_rate_limit:
301
+ self._rate_limiter.wait()
302
+
258
303
  params = {
259
304
  'q': query,
260
305
  'per_page': per_page,
@@ -294,6 +339,9 @@ class GitHubAPIClient:
294
339
  Returns:
295
340
  Contenido del archivo como string, o None si no existe
296
341
  """
342
+ if self.enable_rate_limit:
343
+ self._rate_limiter.wait()
344
+
297
345
  response = requests.get(api_url, headers=self.headers)
298
346
 
299
347
  if response.status_code == 200:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: commons_metrics
3
- Version: 0.0.22
3
+ Version: 0.0.24
4
4
  Summary: A simple library for basic statistical calculations
5
5
  Author: Bancolombia
6
6
  Author-email: omar.david.pino@email.com
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='commons_metrics',
5
- version='0.0.22',
5
+ version='0.0.24',
6
6
  description='A simple library for basic statistical calculations',
7
7
  #long_description=open('USAGE.md').read(),
8
8
  #long_description_content_type='text/markdown',