Skip to content

fix: collapse SPDXMarkdown into single file - #5

Merged
redtux merged 15 commits into
mainfrom
fix/4-collapse-impl
Jun 23, 2026
Merged

fix: collapse SPDXMarkdown into single file#5
redtux merged 15 commits into
mainfrom
fix/4-collapse-impl

Conversation

@redtux

@redtux redtux commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Description

Collapse the two-file SPDXMarkdown architecture into a single module. The
original two-file split (spdx_markdown.py + _impl.py) with a __new__-based
lazy wrapper was necessary to avoid a circular import during commitizen's
entry-point scanning, but introduced a latent bug: isinstance(formatter, SPDXMarkdown) returned False because _SPDXMarkdownImpl did not subclass
SPDXMarkdown.

This PR merges _impl.py into spdx_markdown.py, keeps the __new__ pattern
(circular import is real), and fixes isinstance via multiple inheritance:
_SPDXMarkdownImpl(SPDXMarkdown, Markdown).

Changes

File Change
src/.../spdx_markdown.py Single-file collapse: wrapper defined first, then _SPDXMarkdownImpl(SPDXMarkdown, Markdown) with __new__ override
src/.../_impl.py Deleted — merged into spdx_markdown.py
docs/plans/10-collapse-impl.md New — implementation plan for the collapse
docs/plans/index.md Added row for plan 10
openspec/changes/collapse-impl-module/ OpenSpec change with proposal, design, specs, tasks

