Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Features added
* #9445: autodoc: Support class properties
* #9445: py domain: ``:py:property:`` directive supports ``:classmethod:``
option to describe the class property
* #9378: setuptools: Add the build directory to sys.path automatically if
``build_sphinx`` command is invoked after ``build`` command

Bugs fixed
----------
Expand Down
9 changes: 9 additions & 0 deletions sphinx/setup_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ def run(self) -> None:
if self.nitpicky:
confoverrides['nitpicky'] = self.nitpicky

self.setup_syspath()

for builder, builder_target_dir in self.builder_target_dirs:
app = None

Expand Down Expand Up @@ -187,3 +189,10 @@ def run(self) -> None:
src = app.config.root_doc + app.builder.out_suffix # type: ignore
dst = app.builder.get_outfilename('index') # type: ignore
os.symlink(src, dst)

def setup_syspath(self) -> None:
"""Set up sys.path to import target modules from the build directory."""
build = self.distribution.command_obj.get('build') # type: ignore
build_lib = getattr(build, 'build_lib', None)
if build_lib and os.path.exists(build_lib) and build_lib not in sys.path:
sys.path.append(build_lib)