Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .github/dependabot.yml
Binary file not shown.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ jobs:
run: |
pip install --upgrade pip
# 安装特定版本的格式化工具以确保一致性
pip install yapf==0.32.0 isort==5.10.1 flake8>=3.8.0 mypy>=0.800
pip install yapf==0.32.0 isort==5.10.1 flake8>=3.8.0 mypy>=0.800 toml>=0.10.2

- name: Format & Lint
run: |
# 步骤1: isort
isort torch_rechub/ examples/ tests/
isort --profile black torch_rechub/ examples/ tests/
# 步骤2: yapf
yapf_style="{based_on_style: google, column_limit: 248, join_multiple_lines: false, split_all_comma_separated_values: true, split_before_logical_operator: true, dedent_closing_brackets: true, align_closing_bracket_with_visual_indent: true, indent_width: 4}"
yapf --in-place --recursive --style="$yapf_style" torch_rechub/ examples/ tests/
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ repos:
hooks:
- id: yapf
name: yapf (Python代码格式化)
args: [--style=config/.style.yapf, --in-place]
args: [--style=pyproject.toml, --in-place]
additional_dependencies: []

# isort - 导入语句排序
Expand Down
61 changes: 49 additions & 12 deletions config/.flake8
Original file line number Diff line number Diff line change
@@ -1,36 +1,73 @@
[flake8]
# 基本配置
max-line-length = 248
extend-ignore =
max-complexity = 30
exclude =
.git,
__pycache__,
docs/,
build/,
dist/,
.eggs/,
*.egg-info/,
htmlcov/,
.pytest_cache/,
.mypy_cache/,
.tox/,
.venv/,
venv/,
env/

# 忽略的错误代码
ignore =
# E203: whitespace before ':' (与Black格式化工具冲突)
E203,
# W503: line break before binary operator (已过时的规则)
W503,
# E501: line too long (我们用248字符限制)
E501,
# E722: do not use bare except (有时确实需要)
E722,
# E402: module level import not at top of file
E402,
# F821: undefined name (有时是动态导入)
F821,
# F523: '...'.format(...) has unused arguments
F523,
# E711: comparison to None should be 'if cond is None:'
E711,
# E741: ambiguous variable name
E741,
# F401: imported but unused (在__init__.py中常见)
F401,
# E265: block comment should start with '# '
E265,
# C901: too complex (已通过max-complexity设置)
C901,
# E301: expected 1 blank line, found 0
E301,
# E305: expected 2 blank lines after class or function definition
E305,
# W293: blank line contains whitespace
W293,
# E261: at least two spaces before inline comment
E261,
# W291: trailing whitespace
W291,
# W292: no newline at end of file
W292,
# E111: indentation is not a multiple of four
E111,
# E117: over-indented
E117,
# F841: local variable is assigned to but never used
F841,
# E302: expected 2 blank lines, found 1
E302
exclude =
.git,
__pycache__,
build,
dist,
.venv,
venv,
.eggs,
*.egg
max-complexity = 30
docstring-convention = google

# 每个文件的最大导入数
max-imports = 30

# 统计信息
statistics = True
count = True
1 change: 1 addition & 0 deletions config/.pep8
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[pep8]
max-line-length = 248
ignore = E402

2 changes: 1 addition & 1 deletion config/format_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def main():

# 阶段一: isort
print("\n--- 阶段一: 使用 isort 排序导入 ---")
isort_command = [sys.executable, '-m', 'isort'] + source_dirs
isort_command = [sys.executable, '-m', 'isort', '--profile', 'black'] + source_dirs
run_command(isort_command, "isort")

# 阶段二: yapf
Expand Down
83 changes: 58 additions & 25 deletions config/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,72 @@
# pytest是Python最流行的测试框架,支持单元测试、集成测试等
# 更多配置说明请参考: config/CONFIG_GUIDE.md

[tool:pytest]
# 测试目录 - pytest会在这些目录中查找测试文件
[pytest]
# pytest配置文件
# 用于测试运行的配置

# 最小版本要求
minversion = 6.0

# 命令行选项
addopts =
-ra
-q
--strict-markers
--tb=short
--maxfail=3
-v

# 测试路径
testpaths = tests

# 测试文件模式 - 匹配以test_开头的Python文件
python_files = test_*.py
# Python文件模式
python_files =
test_*.py
*_test.py

# 测试类模式 - 匹配以Test开头的类
# Python类模式
python_classes = Test*

# 测试函数模式 - 匹配以test_开头的函数
# Python函数模式
python_functions = test_*

# 附加选项 - 控制pytest的行为
addopts =
--strict-markers # 严格标记模式,未定义的标记会报错
--strict-config # 严格配置模式,配置错误会报错
--verbose # 详细输出模式
--tb=short # 简短的回溯信息
--cov=torch_rechub # 代码覆盖率分析 - 分析torch_rechub包
--cov-report=term-missing:skip-covered # 终端报告,显示未覆盖的行
--cov-report=html # HTML格式的覆盖率报告
--cov-report=xml # XML格式的覆盖率报告 (CI/CD使用)
--cov-branch # 分支覆盖率分析

