Command Line Interface

This document describes the command-line interface of Deply.

Available Commands

Analyze Command

The main command for analyzing your project:

deply analyze

Analysis validates the configuration first and exits with status 1 without scanning project files when validation fails. It also exits with status 1 when files cannot be read or parsed, no Python files are found, or no code elements map to configured layers. Completed reports include analysis completeness metrics. Incomplete analysis writes the available metrics to standard error. JSON also generates a report on invalid configuration or incomplete analysis; other formats do not generate a report in these cases.

Validate Command

Validate your configuration without analyzing project files:

deply validate

Init Command

Write a validated starter configuration from a packaged preset:

deply init --preset fastapi

The init command is available starting with Deply v1.3.2. Presets are layered, django, fastapi, and flask, derived from the documented recipes. The written file is validated before it is created; validation errors exit 1 and write nothing. An existing output file is never overwritten without --force and exits 1. Until the preset’s layer directories match your project, the first deply analyze either exits 1 with “no code elements mapped to configured layers” when nothing matches, or passes with mostly empty layers when only a regex or decorator collector matches, so adjust the collectors to your layout before trusting the result.

Help Command

Display help information:

deply --help

Command Line Arguments

Analyze Command Options

  • --config: Path to the configuration file (deply.yaml or pyproject.toml); see Configuration File Discovery
  • --report-format: Format of the output report (choices: text, json, github-actions, sarif, default: text)
  • --output: Output file for the report (if not specified, prints to console)
  • --mermaid: Generates a Mermaid diagram of layer dependencies
  • --max-violations: Maximum number of allowed violations before failing (default: 0)
  • --baseline: Compare against an accepted violation baseline
  • --write-baseline: Create a new baseline after complete analysis (never overwrite)
  • --parallel: Enable parallel processing of code elements

Validate Command Options

Configuration File Discovery

pyproject.toml configuration is available starting with Deply v1.3.2. When --config is omitted, every command resolves the configuration file in this order:

  1. deply.yaml in the working directory.
  2. pyproject.toml in the working directory, when it contains a [tool.deply] table.
  3. Otherwise Deply reports that deply.yaml does not exist.

A --config path ending in .toml is read as pyproject.toml with a [tool.deply] table. TOML support uses the standard library tomllib and requires Python 3.11 or newer; on older interpreters a discovered or explicit pyproject.toml fails with an explicit error, so create deply.yaml there. See Using pyproject.toml.

Init Command Options

  • --preset: Preset to write (choices: layered, django, fastapi, flask); mutually exclusive with --list-presets
  • --list-presets: Print the available preset names, one per line, and exit
  • --output: Configuration file to create (default: deply.yaml)
  • --force: Overwrite an existing configuration file

Examples

Basic Analysis

deply analyze

Custom Configuration File

deply analyze --config=custom_config.yaml

Validate Configuration

deply validate --config=custom_config.yaml

Create a Starter Configuration

deply init --list-presets
deply init --preset django --output architecture.yaml

Generate GitHub Actions Report

deply analyze --report-format=github-actions

Generate Mermaid Diagram

deply analyze --mermaid

Allow Some Violations

deply analyze --max-violations=5

Enable Parallel Processing

deply analyze --parallel

CI Integration

The pre-commit hooks and the GitHub Action are available starting with Deply v1.3.2.

pre-commit

repos:
  - repo: https://github.com/Vashkatsi/deply
    rev: v1.3.3
    hooks:
      - id: deply
        args: [--config=deply.yaml, --baseline=deply-baseline.json]
      - id: deply-validate
        args: [--config=deply.yaml]
Hook id Command Runs when
deply deply analyze Python files are staged
deply-validate deply validate A file named deply.yaml, deply.yml or pyproject.toml is staged

Both hooks analyze the configured project, not the staged files: file names are not passed to Deply. Extra options go in args. If the configuration file has another name, override files for deply-validate, for example files: '^architecture\.yaml$'. pre-commit installs Deply from the hook repository at rev, so the hook version matches the tag.

