solidworks_mcp.doc_links.links¶
solidworks_mcp.doc_links.links ¶
Find every link in the README and the docs, and check it.
- :func:
find_linksreads Markdown (andllms.txt) and returns each link with its file and line. Links in fenced or inline code are examples, not links, and are left out, as aremailto:links. - :func:
check_internalchecks, offline, links to this project's own pages and files (relative links,site_urllinks andblob/treelinks into this repository), including#anchors. - :func:
check_externalvisits every other URL once and fails a dead link or a redirect to a different site (specdocs/link-check).
Attributes¶
NOT_CHECKED
module-attribute
¶
NOT_CHECKED: dict[str, str] = {'https://towardsdatascience.com/': 'answers 403 to any script; a reference article, check it by hand', 'https://www.solidworks.com/': "never answers a script (times out); the vendor's home page"}
SAME_SITE
module-attribute
¶
SAME_SITE: dict[str, tuple[str, ...]] = {'github.com': ('objects.githubusercontent.com', 'raw.githubusercontent.com', 'release-assets.githubusercontent.com', 'avatars.githubusercontent.com')}
USER_AGENT
module-attribute
¶
USER_AGENT = 'SolidworksMCP-python docs link check (+https://github.com/andrewbartels1/SolidworksMCP-python)'
_BARE
module-attribute
¶
_GITHUB_CONTENT
module-attribute
¶
_GITHUB_CONTENT = re.compile('^https://github\\.com/([\\w.-]+)/([\\w.-]+)/(?:blob|tree)/([^/]+)/([^?#]+)(?:[?#].*)?$')
_GITHUB_HISTORY
module-attribute
¶
_GITHUB_HISTORY = re.compile('^https://github\\.com/([\\w.-]+)/([\\w.-]+)/commits/([^/?#]+)/?(?:[?#].*)?$')
_GITHUB_ITEM
module-attribute
¶
_IMAGE
module-attribute
¶
_IMAGE = re.compile('!\\[[^\\[\\]]*\\]\\(\\s*<?([^)\\s>]+)>?(?:\\s+[\\"\'][^\\"\']*[\\"\'])?\\s*\\)')
_INLINE
module-attribute
¶
_INLINE = re.compile('\\[[^\\[\\]]*\\]\\(\\s*<?([^)\\s>]+)>?(?:\\s+[\\"\'][^\\"\']*[\\"\'])?\\s*\\)')
_REF_DEF
module-attribute
¶
Classes¶
Link
dataclass
¶
One link and where it appears.
Attributes:
| Name | Type | Description |
|---|---|---|
file |
str
|
The file it is in, relative to the repository root. |
line |
int
|
Its line number. |
target |
str
|
The link as written. |
Result
dataclass
¶
What visiting one URL found.
Attributes:
| Name | Type | Description |
|---|---|---|
url |
str
|
The URL as written. |
ok |
bool
|
Whether it passed. |
detail |
str
|
The status, or what went wrong. |
final_url |
str | None
|
Where redirects ended, when they moved it. |
where |
list[str]
|
Every |
Site
dataclass
¶
The settings llms.txt and the link checks use.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
|
description |
str
|
|
url |
str
|
|
repo_url |
str
|
|
nav |
list[Any]
|
The nav as written in |
Functions:¶
_host ¶
_index_of ¶
The page a directory link opens: its index.md or README.md.
Source code in src/solidworks_mcp/doc_links/links.py
_is_api ¶
Whether path is under the generated docs/api/ reference.
_local_target ¶
The file (and anchor) a link points at in the checkout, or None.
None means the link isn't this project's to check offline: another
site, the generated API reference, or a repository page that isn't a
file (issues, pull requests, actions).
Source code in src/solidworks_mcp/doc_links/links.py
_rel ¶
path relative to root when it is inside it.
_repo_target ¶
A <repo_url>/blob|tree/<branch>/<path> link mapped to the checkout.
Source code in src/solidworks_mcp/doc_links/links.py
_retry_after ¶
Seconds a 429/503 asks to wait (Retry-After), at most 60; else 0.
Source code in src/solidworks_mcp/doc_links/links.py
_site_target ¶
A site_url link mapped back to the page or file in docs/.
Source code in src/solidworks_mcp/doc_links/links.py
all_links ¶
Every link in every checked file under root.
Source code in src/solidworks_mcp/doc_links/links.py
api_probe ¶
The GitHub API URL for issues, PRs, content or commit history.
GitHub's HTML pages can reject scripts with 429/503 while the API serves
the same resource. Content probes retain the link's ref and file path;
refs containing slashes must encode them as %2F in the URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
A link. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The API URL, or |
Source code in src/solidworks_mcp/doc_links/links.py
check_external
async
¶
check_external(links: Iterable[Link], *, transport: AsyncBaseTransport | None = None, concurrency: int = 8, per_host: int = 2, timeout: float = 30.0, pause: float = 2.0) -> list[Result]
Visit every external URL once, eight at a time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
links
|
Iterable[Link]
|
The links; those that aren't |
required |
transport
|
AsyncBaseTransport | None
|
An httpx transport (tests pass a mock one). |
None
|
concurrency
|
int
|
How many URLs are visited at once. |
8
|
per_host
|
int
|
How many at once on one host (GitHub answers 429 to more). |
2
|
timeout
|
float
|
Seconds per request. |
30.0
|
pause
|
float
|
Seconds before the first retry. |
2.0
|
Returns:
| Type | Description |
|---|---|
list[Result]
|
One result per unique URL, sorted by URL, each listing where it |
list[Result]
|
appears. |
Source code in src/solidworks_mcp/doc_links/links.py
check_internal ¶
Problems with links to this project's own pages and files.
Relative links resolve from the linking file; site_url links map
back to docs/; <repo_url>/blob|tree/<branch>/<path> links map to
the checkout. Links to other sites are left to :func:check_external.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
Path
|
The repository root. |
required |
site
|
Site
|
The site settings. |
required |
links
|
Iterable[Link]
|
The links to check. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
|
Source code in src/solidworks_mcp/doc_links/links.py
checked_files ¶
The README, every Markdown page under docs/ and docs/llms.txt.
Source code in src/solidworks_mcp/doc_links/links.py
find_links ¶
Every link in a Markdown text, outside code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The file's text. |
required |
file
|
str
|
Its path relative to the repository root. |
required |
Returns:
| Type | Description |
|---|---|
list[Link]
|
The links, in file order. |
Source code in src/solidworks_mcp/doc_links/links.py
github_headers ¶
The headers for GitHub API calls: the CI token when one is set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
environ
|
dict[str, str]
|
The environment ( |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
An |
Source code in src/solidworks_mcp/doc_links/links.py
heading_ids ¶
Every anchor the page's headings get, and every {#id} it sets.
Repeated slugs get _1, _2 in page order, as the toc
extension makes them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The page's Markdown. |
required |
Returns:
| Type | Description |
|---|---|
set[str]
|
The ids. |
Source code in src/solidworks_mcp/doc_links/pages.py
is_external ¶
Whether a link names a scheme (https://...) rather than a path.
report ¶
The Markdown report: a count, then every URL with its result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
list[Result]
|
The results of :func: |
required |
Returns:
| Type | Description |
|---|---|
str
|
The report's text. |
Source code in src/solidworks_mcp/doc_links/links.py
same_site ¶
Whether a redirect from url to final stays on the same site.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL as written. |
required |
final
|
str
|
Where its redirects ended. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True when the hosts match ( |
bool
|
the other ( |
bool
|
of the hosts :data: |
Source code in src/solidworks_mcp/doc_links/links.py
source_lines ¶
The page's lines as (line number, text, inside a fenced code block).
Front matter, if any, is blanked out (its lines kept so line numbers still match the file). Fence lines themselves count as code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The page's Markdown. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[int, str, bool]]
|
One tuple per line, numbered from 1. |
Source code in src/solidworks_mcp/doc_links/pages.py
visit
async
¶
visit(client: AsyncClient, url: str, *, attempts: int = 4, pause: float = 2.0, sleep: Callable[[float], object] = asyncio.sleep, probe: str | None = None, headers: dict[str, str] | None = None) -> Result
Visit one URL and judge it.
A GET follows redirects. It passes on a 2xx that ended on the same
site. Timeouts, dropped connections, 429 and 5xx are retried up to
attempts times; any other failure is final at once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
AsyncClient
|
The HTTP client (redirects followed). |
required |
url
|
str
|
The URL to visit. |
required |
attempts
|
int
|
How many tries before a retryable failure is final. |
4
|
pause
|
float
|
Seconds before the first retry; doubled each time. |
2.0
|
sleep
|
Callable[[float], object]
|
The pause function (tests pass one that doesn't wait). |
sleep
|
probe
|
str | None
|
A URL to request instead of |
None
|
headers
|
dict[str, str] | None
|
Extra request headers (sent only to |
None
|
Returns:
| Type | Description |
|---|---|
Result
|
The result. |