Skip to content

MAINT: Defining pyrit.models boundary#1771

Merged
rlundeen2 merged 6 commits into
microsoft:mainfrom
rlundeen2:rlundeen2/models-pydantic-phase-0
May 29, 2026
Merged

MAINT: Defining pyrit.models boundary#1771
rlundeen2 merged 6 commits into
microsoft:mainfrom
rlundeen2:rlundeen2/models-pydantic-phase-0

Conversation

@rlundeen2
Copy link
Copy Markdown
Contributor

Adding guardrails to pyrit.models and deprecation helpers to help in migrating pyrit.models to only include very slim models.

Contributors: see pyrit.shared design for more context [phase 0]

rlundeen2 and others added 4 commits May 20, 2026 17:36
- Add tests/unit/models/test_import_boundary.py: AST-based ratchet that
  enforces the pyrit.models -> {stdlib, pydantic, pyrit.common.deprecation,
  pyrit.models.*} import rule. Known transitional violations are listed
  with phase tags so they shrink monotonically as later phases land.
- Extend pyrit/common/deprecation.py with deprecated_kwarg (for Pydantic
  model_validator(mode=before) kwarg promotion) and module_deprecation_getattr
  (for module-level __getattr__ deprecation shims, e.g. pyrit.identifiers
  re-export after Phase 2).
- Document the import boundary in style-guide.instructions.md and the
  pyrit.models package docstring.

No production model code changed in this phase.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Per review feedback: scope the rule to pyrit/models/** via applyTo so it
only loads when models code is in scope, instead of being a subsection of
the global style guide.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Per review feedback: reuse the existing helper instead of duplicating the
warnings.warn call. Same message format; tests unchanged.

Note: deprecated_kwarg keeps its inline warnings.warn because its message
format intentionally differs (it mentions the kwarg name and model name,
not the qualified callable path).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Per review feedback: there's nothing special about seeds — it's just another
part of pyrit.models that has not been migrated yet. Treat its existing
cross-package imports the same way as everything else: list them in
KNOWN_TOP_LEVEL_VIOLATIONS with a phase tag ("seeds-followup") and let the
ratchet shrink them as the work lands.

- _scan_files() now uses rglob so seeds/*.py are scanned.
- _module_name_for() handles nested paths.
- test_seeds_excluded removed; seed.py / seed_dataset.py added to the
  scan sanity check.
- Removed the "excluding seeds" carve-out from the instructions file
  and the pyrit.models package docstring.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@romanlutz romanlutz changed the title MAINT: Defining pyrit.models boundry MAINT: Defining pyrit.models boundary May 21, 2026
Copy link
Copy Markdown
Contributor

@adrian-gavrila adrian-gavrila left a comment

Choose a reason for hiding this comment

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

Looks good! One quick question, probably just me missing something though

Comment thread tests/unit/models/test_import_boundary.py Outdated
rlundeen2 and others added 2 commits May 28, 2026 18:45
Per PR feedback: __init__.py is a natural place for stray cross-package re-exports to sneak in. Scanning them adds a real guardrail at no cost (current __init__.py files only do safe self-imports).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
pyrit.common.deprecation is allowed at module level; it should also be allowed inside functions / TYPE_CHECKING blocks. Without this, lazy deprecation imports (e.g. in chat_message, embeddings) incorrectly fail the boundary test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rlundeen2 rlundeen2 enabled auto-merge May 29, 2026 01:55
@rlundeen2 rlundeen2 added this pull request to the merge queue May 29, 2026
Merged via the queue into microsoft:main with commit 76af560 May 29, 2026
48 checks passed
@rlundeen2 rlundeen2 deleted the rlundeen2/models-pydantic-phase-0 branch May 29, 2026 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants