Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
minor fixes for sphinx
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Mar 23, 2019
1 parent eb17089 commit 800e64d
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 23 deletions.
8 changes: 8 additions & 0 deletions _unittests/ut_loghelper/test_process_script.py
Expand Up @@ -71,6 +71,14 @@ def test_dummy_class(self):
st = str(cl)
self.assertEqual(st, "{'d1': 'e', 'r': 4}")

def test_dummy_class_drop(self):
cl = dictionary_as_class(dict(d1="e", r=4))
st = str(cl)
self.assertEqual(st, "{'d1': 'e', 'r': 4}")
cl = cl.drop("d1")
st = str(cl)
self.assertEqual(st, "{'r': 4}")

@skipif_appveyor("job stuck")
def test_run_script_popen(self):
temp = get_temp_folder(__file__, "temp_run_script_popen")
Expand Down
14 changes: 4 additions & 10 deletions src/pyquickhelper/helpgen/default_conf.py
Expand Up @@ -757,12 +757,7 @@ def modify_commit_function(nbch, date, author, comment):
'expected_failing_examples': [],
}

try:
import memory_profiler
sphinx_gallery_conf['show_memory'] = True
except ImportError as e:
warnings.warn(
"memory_profiler is not install, sphinx_gallery will not show memory consumption.")
sphinx_gallery_conf['show_memory'] = False
else:
skipset = {"sphinx_gallery.gen_gallery"}
extensions = [_ for _ in extensions if _ not in skipset]
Expand Down Expand Up @@ -831,9 +826,8 @@ def get_first_line(filename):

