1.2.1: cannot build documentation without installing module

### Describe the bug

Looks like something is wrong and I cannot build docuemtation without installing module.


### Steps/Code to Reproduce

N/A

### Expected Results

It should be possible to build documentation out of only what is in source tree a d withoit have installed module.

### Actual Results

<details>

```console
++ ls -1d lib.linux-x86_64-cpython-38
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.1/build/lib.linux-x86_64-cpython-38
+ PBR_VERSION=1.2.1
+ PDM_PEP517_SCM_VERSION=1.2.1
+ SETUPTOOLS_SCM_PRETEND_VERSION=1.2.1
+ /usr/bin/sphinx-build -n -T -b man doc build/sphinx/man
Running Sphinx v6.1.3

Traceback (most recent call last):
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.1/sklearn/__check_build/__init__.py", line 48, in <module>
    from ._check_build import check_build  # noqa
ModuleNotFoundError: No module named 'sklearn.__check_build._check_build'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/sphinx/config.py", line 351, in eval_config_file
    exec(code, namespace)  # NoQA: S102
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.1/doc/conf.py", line 20, in <module>
    from sklearn.externals._packaging.version import parse
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.1/sklearn/__init__.py", line 81, in <module>
    from . import __check_build  # noqa: F401
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.1/sklearn/__check_build/__init__.py", line 50, in <module>
    raise_build_error(e)
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.1/sklearn/__check_build/__init__.py", line 31, in raise_build_error
    raise ImportError(
ImportError: No module named 'sklearn.__check_build._check_build'
___________________________________________________________________________
Contents of /home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.1/sklearn/__check_build:
__init__.py               _check_build.pyx          _check_build.c
__pycache__
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.

If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.

If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/sphinx/cmd/build.py", line 279, in build_main
    app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
  File "/usr/lib/python3.8/site-packages/sphinx/application.py", line 202, in __init__
    self.config = Config.read(self.confdir, confoverrides or {}, self.tags)
  File "/usr/lib/python3.8/site-packages/sphinx/config.py", line 173, in read
    namespace = eval_config_file(filename, tags)
  File "/usr/lib/python3.8/site-packages/sphinx/config.py", line 364, in eval_config_file
    raise ConfigError(msg % traceback.format_exc()) from exc
sphinx.errors.ConfigError: There is a programmable error in your configuration file:

Traceback (most recent call last):
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.1/sklearn/__check_build/__init__.py", line 48, in <module>
    from ._check_build import check_build  # noqa
ModuleNotFoundError: No module named 'sklearn.__check_build._check_build'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/sphinx/config.py", line 351, in eval_config_file
    exec(code, namespace)  # NoQA: S102
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.1/doc/conf.py", line 20, in <module>
    from sklearn.externals._packaging.version import parse
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.1/sklearn/__init__.py", line 81, in <module>
    from . import __check_build  # noqa: F401
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.1/sklearn/__check_build/__init__.py", line 50, in <module>
    raise_build_error(e)
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.1/sklearn/__check_build/__init__.py", line 31, in raise_build_error
    raise ImportError(
ImportError: No module named 'sklearn.__check_build._check_build'
___________________________________________________________________________
Contents of /home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.1/sklearn/__check_build:
__init__.py               _check_build.pyx          _check_build.c
__pycache__
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.

If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.

If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.


Configuration error:
There is a programmable error in your configuration file:

Traceback (most recent call last):
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.1/sklearn/__check_build/__init__.py", line 48, in <module>
    from ._check_build import check_build  # noqa
ModuleNotFoundError: No module named 'sklearn.__check_build._check_build'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/sphinx/config.py", line 351, in eval_config_file
    exec(code, namespace)  # NoQA: S102
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.1/doc/conf.py", line 20, in <module>
    from sklearn.externals._packaging.version import parse
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.1/sklearn/__init__.py", line 81, in <module>
    from . import __check_build  # noqa: F401
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.1/sklearn/__check_build/__init__.py", line 50, in <module>
    raise_build_error(e)
  File "/home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.1/sklearn/__check_build/__init__.py", line 31, in raise_build_error
    raise ImportError(
ImportError: No module named 'sklearn.__check_build._check_build'
___________________________________________________________________________
Contents of /home/tkloczko/rpmbuild/BUILD/scikit-learn-1.2.1/sklearn/__check_build:
__init__.py               _check_build.pyx          _check_build.c
__pycache__
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.

If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.

If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.
```
</details>

### Versions

```shell
1.2.1
```

