Skip to content

Commit

Permalink
修改项目管理工具
Browse files Browse the repository at this point in the history
1. conda+pip 迁移到 conda+poetry
  • Loading branch information
kingzeus committed Nov 16, 2024
1 parent 80a2171 commit 216377c
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 89 deletions.
26 changes: 22 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
__pycache__
.idea
database
logs

# Poetry
poetry.lock
.venv/
dist/
*.egg-info/

# Python
__pycache__/
*.py[cod]
*$py.class
.pytest_cache/
.coverage
htmlcov/

# IDE
.vscode/
.idea/

# Project specific
logs/
database/
.pylint_rate
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<p align="center">
<img alt="License" src="https://img.shields.io/badge/license-MIT-blue.svg">
<img alt="Version" src="https://img.shields.io/badge/version-0.1.0-green.svg">
<img alt="Python" src="https://img.shields.io/badge/python-3.8+-blue.svg">
<img alt="Python" src="https://img.shields.io/badge/python-3.10+-blue.svg">

</p>
<p align="center">
Expand Down
4 changes: 1 addition & 3 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@

# 数据库配置
DATABASE_CONFIG = {
"path": os.path.join(
ROOT_DIR, "database", "fund_analysis.v4.db"
) # SQLite数据库文件路径
"path": os.path.join(ROOT_DIR, "database", "fund_analysis.v4.db") # SQLite数据库文件路径
}

# API配置
Expand Down
4 changes: 1 addition & 3 deletions data_source/data_source_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ class DataSourceFactory:
@classmethod
def register(cls, source_class: Type[IDataSource]) -> None:
"""注册新的数据源类型"""
logger.info(
"注册数据源: %s %s", source_class.get_name(), source_class.get_version()
)
logger.info("注册数据源: %s %s", source_class.get_name(), source_class.get_version())
cls._sources[source_class.get_name()] = source_class

@classmethod
Expand Down
4 changes: 1 addition & 3 deletions models/fund.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ class Fund(BaseModel):
type = CharField(max_length=20) # 基金类型
issue_date = DateField() # 发行日期
establishment_date = DateField() # 成立日期
establishment_size = DecimalField(
max_digits=20, decimal_places=4
) # 成立规模(单位:亿份)
establishment_size = DecimalField(max_digits=20, decimal_places=4) # 成立规模(单位:亿份)
company = CharField(max_length=100) # 基金管理公司
custodian = CharField(max_length=100) # 基金托管人
fund_manager = CharField(max_length=100) # 基金经理人
Expand Down
43 changes: 43 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[tool.poetry]
name = "fund-analysis"
version = "0.1.0"
description = "基金分析系统"
authors = ["Fan Yefei <[email protected]>"]

[tool.poetry.dependencies]
python = "~3.10"
# Web框架
dash = {version = "^2.18.1", extras = ["compress"]}
"dash-bootstrap-components" = "^1.5.0"
plotly = "^5.18.0"

"feffery-antd-components" = "^0.3.8"
"feffery-dash-utils" = "^0.1.4"
"feffery-markdown-components" = "^0.3.0rc3"
"feffery-utils-components" = "^0.2.0rc20"

# 服务端
Flask = "^3.0.3"
"flask-restx" = "^1.3.0"

# 网络
requests = "^2.32.3"

# 数据处理
pandas = "^2.2.3"
numpy = "^1.26.2"
"beautifulsoup4" = "^4.12.3"
"flask-apscheduler" = "^1.13.1"

# 数据库
peewee = "^3.17.0"

[tool.poetry.group.dev.dependencies]
# 开发工具
black = "^23.11.0" # 代码格式化检查
pylint = "^3.1.0" # 代码质量检查
colorama = "^0.4.6" # 测试用

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
18 changes: 0 additions & 18 deletions requirements.txt

This file was deleted.

4 changes: 1 addition & 3 deletions scheduler/tasks/fund_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,5 @@ def execute(self, **kwargs) -> Dict[str, Any]:
return fund_data

except Exception as e:
logger.error(
"更新基金信息失败: %s", str(e), exc_info=True
) # 添加完整的错误堆栈
logger.error("更新基金信息失败: %s", str(e), exc_info=True) # 添加完整的错误堆栈
raise
4 changes: 1 addition & 3 deletions scheduler/tasks/fund_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,5 @@ def execute(self, **kwargs) -> Dict[str, Any]:
}

except Exception as e:
logger.error(
f"更新基金信息失败: {str(e)}", exc_info=True
) # 添加完整的错误堆栈
logger.error(f"更新基金信息失败: {str(e)}", exc_info=True) # 添加完整的错误堆栈
raise
94 changes: 55 additions & 39 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,39 +57,53 @@ activate_conda_env() {
if ! conda activate fund; then
echo -e "${RED}激活conda环境失败${NC}"
read -p "按回车键继续..."
return 1
exit 1
fi
echo -e "${GREEN}conda环境激活成功${NC}"
return 0
}

