Skip to content

Commit dd626da

Browse files
committed
chore(numpydoc.py): use package-relative filename instead of absolute.
1 parent 8f61726 commit dd626da

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

numpydoc/numpydoc.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
"""
1919

2020
import hashlib
21+
import importlib
2122
import inspect
2223
import itertools
2324
import pydoc
2425
import re
2526
import sys
2627
from collections.abc import Callable
2728
from copy import deepcopy
29+
from pathlib import Path
2830

2931
from docutils.nodes import Text, citation, comment, inline, reference, section
3032
from sphinx.addnodes import desc_content, pending_xref
@@ -201,8 +203,23 @@ def mangle_docstrings(app: SphinxApp, what, name, obj, options, lines):
201203
excluder = app.config.numpydoc_validation_files_excluder
202204
module = inspect.getmodule(obj)
203205
try:
204-
path = module.__file__ if module else None
205-
except AttributeError:
206+
# Get the module relative path from the name
207+
if module:
208+
mod_path = Path(module.__file__)
209+
package_rel_path = mod_path.parent.relative_to(
210+
Path(
211+
importlib.import_module(
212+
module.__name__.split(".")[0]
213+
).__file__
214+
).parent
215+
).as_posix()
216+
module_file = mod_path.as_posix().replace(
217+
mod_path.parent.as_posix(), ""
218+
)
219+
path = package_rel_path + module_file
220+
else:
221+
path = None
222+
except AttributeError as e:
206223
path = None
207224

208225
if path and excluder and excluder.search(path):

0 commit comments

Comments
 (0)