GitHub Action

jobs:
  architecture:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: Vashkatsi/deply@v1
        with:
          config: deply.yaml
          baseline: deply-baseline.json

The action is a composite action. It sets up Python, installs Deply from the action checkout, so the installed version matches the referenced ref, then runs deply validate followed by deply analyze.

Input Default Description
config empty When set, passes --config=<path> to both commands; otherwise Deply discovers deply.yaml or pyproject.toml
report-format github-actions Report format for deply analyze; the default reports violations as annotations
baseline empty When set, passes --baseline=<path> to deply analyze
args empty Extra arguments appended to deply analyze, split on whitespace
python-version 3.x Python version for actions/setup-python

The action fails the job when validation fails or deply analyze exits with status 1. To upload SARIF to GitHub Code Scanning instead of annotations, use the SARIF upload recipe.

Reference the action by one of:

  • @v1: the latest stable v1 release; the release workflow moves this tag on each stable release.
  • A release tag such as @v1.3.2: a fixed version.
  • @main: the current default branch.

Other CI systems

Install Deply from PyPI and run it in any job with Python available. GitLab CI example:

architecture:
  image: python:3.12
  script:
    - pip install deply
    - deply validate --config=deply.yaml
    - deply analyze --config=deply.yaml

Context command

Inspect one existing Python file before editing:

deply context --file src/orders/service.py --config deply.yaml --report-format=json

--file is required. --config follows the same discovery as analyze; --report-format defaults to json, the only supported format. Paths supplied on the CLI and paths inside the config resolve from the working directory, just as for analyze. Check deply context --help first: this command requires Deply v1.3.0 or later.

Context reuses the full configured analysis, including validation, exclusions, collectors, module resolution, rules and inline suppressions. Selecting a file filters the output, not the scan: callers in other files must still be analyzed. There is no incremental analysis, transitive expansion, runtime inference, baseline comparison, output-file option, Mermaid output or automatic fix in this command.

JSON context contract

The context schema is separate from the analyze schema; its initial schema_version is 1. Reports contain:

Field Meaning
status complete or incomplete for the full configured analysis; neither means runtime completeness or absence of violations.
errors Sorted {code: "incomplete_analysis", message: "..."} diagnostics, empty on complete analysis.
file Canonical selected path, relative to the working directory, using / separators; files outside the working directory use the absolute resolved path, never ../ segments.
file_status File availability and membership, listed below.
elements Collected definitions in the selected file: {file, name, type, line, column, layers} with every matching layer. Uncollected definitions are not listed.
rules Effective constraints owned by selected layers, plus dependency restrictions from other layers that forbid selected layers. Each record contains {rule_id, source_layer, kind, configuration}.
incoming Direct resolved dependencies whose target is in the selected file.
outgoing Direct resolved dependencies whose source is in the selected file.
violations Unsuppressed findings originating in the selected file or targeting its elements; same records, rule_id and fingerprints as analyze --report-format=json.
metrics Completeness counters for the entire configured project, not just the selected file.

Each dependency has {source, target, dependency_type, line, column}. Endpoints have the same shape as elements, including definition locations and all layer memberships. The edge’s line and column locate the use in the source file. Lines are one-based; columns are zero-based AST byte offsets. Same-file edges appear in both directions. Distinct locations and dependency types are retained; layer overlap does not duplicate an edge. Only statically resolved dependencies between collected elements appear. External import restrictions can appear in rules and violations, but external packages are not graph endpoints.

Rule configuration contains the effective parameters used by the existing rule factory, including defaults and normalized sets, not arbitrary YAML metadata. Rules are layer-level constraints, not a claim that every rule checks every element type. Incoming restrictions are included even when no violating edge currently exists. Repeated identical configured rules appear once per rule_id.

