-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathinstall_unix.sh
More file actions
executable file
·119 lines (99 loc) · 4.33 KB
/
install_unix.sh
File metadata and controls
executable file
·119 lines (99 loc) · 4.33 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
# Store the original directory
ORIGINAL_DIR=$(pwd)
# Set path variables
BACKTRADER_PATH="$ORIGINAL_DIR"
BUILD_DIR="build"
EGG_INFO_DIR="backtrader.egg-info"
BENCHMARKS_DIR=".benchmarks"
PYFOLIO_VERSION="0.9.6"
# 获取默认工作目录(用户主目录)
DEFAULT_WORK_DIR="$HOME"
echo "Default working directory: $DEFAULT_WORK_DIR"
# # 切换到默认工作目录
# echo "Switching to the default working directory..."
# cd "$DEFAULT_WORK_DIR" || { echo "Failed to switch to default working directory. Exiting..."; exit 1; }
# Function to check if a Python package is installed with specific version
check_package_version() {
local package=$1
local version=$2
# 使用 importlib.metadata 替代废弃的 pkgutil
python3 -c "
from importlib.metadata import version, PackageNotFoundError
try:
installed_version = version('$package')
if installed_version == '$version':
exit(0)
else:
print(f'Found $package version {installed_version}, but version $version is required')
exit(2)
except PackageNotFoundError:
exit(1)
"
}
# # 检查 pyfolio 版本
# echo "Checking if pyfolio $PYFOLIO_VERSION is installed..."
# check_package_version "pyfolio" "$PYFOLIO_VERSION"
# version_check_status=$?
# if [ $version_check_status -eq 1 ]; then
# echo "pyfolio not found. Installing version $PYFOLIO_VERSION..."
# # 检查当前目录下是否存在 pyfolio 文件夹
# if [ ! -d "pyfolio" ]; then
# echo "pyfolio directory does not exist. Cloning pyfolio from Gitee..."
# git clone https://gitee.com/yunjinqi/pyfolio || { echo "Failed to clone pyfolio repository. Exiting..."; exit 1; }
# fi
# # 运行 install_unix.sh 安装 pyfolio
# echo "Running install_unix.sh for pyfolio..."
# cd pyfolio || { echo "Failed to enter pyfolio directory. Exiting..."; exit 1; }
# sh install_unix.sh || { echo "Failed to run install_unix.sh for pyfolio. Exiting..."; exit 1; }
# cd .. || { echo "Failed to return to parent directory. Exiting..."; exit 1; }
# # 清理 pyfolio 目录
# echo "Cleaning up pyfolio directory..."
# rm -rf pyfolio
# elif [ $version_check_status -eq 2 ]; then
# echo "Incorrect pyfolio version installed. Installing version $PYFOLIO_VERSION..."
# pip install --no-deps --force-reinstall "pyfolio==$PYFOLIO_VERSION" || { echo "Failed to install pyfolio $PYFOLIO_VERSION. Exiting..."; exit 1; }
# else
# echo "pyfolio $PYFOLIO_VERSION is already installed correctly. Skipping installation."
# fi
# Function to handle errors
handle_error() {
echo "Error: $1"
exit 1
}
# # Return to original directory and install dependencies
# echo "Returning to original directory..."
# cd "$ORIGINAL_DIR" || handle_error "Failed to return to original directory"
# # Install core dependencies first
# echo "Installing core dependencies..."
# pip install pandas numpy matplotlib plotly python-dateutil pytz tzlocal future cython setuptools requests scipy pyecharts tqdm numba spdlog python-rapidjson || handle_error "Failed to install core dependencies"
# Install test dependencies
echo "Installing test dependencies..."
pip install pytest pytest-benchmark pytest-sugar pytest-cov pytest-picked pytest-xdist pytest-asyncio pytest-html pytest-ordering pytest-mock pytest-timeout requests-mock || handle_error "Failed to install test dependencies"
# Install the backtrader package
echo "Installing the backtrader package..."
pip install -U --no-build-isolation . || handle_error "Failed to install the backtrader package."
# Delete intermediate build and egg-info directories
echo "Deleting intermediate files..."
if [ -d "$BUILD_DIR" ]; then
rm -rf "$BUILD_DIR"
echo "Deleted $BUILD_DIR directory."
fi
if [ -d "$EGG_INFO_DIR" ]; then
rm -rf "$EGG_INFO_DIR"
echo "Deleted $EGG_INFO_DIR directory."
fi
# Run pytest tests (excluding problematic tests)
echo "Running pytest tests (excluding problematic tests)..."
pytest tests --ignore=tests/crypto_tests --timeout=30 --timeout-method=thread -n 8 -v
# Delete the .benchmarks directory generated by pytest
if [ -d "$BENCHMARKS_DIR" ]; then
rm -rf "$BENCHMARKS_DIR"
echo "Deleted $BENCHMARKS_DIR directory."
fi
# Delete all .log files and logs directory
echo "Cleaning up log files..."
find . -type f -name "*.log" -delete
rm -rf logs
echo "Log files cleaned up."
echo "Installation and setup completed successfully!"