Managing Imports for Organized Python Projects
Explore best practices for organizing and managing imports in Python to avoid circular dependencies and maintain clean project structures.
0 likes
194 views
Rule Content
{
"title": "Managing Imports for Organized Python Projects",
"description": "Enforce best practices for organizing and managing imports in Python to avoid circular dependencies and maintain clean project structures.",
"category": "Python Cursor Rules",
"rules": [
{
"name": "import-order",
"description": "Ensure imports are grouped and ordered correctly.",
"applyTo": "**/*.py",
"onSave": true,
"actions": [
{
"type": "format",
"tool": "isort",
"config": {
"profile": "black",
"multi_line_output": 3,
"line_length": 80
}
}
]
},
{
"name": "no-wildcard-imports",
"description": "Disallow the use of wildcard imports to maintain clarity and prevent namespace pollution.",
"applyTo": "**/*.py",
"onSave": true,
"actions": [
{
"type": "lint",
"tool": "flake8",
"config": {
"select": ["F403", "F405"]
}
}
]
},
{
"name": "absolute-imports",
"description": "Encourage the use of absolute imports for better readability and maintainability.",
"applyTo": "**/*.py",
"onSave": true,
"actions": [
{
"type": "lint",
"tool": "flake8",
"config": {
"select": ["E402"]
}
}
]
},
{
"name": "import-optimization",
"description": "Remove unused imports to keep the codebase clean and efficient.",
"applyTo": "**/*.py",
"onSave": true,
"actions": [
{
"type": "lint",
"tool": "flake8",
"config": {
"select": ["F401"]
}
}
]
}
]
}