Skip to content

Commit d7e5cbf

Browse files
rtobarcmaureir
andauthored
Ejecuta configuración de Sphinx de CPython de forma correcta (#3425)
Si bien la forma en que se ejecutaba e importaban la configuración de Sphinx de CPython funciona, no es la mejor manera de hacerlo. Esto dado que Sphinx inyecta algunos nombres globales al cual pueden acceder los archivos conf.py, y que nuestro método no toma en cuenta. Este commit cambia la forma en que se importa y ejecuta el archivo conf.py de la documentación de CPython. En vez de añadirlo al path e importarlo via "import" ahora se compilan los contenidos del archivo, y se ejecutan directamente con eval(). A este último se le entrega como contexto el diccionario globals(), con lo que se logra el objetivo de que éste sea modificado por el código siendo ejecutado. Asimismo el uso de globals() también logra hacer llegar cualquier valor que Sphinx haya inyectado en nuestro conf.py al conf.py de CPython. --------- Signed-off-by: Rodrigo Tobar <[email protected]> Co-authored-by: Cristián Maureira-Fredes <[email protected]>
1 parent b9de17d commit d7e5cbf

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

conf.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
2121
sys.path.append(os.path.abspath('cpython/Doc/tools/extensions'))
2222
sys.path.append(os.path.abspath('cpython/Doc/includes'))
2323

24-
# Import all the Sphinx settings from cpython
25-
# This import will trigger warnings on the 'Include/patchlevel.h'
26-
# not being found, because it execute the content of the whole file,
27-
# and there there is a local call to 'get_header_version' like the one
28-
# we have in a few lines.
29-
sys.path.insert(0, os.path.abspath('cpython/Doc'))
30-
from conf import *
24+
# Import all the Sphinx settings from cpython.
25+
# Warning: calling 'eval' and 'compile' is usually not recommended, but in this case
26+
# we are relying on the official sphinx configuration from cpython.
27+
cpython_sphinx_conf = Path(os.path.abspath('cpython/Doc/conf.py'))
28+
eval(compile(cpython_sphinx_conf.read_bytes(), str(cpython_sphinx_conf), "exec"), globals())
3129

3230
project = 'Python en Español'
3331

0 commit comments

Comments
 (0)