Integrating with isort¶
If you rely on sqliteimport’s auto-loading of .sqlite3 files on the PYTHONPATH,
the import sqliteimport line needs to appear before third-party modules:
import os
import sys
import sqliteimport
import boto3
import requests
However, isort would normally sort these lines alphabetically and break your imports:
import os
import sys
import boto3
import requests
import sqliteimport # <--- Sorted to the bottom. Bad!
There are two ways to address this.
Custom section¶
You can configure isort to put sqliteimport into a custom section that always sorts before third-party packages:
pyproject.toml¶[tool.isort]
sections=[
"FUTURE",
"STDLIB",
"SQLITEIMPORT", # <--- New isort section!
"THIRDPARTY",
"FIRSTPARTY",
"LOCALFOLDER",
]
known_sqliteimport=["sqliteimport"]
.isort.cfg¶[isort]
sections=FUTURE,STDLIB,SQLITEIMPORT,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
known_sqliteimport=sqliteimport
Result:
import os
import sys
import sqliteimport
import boto3
import requests
force_to_top¶
You can force sqliteimport to the top of the third party section:
pyproject.toml¶[tool.isort]
force_to_top = ["sqliteimport"]
.isort.cfg¶[isort]
force_to_top = sqliteimport
Result:
import os
import sys
import sqliteimport
import boto3
import requests