# 自定义标记 - 用于分类和选择测试
# 标记定义
markers =
slow: marks tests as slow (deselect with '-m "not slow"')
# 标记慢速测试,可用 pytest -m "not slow" 跳过
integration: marks tests as integration tests
# 标记集成测试
unit: marks tests as unit tests
# 标记单元测试
slow: 标记为慢速测试 (使用 '-m "not slow"' 排除)
integration: 标记为集成测试
unit: 标记为单元测试
e2e: 标记为端到端测试

# 覆盖率设置
[coverage:run]
source = torch_rechub
omit =
*/tests/*
*/examples/*
*/docs/*
*/__pycache__/*
*/htmlcov/*

[coverage:report]
# 排除的行
exclude_lines =
pragma: no cover
def __repr__
if self\.debug:
if __name__ == .__main__.:
raise AssertionError
raise NotImplementedError
pass

# 精度设置
precision = 2

# 显示缺失的行
show_missing = True

# 跳过覆盖的文件
skip_covered = False

# 过滤警告 - 忽略特定类型的警告
filterwarnings =
Expand Down
4 changes: 2 additions & 2 deletions examples/matching/run_ml_comirec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from movielens_utils import match_evaluation
from sklearn.preprocessing import LabelEncoder, MinMaxScaler

from torch_rechub.basic.features import (DenseFeature, SequenceFeature, SparseFeature)
from torch_rechub.basic.features import DenseFeature, SequenceFeature, SparseFeature
from torch_rechub.models.matching import ComirecDR, ComirecSA
from torch_rechub.trainers import MatchTrainer
from torch_rechub.utils.data import MatchDataGenerator, df_to_dict
from torch_rechub.utils.match import (gen_model_input, generate_seq_feature_match)
from torch_rechub.utils.match import gen_model_input, generate_seq_feature_match

sys.path.append("../..")

Expand Down
4 changes: 2 additions & 2 deletions examples/matching/run_ml_dssm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from movielens_utils import match_evaluation
from sklearn.preprocessing import LabelEncoder, MinMaxScaler

from torch_rechub.basic.features import (DenseFeature, SequenceFeature, SparseFeature)
from torch_rechub.basic.features import DenseFeature, SequenceFeature, SparseFeature
from torch_rechub.models.matching import DSSM
from torch_rechub.trainers import MatchTrainer
from torch_rechub.utils.data import MatchDataGenerator, df_to_dict
from torch_rechub.utils.match import (gen_model_input, generate_seq_feature_match)
from torch_rechub.utils.match import gen_model_input, generate_seq_feature_match

sys.path.append("../..")

Expand Down
6 changes: 3 additions & 3 deletions examples/matching/run_ml_facebook_dssm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from movielens_utils import match_evaluation
from sklearn.preprocessing import LabelEncoder, MinMaxScaler

from torch_rechub.basic.features import (DenseFeature, SequenceFeature, SparseFeature)
from torch_rechub.basic.features import DenseFeature, SequenceFeature, SparseFeature
from torch_rechub.models.matching import FaceBookDSSM
from torch_rechub.trainers import MatchTrainer
from torch_rechub.utils.data import (MatchDataGenerator, array_replace_with_dict, df_to_dict)
from torch_rechub.utils.match import (gen_model_input, generate_seq_feature_match)
from torch_rechub.utils.data import MatchDataGenerator, array_replace_with_dict, df_to_dict
from torch_rechub.utils.match import gen_model_input, generate_seq_feature_match

sys.path.append("../..")

Expand Down
4 changes: 2 additions & 2 deletions examples/matching/run_ml_gru4rec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from movielens_utils import match_evaluation
from sklearn.preprocessing import LabelEncoder, MinMaxScaler

from torch_rechub.basic.features import (DenseFeature, SequenceFeature, SparseFeature)
from torch_rechub.basic.features import DenseFeature, SequenceFeature, SparseFeature
from torch_rechub.models.matching import GRU4Rec
from torch_rechub.trainers import MatchTrainer
from torch_rechub.utils.data import MatchDataGenerator, df_to_dict
from torch_rechub.utils.match import (gen_model_input, generate_seq_feature_match)
from torch_rechub.utils.match import gen_model_input, generate_seq_feature_match

sys.path.append("../..")

Expand Down
4 changes: 2 additions & 2 deletions examples/matching/run_ml_mind.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from movielens_utils import match_evaluation
from sklearn.preprocessing import LabelEncoder, MinMaxScaler

from torch_rechub.basic.features import (DenseFeature, SequenceFeature, SparseFeature)
from torch_rechub.basic.features import DenseFeature, SequenceFeature, SparseFeature
from torch_rechub.models.matching import MIND
from torch_rechub.trainers import MatchTrainer
from torch_rechub.utils.data import MatchDataGenerator, df_to_dict
from torch_rechub.utils.match import (gen_model_input, generate_seq_feature_match)
from torch_rechub.utils.match import gen_model_input, generate_seq_feature_match

sys.path.append("../..")

Expand Down
2 changes: 1 addition & 1 deletion examples/matching/run_ml_sine.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from torch_rechub.models.matching import SINE
from torch_rechub.trainers import MatchTrainer
from torch_rechub.utils.data import MatchDataGenerator, df_to_dict
from torch_rechub.utils.match import (gen_model_input, generate_seq_feature_match)
from torch_rechub.utils.match import gen_model_input, generate_seq_feature_match

sys.path.append("../..")

Expand Down
4 changes: 2 additions & 2 deletions examples/matching/run_ml_youtube_dnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from movielens_utils import match_evaluation
from sklearn.preprocessing import LabelEncoder, MinMaxScaler

from torch_rechub.basic.features import (DenseFeature, SequenceFeature, SparseFeature)
from torch_rechub.basic.features import DenseFeature, SequenceFeature, SparseFeature
from torch_rechub.models.matching import YoutubeDNN
from torch_rechub.trainers import MatchTrainer
from torch_rechub.utils.data import MatchDataGenerator, df_to_dict
from torch_rechub.utils.match import (gen_model_input, generate_seq_feature_match)
from torch_rechub.utils.match import gen_model_input, generate_seq_feature_match

sys.path.append("../..")

Expand Down
4 changes: 2 additions & 2 deletions examples/matching/run_ml_youtube_sbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
from movielens_utils import get_item_sample_weight, match_evaluation
from sklearn.preprocessing import LabelEncoder, MinMaxScaler

from torch_rechub.basic.features import (DenseFeature, SequenceFeature, SparseFeature)
from torch_rechub.basic.features import DenseFeature, SequenceFeature, SparseFeature
from torch_rechub.models.matching import YoutubeSBC
from torch_rechub.trainers import MatchTrainer
from torch_rechub.utils.data import MatchDataGenerator, df_to_dict
from torch_rechub.utils.match import (gen_model_input, generate_seq_feature_match)
from torch_rechub.utils.match import gen_model_input, generate_seq_feature_match

sys.path.append("../..")

Expand Down
2 changes: 1 addition & 1 deletion examples/matching/run_sbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pandas as pd
import torch
import torch.nn.utils.rnn as rnn_utils
from data.session_based.preprocess_session_based import (INTERNAL_ITEM_ID_FIELD, TEST_DATA_PREFIX, TRAIN_DATA_PREFIX)
from data.session_based.preprocess_session_based import INTERNAL_ITEM_ID_FIELD, TEST_DATA_PREFIX, TRAIN_DATA_PREFIX
from torch.utils.data import DataLoader

from torch_rechub.basic.features import SequenceFeature
Expand Down
4 changes: 2 additions & 2 deletions examples/ranking/run_amazon_electronics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import pandas as pd
import torch

from torch_rechub.basic.features import (DenseFeature, SequenceFeature, SparseFeature)
from torch_rechub.basic.features import DenseFeature, SequenceFeature, SparseFeature
from torch_rechub.models.ranking import DIN
from torch_rechub.trainers import CTRTrainer
from torch_rechub.utils.data import (DataGenerator, df_to_dict, generate_seq_feature, pad_sequences)
from torch_rechub.utils.data import DataGenerator, df_to_dict, generate_seq_feature, pad_sequences

sys.path.append("../..")

Expand Down
2 changes: 1 addition & 1 deletion examples/ranking/run_avazu.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from tqdm import tqdm

from torch_rechub.basic.features import DenseFeature, SparseFeature
from torch_rechub.models.ranking import (DCN, DeepFFM, DeepFM, FatDeepFFM, WideDeep)
from torch_rechub.models.ranking import DCN, DeepFFM, DeepFM, FatDeepFFM, WideDeep
from torch_rechub.trainers import CTRTrainer
from torch_rechub.utils.data import DataGenerator

Expand Down
2 changes: 1 addition & 1 deletion examples/ranking/run_criteo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from tqdm import tqdm

from torch_rechub.basic.features import DenseFeature, SparseFeature
from torch_rechub.models.ranking import (DCN, EDCN, DCNv2, DeepFFM, DeepFM, FatDeepFFM, FiBiNet, WideDeep)
from torch_rechub.models.ranking import DCN, EDCN, DCNv2, DeepFFM, DeepFM, FatDeepFFM, FiBiNet, WideDeep
from torch_rechub.trainers import CTRTrainer
from torch_rechub.utils.data import DataGenerator

Expand Down
Loading
Loading