Output ordering is deterministic for unchanged inputs: elements by location/name/ type, rules by ID, edges by their canonical JSON representation, and violations by the existing analysis ordering. Element and endpoint paths follow the same working-directory contract as file, so they map directly onto the working tree even when the config lives outside the project. Starting with Deply v1.3.2 these paths are relative to the working directory; earlier versions reported them relative to the config directory. Violation records preserve the analysis contract, including its legacy file field; use source.file and target.file for normalized identities. These remain relative to the config directory and guarantee compatible fingerprints without rewriting baselines, so they only match element paths when the config directory is the working directory.

file_status Meaning
mapped Included file with at least one collected element.
unmapped Included, parsed file with no collected elements.
excluded Discovered Python file excluded from every configured scan root. Inclusion through any root wins.
outside_scope Existing Python file not discovered under the configured roots.
not_found Selected path does not exist.
not_python Existing path is a directory or is not a .py file.
parse_failed Selected file failed reading or parsing during collection.

Exit 0 means status: complete and file_status: mapped, even if violations exist. Exit 1 means unavailable context, incomplete analysis, or invalid config. Argument errors, including a missing --file, exit 2. Logs go to stderr; stdout contains one JSON object. Context does not write project files or baselines.

Configuration validation happens before scanning. On invalid config, the command returns the existing JSON error envelope with status: invalid_configuration, schema_version, errors, total_violations, by_type, and violations; no context fields or metrics are available. Check status before reading context. On incomplete analysis, context fields may be partial: for example, collection errors stop dependency analysis, leaving edge lists empty. A mapped file can still have incomplete project context. Never interpret these empty lists as isolation.

After editing, run deply analyze --report-format=json, adding the existing reviewed --baseline when used by the project. Context is discovery, not a replacement for that enforcement step.

Violation baseline

Baseline support is available starting with v1.2.2. Pin a baseline-capable version in CI; v1.2.1 and earlier do not support these options.

Explicitly accept reviewed existing debt, then check subsequent changes:

# Run from the project root; creates a new file, never overwrites one.
deply analyze --config=deply.yaml --write-baseline=deply-baseline.json

# Use this in local checks and CI.
deply analyze --config=deply.yaml --baseline=deply-baseline.json --report-format=json
  • Creation requires complete analysis and returns exit 0 even when violations exist. A missing parent directory, existing destination (including symlinks), or write failure returns 1. Publication is atomic and requires filesystem hard-link support. Commit the baseline only after reviewing the accepted findings.
  • Comparison returns 1 for any new relationship, missing/invalid baseline, invalid configuration, or incomplete analysis; otherwise 0. It never updates the baseline.
  • --baseline and --write-baseline are mutually exclusive. A nonzero --max-violations cannot be combined with either option. Argument conflicts return 2. Creation cannot be combined with --output; its analysis report goes to stdout. During comparison, --output must not alias the baseline or configuration file.
  • JSON keeps schema_version: 1, all current violations, total_violations, and metrics. Successful comparison adds baseline: {"new": [...], "existing": [...], "resolved": [...]}. Entries are full violation records. New/existing use current locations; resolved uses stored locations. Counts are array lengths, counting diagnostic occurrences, not unique relationships.
  • Text, GitHub Actions, and SARIF comparison reports contain only new violations. Metrics and Mermaid still describe the full analyzed project; Mermaid marks all detected violations, including accepted ones.
  • Baseline I/O/validation failures in JSON produce status: "incomplete" and an error with code: "baseline_error". No comparison categories are emitted on failure. Configuration and analysis errors retain their existing status/error codes.
  • The baseline file has exactly schema_version: 1 and violations: [...], using JSON v1 diagnostic records with verified fingerprints. It is distinct from an analysis report. Unsupported versions, malformed records, duplicate JSON keys, and identity/fingerprint mismatches are rejected.

Identity paths are relative to the configuration directory, so preserve its relationship to source files across checkouts. Moving lines or changing messages preserves fingerprints. Changing files, symbols, rule parameters, or layer pairs can produce new findings. Multiple call sites for an already accepted relationship remain accepted; baseline does not detect additional occurrences of that relationship.

