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

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
xadupre committed Jul 20, 2022
1 parent 8edd7fb commit 71136bd
Show file tree
Hide file tree
Showing 22 changed files with 52 additions and 34 deletions.
3 changes: 2 additions & 1 deletion _unittests/ut_helpgen/test_missing_function_helpgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def test_nb_image(self):
r = NbImage("completion.png")
self.assertTrue(r is not None)
self.assertRaise(lambda: NbImage("_completion.png"), FileNotFoundError)
self.assertRaise(lambda: _NbImage("_completion.png"), FileNotFoundError)
self.assertRaise(lambda: _NbImage(
"_completion.png"), FileNotFoundError)
r = _NbImage("completion.png")
self.assertTrue(r is not None)

Expand Down
6 changes: 4 additions & 2 deletions src/pyquickhelper/benchhelper/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,16 @@ def run(self, params_list):
def cache_():
"local function"
if self._cache_file is not None and os.path.exists(self._cache_file):
self.fLOG(f"[BenchMark.run] retrieve cache '{self._cache_file}'")
self.fLOG(
f"[BenchMark.run] retrieve cache '{self._cache_file}'")
with open(self._cache_file, "rb") as f:
cached.update(self._pickle.load(f))
self.fLOG("[BenchMark.run] number of cached run: {0}".format(
len(cached["params_list"])))
else:
if self._cache_file is not None:
self.fLOG(f"[BenchMark.run] cache not found '{self._cache_file}'")
self.fLOG(
f"[BenchMark.run] cache not found '{self._cache_file}'")
cached.update(dict(metrics=[], appendix=[], params_list=[]))
self.uncache(cached)

Expand Down
6 changes: 3 additions & 3 deletions src/pyquickhelper/filehelper/visual_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ def cleanh(s):

vars = [f"var tview={1 if inline_view else 0};",
f"var csize='{'' if context_size is None else context_size}';",
"var bt = '{0}';".format(
string1.replace("\n", "\\n").replace("'", "\\'")),
"var nt = '{0}';".format(string2.replace("\n", "\\n").replace("'", "\\'"))]
"var bt = '{0}';".format(
string1.replace("\n", "\\n").replace("'", "\\'")),
"var nt = '{0}';".format(string2.replace("\n", "\\n").replace("'", "\\'"))]
vars = "\n".join(vars)

data = js_page_nb.replace("__ID__", did) \
Expand Down
3 changes: 2 additions & 1 deletion src/pyquickhelper/helpgen/process_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,8 @@ def build_thumbail_in_gallery(nbfile, folder_snippet, relative, rst_link, layout
if custom_snippet is not None and os.path.exists(custom_snippet):
# reading a custom snippet
if fLOG:
fLOG(f"[build_thumbail_in_gallery] custom snippet '{custom_snippet}'")
fLOG(
f"[build_thumbail_in_gallery] custom snippet '{custom_snippet}'")
try:
from PIL import Image
except ImportError: # pragma: no cover
Expand Down
3 changes: 2 additions & 1 deletion src/pyquickhelper/helpgen/sphinx_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def post_process_html_nb_output_static_file(build, fLOG=noLOG):
for k, v in repl.items():
if k in content:
if fLOG:
fLOG(f"[post_process_html_output] js: replace {k!r} -> {v!r}")
fLOG(
f"[post_process_html_output] js: replace {k!r} -> {v!r}")
content = content.replace(k, v)
modif = True

Expand Down
12 changes: 8 additions & 4 deletions src/pyquickhelper/helpgen/sphinx_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,8 @@ def lay_build_override_newconf(t3):
dest_doc = os.path.join(root, "_doc", "sphinxdoc", "source")
fLOG(f"[generate_help_sphinx] module_name='{module_name}'")
fLOG(f"[generate_help_sphinx] project_var_name='{project_var_name}'")
fLOG(f"[generate_help_sphinx] root='{root}' root_package='{root_package}'")
fLOG(
f"[generate_help_sphinx] root='{root}' root_package='{root_package}'")
fLOG(f"[generate_help_sphinx] dest_doc='{dest_doc}'")
subfolders = []
if root_package.endswith("src"):
Expand Down Expand Up @@ -927,7 +928,8 @@ def customfLOG(*args, **kwargs):
_ for _ in lines if "toctree contains reference to document 'blog/" not in _]
out = "\n".join(lines)

fLOG(f"[generate_help_sphinx] end cmd len(out)={len(out)} len(err)={len(err)}")
fLOG(
f"[generate_help_sphinx] end cmd len(out)={len(out)} len(err)={len(err)}")

