Skip to content

Added try-catch for autodoc mock-import#89

Merged
RobertoRoos merged 2 commits into
mainfrom
bugfix/autodoc-mock-import
Jul 1, 2026
Merged

Added try-catch for autodoc mock-import#89
RobertoRoos merged 2 commits into
mainfrom
bugfix/autodoc-mock-import

Conversation

@RobertoRoos

@RobertoRoos RobertoRoos commented Mar 7, 2026

Copy link
Copy Markdown
Collaborator

Resolving #82 (again...)

This is the suggestion of @lucc , posted here: #82 (comment)

@RobertoRoos RobertoRoos self-assigned this Mar 7, 2026
@codecov

codecov Bot commented Mar 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.15%. Comparing base (528aa98) to head (4e8f1c4).

Files with missing lines Patch % Lines
sphinxarg/ext.py 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #89      +/-   ##
==========================================
- Coverage   50.19%   50.15%   -0.04%     
==========================================
  Files          18       18              
  Lines        1289     1292       +3     
  Branches      262      262              
==========================================
+ Hits          647      648       +1     
- Misses        598      600       +2     
  Partials       44       44              
Flag Coverage Δ
unittests 49.92% <50.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread sphinxarg/ext.py
Comment on lines +22 to +27
try:
from sphinx.ext.autodoc.mock import mock
except ImportError:
from sphinx.ext.autodoc import mock
# A persistent bug in sphinx / autodoc causes problems during importing (#82)

@RobertoRoos RobertoRoos Mar 7, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hm, I'm a little in doubt now. I feel the intended method to import is the short version:

from sphinx.ext.autodoc import mock

So maybe we should prioritize that one. If for no other reason then to prevent us being the cause of an import error for the next package.

EDIT: I changed it but let's see what the bosses say over at sphinx-doc/sphinx#14333

@dvzrv

dvzrv commented Jun 16, 2026

Copy link
Copy Markdown

FYI: We are still/again seeing this issue with khard 0.21.0, sphinx 9.1.0 when trying to build the package for Arch Linux: lucc/khard#356

@RobertoRoos RobertoRoos force-pushed the bugfix/autodoc-mock-import branch from 88cd1f0 to 46a37d2 Compare June 25, 2026 06:34
@RobertoRoos RobertoRoos marked this pull request as ready for review June 25, 2026 06:34
@RobertoRoos

RobertoRoos commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator Author

I want to merge this try-catch import, I think that should be future proof even if Sphinx rearranged their module structure.
@dvzrv would you have a chance to test this branch on your project to see if it actually resolves the bug?

With pip you can do this with an install like this:

pip install git+https://github.com/sphinx-doc/sphinx-argparse.git@bugfix/autodoc-mock-import

@RobertoRoos

Copy link
Copy Markdown
Collaborator Author

I kind of want to get the release out. I can demonstrate locally that this works, so I'm merging it.

