SKY-Q807 · Quality, structure and performance
Sibling package dependency cycle
Sibling Python packages import one another directly or through other siblings. Each import may involve a different file, so a cycle can exist between packages even when the individual files form an acyclic graph.
- Languages
- Python
- Turned on by
--qualitywithcheck_package_cycles = trueunder[tool.skylos.architecture]- Quality gate
- counted toward the gate limits (full and diff scans). Findings from the enabled check count toward
max_quality. - Needs
- Set
check_package_cycles = trueunder[tool.skylos.architecture]. - Finding type
- review
Why it matters
When packages depend on one another, a change to one package's interface can require edits on both sides. The import locations show which parts of each interface create the dependency.
What Skylos flags
"""Shop package.""""""Billing package."""from shop.orders.records import order_total INVOICE_TOTAL = order_totalTAX_RATE = 0.08"""Orders package."""from shop.billing.records import TAX_RATE CHECKOUT_TAX = TAX_RATEorder_total = 100[tool.skylos.architecture]check_package_cycles = trueWhat Skylos leaves alone
def invoice_total(order_total): return order_totalWhy Skylos leaves it alone
Orders imports billing. Billing receives the order total as a value and has no import dependency on orders.
How Skylos decides
- Start with resolved top-level imports between scanned Python modules. Exclude test files and imports whose module cannot be resolved.
- For each import between branches, identify the packages below the nearest common parent. Both packages must have a scanned
__init__.pyand share a parent directory. - Report one finding per mutually dependent group of packages. Include each contributing import site in the finding evidence.
How to fix it
Remove the dependency that crosses the boundary in the wrong direction. For this example, pass the order total into the invoice code.
Removed: from shop.orders.records import order_totalRemoved: Removed: INVOICE_TOTAL = order_totalAdded: def invoice_total(order_total):Added: return order_totalWhen it can be wrong
- Namespace packages without
__init__.py, imports inside functions, and imports insideif TYPE_CHECKINGare outside the check. - A cycle can be deliberate, such as between sibling adapters that compose their interfaces at startup.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
Use the findings baseline to accept existing package cycles, or set
check_package_cycles = falseto disable the quality check.