Path.parent
Path.parent(...)Description
Documentation for Path.parent.
Real-World Examples
Practical code examples showing how Path.parent is used in real projects.
Example 1
From OpenHUTB/mcp (llm/src/server.py)
import os
from typing import Optional
# 添加父目录到Python路径,以便导入src模块
current_dir = os.path.dirname(os.path.abspath(__file__))
parent_dir = os.path.dirname(current_dir)
sys.path.insert(0, parent_dir)
from fastmcp import FastMCP
from src.config import config
from src.utils.logger import app_logger
from src.github_client import GitHubClient
# 创建FastMCP实例
mcp = FastMCP("GitHub搜索助手")
# 创建GitHub客户端实例
github_client = GitHubClient()
@mcp.tool()
def search_repositories(query: str, language: Optional[str] = None,
sort: str = "stars", per_page: int = 10) -> str:
"""搜索GitHub仓库工具
根据关键词、编程语言等条件搜索GitHub仓库,返回热门匹配结果。
self.github_token = os.getenv('GITHUB_TOKEN')
print(f"GITHUB_TOKEN: {self.github_token}")
self.sizes = ['small', 'medium', 'large']
self.languages = ['Python', 'Java', 'Rust', 'C++', 'C', 'Rust', 'Javascript', 'PHP']
script_dir = Path(__file__).parent
project_root = script_dir.parent
self.data_dir = project_root / '.data'
self.data_dir.mkdir(exist_ok=True)
async def get_popular_topics(self, n: int) -> List[str]:
"""Use LLM to get n most popular programming topics."""
try:
# Define the function for LLM to call
tools = [
{
"type": "function",
"function": {
"name": "get_popular_topics",
"description": "Get the most popular programming and technology topics",
"parameters": {
"type": "object",
"properties": {
"topics": {