Skip to content

ci: enable blocking deptry DEP001 with uv-installed deps (#7161) - #7630

Open
Thibaut Rouxel (throuxel) wants to merge 2 commits into
masterfrom
ci/7161-deptry-dep001
Open

Thibaut Rouxel (throuxel) wants to merge 2 commits into
masterfrom
ci/7161-deptry-dep001

Conversation

@throuxel

@throuxel Thibaut Rouxel (throuxel) commented Sep 9, 2026

Copy link
Copy Markdown
Member

Test PR to see results: #7631

Proposed changes

  • Install each changed connector's dependencies in an isolated uv environment before running deptry, so transitive imports (provided by pycti) resolve as DEP003 instead of false DEP001.
  • Make DEP001 (undeclared import) blocking — the job fails so undeclared dependencies are caught at PR time instead of at OCTI release time.
  • Keep DEP002 (unused) and DEP003 (transitive) as non-blocking warnings surfaced via annotations and a PR comment.
  • Suppress false positives: recursive first-party module detection under src/, exclude test directories, and ignore the __main__ pydantic BaseSettings false positive.
  • Scan the changed connectors in parallel (xargs -P 6).
  • Add python-magic=magic to .github/deptry-package-map.txt (the package whose transitive removal originally broke the release).

Related issues

Checklist

  • I consider the submitted work as finished
  • I have signed my commits using GPG key.
  • I tested the code for its functionality using different use cases
  • I added/update the relevant documentation (either on github or on notion)
  • Where necessary I refactored code to improve the overall quality

Further comments

Follow-up from the python-magic release breakage (revert PR #7158).

Validated locally against the whole repo with deptry==0.25.1 and uv:

  • Without installed deps, DEP001 reported 530 findings (mostly stix2/pydantic/requests provided transitively by pycti, plus local src imports).
  • With deps installed + first-party detection + test exclusion + __main__ ignore, real DEP001 findings drop to 0 false positives; a genuinely undeclared package (e.g. tabulate) is still correctly flagged and would block.
  • DEP003 (~630 findings, all pycti-transitive: requests, yaml, stix2, dateutil, …) stays informational.

Copilot AI lite review requested due to automatic review settings September 9, 2026 13:55
@throuxel Thibaut Rouxel (throuxel) added filigran team Item from the Filigran team. do not merge Do not merge until this label is removed. labels Sep 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the existing deptry-based CI workflow to catch missing dependency declarations at PR time by running deptry with connector dependencies installed via uv, making DEP001 blocking while keeping DEP002/DEP003 informational.

Changes:

  • Run deptry inside an isolated uv environment with each connector’s requirements.txt installed, and scan changed connectors in parallel.
  • Treat DEP001 (imported but not declared) as a failing condition; keep DEP002/DEP003 as warnings surfaced via annotations and a PR comment.
  • Extend the deptry package→module mapping with python-magic=magic.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
.github/workflows/ci-unused-deps.yml Reworks the CI job to run deptry with uv-installed deps, adds DEP001 blocking behavior, and enhances annotations/commenting.
.github/deptry-package-map.txt Adds python-magic=magic mapping to reduce false positives and correctly attribute the magic import.
Suppressed comments (1)

.github/workflows/ci-unused-deps.yml:166

  • Same as warnings: printf '%s\n' "$errors" produces a non-empty output (newline) when errors is empty, which can incorrectly trip the steps.deptry.outputs.errors != '' condition. Avoid forcing a newline in the output value.
            printf '%s\n' "$errors"

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread .github/workflows/ci-unused-deps.yml Outdated
Comment thread .github/workflows/ci-unused-deps.yml Outdated
- 'stream/**'
- '.github/deptry-package-map.txt'
- '.github/workflows/unused-deps.yml'
- '.github/workflows/ci-unused-deps.yml'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: This triggers does nothing because you will run deptry only if the code of a connector has changed due to https://github.com/OpenCTI-Platform/connectors/pull/7630/changes#diff-007841c83bdb5286672b72b04f8c6b914aa6bf9c1c8a08705e19f8babe73ed9dR134. What you can do is to run deptry on all connectors when you update this file and deptry-package-map.txt

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed those triggers, it will just make a lot of noises to apply to all connectors.

Comment thread .github/workflows/ci-unused-deps.yml Outdated
Comment thread .github/workflows/ci-unused-deps.yml Outdated
- name: Install uv
uses: astral-sh/setup-uv@v6

- name: Run deptry on changed connectors

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: This step is becoming quite large and difficult to read in a YAML file. Perhaps you could move it into a proper script file and simply call it here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread .github/workflows/ci-unused-deps.yml Outdated
per_rule="DEP001=__main__"
[ -n "${IGNORE_PKGS:-}" ] && per_rule="$per_rule,DEP002=$IGNORE_PKGS"

out=$(uv run --isolated --no-project \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 2>&1 | grep ... || true  discards  uv run 's exit code, so if the env fails to build.  out  is empty →  return 0  → connector reported clean, job green. Maybe separate "deptry ran and found nothing" from "deptry never ran".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, exit codes are now different.

Install each changed connector's dependencies in an isolated uv environment before running deptry so transitive imports resolve as DEP003 instead of false DEP001. Make DEP001 (undeclared) blocking; keep DEP002 (unused) and DEP003 (transitive) as non-blocking warnings. Auto-detect first-party modules, exclude tests, ignore __main__, and add python-magic=magic mapping. Scan connectors in parallel.
Split the deptry logic into .github/scripts/deptry_scan.py (JSON output) and scan each changed connector in parallel via a discover -> matrix -> report workflow. Distinguish 'deptry could not run' (env build failure -> exit 2, blocking) from 'no findings'. Cover connectors declaring dependencies via pyproject.toml (generate a requirements file from [project.dependencies]) in addition to requirements.txt, scan the whole connector root so every layout is handled, and detect first-party modules across it. Drop the workflow/map files from the path trigger.

@jabesq Hugo Dupras (jabesq) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not merge Do not merge until this label is removed. filigran team Item from the Filigran team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci: enable deptry DEP001/DEP003 to catch undeclared (transitive) dependencies

4 participants