From 4c95f5a3e1b96c15f46e582921443dbbb5c113a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dieter=20Werthm=C3=BCller?= Date: Sat, 23 Jul 2022 16:14:53 +0200 Subject: [PATCH] Introduce a compact layout for ncol=1 (#89) Co-authored-by: Alex Kaszynski --- scooby/report.py | 49 ++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/scooby/report.py b/scooby/report.py index 3e05d42..7f8968e 100644 --- a/scooby/report.py +++ b/scooby/report.py @@ -161,20 +161,23 @@ class Report(PlatformInfo, PythonInfo): optional : list(ModuleType), list(str) A list of packages to list if they are available. If not available, no warnings or error will be thrown. - Defaults to ['numpy', 'scipy', 'IPython', 'matplotlib', 'scooby'] + Defaults to ``['numpy', 'scipy', 'IPython', 'matplotlib', 'scooby']`` ncol : int, optional Number of package-columns in html table (no effect in text-version); Defaults to 3. text_width : int, optional - The text width for non-HTML display modes + The text width for non-HTML display modes. sort : bool, optional - Sort the packages when the report is shown + Sort the packages when the report is shown. - extra_meta : tuple(str, str) - Additional two component pairs of meta information to display + extra_meta : tuple(str, str), optional + Additional two component pairs of meta information to display. + + max_width : int, optional + Max-width of html-table. By default None. """ @@ -187,6 +190,7 @@ def __init__( text_width=80, sort=False, extra_meta=None, + max_width=None, ): """Initialize report.""" # Set default optional packages to investigate @@ -196,6 +200,7 @@ def __init__( PythonInfo.__init__(self, additional=additional, core=core, optional=optional, sort=sort) self.ncol = int(ncol) self.text_width = int(text_width) + self.max_width = max_width if extra_meta is not None: if not isinstance(extra_meta, (list, tuple)): @@ -229,7 +234,7 @@ def __repr__(self): else: row_width = 18 - # ########## Platform/OS details ############ + # Platform/OS details repr_dict = self.to_dict() for key in ['OS', 'CPU(s)', 'Machine', 'Architecture', 'RAM', 'Environment', 'File system']: if key in repr_dict: @@ -237,7 +242,7 @@ def __repr__(self): for key, value in self._extra_meta: text += f'{key:>{row_width}} : {value}\n' - # ########## Python details ############ + # Python details text += '\n' for txt in textwrap.wrap('Python ' + self.sys_version, self.text_width - 4): text += ' ' + txt + '\n' @@ -248,13 +253,13 @@ def __repr__(self): for name, version in self._packages.items(): text += f'{name:>{row_width}} : {version}\n' - # ########## MKL details ############ + # MKL details if MKL_INFO: text += '\n' for txt in textwrap.wrap(MKL_INFO, self.text_width - 4): text += ' ' + txt + '\n' - # ########## Finish ############ + # Finish text += self.text_width * '-' return text @@ -267,11 +272,15 @@ def _repr_html_(self): def colspan(html, txt, ncol, nrow): r"""Print txt in a row spanning whole table.""" html += " \n" - html += " %s\n" % txt + html += f"{2 * ncol}'>{txt}\n" html += " \n" return html @@ -282,7 +291,8 @@ def cols(html, version, name, ncol, i): html += " \n" html += " \n" - html += " %s\n" % name html += " \n" + html = "\n" # Date and time info as title html = colspan(html, self.date, self.ncol, 0) - # ########## Platform/OS details ############ + # Platform/OS details html += " \n" repr_dict = self.to_dict() i = 0 @@ -308,10 +321,10 @@ def cols(html, version, name, ncol, i): # Finish row html += " \n" - # ########## Python details ############ + # Python details html = colspan(html, 'Python ' + self.sys_version, self.ncol, 1) - html += " \n" + # Loop over packages i = 0 # Reset count for rows. for name, version in self.packages.items(): @@ -324,11 +337,11 @@ def cols(html, version, name, ncol, i): # Finish row html += " \n" - # ########## MKL details ############ + # MKL details if MKL_INFO: html = colspan(html, MKL_INFO, self.ncol, 2) - # ########## Finish ############ + # Finish html += "
" return html