if len(err) > 0 or len(out) > 0:
if ((len(err) > 0 and "Exception occurred:" in err) or
Expand Down Expand Up @@ -983,7 +985,8 @@ def keep_line(_): # pragma: no cover
# we should not need that
for build_path in build_paths:
if not os.path.exists(build_path):
fLOG(f"[generate_help_sphinx] build_path not found '{build_path}'")
fLOG(
f"[generate_help_sphinx] build_path not found '{build_path}'")
continue
dest = os.path.join(build_path, "_static", style_figure_notebook[0])
if not os.path.exists(dest): # pragma: no cover
Expand Down Expand Up @@ -1017,7 +1020,8 @@ def keep_line(_): # pragma: no cover
if os.path.exists(dest):
shutil.copy(toco, dest)
else:
fLOG(f"[generate_help_sphinx] not found '{os.path.split(toco)[-1]}'")
fLOG(
f"[generate_help_sphinx] not found '{os.path.split(toco)[-1]}'")

fLOG("---- JENKINS END COPY RSS.XML ----")

Expand Down
2 changes: 1 addition & 1 deletion src/pyquickhelper/helpgen/sphinxm_mock_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def add_source_parser(self, ext, parser, exc=False):
if exc:
raise
logger = logging.getLogger("MockSphinxApp")
logger.warning(f'[MockSphinxApp] {e}')
logger.warning('[MockSphinxApp] %s', e)

def disconnect_env_collector(self, clname):
"""
Expand Down
3 changes: 2 additions & 1 deletion src/pyquickhelper/helpgen/utils_sphinx_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,8 @@ def prepare_file_for_sphinx_help_generation(store_obj, input, output,
fLOG=fLOG)
rsts += rstadd
else:
fLOG(f"[prepare_file_for_sphinx_help_generation] processing '{src}'")
fLOG(
f"[prepare_file_for_sphinx_help_generation] processing '{src}'")

actions_t = copy_source_files(src, dst, fmod_copy, silent=silent,
softfile=softfile, fexclude=fexclude,
Expand Down
3 changes: 2 additions & 1 deletion src/pyquickhelper/helpgen/utils_sphinx_doc_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,8 @@ def import_module(rootm, filename, log_function, additional_sys_path=None,
filename, mo.__file__, "\n - ".join(sys.path)))

sys.path = memo
log_function(f"[import_module] import '{filename}' successfully", mo.__file__)
log_function(
f"[import_module] import '{filename}' successfully", mo.__file__)
for n, m in addback:
if n not in sys.modules:
sys.modules[n] = m
Expand Down
3 changes: 2 additions & 1 deletion src/pyquickhelper/ipythonhelper/unittest_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def test_notebook_example_pyquickhelper(self):
if not os.path.exists(dest_dir):
os.mkdir(dest_dir) # pragma: no cover
src_file = os.path.join(doc, name_)
fLOG(f"[a_test_notebook_runner] copy '{src_file}' to '{dest_dir}'.")
fLOG(
f"[a_test_notebook_runner] copy '{src_file}' to '{dest_dir}'.")
shutil.copy(src_file, dest_dir)

if 'pyquickhelper' in this_module_name:
Expand Down
3 changes: 2 additions & 1 deletion src/pyquickhelper/jenkinshelper/jenkins_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,8 @@ def _setup_jenkins_server_job_iteration(self, job, get_jenkins_script, location,
done[name] = (aj, name, var)
loc = None if location is None else os.path.join(
location, name)
self.fLOG(f"[jenkins] adding i={len(created)}: '{name}' var='{var}'")
self.fLOG(
f"[jenkins] adding i={len(created)}: '{name}' var='{var}'")
created.append((job, name, loc, job, aj))

indexes["order"] = order
Expand Down
6 changes: 4 additions & 2 deletions src/pyquickhelper/loghelper/time_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ def repeat_execution(fct, every_second=1, stop_after_second=5,
if exc:
r = fct()
if verbose > 0 and fLOG is not None:
fLOG(f"[repeat_execution] iter={iter} time={current} end={end}")
fLOG(
f"[repeat_execution] iter={iter} time={current} end={end}")
if stop_after_second is not None:
res.append(r)
else:
try:
r = fct()
if verbose > 0 and fLOG is not None:
fLOG(f"[repeat_execution] iter={iter} time={current} end={end}")
fLOG(
f"[repeat_execution] iter={iter} time={current} end={end}")
if stop_after_second is not None:
res.append(r)
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion src/pyquickhelper/pandashelper/tblformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def df2html(self, class_table=None, class_td=None, class_tr=None,

rows = [f"<table{clta}>"]
rows.append(f"<tr{cltr}><th{clth}>" + ("</th><th%s>" %
clth).join(self.columns) + "</th></tr>")
clth).join(self.columns) + "</th></tr>")
septd = f"</td><td{cltd}>"
strtd = f"<tr{cltr}><td{cltd}>"

Expand Down
3 changes: 2 additions & 1 deletion src/pyquickhelper/pycode/tkinter_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ def look_for(where, prefix): # pragma: no cover
if "DISPLAY" not in os.environ:
p = ":0"
if fLOG:
fLOG(f"Change DISPLAY: '{os.environ.get('DISPLAY', None)}' --> '{p}'")
fLOG(
f"Change DISPLAY: '{os.environ.get('DISPLAY', None)}' --> '{p}'")
os.environ["DISPLAY"] = p
else:
# if "DISPLAY" not in os.environ:
Expand Down
3 changes: 2 additions & 1 deletion src/pyquickhelper/pycode/unittestclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,8 @@ def assert_almost_equal_detailed(expected, value, **kwargs):
assert_almost_equal(r1, r2, **kwargs)
except AssertionError as ee:
rows.append('----------------------')
rows.append(f"ISSUE WITH ROW {i}/{expected.shape[0]}:0 {str(ee)}")
rows.append(
f"ISSUE WITH ROW {i}/{expected.shape[0]}:0 {str(ee)}")
if len(rows) > 10:
break # pragma: no cover
raise AssertionError("\n".join(rows))
4 changes: 2 additions & 2 deletions src/pyquickhelper/sphinxext/_sphinx_common_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def base_visit_image(self, node, image_dest=None):
repl = os.path.join(
this, "sphinximages", "sphinxtrib", "missing.png")
logger = logging.getLogger("image")
logger.warning(
f"[image] unable to find image '{full}', replaced by '{repl}'")
logger.warning("[image] unable to find image %r, replaced by %r.",
full, repl)
full = repl

ext = os.path.splitext(full)[-1]
Expand Down
2 changes: 1 addition & 1 deletion src/pyquickhelper/sphinxext/sphinx_collapse_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def run(self):
if '/' not in legend:
logger = logging.getLogger("sphinx")
logger.warning(
f"[CollapseDirective] unable to interpret parameter legend '{legend}'")
"[CollapseDirective] unable to interpret parameter legend %r.", legend)
legend = None
spl = legend.split('/')
hide = spl[0].strip()
Expand Down
2 changes: 1 addition & 1 deletion src/pyquickhelper/sphinxext/sphinx_gdot_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def run(self):
if docname is None or 'HERE' not in info:
url = GDotDirective._default_url
logger = logging.getLogger("gdot")
logger.warning(f"[gdot] docname is none, falling back to '{url}'")
logger.warning("[gdot] docname is none, falling back to %r.", url)
else:
spl = docname.split("/")
sp = ['..'] * (len(spl) - 1) + ['_static', 'viz.js']
Expand Down
3 changes: 2 additions & 1 deletion src/pyquickhelper/sphinxext/sphinx_latex_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def __init__(self, document, builder, theme=None):
LaTeXTranslator.__init__(self, document, builder, theme=theme)
except TypeError:
# Sphinx<5
LaTeXTranslator.__init__(self, document, builder) # pylint: disable=E1120
LaTeXTranslator.__init__(
self, document, builder) # pylint: disable=E1120

newlines = builder.config.text_newlines
if newlines == 'windows':
Expand Down
3 changes: 2 additions & 1 deletion src/pyquickhelper/sphinxext/sphinx_rst_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,8 @@ def clean_refuri(uri):
else:
self.log_unknown(type(node), node)
elif 'internal' not in node and 'name' in node.attributes:
self.add_text(f"`{node['name']} <{clean_refuri(node['refuri'])}>`_")
self.add_text(
f"`{node['name']} <{clean_refuri(node['refuri'])}>`_")
elif 'internal' not in node and 'names' in node.attributes:
anchor = node['names'][0] if len(
node['names']) > 0 else node['refuri']
Expand Down
1 change: 0 additions & 1 deletion src/pyquickhelper/sphinxext/sphinx_toctree_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ class CustomTocTreeCollector(TocTreeCollector):
def enable(self, app):
# It needs to disable TocTreeCollector.
app.disconnect_env_collector("TocTreeCollector", exc=False)
assert self.listener_ids is None
self.listener_ids = {
'doctree-read': app.connect('doctree-read', self.process_doc),
'env-merge-info': app.connect('env-merge-info', self.merge_other),
Expand Down
10 changes: 5 additions & 5 deletions src/pyquickhelper/sphinxext/sphinximages/sphinxtrib/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def get_image_extension(uri):
if ('?' + ext[1:]) in uri:
return ext
logger = logging.getLogger('image')
logger.warning(f"[image] unable to guess extension for '{uri}'")
logger.warning("[image] unable to guess extension for %r.", uri)
return ''


Expand Down Expand Up @@ -160,7 +160,7 @@ def run(self):
self.arguments[0] = repl
is_remote = self.is_remote(self.arguments[0])
logger = logging.getLogger('image')
logger.warning(f"[image] {e}, replaced by '{repl}'")
logger.warning("[image] %r, replaced by %r", e, repl)

if is_remote:
img['remote'] = True
Expand Down Expand Up @@ -283,16 +283,16 @@ def download_images(app, env):
ensuredir(dirn)
if not os.path.isfile(dst):

logger.info(f'{src} -> {dst} (downloading)')
logger.info('%r -> %r (downloading)', src, dst)
with open(dst, 'wb') as f:
# TODO: apply reuqests_kwargs
try:
f.write(requests.get(src,
**conf['requests_kwargs']).content)
except requests.ConnectionError:
logger.info(f"Cannot download `{src}`")
logger.info("Cannot download %r", src)
else:
logger.info(f'{src} -> {dst} (already in cache)')
logger.info('%r -> %r (already in cache)', src, dst)


def configure_backend(app):
Expand Down

0 comments on commit 71136bd

Please sign in to comment.