This repository was archived by the owner on May 10, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_analyzer.py
More file actions
66 lines (56 loc) · 2.61 KB
/
Copy pathpython_analyzer.py
File metadata and controls
66 lines (56 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from utils.github_utils import fetch_file_from_github, check_file_existence_in_repo
def analyze_python(repo_url):
"""
Analyze a Python project by fetching and analyzing its requirements.txt or Pipfile and checking for other files.
:param repo_url: URL of the GitHub repository to analyze
"""
analysis_result = {
"languages": ["Python"], # default assumption
"frameworks": [],
"build_tools": [],
"dockerised": False,
"dependency_manager": "pip", # defaults to pip
}
# Dependency manager detection
if check_file_existence_in_repo(repo_url, "Pipfile"):
analysis_result["dependency_manager"] = "pipenv"
if check_file_existence_in_repo(repo_url, "pyproject.toml"):
analysis_result["dependency_manager"] = "poetry"
# Pip is the default, no need to check for requirements.txt explicitly
# @cfc add more dependency manager checks
# Fetch requirements or Pipfile content
dependency_file = (
"requirements.txt"
if check_file_existence_in_repo(repo_url, "requirements.txt")
else "Pipfile"
)
dependencies_content = fetch_file_from_github(repo_url, dependency_file)
if dependencies_content:
dependencies = dependencies_content.splitlines()
# Framework detection
if any("django==" in dep for dep in dependencies):
analysis_result["frameworks"].append("Django")
if any("flask==" in dep for dep in dependencies):
analysis_result["frameworks"].append("Flask")
if any("fastapi" in dep for dep in dependencies):
analysis_result["frameworks"].append("FastAPI")
if any("pyramid==" in dep for dep in dependencies):
analysis_result["frameworks"].append("Pyramid")
# @cfc add more framework checks
# Build tool detection
if any("pytest" in dep for dep in dependencies):
analysis_result["build_tools"].append("Pytest")
if any("tox" in dep for dep in dependencies):
analysis_result["build_tools"].append("Tox")
# @cfc add more build tool checks
# Docker detection
if check_file_existence_in_repo(
repo_url, "Dockerfile"
) or check_file_existence_in_repo(repo_url, "docker-compose.yml"):
analysis_result["dockerised"] = True
# Additional check for frontend files like package.json to indicate potential full stack development
if check_file_existence_in_repo(repo_url, "package.json"):
analysis_result["languages"].append(
"JavaScript"
) # This adds a JS layer suggesting frontend involvement
return analysis_result