@RobertoRoos RobertoRoos merged commit 8959ab6 into main Jul 1, 2026
11 of 12 checks passed
@RobertoRoos RobertoRoos deleted the bugfix/autodoc-mock-import branch July 1, 2026 06:32
inmantaci pushed a commit to inmanta/inmanta-core that referenced this pull request Jul 1, 2026
Bumps [sphinx-argparse](https://github.com/sphinx-doc/sphinx-argparse) from 0.5.2 to 0.6.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/sphinx-doc/sphinx-argparse/releases">sphinx-argparse's releases</a>.</em></p>
<blockquote>
<h2>Release v0.6.0</h2>
<h2>What's Changed</h2>
<ul>
<li>Added default feature to disable ArgumentParser coloring by <a href="https://github.com/RobertoRoos"><code>@​RobertoRoos</code></a> in <a href="https://redirect.github.com/sphinx-doc/sphinx-argparse/pull/74">sphinx-doc/sphinx-argparse#74</a></li>
<li>Trying to fix RTD refusing to build by <a href="https://github.com/RobertoRoos"><code>@​RobertoRoos</code></a> in <a href="https://redirect.github.com/sphinx-doc/sphinx-argparse/pull/77">sphinx-doc/sphinx-argparse#77</a></li>
<li>Moved color-disabling into <code>parse_parser</code> to fix subparsers by <a href="https://github.com/RobertoRoos"><code>@​RobertoRoos</code></a> in <a href="https://redirect.github.com/sphinx-doc/sphinx-argparse/pull/84">sphinx-doc/sphinx-argparse#84</a></li>
<li>Unpinned ruff for CI + Cleaned up workflow files a little by <a href="https://github.com/RobertoRoos"><code>@​RobertoRoos</code></a> in <a href="https://redirect.github.com/sphinx-doc/sphinx-argparse/pull/79">sphinx-doc/sphinx-argparse#79</a></li>
<li>Updated license metadata by <a href="https://github.com/RobertoRoos"><code>@​RobertoRoos</code></a> in <a href="https://redirect.github.com/sphinx-doc/sphinx-argparse/pull/81">sphinx-doc/sphinx-argparse#81</a></li>
<li>Changed filename field to be explicit by <a href="https://github.com/RobertoRoos"><code>@​RobertoRoos</code></a> in <a href="https://redirect.github.com/sphinx-doc/sphinx-argparse/pull/88">sphinx-doc/sphinx-argparse#88</a></li>
<li>Fixed MyPy by <a href="https://github.com/RobertoRoos"><code>@​RobertoRoos</code></a> in <a href="https://redirect.github.com/sphinx-doc/sphinx-argparse/pull/90">sphinx-doc/sphinx-argparse#90</a></li>
<li>Added try-catch for autodoc mock-import by <a href="https://github.com/RobertoRoos"><code>@​RobertoRoos</code></a> in <a href="https://redirect.github.com/sphinx-doc/sphinx-argparse/pull/89">sphinx-doc/sphinx-argparse#89</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a href="https://github.com/sphinx-doc/sphinx-argparse/compare/v0.5.2...v0.6.0">https://github.com/sphinx-doc/sphinx-argparse/compare/v0.5.2...v0.6.0</a></p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/sphinx-doc/sphinx-argparse/blob/main/docs/changelog.rst">sphinx-argparse's changelog</a>.</em></p>
<blockquote>
<p>0.6.0</p>
<h5></h5>
<p>The following enhancements to the HTML output are described on the :doc:<code>usage</code> page.</p>
<ul>
<li>Optional command index.</li>
<li>Optional <code>:index-groups:</code> field to the directive for an command-by-group index.</li>
<li>A <code>sphinxarg_full_subcommand_name</code> option to print fully-qualified sub-command headings.
This option helps when more than one sub-command offers a <code>create</code> or <code>list</code> or other
repeated sub-command.</li>
<li>Each command heading is a domain-specific link target.
You can link to commands and sub-commands with the <code>:ref:</code> role, but this
release adds support for the domain-specific role like
<code>:commands:command:`sample-directive-opts A` </code>.
The <code>:commands:command:</code> role supports linking from other projects through the
intersphinx extension.</li>
</ul>
<p>Changes</p>
<ul>
<li>Previously, common headings such as <strong>Positional Arguments</strong> were subject to a
process that made them unique by adding a <code>_repeatX</code> suffix to the HREF target.
This release continues to support those HREF targets as secondary targets so that
bookmarks continue to work.
However, this release prefers using fully-qualified HREF targets like
<code>sample-directive-opts-positional-arguments</code> as the primary HREF so that customers
are less likely to witness the <code>_repeatX</code> link in URLs.</li>
<li><code>[#32](sphinx-doc/sphinx-argparse#32) &lt;https://github.com/sphinx-doc/sphinx-argparse/issues/32&gt;</code>__ Argparse commands are now part of a Sphinx domain</li>
<li><code>[#72](sphinx-doc/sphinx-argparse#72) &lt;https://github.com/sphinx-doc/sphinx-argparse/issues/72&gt;</code>__ Coloring in argparse output can be disabled (default)</li>
<li><code>[#87](sphinx-doc/sphinx-argparse#87) &lt;https://github.com/sphinx-doc/sphinx-argparse/issues/87&gt;</code>__ The <code>:filename:</code> input is now resolved only to the
<code>conf.py</code> directory (<code>srcdir</code> in Sphinx)</li>
<li><code>[#89](sphinx-doc/sphinx-argparse#89) &lt;https://github.com/sphinx-doc/sphinx-argparse/pull/89&gt;</code>__ Changed the way <code>mock</code> from <code>autodoc</code> is important to
work around a persistent Sphinx bug</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/sphinx-doc/sphinx-argparse/commit/f918d4ebde3cef185ddd362de2967126716842be"><code>f918d4e</code></a> Bumped version to 0.6.0</li>
<li><a href="https://github.com/sphinx-doc/sphinx-argparse/commit/9a74f452262db01bd969b7cb032cf1f91c07329b"><code>9a74f45</code></a> Updated changelog</li>
<li><a href="https://github.com/sphinx-doc/sphinx-argparse/commit/8959ab6e9350fcdff51ec5e8656d6cbac7306ccc"><code>8959ab6</code></a> Dropped Sphinx upper version limit</li>
<li><a href="https://github.com/sphinx-doc/sphinx-argparse/commit/034110391b1ff274bcad7042e3c8177b55684ab0"><code>0341103</code></a> Added try-catch for autodoc mock-import</li>
<li><a href="https://github.com/sphinx-doc/sphinx-argparse/commit/528aa981c86f07990392d23edfb2564546093f20"><code>528aa98</code></a> Fixed mypy warning from CI</li>
<li><a href="https://github.com/sphinx-doc/sphinx-argparse/commit/abd20c5b9ec1c6bb599354edcd2b6cf3839d248b"><code>abd20c5</code></a> Changed mypy python version to 3.13 + Fixed mypy in a test + Re-enabled mypy ...</li>
<li><a href="https://github.com/sphinx-doc/sphinx-argparse/commit/61b8bf0e2ffab20664acaba99e0f16e6f04e0ad0"><code>61b8bf0</code></a> Updated changelog</li>
<li><a href="https://github.com/sphinx-doc/sphinx-argparse/commit/de7c367545212653270c7195f6bea17e1406ce0e"><code>de7c367</code></a> Removed pass from OSerror</li>
<li><a href="https://github.com/sphinx-doc/sphinx-argparse/commit/00964a323bd96922c91a703badf9e8476e7436f0"><code>00964a3</code></a> Updated docs</li>
<li><a href="https://github.com/sphinx-doc/sphinx-argparse/commit/61365d08b88332860a2c92f0bd69b7be5856f6c8"><code>61365d0</code></a> Fixed tests through mock</li>
<li>Additional commits viewable in <a href="https://github.com/sphinx-doc/sphinx-argparse/compare/v0.5.2...v0.6.0">compare view</a></li>
</ul>
</details>
<br />

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=sphinx-argparse&package-manager=pip&previous-version=0.5.2&new-version=0.6.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)

</details>
inmantaci pushed a commit to inmanta/inmanta-core that referenced this pull request Jul 1, 2026
Bumps [sphinx-argparse](https://github.com/sphinx-doc/sphinx-argparse) from 0.5.2 to 0.6.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/sphinx-doc/sphinx-argparse/releases">sphinx-argparse's releases</a>.</em></p>
<blockquote>
<h2>Release v0.6.0</h2>
<h2>What's Changed</h2>
<ul>
<li>Added default feature to disable ArgumentParser coloring by <a href="https://github.com/RobertoRoos"><code>@​RobertoRoos</code></a> in <a href="https://redirect.github.com/sphinx-doc/sphinx-argparse/pull/74">sphinx-doc/sphinx-argparse#74</a></li>
<li>Trying to fix RTD refusing to build by <a href="https://github.com/RobertoRoos"><code>@​RobertoRoos</code></a> in <a href="https://redirect.github.com/sphinx-doc/sphinx-argparse/pull/77">sphinx-doc/sphinx-argparse#77</a></li>
<li>Moved color-disabling into <code>parse_parser</code> to fix subparsers by <a href="https://github.com/RobertoRoos"><code>@​RobertoRoos</code></a> in <a href="https://redirect.github.com/sphinx-doc/sphinx-argparse/pull/84">sphinx-doc/sphinx-argparse#84</a></li>
<li>Unpinned ruff for CI + Cleaned up workflow files a little by <a href="https://github.com/RobertoRoos"><code>@​RobertoRoos</code></a> in <a href="https://redirect.github.com/sphinx-doc/sphinx-argparse/pull/79">sphinx-doc/sphinx-argparse#79</a></li>
<li>Updated license metadata by <a href="https://github.com/RobertoRoos"><code>@​RobertoRoos</code></a> in <a href="https://redirect.github.com/sphinx-doc/sphinx-argparse/pull/81">sphinx-doc/sphinx-argparse#81</a></li>
<li>Changed filename field to be explicit by <a href="https://github.com/RobertoRoos"><code>@​RobertoRoos</code></a> in <a href="https://redirect.github.com/sphinx-doc/sphinx-argparse/pull/88">sphinx-doc/sphinx-argparse#88</a></li>
<li>Fixed MyPy by <a href="https://github.com/RobertoRoos"><code>@​RobertoRoos</code></a> in <a href="https://redirect.github.com/sphinx-doc/sphinx-argparse/pull/90">sphinx-doc/sphinx-argparse#90</a></li>
<li>Added try-catch for autodoc mock-import by <a href="https://github.com/RobertoRoos"><code>@​RobertoRoos</code></a> in <a href="https://redirect.github.com/sphinx-doc/sphinx-argparse/pull/89">sphinx-doc/sphinx-argparse#89</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a href="https://github.com/sphinx-doc/sphinx-argparse/compare/v0.5.2...v0.6.0">https://github.com/sphinx-doc/sphinx-argparse/compare/v0.5.2...v0.6.0</a></p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/sphinx-doc/sphinx-argparse/blob/main/docs/changelog.rst">sphinx-argparse's changelog</a>.</em></p>
<blockquote>
<p>0.6.0</p>
<h5></h5>
<p>The following enhancements to the HTML output are described on the :doc:<code>usage</code> page.</p>
<ul>
<li>Optional command index.</li>
<li>Optional <code>:index-groups:</code> field to the directive for an command-by-group index.</li>
<li>A <code>sphinxarg_full_subcommand_name</code> option to print fully-qualified sub-command headings.
This option helps when more than one sub-command offers a <code>create</code> or <code>list</code> or other
repeated sub-command.</li>
<li>Each command heading is a domain-specific link target.
You can link to commands and sub-commands with the <code>:ref:</code> role, but this
release adds support for the domain-specific role like
<code>:commands:command:`sample-directive-opts A` </code>.
The <code>:commands:command:</code> role supports linking from other projects through the
intersphinx extension.</li>
</ul>
<p>Changes</p>
<ul>
<li>Previously, common headings such as <strong>Positional Arguments</strong> were subject to a
process that made them unique by adding a <code>_repeatX</code> suffix to the HREF target.
This release continues to support those HREF targets as secondary targets so that
bookmarks continue to work.
However, this release prefers using fully-qualified HREF targets like
<code>sample-directive-opts-positional-arguments</code> as the primary HREF so that customers
are less likely to witness the <code>_repeatX</code> link in URLs.</li>
<li><code>[#32](sphinx-doc/sphinx-argparse#32) &lt;https://github.com/sphinx-doc/sphinx-argparse/issues/32&gt;</code>__ Argparse commands are now part of a Sphinx domain</li>
<li><code>[#72](sphinx-doc/sphinx-argparse#72) &lt;https://github.com/sphinx-doc/sphinx-argparse/issues/72&gt;</code>__ Coloring in argparse output can be disabled (default)</li>
<li><code>[#87](sphinx-doc/sphinx-argparse#87) &lt;https://github.com/sphinx-doc/sphinx-argparse/issues/87&gt;</code>__ The <code>:filename:</code> input is now resolved only to the
<code>conf.py</code> directory (<code>srcdir</code> in Sphinx)</li>
<li><code>[#89](sphinx-doc/sphinx-argparse#89) &lt;https://github.com/sphinx-doc/sphinx-argparse/pull/89&gt;</code>__ Changed the way <code>mock</code> from <code>autodoc</code> is important to
work around a persistent Sphinx bug</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/sphinx-doc/sphinx-argparse/commit/f918d4ebde3cef185ddd362de2967126716842be"><code>f918d4e</code></a> Bumped version to 0.6.0</li>
<li><a href="https://github.com/sphinx-doc/sphinx-argparse/commit/9a74f452262db01bd969b7cb032cf1f91c07329b"><code>9a74f45</code></a> Updated changelog</li>
<li><a href="https://github.com/sphinx-doc/sphinx-argparse/commit/8959ab6e9350fcdff51ec5e8656d6cbac7306ccc"><code>8959ab6</code></a> Dropped Sphinx upper version limit</li>
<li><a href="https://github.com/sphinx-doc/sphinx-argparse/commit/034110391b1ff274bcad7042e3c8177b55684ab0"><code>0341103</code></a> Added try-catch for autodoc mock-import</li>
<li><a href="https://github.com/sphinx-doc/sphinx-argparse/commit/528aa981c86f07990392d23edfb2564546093f20"><code>528aa98</code></a> Fixed mypy warning from CI</li>
<li><a href="https://github.com/sphinx-doc/sphinx-argparse/commit/abd20c5b9ec1c6bb599354edcd2b6cf3839d248b"><code>abd20c5</code></a> Changed mypy python version to 3.13 + Fixed mypy in a test + Re-enabled mypy ...</li>
<li><a href="https://github.com/sphinx-doc/sphinx-argparse/commit/61b8bf0e2ffab20664acaba99e0f16e6f04e0ad0"><code>61b8bf0</code></a> Updated changelog</li>
<li><a href="https://github.com/sphinx-doc/sphinx-argparse/commit/de7c367545212653270c7195f6bea17e1406ce0e"><code>de7c367</code></a> Removed pass from OSerror</li>
<li><a href="https://github.com/sphinx-doc/sphinx-argparse/commit/00964a323bd96922c91a703badf9e8476e7436f0"><code>00964a3</code></a> Updated docs</li>
<li><a href="https://github.com/sphinx-doc/sphinx-argparse/commit/61365d08b88332860a2c92f0bd69b7be5856f6c8"><code>61365d0</code></a> Fixed tests through mock</li>
<li>Additional commits viewable in <a href="https://github.com/sphinx-doc/sphinx-argparse/compare/v0.5.2...v0.6.0">compare view</a></li>
</ul>
</details>
<br />

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=sphinx-argparse&package-manager=pip&previous-version=0.5.2&new-version=0.6.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)

</details>
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