From 80f69b08367cb40c8584ba7838cbaeadc45f7f60 Mon Sep 17 00:00:00 2001 From: zhangxunhui Date: Sat, 10 Jan 2026 08:27:57 +0800 Subject: [PATCH] =?UTF-8?q?add=20.gitignore=20and=20env.yml=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8Dgithub=E7=9B=B8=E5=85=B3=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=B3=84=E9=9C=B2=E5=92=8C=E7=81=B5=E6=B4=BB=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example.yml | 12 ++++++++++++ .gitignore | 26 ++++++++++++++++++++++++++ README.md | 7 +++++++ springf_preject.py | 29 ++++++++++++++++++++++------- 4 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 .env.example.yml create mode 100644 .gitignore diff --git a/.env.example.yml b/.env.example.yml new file mode 100644 index 0000000..480c9c9 --- /dev/null +++ b/.env.example.yml @@ -0,0 +1,12 @@ +# GitHub Configuration +github_token: ghp_your_github_token_here + +# GitHub API Configuration +base_url: https://api.github.com +min_stars: 20 +request_interval: 0.8 +max_retry_5xx: 3 + +# Clone Configuration +clone_retry: 2 +clone_timeout: 180 \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d05d2e5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,26 @@ +# Environment files +.env.yml +.env + +# Python +__pycache__/ +*.pyc +*.pyo +*.pyd + +# Logs +logs/ +*.log + +# Data directories +data/ + +# IDE +.vscode/ +.idea/ +*.swp +*.swo + +# OS +.DS_Store +Thumbs.db \ No newline at end of file diff --git a/README.md b/README.md index d899c54..59bac25 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,9 @@ # benchmark +## 开发模式 + +- 创建环境变量文件 + +``` +cp .env.example.yml .env.yml +``` diff --git a/springf_preject.py b/springf_preject.py index 08514a2..44d2eea 100644 --- a/springf_preject.py +++ b/springf_preject.py @@ -7,6 +7,7 @@ import json import xml.etree.ElementTree as ET import subprocess import re +import yaml # 路径配置 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -24,20 +25,34 @@ MISSING_REPO_LOG = os.path.join(LOG_DIR, "missing_repo.log") for d in [DATA_DIR, REPO_DIR, LOG_DIR]: os.makedirs(d, exist_ok=True) +# 读取配置文件 +def load_config(): + config_path = os.path.join(SCRIPT_DIR, ".env.yml") + if not os.path.exists(config_path): + print(f"Config file not found: {config_path}") + print(f"Please create it based on .env.example.yml") + exit(1) + + with open(config_path, "r") as f: + return yaml.safe_load(f) + +# 加载配置 +config = load_config() + # GitHub 配置 -GITHUB_TOKEN = os.getenv("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") +GITHUB_TOKEN = config.get("github_token") HEADERS = {"Accept": "application/vnd.github+json"} if GITHUB_TOKEN: HEADERS["Authorization"] = f"token {GITHUB_TOKEN}" -BASE_URL = "https://api.github.com" -MIN_STARS = 20 -REQUEST_INTERVAL = 0.8 -MAX_RETRY_5XX = 3 +BASE_URL = config.get("base_url", "https://api.github.com") +MIN_STARS = config.get("min_stars", 20) +REQUEST_INTERVAL = config.get("request_interval", 0.8) +MAX_RETRY_5XX = config.get("max_retry_5xx", 3) # clone 控制参数 -CLONE_RETRY = 2 -CLONE_TIMEOUT = 180 +CLONE_RETRY = config.get("clone_retry", 2) +CLONE_TIMEOUT = config.get("clone_timeout", 180) # 日志工具 def log_to_file(path, msg):