greenmining 1.1.8__py3-none-any.whl → 1.1.9__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.
greenmining/__init__.py CHANGED
@@ -9,7 +9,7 @@ from greenmining.gsf_patterns import (
9
9
  is_green_aware,
10
10
  )
11
11
 
12
- __version__ = "1.1.8"
12
+ __version__ = "1.1.9"
13
13
 
14
14
 
15
15
  def fetch_repositories(
@@ -1,4 +1,9 @@
1
- # Repository Controller - Handles repository fetching operations.
1
+ # Repository Controller - Handles repository fetching + cloning operations.
2
+ import os
3
+ import re
4
+ import shutil
5
+ from pathlib import Path
6
+ from typing import List, Dict
2
7
 
3
8
  from greenmining.config import Config
4
9
  from greenmining.models.repository import Repository
@@ -13,23 +18,81 @@ class RepositoryController:
13
18
  # Initialize controller with configuration.
14
19
  self.config = config
15
20
  self.graphql_fetcher = GitHubGraphQLFetcher(config.GITHUB_TOKEN)
16
-
17
- def fetch_repositories(
18
- self,
19
- max_repos: int = None,
20
- min_stars: int = None,
21
- languages: list[str] = None,
22
- keywords: str = None,
23
- created_after: str = None,
24
- created_before: str = None,
25
- pushed_after: str = None,
26
- pushed_before: str = None,
27
- ) -> list[Repository]:
21
+ self.repos_dir = Path.cwd() / "greenmining_repos"
22
+
23
+ def _sanitize_repo_name(self, repo: Repository, index: int = 0) -> str:
24
+ """Safe unique dir name: owner_repo[_index]. Handles case collisions."""
25
+ base = re.sub(r'[^a-z0-9-]', '_', repo.full_name.replace('/', '_').lower())
26
+ name = f"{base}_{index}" if index else base
27
+ path = self.repos_dir / name
28
+ counter = 1
29
+ while path.exists():
30
+ name = f"{base}_{counter}"
31
+ path = self.repos_dir / name
32
+ counter += 1
33
+ return name
34
+
35
+ def clone_repositories(
36
+ self,
37
+ repositories: List[Repository],
38
+ github_token: str = None,
39
+ cleanup: bool = True,
40
+ depth: int = 1 # Shallow clone
41
+ ) -> List[Dict]:
42
+ """Clone repos to ./greenmining_repos/ with unique sanitized names."""
43
+ self.repos_dir.mkdir(exist_ok=True)
44
+ if cleanup:
45
+ shutil.rmtree(self.repos_dir, ignore_errors=True)
46
+ self.repos_dir.mkdir(exist_ok=True)
47
+ colored_print(f"Cleaned {self.repos_dir}", "yellow")
48
+
49
+ results = []
50
+ for i, repo in enumerate(repositories, 1):
51
+ safe_name = self._sanitize_repo_name(repo, i)
52
+ clone_path = self.repos_dir / safe_name
53
+
54
+ colored_print(f"[{i}/{len(repositories)}] Cloning {repo.full_name} → {safe_name}", "cyan")
55
+
56
+ url = f"https://{github_token}@github.com/{repo.full_name}.git" if github_token else repo.url
57
+ cmd = ["git", "clone", f"--depth={depth}", "-v", url, str(clone_path)]
58
+
59
+ import subprocess
60
+ try:
61
+ subprocess.check_call(cmd, cwd=self.repos_dir.parent)
62
+ colored_print(f"{safe_name}", "green")
63
+ results.append({
64
+ "full_name": repo.full_name,
65
+ "local_path": str(clone_path),
66
+ "success": True
67
+ })
68
+ except subprocess.CalledProcessError as e:
69
+ colored_print(f"{safe_name}: {e}", "red")
70
+ results.append({
71
+ "full_name": repo.full_name,
72
+ "local_path": str(clone_path),
73
+ "success": False,
74
+ "error": str(e)
75
+ })
76
+
77
+ # Save map for analyze_repositories
78
+ save_json_file(results, self.repos_dir / "clone_results.json")
79
+ success_rate = sum(1 for r in results if r["success"]) / len(results) * 100
80
+ colored_print(f"Cloned: {success_rate:.1f}% ({self.repos_dir}/clone_results.json)", "green")
81
+ return results
82
+
83
+
84
+
85
+
86
+
87
+ def fetch_repositories(self, max_repos: int = None, min_stars: int = None,
88
+ languages: list[str] = None, keywords: str = None,
89
+ created_after: str = None, created_before: str = None,
90
+ pushed_after: str = None, pushed_before: str = None) -> list[Repository]:
28
91
  # Fetch repositories from GitHub using GraphQL API.
29
92
  max_repos = max_repos or self.config.MAX_REPOS
30
93
  min_stars = min_stars or self.config.MIN_STARS
31
94
  languages = languages or self.config.SUPPORTED_LANGUAGES
32
- keywords = keywords or "microservices"
95
+ keywords = keywords
33
96
 
34
97
  colored_print(f"Fetching up to {max_repos} repositories...", "cyan")
35
98
  colored_print(f" Keywords: {keywords}", "cyan")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: greenmining
3
- Version: 1.1.8
3
+ Version: 1.1.9
4
4
  Summary: An empirical Python library for Mining Software Repositories (MSR) in Green IT research
5
5
  Author-email: Adam Bouafia <a.bouafia@student.vu.nl>
6
6
  License: MIT
@@ -70,7 +70,7 @@ An empirical Python library for Mining Software Repositories (MSR) in Green IT r
70
70
 
71
71
  - **Mine repositories at scale** - Search, Fetch and analyze GitHub repositories via GraphQL API with configurable filters
72
72
 
73
- - **Classify green commits** - Detect 122 sustainability patterns from the Green Software Foundation (GSF) catalog
73
+ - **Classify green commits** - Detect 124 sustainability patterns from the Green Software Foundation (GSF) catalog
74
74
  - **Analyze any repository by URL** - Direct Git-based analysis with support for private repositories
75
75
  - **Measure energy consumption** - RAPL, CodeCarbon, and CPU Energy Meter backends for power profiling
76
76
  - **Carbon footprint reporting** - CO2 emissions calculation with 20+ country profiles and cloud region support
@@ -113,7 +113,7 @@ docker pull adambouafia/greenmining:latest
113
113
  from greenmining import GSF_PATTERNS, is_green_aware, get_pattern_by_keywords
114
114
 
115
115
  # Check available patterns
116
- print(f"Total patterns: {len(GSF_PATTERNS)}") # 122 patterns across 15 categories
116
+ print(f"Total patterns: {len(GSF_PATTERNS)}") # 124 patterns across 15 categories
117
117
 
118
118
  # Detect green awareness in commit messages
119
119
  commit_msg = "Optimize Redis caching to reduce energy consumption"
@@ -670,8 +670,8 @@ config = Config(
670
670
 
671
671
  ### Core Capabilities
672
672
 
673
- - **Pattern Detection**: 122 sustainability patterns across 15 categories from the GSF catalog
674
- - **Keyword Analysis**: 321 green software detection keywords
673
+ - **Pattern Detection**: 124 sustainability patterns across 15 categories from the GSF catalog
674
+ - **Keyword Analysis**: 332 green software detection keywords
675
675
  - **Repository Fetching**: GraphQL API with date, star, and language filters
676
676
  - **URL-Based Analysis**: Direct Git-based analysis from GitHub URLs (HTTPS and SSH)
677
677
  - **Batch Processing**: Parallel analysis of multiple repositories with configurable workers
@@ -739,7 +739,7 @@ print(f"Equivalent: {report.tree_months:.2f} tree-months to offset")
739
739
 
740
740
  ### Pattern Database
741
741
 
742
- **122 green software patterns based on:**
742
+ **124 green software patterns based on:**
743
743
  - Green Software Foundation (GSF) Patterns Catalog
744
744
  - VU Amsterdam 2024 research on ML system sustainability
745
745
  - ICSE 2024 conference papers on sustainable software
@@ -749,11 +749,11 @@ print(f"Equivalent: {report.tree_months:.2f} tree-months to offset")
749
749
  - **Coverage**: 67% of patterns actively detect in real-world commits
750
750
  - **Accuracy**: 100% true positive rate for green-aware commits
751
751
  - **Categories**: 15 distinct sustainability domains covered
752
- - **Keywords**: 321 detection terms across all patterns
752
+ - **Keywords**: 332 detection terms across all patterns
753
753
 
754
754
  ## GSF Pattern Categories
755
755
 
756
- **122 patterns across 15 categories:**
756
+ **124 patterns across 15 categories:**
757
757
 
758
758
  ### 1. Cloud (40 patterns)
759
759
  Auto-scaling, serverless computing, right-sizing instances, region selection for renewable energy, spot instances, idle resource detection, cloud-native architectures
@@ -1,4 +1,4 @@
1
- greenmining/__init__.py,sha256=LRyVPcKKGGK9l2r2nn5EAEsPFTiFomity3Hc4CE6hGM,3390
1
+ greenmining/__init__.py,sha256=tQoU8k_I_ymm67bNlYo0laMgS_eP9ersn5NAkdRjRvc,3390
2
2
  greenmining/__main__.py,sha256=NYOVS7D4w2XDLn6SyXHXPKE5GrNGOeoWSTb_KazgK5c,590
3
3
  greenmining/config.py,sha256=MQ5aPaa_Y9MZke774dmibz2-XSqRVsQiiNaLDr8f7S0,2771
4
4
  greenmining/gsf_patterns.py,sha256=UvNJPY3HlAx1SicwUqci40TlLg8lCL0tszSOH4haxQs,55921
@@ -12,7 +12,7 @@ greenmining/analyzers/statistical_analyzer.py,sha256=PA0w0sytRmMO6N1a2iH7VdA6Icg
12
12
  greenmining/analyzers/temporal_analyzer.py,sha256=JfTcAoI20oCFMehGrSRnDqhJTXI-RUbdCTMwDOTW9-g,14259
13
13
  greenmining/analyzers/version_power_analyzer.py,sha256=2P6zOqBg-ButtIhF-4cutiwD2Q1geMY49VFUghHXXoI,8119
14
14
  greenmining/controllers/__init__.py,sha256=UiAT6zBvC1z_9cJWfzq1cLA0I4r9b2vURHipj8oDczI,180
15
- greenmining/controllers/repository_controller.py,sha256=hQb9kRuGNeA5cNHKqX-CZTzYvPpgzWCX6w8NzllxuDc,3857
15
+ greenmining/controllers/repository_controller.py,sha256=ZRMU6oUWUELW91qcZ_iBiRcDNT8ruTIy2aRjQbOb0O0,6571
16
16
  greenmining/energy/__init__.py,sha256=GoCYh7hitWBoPMtan1HF1yezCHi7o4sa_YUJgGkeJc8,558
17
17
  greenmining/energy/base.py,sha256=3hIPgc4B0Nz9V7DTh2Xd6trDRtmozUBBpa5UWRuWzcw,5918
18
18
  greenmining/energy/carbon_reporter.py,sha256=bKIFlLhHfYzI4DBu_ff4GW1Psz4oSCAF4NmzQb-EShA,8298
@@ -33,8 +33,8 @@ greenmining/services/data_analyzer.py,sha256=0XqW-slrnt7RotrHDweOqKtoN8XIA7y6p7s
33
33
  greenmining/services/github_graphql_fetcher.py,sha256=ZklXdEAc60KeFL83zRYMwW_-2OwMKpfPY7Wrifl0D50,11539
34
34
  greenmining/services/local_repo_analyzer.py,sha256=PYHj-zz0cePWbQq9HtGvd2OcZUYM8rRGe8eKIAp1_fI,24874
35
35
  greenmining/services/reports.py,sha256=nhJuYiA5tPD_9AjtgSLEnrpW3x15sZXrwIxpxQEBbh0,23219
36
- greenmining-1.1.8.dist-info/licenses/LICENSE,sha256=M7ma3JHGeiIZIs3ea0HTcFl_wLFPX2NZElUliYs4bCA,1083
37
- greenmining-1.1.8.dist-info/METADATA,sha256=6gb4TO8nLcxqhekL3_uFYnBsIGEZKM_51dq_L24BiEA,30175
38
- greenmining-1.1.8.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
39
- greenmining-1.1.8.dist-info/top_level.txt,sha256=nreXgXxZIWI-42yQknQ0HXtUrFnzZ8N1ra4Mdy2KcsI,12
40
- greenmining-1.1.8.dist-info/RECORD,,
36
+ greenmining-1.1.9.dist-info/licenses/LICENSE,sha256=M7ma3JHGeiIZIs3ea0HTcFl_wLFPX2NZElUliYs4bCA,1083
37
+ greenmining-1.1.9.dist-info/METADATA,sha256=QVrwbhh-huQmP8Uv0YQDgraGOFoTmFRNxq7T27bZ4wk,30175
38
+ greenmining-1.1.9.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
39
+ greenmining-1.1.9.dist-info/top_level.txt,sha256=nreXgXxZIWI-42yQknQ0HXtUrFnzZ8N1ra4Mdy2KcsI,12
40
+ greenmining-1.1.9.dist-info/RECORD,,