Verification

  • Tests pass: uv run pytest -v (19/19)
  • Ruff clean: ruff check src/ (E402 suppressed)
  • py.typed in wheel: uv build && unzip -l dist/*.whl | grep py.typed
  • REUSE compliant: make reuse

Closes #4

redtux added 10 commits June 22, 2026 20:04
NOTE: We already use `ty` for type checking and `ruff` for linting.

Ref: #4
Archive the completed `docs-best-practices` change
after all tasks were implemented and verified.

- All 5 tasks across 4 spec areas were marked done before archiving.
- Completed tasks: Enhanced docs landing page, enhanced API
  reference, created usage guide (docs/guide.md), polished
  changelog, final verification (tests + docs-build).
- Moves all docs-best-practices artifacts under
  `archive/2026-06-22-docs-best-practices/`.

Ref: #4
Commit the three synced delta specs from
archiving the docs-best-practices change:

- docs-api-enhancement
- docs-guide
- docs-landing

Ref: #4
Create the collapse-impl-module change to define the implementation
plan for collapsing the two-file architecture into a single module.

- Define scope of the refactor via proposal and design artifacts.
- Establish a new spec for the `SPDXMarkdown` formatter behavior.
- Outline tasks for implementing each step.

Ref: #4
Mark all tasks as done after implementing the
single-file collapse of the SPDXMarkdown formatter.

- All verification tasks passed (ruff, tests, smoke test).
- Plan and OpenSpec artifacts updated to reflect actual implementation.

Ref: #4
Update proposal, design, and specs to reflect the actual implementation:

Single-file architecture with `SPDXMarkdown` wrapper defined first, then
`_SPDXMarkdownImpl(SPDXMarkdown, Markdown)` after commitizen imports.

- Design: Document multiple-inheritance approach and __new__ override.
- Proposal: Correct the circular-import description.
- Spec: Update requirements to match actual architecture.

Ref: #4
Add implementation plan for collapsing the two-file
`SPDXMarkdown` architecture into a single module.

- Defines problem, resolution, and acceptance criteria.
- References this OpenSpec change, and GitHub issue #4.

Ref: #4
Add row and reference link for the new action plan.

Ref: #4
The implementation now lives in spdx_markdown.py
as `_SPDXMarkdownImpl(SPDXMarkdown, Markdown)`.

Ref: #4
Merge _impl.py into spdx_markdown.py. Define SPDXMarkdown wrapper first
(avoids circular import), then _SPDXMarkdownImpl(SPDXMarkdown, Markdown)
after commitizen imports fix isinstance checks via multiple inheritance.

- Override __new__ on impl class to prevent recursion.
- Remove import sys as _sys (unused).
- Suppress E402 with noqa (inherent to staggered imports).

Ref: #4
@redtux redtux added the bug Something isn't working label Jun 22, 2026
@redtux redtux linked an issue Jun 22, 2026 that may be closed by this pull request

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request collapses the formatter implementation from a two-file structure into a single spdx_markdown.py file, resolving an isinstance type-checking bug and removing the _impl.py file. It also removes basedpyright from the development dependencies. The reviewer feedback suggests a cleaner approach to solving the isinstance issue: using virtual subclassing via Python's abc module instead of multiple inheritance and __new__ overrides, which avoids fragile recursion workarounds.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/commitizen_spdx_changelog/formatters/spdx_markdown.py
Comment thread src/commitizen_spdx_changelog/formatters/spdx_markdown.py Outdated
Comment thread src/commitizen_spdx_changelog/formatters/spdx_markdown.py
@redtux redtux self-assigned this Jun 22, 2026
redtux added 5 commits June 22, 2026 23:54
Use abc.ABCMeta virtual subclassing instead of multiple inheritance
to satisfy isinstance checks, addressing Gemini code review feedback.

- SPDXMarkdown inherits from abc.ABC for register() support
- SPDXMarkdown.register(_SPDXMarkdownImpl) for virtual subclassing
- _SPDXMarkdownImpl inherits only Markdown, no __new__ override.

Ref: #4, PR #5
Update all OpenSpec artifacts to describe `abc.ABC` virtual subclassing
instead of multiple inheritance with the `__new__` recursion workaround.

- Delta spec: Add ADDED Requirements header for archive compatibility.
- Design: Update decision section, rationale, and alternatives.
- Proposal: Change multiple inheritance to abc.ABCMeta virtual subclassing.
- Tasks: Clarify single-file implementation description.

Ref: #4, PR #5
Update plan to reflect actual implementation using abc.ABC virtual
subclassing instead of multiple inheritance with __new__ recursion workaround.

- Resolution section: Describe SPDXMarkdown(abc.ABC)
  wrapper and _SPDXMarkdownImpl(Markdown) with register().
- Tasks and acceptance criteria updated accordingly.

Ref: #4, PR #5
Archive the `collapse-impl-module` change by moving it to
openspec/changes/archive/2026-06-23-collapse-impl-module/.

Ref: #4, PR #5
Create main spec for spdx-markdown-formatter
after archiving collapse-impl-module change.

4 requirements with scenarios for isinstance, frontmatter stripping,
circular-import avoidance, and entry point registration.

Ref: #4, PR #5
@redtux
redtux merged commit 00c539a into main Jun 23, 2026
3 checks passed
redtux added a commit that referenced this pull request Jun 23, 2026
Use abc.ABCMeta virtual subclassing instead of multiple inheritance
to satisfy isinstance checks, addressing Gemini code review feedback.

- SPDXMarkdown inherits from abc.ABC for register() support
- SPDXMarkdown.register(_SPDXMarkdownImpl) for virtual subclassing
- _SPDXMarkdownImpl inherits only Markdown, no __new__ override.

Ref: #4, PR #5
redtux added a commit that referenced this pull request Jun 23, 2026
Update all OpenSpec artifacts to describe `abc.ABC` virtual subclassing
instead of multiple inheritance with the `__new__` recursion workaround.

- Delta spec: Add ADDED Requirements header for archive compatibility.
- Design: Update decision section, rationale, and alternatives.
- Proposal: Change multiple inheritance to abc.ABCMeta virtual subclassing.
- Tasks: Clarify single-file implementation description.

Ref: #4, PR #5
redtux added a commit that referenced this pull request Jun 23, 2026
Update plan to reflect actual implementation using abc.ABC virtual
subclassing instead of multiple inheritance with __new__ recursion workaround.

- Resolution section: Describe SPDXMarkdown(abc.ABC)
  wrapper and _SPDXMarkdownImpl(Markdown) with register().
- Tasks and acceptance criteria updated accordingly.

Ref: #4, PR #5
redtux added a commit that referenced this pull request Jun 23, 2026
Archive the `collapse-impl-module` change by moving it to
openspec/changes/archive/2026-06-23-collapse-impl-module/.

Ref: #4, PR #5
@redtux
redtux deleted the fix/4-collapse-impl branch June 23, 2026 01:27
@redtux redtux mentioned this pull request Jun 23, 2026
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: collapse module into single file and remove lazy import

1 participant