def _skip(app, what, name, obj, skip, options):
"""
to skip some functions,
see `Skipping members <http://sphinx-doc.org/ext/autodoc.html#event-autodoc-skip-member>`_
To skip some functions,
see `Skipping members <http://sphinx-doc.org/ext/autodoc.html#event-autodoc-skip-member>`_.
"""
if name.startswith("_") and name not in \
["__qualname__",
Expand Down Expand Up @@ -941,7 +935,7 @@ def custom_setup(app, author):

def get_default_stylesheet():
"""
Returns the style of additional style sheets
Returns the style of additional style sheets.
@return list of files
"""
Expand Down
2 changes: 1 addition & 1 deletion src/pyquickhelper/helpgen/install_js_dep.py
Expand Up @@ -50,6 +50,6 @@ def install_javascript_tools(root, dest, fLOG=noLOG,
if not os.path.exists(expected):
one = download_requirejs(dest, fLOG=fLOG)
else:
one = expected
one = [expected]
lfiles.extend(one)
return lfiles
13 changes: 7 additions & 6 deletions src/pyquickhelper/helpgen/sphinx_main.py
Expand Up @@ -423,10 +423,10 @@ def lay_build_override_newconf(t3):
if len(module_conf) == 0:
raise ImportError("No extracted local variable.")
theconf = dictionary_as_class(module_conf)
fLOG("[generate_help_sphinx] conf.__file__='{0}'".format(
os.path.abspath(theconf.__file__))) # pylint: disable=E1101
tocs = add_missing_files(root, theconf, "__INSERT__")
all_tocs.extend(tocs)
fLOG("[generate_help_sphinx] conf.__file__='{0}'".format(
os.path.abspath(theconf.__file__))) # pylint: disable=E1101
tocs = add_missing_files(root, theconf, "__INSERT__", fLOG)
all_tocs.extend(tocs)

##############################
# some checkings on the configuration
Expand Down Expand Up @@ -1251,9 +1251,10 @@ def _import_conf_extract_parameter(root, root_source, folds, build, newconf,
"Unable to import '{0}' which defines the help generation".format(newconf))
thenewconf = dictionary_as_class(module_conf)
if fLOG:
fLOG("[_import_conf_extract_parameter] import:", thenewconf)
fLOG("[_import_conf_extract_parameter] import:", thenewconf.drop(
"epkg_dictionary", "latex_elements", "imgmath_latex_preamble", "preamble"))

tocs = add_missing_files(root, thenewconf, "__INSERT__")
tocs = add_missing_files(root, thenewconf, "__INSERT__", fLOG)
all_tocs.extend(tocs)

# check if we need to run ie_layout_html
Expand Down
21 changes: 20 additions & 1 deletion src/pyquickhelper/helpgen/sphinx_main_missing_html_files.py
Expand Up @@ -3,10 +3,11 @@
@brief function around missing file for the documentation
"""
import os
import shutil
from ..texthelper.texts_language import TITLES


def add_missing_files(root, conf, blog_list):
def add_missing_files(root, conf, blog_list, fLOG):
"""
Adds missing files for the documentation,
``moduletoc.html``, ``blogtoc.html``, ``searchbox.html``.
Expand All @@ -16,6 +17,7 @@ def add_missing_files(root, conf, blog_list):
@param blog_list list of recent blog posts to add to the navigational bar (list)
or a name for a placeholder (such as ``__INSERT__``)
@param theme theme, missing files depend on it
@param fLOG logging function
@return list of modified files
The function considers the theme for the searchbox.
Expand Down Expand Up @@ -56,6 +58,8 @@ def add_missing_files(root, conf, blog_list):

# moduletoc.html
mt = os.path.join(loc, "moduletoc.html")
if fLOG:
fLOG("[add_missing_files] create '{}'".format(mt))
tocs.append(mt)
with open(mt, "w", encoding="utf8") as f:
f.write("\n<h3>{0}</h3>".format(TITLES[language]["toc0"]))
Expand Down Expand Up @@ -91,6 +95,8 @@ def add_missing_files(root, conf, blog_list):

# blogtoc.html
mt = os.path.join(loc, "blogtoc.html")
if fLOG:
fLOG("[add_missing_files] create '{}'".format(mt))
tocs.append(mt)
with open(mt, "w", encoding="utf8") as f:
f.write("""<a href="{{ pathto('',1) }}/genindex.html">Index</a>\n""")
Expand All @@ -108,6 +114,8 @@ def add_missing_files(root, conf, blog_list):
# searchbox.html
theme = conf.theme
mt = os.path.join(loc, "searchbox.html")
if fLOG:
fLOG("[add_missing_files] create '{}'".format(mt))
tocs.append(mt)
with open(mt, "w", encoding="utf8") as f:
if theme == "sphinx_rtd_theme":
Expand Down Expand Up @@ -154,6 +162,17 @@ def add_missing_files(root, conf, blog_list):
""".replace(" ", "")
f.write(text)

missings = ['layout.html', 'page.html']
import sphinx
themes = os.path.join(os.path.dirname(sphinx.__file__), "themes", "basic")
for mis in missings:
mt = os.path.join(loc, mis)
if not os.path.exists(mt):
sr = os.path.join(themes, mis)
if os.path.exists(sr):
if fLOG:
fLOG("[add_missing_files] create '{}'".format(mt))
shutil.copy(sr, loc)
return tocs


Expand Down
17 changes: 12 additions & 5 deletions src/pyquickhelper/loghelper/process_script.py
Expand Up @@ -138,17 +138,24 @@ def dictionary_as_class(dico):
@return class
"""
class dummy_class:
def __init__(self, dico):
for k, v in dico.items():
if not isinstance(k, str):
raise TypeError("Key '{}' must be a string.".format(k))
setattr(self, k, v)

def __str__(self):
data = {k: v for k, v in self.__dict__.items()
if not k.startswith("_")}
return pprint.pformat(data)

du = dummy_class()
def drop(self, *dr):
sdr = set(dr)
data = {k: v for k, v in self.__dict__.items()
if not k.startswith("_") and k not in sdr}
return dummy_class(data)

for k, v in dico.items():
if not isinstance(k, str):
raise TypeError("Key '{}' must be a string.".format(k))
setattr(du, k, v)
du = dummy_class(dico)
return du


Expand Down

0 comments on commit 800e64d

Please sign in to comment.