Remove duplicate code from structure processors#6
Merged
emcd merged 5 commits intoNov 20, 2025
Conversation
Eliminates code duplication by creating a shared URL utilities module at the structures level. The normalize_base_url function was duplicated identically in both sphinx and pydoctor structure processors. Changes: - Create sources/librovore/structures/urls.py with normalize_base_url - Update sources/librovore/structures/__.py to export shared utilities - Refactor sphinx/urls.py to import shared normalize_base_url - Refactor pydoctor/urls.py to import shared normalize_base_url - Add implementation tracking file for documentation Benefits: - Reduces code duplication (25 lines per processor) - Ensures consistent URL handling across all structure processors - Simplifies maintenance and reduces risk of divergence - Makes shared utilities available to future processors All linters pass (ruff, isort, pyright). All 171 tests pass.
Corrects the import pattern for shared URL utilities and extracts duplicate from_source method to base class. Import Pattern Fixes: - Remove wildcard import of urls from structures/__.py - Add `from ..urls import *` to individual processor __.py files - Update callers to use __.normalize_base_url instead of _urls.normalize_base_url - Remove unused _urls imports from main.py and extraction.py files - Simplify urls.py modules to not re-export shared functions from_source Duplication Elimination: - Move identical from_source implementation to StructureDetection base class - Remove duplicate implementations from all 4 Detection classes: * SphinxDetection * PydoctorDetection * MkDocsDetection * RustdocDetection - Eliminates 10 lines of duplicate code per class (40 lines total) Benefits: - Correct import hierarchy following project patterns - Reduces code duplication and maintenance burden - Ensures consistent behavior across all structure processors - Prevents implementation drift between Detection classes All linters pass (ruff, isort, pyright). All 171 tests pass.
Ensures all four structure processors use the same shared normalize_base_url from sources/librovore/structures/urls.py. Before this fix: - Sphinx & Pydoctor: Used shared normalize_base_url from structures/urls.py - Mkdocs & Rustdoc: Used different normalize_base_url from librovore/urls.py (via xtnsapi) The two implementations had subtle differences that could lead to inconsistent behavior. This fix ensures all structure processors use the same shared implementation. Changes: - Add `from ..urls import *` to mkdocs/__.py - Add `from ..urls import *` to rustdoc/__.py All linters pass (ruff, isort, pyright). All 171 tests pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Eliminates code duplication by creating a shared URL utilities module at the structures level. The normalize_base_url function was duplicated identically in both sphinx and pydoctor structure processors.
Changes:
Benefits:
All linters pass (ruff, isort, pyright).
All 171 tests pass.