From facf014e77102af6996989aa63ea17009b5a0fbe Mon Sep 17 00:00:00 2001 From: redatman Date: Tue, 6 Aug 2024 20:37:07 +0800 Subject: [PATCH] chore: Update isort configuration for more accurate imports Refines the isort configuration to improve import order and structure within the project. This includes: - Enabling `skip_gitignore` to avoid sorting imports in ignored files. - Specifying `src_paths` to limit sorting to relevant source code directories. - Updating `skip_glob` to exclude additional files from import sorting. This ensures that imports are organized according to project conventions and improves code readability. --- pyproject.toml | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7a6b8fd..4bdb0be 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -76,10 +76,12 @@ norecursedirs = [ [tool.isort] # reference: https://pycqa.github.io/isort/docs/configuration/options.html # settings_file = ".isort.cfg" -profile = "black" -# reverse_sort = true atomic = true line_length = 120 +skip_gitignore = true +profile = "black" +src_paths = ["isort", "test"] +# reverse_sort = true # tuple_bracket_spacing = true # tuple_brackets = false force_grid_wrap = 0 @@ -87,23 +89,16 @@ force_grid_wrap = 0 # 是否按照嵌套顺序分组导入 force_sort_within_sections = true # 导入顺序 例如: 在项目中应该先导入标准库、然后是第三方库、最后是自己的模块 -sections = [ - "FUTURE", - "STDLIB", - "DJANGO", - "THIRDPARTY", - "FIRSTPARTY", - "LOCALFOLDER", -] -# no_lines_before = ["FUTURE", "STDLIB", "DJANGO", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"] +sections = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"] +# no_lines_before = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"] # 是否根据文件中导入语句的顺序对导入进行排序 force_single_line = false # 是否在导入语句过多时分割成多行 combine_as_imports = false -known_third_party = ["django", "rest_framework"] -known_first_party = ["my_module1"] -known_local_folder = ["my_module3"] -known_django = "django" +# known_third_party = ["django", "rest_framework"] +# known_first_party = ["black", "blib2to3", "blackd", "_black_version"] +# known_local_folder = ["my_module3"] +# known_django = "django" lines_after_imports = 2 lines_between_types = 1 # multi_line = 3 @@ -116,6 +111,8 @@ skip = [ "static", "templates", 'node_modules', + "build", + ".tox", 'venv', 'env', "apps/*/migrations", @@ -123,7 +120,7 @@ skip = [ "apps/*/templates", ] extend_skip = ['.md', '.json', '.gitignore', '.dockerignore'] -skip_glob = ['docs/*'] +skip_glob = ['docs/*', "tests/data", "profiling"] extend_skip_glob = ['my_*_module.py'] -# 是否在导入中添加导入时间戳注释: 要求 isort=>5.5.0 +# 在导入中添加导入时间戳注释: 要求 isort=>5.5.0 # annotate = true