banesullivan / scooby

🐶 🕵️ Great Dane turned Python environment detective
MIT License
47 stars 12 forks source link

Fix bug for empty package list #87

Closed prisae closed 2 years ago

prisae commented 2 years ago

Currently, the Report() fails if there is an empty package list, which you get if you call

import scooby
scooby.Report(optional=[])

This PR fixes this, so it works just nicely (it always worked with the _repr_html, there was no issue there).

Example output (with the fix):

--------------------------------------------------------------------------------
  Date: Fri Jul 22 17:08:49 2022 CEST

                                      OS : Linux
                                  CPU(s) : 4
                                 Machine : x86_64
                            Architecture : 64bit
                                     RAM : 7.7 GiB
                             Environment : IPython
                             File system : ext4

  Python 3.9.10 | packaged by conda-forge | (main, Feb  1 2022, 21:24:11)
  [GCC 9.4.0]

  Intel(R) oneAPI Math Kernel Library Version 2022.0-Product Build 20211112
  for Intel(R) 64 architecture applications
--------------------------------------------------------------------------------

This came up in the introduction of the --no-opt-flag for the CLI in #86 - but I thought I'd open a separate PR, as this bug is not really related to the CLI.

codecov-commenter commented 2 years ago

Codecov Report

Merging #87 (8b29c5d) into main (999d9ca) will decrease coverage by 0.20%. The diff coverage is 80.00%.

@@            Coverage Diff             @@
##             main      #87      +/-   ##
==========================================
- Coverage   87.15%   86.95%   -0.21%     
==========================================
  Files           4        4              
  Lines         366      368       +2     
==========================================
+ Hits          319      320       +1     
- Misses         47       48       +1     
prisae commented 2 years ago

Looking at this, I have second thoughts. I think that is a left-over from my old code snippet. Currently it adjusts the spacing to anything between 18 (shortest/default) to 40 (longest) characters, as is shown in the following screenshot with annotations (I think this is partly a leftover because first I had version names on the left and package name on the right. Then, with packages including git hashes etc into the dev-numbers, I had to move the spacing).

2022-07-22-01

My suggestion is to simply centre it and have it the same all the time. What do you think @banesullivan?

Hence, I would replace

# Get length of longest package: min of 18 and max of 40
if self._packages:
    row_width = min(40, max(18, len(max(self._packages.keys(), key=len))))
else:
    row_width = 40

simply with

row_width = self.text_width // 2 - 2

Any objections to that?

prisae commented 2 years ago

Or maybe

row_width = self.text_width // 3

That would, by the default 80 textwidth, give a column width of 26, which looks nice and should accommodate 99.9% of package names...

Here is how the two suggestions look like: 2022-07-22-02

prisae commented 2 years ago

I leave the discussion about the general layout for another day. I just changed the width from 40 to 18 if there is no package at all; this is the status quo for "regular", short-named packages. As such this PR does really only one thing, fix this bug. I'll merge if all tests pass.