resolved means absent from the current configured analysis. It can result from a fix, changed scope/rules, or inline suppression. Review those changes; baseline does not prove that debt was fixed. Removed fingerprints remain accepted until the file is deliberately refreshed, so a reintroduced relationship stays accepted meanwhile.

To refresh after reviewed fixes, create a different candidate baseline file, review the diff, and explicitly replace the tracked file. Never regenerate it in CI or let an agent refresh it merely to pass a failing check.

Output Formats

Text Format

The default output format shows violations and a separate completeness section:

/path/to/your_project/your_project/app1/views_api.py:74:4 - Layer 'views' is not allowed to depend on layer 'models'. Dependency type: function_call.

Analysis completeness
files_discovered: 12
files_excluded: 2
files_included: 10

JSON Format

JSON schema v1 preserves the existing total_violations, by_type, violations, and optional metrics fields and adds machine-readable context:

deply analyze --report-format=json --output=deply-report.json
{
  "schema_version": 1,
  "status": "complete",
  "errors": [],
  "total_violations": 1,
  "by_type": {
    "disallowed_dependency": 1
  },
  "violations": [
    {
      "file": "/path/to/your_project/your_project/app1/views_api.py",
      "element_name": "list_users",
      "element_type": "function",
      "line": 74,
      "column": 4,
      "message": "Layer 'views' is not allowed to depend on layer 'models'. Dependency type: function_call.",
      "violation_type": "disallowed_dependency",
      "rule_id": "views:disallow_layer_dependencies:bf4644a7ec41e8bcaf3dbdc1d0e47b5ee5bb0183c5c44fa4edcdc02ed31cd252",
      "source": {
        "file": "your_project/app1/views_api.py",
        "name": "list_users",
        "type": "function"
      },
      "target": {
        "file": "your_project/app2/models.py",
        "name": "User",
        "type": "class"
      },
      "source_layer": "views",
      "target_layer": "models",
      "dependency_type": "function_call",
      "fingerprint": "122cf66fef3a27215b032b6181347ddb9643c8b43c41d29f9a161531b396e117"
    }
  ],
  "metrics": {
    "files_discovered": 12,
    "files_excluded": 2,
    "files_included": 10,
    "files_parsed": 10,
    "files_parse_failed": 0,
    "files_mapped": 8,
    "files_unmapped": 2,
    "elements_mapped": 31,
    "elements_overlapping": 3,
    "dependencies_detected": 47
  }
}

Analysis status and errors

  • schema_version: integer 1. Consumers should check it and tolerate unknown additive fields.
  • status: complete, incomplete, or invalid_configuration. complete means the supported analysis passes finished; it does not mean no violations or complete understanding of dynamic Python behavior.
  • errors: an array of { "code": string, "message": string }. Codes are incomplete_analysis, invalid_configuration, or baseline_error; messages are diagnostics, not identifiers to parse. A complete report has an empty array.
  • metrics: existing counters, including partial counters for incomplete analysis. Invalid configuration has no metrics because scanning never started.

All three statuses produce JSON on stdout or overwrite --output. Errors still print to stderr. Invalid configuration and incomplete analysis exit 1, even with a permissive --max-violations. Complete analysis retains the existing threshold exit behavior. Partial violations in an incomplete report are not an exhaustive result. With JSON and --mermaid, the diagram goes to stderr, keeping stdout parseable. deply validate retains its text-only behavior.

Deduplication now preserves different source/target relationships and configured rules even when their location and message match. This applies to every report format: counts may increase for previously collapsed violations. Re-evaluate existing --max-violations thresholds against the corrected totals.

