Skip to content

Commit bab26e2

Browse files
committed
Ejecuta configuración de Sphinx de CPython de forma correcta
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]>
1 parent 589239e commit bab26e2

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

conf.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@
2222
sys.path.append(os.path.abspath('cpython/Doc/includes'))
2323

2424
# 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 *
25+
cpython_sphinx_conf = Path(os.path.abspath('cpython/Doc/conf.py'))
26+
eval(compile(cpython_sphinx_conf.read_bytes(), str(cpython_sphinx_conf), "exec"), globals())
3127

3228
project = 'Python en Español'
3329

0 commit comments

Comments
 (0)