Skip to main content

SKY-Q807 · Quality, structure and performance

Sibling package dependency cycle

Low

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
--quality with check_package_cycles = true under [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 = true under [tool.skylos.architecture].
Finding type
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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/__init__.py · Python
"""Shop package."""
shop/billing/__init__.py · Python
"""Billing package."""
shop/billing/invoices.py · PythonReported on line 1
from shop.orders.records import order_total INVOICE_TOTAL = order_total
shop/billing/records.py · Python
TAX_RATE = 0.08
shop/orders/__init__.py · Python
"""Orders package."""
shop/orders/checkout.py · Python
from shop.billing.records import TAX_RATE CHECKOUT_TAX = TAX_RATE
shop/orders/records.py · Python
order_total = 100
pyproject.toml · TOML
[tool.skylos.architecture]check_package_cycles = true

What Skylos leaves alone

shop/__init__.py: same as in the flagged example.

shop/billing/__init__.py: same as in the flagged example.

shop/billing/invoices.py · Python
def invoice_total(order_total):    return order_total

shop/billing/records.py: same as in the flagged example.

shop/orders/__init__.py: same as in the flagged example.

shop/orders/checkout.py: same as in the flagged example.

pyproject.toml: same as in the flagged example.

Why 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

  1. Start with resolved top-level imports between scanned Python modules. Exclude test files and imports whose module cannot be resolved.
  2. For each import between branches, identify the packages below the nearest common parent. Both packages must have a scanned __init__.py and share a parent directory.
  3. 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.

shop/billing/invoices.py · Python · the fix, against the flagged file
Removed: from shop.orders.records import order_totalRemoved:  Removed: INVOICE_TOTAL = order_totalAdded: def invoice_total(order_total):Added:     return order_total

When it can be wrong

  • Namespace packages without __init__.py, imports inside functions, and imports inside if TYPE_CHECKING are 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 = false to disable the quality check.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.