Violation identity

  • Legacy file, element_name, element_type, line, column, message, and violation_type fields retain their meanings. Columns are zero-based UTF-8 byte offsets from Python AST, not character offsets.
  • source and internal target contain file, name, and type. Names preserve collected qualified names, including enclosing scopes where available. Paths use forward slashes and are relative to the configuration directory; files outside it use ../ segments. These are identity inputs, not display paths: context reports file and element paths relative to the working directory instead. On Windows, files on a different drive use absolute file: URIs, whose fingerprints depend on that drive/path. Run with a configuration in the same relative location across checkouts to retain identity.
  • source_layer and target_layer identify the particular checked membership pair. Overlapping memberships remain separate violations.
  • dependency_type identifies an internal dependency, such as function_call. Element checks have a null target, target_layer, and dependency_type.
  • External import checks identify the source as the file’s <module> with type module; the target is { "module": "requests.sessions", "type": "external_module" }. Their target_layer and dependency_type are null. The legacy element fields still identify the collected representative element.
  • rule_id is layer:configuration_key:sha256, where the digest covers compact, sorted-key, ASCII-escaped JSON of the effective configured rule (type, supported parameters, and defaults). Ignored metadata does not affect identity. Dependency target lists and external import roots are normalized as sorted sets; other rule configurations retain list order. Identical configured constraints share an ID. Changed constraints change the ID. Bool rules identify the full configured expression, including when a subrule produces the diagnostic.
  • fingerprint is the SHA-256 of compact, sorted-key, ASCII-escaped JSON containing rule_id, source, target, source_layer, target_layer, and dependency_type. JSON uses separators=(",", ":") and UTF-8 encoding for both digests. It excludes locations and messages; same-drive paths exclude the absolute checkout root. Different call sites for the same relationship share a fingerprint but keep separate locations. Renaming or moving a symbol/file, changing a rule, or changing a membership pair changes the fingerprint. It is not an occurrence ID or proof of semantic equivalence.

Direct JsonReport/ReportGenerator callers default the identity root to the working directory; pass root=Path(...) for a different root. Manually constructed violations without configured context use violation_type as their rule_id and null layers; use the analysis CLI for full configured identities.

Fingerprints are shared by JSON reporting and baseline comparison. Existing wildcard-import, dynamic-type, and control-flow limitations remain. A complete report is not a complete call graph.

File metrics count unique Python paths. files_parsed means the collection pass parsed the file successfully. files_mapped and files_unmapped partition parsed files. dependencies_detected counts raw dependency events before layer-pair expansion, suppression, and violation checks. GitHub Actions reports expose the same metrics as comment lines without changing annotations.

SARIF Report

deply analyze --report-format=sarif --output=deply.sarif

SARIF 2.1.0 output contains rule IDs, messages, file locations, and metrics in runs[0].properties.metrics. Results use warning severity and line-level locations. Columns are omitted because Python AST offsets count UTF-8 bytes. Files inside the analysis working directory use relative URIs with an explicit source root; files outside it use absolute file URIs. Run from the repository root for GitHub uploads. Existing dependency-inference limitations still apply.

An empty successful report has no results. Violations above --max-violations still produce a report and exit with status 1. Invalid configuration or incomplete analysis exits 1 without writing a new report; an existing output file is not deleted. With --mermaid, use --output to keep diagram text out of the SARIF document.

For an existing GitHub Actions job that checks out the sources and installs Deply, add these steps. The job needs security-events: write permission; private repositories also need actions: read and contents: read.

- name: Analyze architecture
  run: |
    rm -f deply.sarif
    deply analyze --report-format=sarif --output=deply.sarif

- name: Upload architecture findings
  if: ${{ !cancelled() && hashFiles('deply.sarif') != '' }}
  uses: github/codeql-action/upload-sarif@v4
  with:
    sarif_file: deply.sarif
    category: deply

The upload runs even when findings fail the analysis step; the job retains that failure. Removing the previous file prevents stale uploads after an incomplete analysis. See GitHub’s upload documentation for repository availability and permissions. Deply does not emit SARIF partialFingerprints; the upload action can derive fingerprints from checked-out source.

For more information about:


This site uses Just the Docs, a documentation theme for Jekyll.