COMMENT:
> From what I've seen, numerical Python libraries, such as [NumPy's docs](https://numpy.org/doc/stable/dev/howto_build_docs.html#prerequisites) and [SciPy's docs](https://docs.scipy.org/doc/scipy/dev/contributor/rendering_documentation.html#rendering-documentation-locally-with-sphinx), require the library to be built and installed before building the documentation.

You are 100% right in case of `numpy` .. but it is only part of the whole picture.
To build `numpy` documentation you need  to have installed `numpydoc`. That module requires `mathplot` and that module requires `numpy`.
In other words if you want ot have consistent build env to build `numpy` documentation you must have installed some version of the `numpy` (not exactly the same which is build).
However .. to prevent build that documentation against installed `numpy` (not that one which you have currently in source tree)
it needs to be added `PYTHONPATH=$PWD/build/$(cd build; ls -d1 lib*)` to sphinx-build execution env to hint python to take that `numpy` version first from that location.
Just checked my python-numpy.spec file and here what I have in that file
```spec
BuildRequires:  flexiblas-devel
BuildRequires:  gcc
BuildRequires:  gcc-c++
BuildRequires:  gcc-gfortran
BuildRequires:  lapack-devel
BuildRequires:  python3-devel
BuildRequires:  python3dist(build)
BuildRequires:  python3dist(cython)     >= 0.29.24
BuildRequires:  python3dist(installer)
BuildRequires:  python3dist(ipython)
BuildRequires:  python3dist(setuptools) >= 59.2
BuildRequires:  python3dist(matplotlib)
%{?with_loopy_deps:
BuildRequires:  python3dist(numpydoc)
BuildRequires:  python3dist(scipy)
BuildRequires:  python3dist(pydata-sphinx-theme)
BuildRequires:  python3dist(sphinx)
BuildRequires:  python3dist(sphinx-design)
BuildRequires:  python3dist(sphinxcontrib-restbuilder)
BuildRequires:  python3dist(sphinx-panels)}
BuildRequires:  python3dist(wheel)

[..]

%build
%{set_build_flags} \
BLAS=%{_libdir} \
LAPACK=%{_libdir} \
OPENBLAS=%{_libdir} \
SETUPTOOLS_USE_DISTUTILS=stdlib \
%pyproject_wheel
%{?with_loopy_deps:
PYTHONPATH=$PWD/build/$(cd build; ls -d1 lib*) \
%sphinx_build_man doc/source}
```
To boostrap `numpy` as you see I have special build mode which (without loopy_deps) which allows skip building documentation. That boostraping affects as wll list of BuildRequires.

On building `scipy` none of that module build dependencies requires `scipy` so in this case you don't need to have installed `scipy` to build documentation and that trick with:
```spec
PYTHONPATH=$PWD/build/$(cd build; ls -d1 lib*) \
%sphinx_build_man doc/source}
```
it is all what is necessary to build that module documentation.
Additionally there is no any problems with loading DSOs of that module from $PYTHONPATH because ..
```console
[tkloczko@pers-jacek SPECS]$ grep -r "from  \."; grep -r "import \."| grep -v /doc/
[tkloczko@pers-jacek SPECS]$
[tkloczko@pers-jacek scipy-1.11.1]$ grep -r "from  \."; grep -r "import \."| grep -v /doc/
doc/source/release/1.5.0-notes.rst:* `#11623 <https://github.com/scipy/scipy/pull/11623>`__: MAINT: Remove unnecessary 'from __future__ import ...' statements
doc/source/release/1.5.0-notes.rst:* `#11646 <https://github.com/scipy/scipy/pull/11646>`__: MAINT: Remove unnecessary 'from __future__ import ...' statements
scipy/_lib/boost_math/build/Jamfile.v2:import ../../config/checks/config : requires ;
scipy/_lib/boost_math/example/Jamfile.v2:import ../../config/checks/config : requires ;
scipy/_lib/boost_math/reporting/accuracy/Jamfile.v2:import ../../../config/checks/config : requires ;
scipy/_lib/boost_math/reporting/performance/Jamfile.v2:import ../../../config/checks/config : requires ;
scipy/_lib/boost_math/reporting/performance/Jamfile.v2:import ../../../predef/check/predef
scipy/_lib/boost_math/test/Jamfile.v2:import ../../config/checks/config : requires ;
scipy/_lib/boost_math/tools/Jamfile.v2:import ../../config/checks/config : requires ;
scipy/fftpack/tests/test_import.py:the form `from scipy.fftpack import ...`, so that a simple replacement
scipy/fftpack/tests/test_import.py:        regexp = r"\s*from.+\.fftpack import .*\n"
scipy/linalg/_generate_pyx.py:# cimport ..linalg.cython_blas as cython_blas
scipy/linalg/_generate_pyx.py:# cimport ..linalg.cython_lapack as cython_lapack
scipy/linalg/_generate_pyx.py:# cimport ..linalg.cython_blas as cython_blas
scipy/linalg/_generate_pyx.py:# cimport ..linalg.cython_lapack as cython_lapack
scipy/linalg/_matfuncs.py:    # Avoid circular import ... this is OK, right?
```
If you will look on above closer you will find that actually there is no here relative imports.

From that ponit of view `scikit-learn` has no properties like `numpy` and its documentation can be build without have that module installed.

It is yet another aspect of using relative imports.
Theoretically in case `import  .foo` it replaces `import sklearn.foo` which is 7 bytes shorter in source code however in this case it must be made another call to python routine which takes current directory (and additional OS syscall to take that path) and that string needs to be concatenated with `foo` to produce from path from which module or its code (.pyc/.pyo files) needs to be loaded.
I'm sure that it causes that actual JIT code is by this longer and additionally it causes additional syscall to take current directory path.
In other words using relative imports is only apparently better.

I have already packaged
```console
[tkloczko@pers-jacek SPECS]$ ls -l python-*spec|wc -l
1170
```
python modules as rpm packages. I can tell you that using in the code relative imports was one of the top 5 cause of some issues found on packaging especially on testing stage in case of modules with DSOs.
This is why **IMO** using relative imports saves nothing and is nothing more than kind of just asking for troubles 😋

Labels: Bug, Documentation, Needs Decision - Include Feature