# 安装依赖
install_dependencies() {
echo -e "${YELLOW}检查并安装依赖${NC}"
if [ -f "requirements.txt" ]; then
if ! pip install -r requirements.txt; then
echo -e "${RED}安装依赖失败${NC}"
read -p "按回车键继续..."
return 1
fi

# 安装代码检查工具
echo -e "${YELLOW}安装代码检查工具...${NC}"
if ! pip install black pylint; then
echo -e "${RED}安装代码检查工具失败${NC}"
read -p "按回车键继续..."
return 1
# 检查poetry是否已安装
check_poetry() {
if ! command -v poetry &> /dev/null; then
echo -e "${RED}错误: 未找到poetry,正在安装...${NC}"
# 获取当前conda环境信息
conda_env=$(conda info --envs | grep "*" | awk '{print $1}')
echo -e "${YELLOW}当前conda环境: ${conda_env}${NC}"
if ! conda install -y poetry; then
echo -e "${RED}安装poetry失败${NC}"
exit 1
fi
fi
return 0
}

echo -e "${GREEN}依赖安装成功${NC}"
else
echo -e "${RED}错误: 未找到requirements.txt文件${NC}"
read -p "按回车键继续..."
# 创建并配置环境
setup_env() {
echo -e "${YELLOW}配置开发环境...${NC}"
# 获取poetry版本
poetry_version=$(poetry --version | cut -d' ' -f3)
echo -e "${GREEN}当前poetry版本: $poetry_version${NC}"

# 配置poetry不使用虚拟环境
echo -e "${YELLOW}配置poetry...${NC}"
poetry config virtualenvs.create false

# 安装项目依赖
echo -e "${YELLOW}安装项目依赖...${NC}"
if ! poetry install; then
echo -e "${RED}安装依赖失败${NC}"
echo -e "按回车键返回主菜单..."
read
return 1
fi

echo -e "${GREEN}环境配置成功${NC}"
read -p "按回车键继续..."
return 0
}



# 初始化数据库
init_database() {
echo -e "${YELLOW}迁移数据库...${NC}"
Expand Down Expand Up @@ -271,7 +285,7 @@ run_code_check() {
echo -e "${RED}无法解析评分信息${NC}"
fi

# 保存当前评分
# 保存当前��分
echo "$curr_rate" > .pylint_rate

has_error=1
Expand Down Expand Up @@ -338,7 +352,8 @@ do_full_install() {
check_conda || return 1
setup_conda_env || return 1
activate_conda_env || return 1
install_dependencies || return 1
check_poetry || return 1
setup_env || return 1
init_database || return 1
run_code_check || return 1
start_app || return 1
Expand All @@ -354,48 +369,49 @@ while true; do
case $choice in
1)
echo -e "${YELLOW}开始初始化环境...${NC}"
ensure_directories
check_conda
setup_conda_env
activate_conda_env
install_dependencies
ensure_directories || continue
check_conda || continue
setup_conda_env || continue
activate_conda_env || continue
check_poetry || continue
setup_env || continue
if [ $? -eq 0 ]; then
echo -e "${GREEN}环境初始化完成!${NC}"
fi
;;
2)
echo -e "${YELLOW}开始迁移数据库...${NC}"
init_database
init_database || continue
;;
3)
echo -e "${YELLOW}开始运行代码检查...${NC}"
run_code_check
run_code_check || continue
;;
4)
echo -e "${YELLOW}开始启动应用...${NC}"
ensure_directories
activate_conda_env
start_app
ensure_directories || continue
activate_conda_env || continue
start_app || continue
;;
5)
do_full_install
do_full_install || continue
;;
9)
start_test
start_test || continue
;;
0)
echo -e "${GREEN}再见!${NC}"
exit 0
;;
*)
echo -e "${RED}无效的选择,请重试${NC}"
read -p "按回车键继续..."
echo -e "按回车键返回主菜单..."
;;
esac

# 如果不是启动应用,则等待用户按回车继续
if [ "$choice" != "4" ] && [ "$choice" != "5" ]; then
echo
read -p "按回车键继续..."
echo -e "按回车键返回主菜单..."
fi
done
done
4 changes: 1 addition & 3 deletions tests/test_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ def assertIsValidPercentage(self, value, field_name: str):

self.assertIsInstance(float_value, float, "\n".join(error_msg))
except (ValueError, TypeError) as e:
self.fail(
f"\n百分比转换失败: {field_name}\n" f"值: {value!r}\n" f"错误: {str(e)}"
)
self.fail(f"\n百分比转换失败: {field_name}\n" f"值: {value!r}\n" f"错误: {str(e)}")

def test_get_fund_detail(self):
"""测试获取基金详情功能"""
Expand Down
12 changes: 3 additions & 9 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,9 @@ def test_task_execution(self):
self.assertIsNotNone(results["company"], "基金公司不能为空")

# 验证数值字段
self.assertIsInstance(
results["establishment_size"], (int, float), "成立规模应为数值类型"
)
self.assertIsInstance(
results["management_fee"], (int, float), "管理费率应为数值类型"
)
self.assertIsInstance(
results["custodian_fee"], (int, float), "托管费率应为数值类型"
)
self.assertIsInstance(results["establishment_size"], (int, float), "成立规模应为数值类型")
self.assertIsInstance(results["management_fee"], (int, float), "管理费率应为数值类型")
self.assertIsInstance(results["custodian_fee"], (int, float), "托管费率应为数值类型")
self.assertIsInstance(
results["sales_service_fee"], (int, float), "销售服务费率应为数值类型"
)
Expand Down

0 comments on commit 216377c

Please sign in to comment.