urbanpy
urbanpy copied to clipboard
Making the move from tqdm to rich and further progress
This PR is intended to show the capacities of rich as a replacement for tqdm for progress management and console output. The initial step from these code changes is focused on monitoring progress. The main benefit is reducing our code footprint.
The footprint reduction is based on the fact that monitoring if a notebook is used, there is no need for handling that special case (when using "track" the progress bar autorefreshes). Within the changes two ways to track progress are proposed:
- Using rich.progress.track to initialize a progress bar with a custom total (generally df.shape[0]) and a custom description (i.e. "Processing origins for distance matrix")
- Using rich.progress.Progress within a context manager. This provides a way to "add tasks" which are individual progress bars that can be updated individually. This has particular use in the distance matrix calculation and when performing computation that does not provide a notion of progress. An example of this is to use a rich.tree.Tree within the accessibility module to setup a "general" progress and update the individual portions when completing key tasks within the function.
All of the elements within rich support rich text, such that console output can be styled to provide a better user experience (see the changes in routing.py where using "[red] Origins processed" and "[blue] Destinations processed" produces the following output:

Other styles such as the progress color and timing color can also be customized. Furthermore, rich can be used to provide "prettier" error messages, which may need further evaluation and testing.
Kudos, SonarCloud Quality Gate passed!
0 Bugs
0 Vulnerabilities
0 Security Hotspots
0 Code Smells
No Coverage information
0.0% Duplication
This PR does require a change in requirements.txt as well which wasn't committed
Kudos, SonarCloud Quality Gate passed!
0 Bugs
0 Vulnerabilities
0 Security Hotspots
1 Code Smell
No Coverage information
0.0% Duplication