Skip to content

v0.16.0: Audit without importing: static scans, SARIF & multi-path gates

Latest

Choose a tag to compare

@Borda Borda released this 23 Nov 09:24
· 10 commits to main since this release

Audit your deprecations without importing your package, gate whole monorepos in one run, and send the results to GitHub code scanning.

  • Read source with ast using --static, so CI needs none of your package's runtime dependencies.
  • Gate several packages in one run, and publish findings to code scanning with --report-sarif.
  • Fail CI on any recorded gap with --strict, and accept known findings with --ignore or --baseline.
  • Point an old name at a new object with deprecated_instance(target=...).
  • Call the import-free scan from Python with find_deprecation_wrappers_static().

Mostly a drop-in upgrade; check one CLI spelling, the removed empty cli extra and stricter read_only proxies in the Migration guide.

✨ Spotlights / highlights

Audit a package without importing it

pydeprecate expiry and pydeprecate policy take --static, which reads the package source with ast and imports nothing, so a package can be audited without its runtime dependencies installed. It checks wrappers whose settings it can resolve. When it recognizes a form but cannot resolve it, it prints a pydeprecate gap: line instead of guessing; a few dynamic forms stay invisible, so a clean run is not proof of full coverage. The pydeprecate-expiry-static and pydeprecate-policy-static pre-commit hooks run the same checks, and find_deprecation_wrappers_static() returns the scan to Python as a frozen StaticScanResult that the expiry, policy and table helpers accept in place of a module. (#264, #267, #268)

pydeprecate expiry --static --strict src/mypackage
# .pre-commit-config.yaml
repos:
  - repo: https://github.com/Borda/pyDeprecate
    rev: v0.16.0
    hooks:
      - id: pydeprecate-expiry-static
      - id: pydeprecate-policy-static

Strict gates, known findings and monorepos

--strict (or strict = true in [tool.pydeprecate]) makes a run fail when part of the audit could not run; ignore, baseline and gate have [tool.pydeprecate] keys too. --ignore takes module:symbol or rule:module:symbol globs and --baseline takes an earlier --report-json file, so a project can adopt the audit without fixing everything first. Every subcommand now audits several paths in one run, each against its own version and pyproject.toml settings, and pydeprecate all --gate=policy fails on policy violations from the same scan. (#265, #266)

pydeprecate all --gate=policy src/pkg_a src/pkg_b
pydeprecate expiry src/mypackage --ignore='expired:mypackage.legacy:old_api'

SARIF for code scanning and a richer GitHub Action

--report-sarif FILE writes SARIF 2.1.0 with one result per active finding, on every subcommand except status. The composite GitHub Action adds sarif and fail-on-gap inputs, a multi-line path, eight step outputs and finding annotations, at most 10 per level per step. (#265, #266, #267)

- uses: Borda/pyDeprecate@v0.16.0
  id: pydeprecate
  with:
    subcommand: all
    sarif: true
- uses: github/codeql-action/upload-sarif@v4
  if: always() && steps.pydeprecate.outputs.sarif-file != ''
  with:
    sarif_file: ${{ steps.pydeprecate.outputs.sarif-file }}

deprecated_instance forwards to a replacement object

deprecated_instance takes keyword-only target, args_mapping and attrs_mapping, the same options deprecated_class offers. The old name can now serve a new object, rename keyword arguments when it is called, and deprecate selected attributes. TargetMode.AUTO, True, False and a module as target raise TypeError. (#263)

from deprecate import deprecated_instance


def fetch_invoice(*, timeout):
    return f"invoice fetched with timeout={timeout}"


class LegacyFetcher:
    def __call__(self, *, wait):
        return f"invoice fetched with wait={wait}"


old_fetch = deprecated_instance(
    LegacyFetcher(),
    name="old_fetch",
    target=fetch_invoice,
    args_mapping={"wait": "timeout"},
    deprecated_in="0.16",
    remove_in="1.0",
)
old_fetch(wait=5)  # warns once, then calls fetch_invoice(timeout=5)

🔄 Migration guide

A few CLI spellings and proxy behaviours change, so check the list below when you upgrade from v0.15.

Pass the version as --version. A second positional operand on expiry, all and status is read as a path first. If it is read as a version instead, it prints a stderr notice, and that form stops working in v1.0. After --, an operand is always a path, so pydeprecate expiry -- src/pkg 2.0 now treats 2.0 as a second path and exits 2 when no such path exists. A positional version together with --version exits 2. (#266)

# DEPRECATED API — still works with a stderr notice, removed in v1.0
pydeprecate expiry src/mypackage 2.0

# NEW API
pydeprecate expiry src/mypackage --version 2.0

Replace pyDeprecate[cli] pins. The command needs no dependency since v0.15, so the empty cli extra is gone. pip install 'pyDeprecate[cli]' still installs, with pip's warning that the extra does not exist. Use the base package, or pyDeprecate[audit] for the expiry and grace-window checks. (#269)

# BEFORE (v0.15)
pip install 'pyDeprecate[cli]'

# AFTER (v0.16)
pip install 'pyDeprecate[audit]'

read_only=True proxies block six more method names. sort, reverse, popitem, difference_update, intersection_update and symmetric_difference_update now raise AttributeError instead of changing the wrapped list, dict or set, and a custom method with one of these names is blocked too. (#273)

Count warnings per call, not per renamed keyword. A proxy with a callable target and args_mapping now draws on one call-level warning budget within the usual num_warns limit, and its message names the replacement rather than each renamed keyword. A test that counted or matched one warning per renamed keyword needs updating. (#273)

Name-based allowlists may need the function's own name. A function bound under several public names is now reported under the binding named like the function. An allowlist, --ignore pattern or snapshot that named an alias which used to sort first needs the function's own name. (#265)

📝 Notable changes

🚀 Added

  • Import-free --static mode — pydeprecate expiry and pydeprecate policy audit source with ast; check, chains, all and status exit 2 with --static. (#264, #267)
  • Static pre-commit hooks — pydeprecate-expiry-static and pydeprecate-policy-static. (#264)
  • find_deprecation_wrappers_static() and StaticScanResult — the import-free scan as a Python API, accepted by validate_deprecation_expiry, validate_deprecation_policy and generate_deprecation_table. (#268)
  • --strict — a recorded pydeprecate gap: line exits 1; each path in a multi-path run uses its own setting. (#265)
  • --ignore and --baseline — accept known findings by glob or by an earlier --report-json file. (#265)
  • --report-json finding records — id, rule, level, message and location per finding, plus gate and mode; the layout stays schema 1 and a JSON Schema ships as docs/schemas/report-1.schema.json. (#264, #265, #266)
  • Several paths per run — every subcommand audits any number of paths, and importing scans of several paths run in isolated worker processes. (#266)
  • pydeprecate all --gate=policy — fails on policy violations; gate = ["policy"] works in [tool.pydeprecate]. (#266)
  • --report-sarif FILE — SARIF 2.1.0 for code scanning. (#266, #267)
  • GitHub Action inputs and outputs — fail-on-gap, sarif, multi-line path, step outputs and annotations. (#265, #266)
  • deprecated_instance forwards to a replacement — keyword-only target, args_mapping and attrs_mapping. (#263)
  • DeprecationConfig.call_options_inert — tells an inert args_mapping or args_extra from other misconfiguration. (#263)
  • DeprecationWrapperInfo.source_file and source_line — where a wrapper is defined, None by default. (#265, #267)

🌱 Changed

  • Misconfiguration: args_mapping or args_extra on a non-callable proxied object now emit UserWarning and mark the config misconfigured; warnings name deprecated_instance or deprecated_class. (#263)
  • copy.copy of a proxy: shares a replacement → shallow-copies a non-class replacement object. (#263)
  • Audit: a non-callable proxy target is a TARGET chain and reported by type, not str(). (#263)
  • Version detection: an ancestor's version → the nearest pyproject.toml with a [project] table owns it, and a dynamic version is read from the checkout ahead of stale installed metadata. (#264, #267)
  • Audit names: a function bound under several public names → reported under the binding named like itself. (#265)
  • -- operand: possibly read as the legacy positional version → always a path. (#266)
  • Proxy warnings: one per renamed keyword → one call-level warning per call within num_warns, naming the replacement, for a callable target with args_mapping. (#273)
  • read_only=True: 10 guarded method names → 16. (#273)
  • deprecated_module with a message_template no longer warns about a missing deprecated_in. (#273)

🗑️ Deprecated

  • A second positional version on expiry, all and status — use --version; the positional form is removed in v1.0. (#266)
  • args_mapping or args_extra on a non-callable proxied object — they warn now and raise TypeError in v1.0; remove them or pass a callable target. (#263)

❌ Removed

  • The empty cli extra. The command needed no dependency since v0.15; install the base package or pyDeprecate[audit]. (#269)

🔧 Fixed

  • A keyword named like a positional-only parameter stays a keyword when a call is rewritten for a callable with **kwargs. (#263)
  • Matrix audit tables merge 1.0, v1.0 and 1.0.0 into one column per release and order unparsed columns by their header. (#262)
  • validate_deprecation_expiry(<module path>) without a version shows the package's real import error and keeps the caller's module path. (#262)
  • The misconfigured-target finding names ATTRS_REMAP and ARGS_REMAP contradictions correctly. (#273)
  • A self-targeting deprecated_class rename alias is no longer flagged self_reference or no_effect. (#273)
  • Report formatting and nested proxy construction no longer evaluate skip_if; outside an audit, skip_if is honoured across a proxy chain for __class__, __mro_entries__, isinstance, issubclass and operands. (#267)
  • A callable instance without __name__ is rejected with the plain-object TypeError from deprecated_callable, not an AttributeError. (#267)

🏆 Contributors

  • Jirka Borovec (@Borda, LinkedIn) — deprecated_instance forwarding, the import-free --static audit and Python API, strict mode, finding suppression, multi-path audits, SARIF reporting, CI and docs.

Automated contributions: dependabot, claude[bot], Codex, Copilot Autofix.


Full changelog: v0.15.0...v0.16.0
Co-authored with /oss:release.