Skip to content

Commit

Permalink
text prettifyings
Browse files Browse the repository at this point in the history
  • Loading branch information
HollowPrincess committed May 21, 2024
1 parent a338741 commit dda700c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
8 changes: 7 additions & 1 deletion nbtools/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def get_available_gpus(n=1, min_free_memory=0.9, max_processes=2, verbose=False,
Returns
-------
List with indices of available GPUs
available_devices : list
Indices of available GPUs.
"""
try:
import nvidia_smi
Expand Down Expand Up @@ -215,6 +216,11 @@ def set_gpus(n=1, min_free_memory=0.9, max_processes=2, verbose=False, raise_err
If 2, then display memory and process information for each device.
raise_error : bool
Whether to raise an exception if not enough devices are available.
Returns
-------
devices : list
Indices of selected and reserved GPUs.
"""
#pylint: disable=consider-iterating-dictionary
if 'CUDA_VISIBLE_DEVICES' in os.environ.keys():
Expand Down
2 changes: 1 addition & 1 deletion nbtools/nbstat/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def devicewatch():
}

def make_parameters(name):
""" Parse parameters from command line into dictionary.
""" Parse parameters from the command line into a dictionary.
Use `store_const` instad of `store_true` to keep `None` values, if not passed explicitly
"""
# Set defaults
Expand Down
6 changes: 3 additions & 3 deletions nbtools/nbstat/resource_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class ResourceFormatter(list):
""" An ordered sequence to define which resources to request from the system, as well as
how to structure them into formatted table.
how to structure them into a formatted table.
Each element is a dictionary with mandatory `resource` and `include` keys, and defines whether this
`resource` must be fetched/included in the table based on the value of `include` flag.
Expand Down Expand Up @@ -86,7 +86,7 @@ def update(self, other=None, **kwargs):
self.extend(other)

def copy(self):
""" Deep copy of the formatter. Used to not mess up the original formatter. """
""" Deep copy of the formatter. Used to avoid messing up the original formatter. """
return deepcopy(self)

def include_all(self):
Expand All @@ -96,7 +96,7 @@ def include_all(self):

@property
def included_only(self):
""" Return formatter with elements which `include` flag is set to True.
""" Return the formatter, including only the elements where the `include` flag is set to True.
Also removes subsequent duplicates of table delimiters.
"""
formatter = []
Expand Down
8 changes: 5 additions & 3 deletions nbtools/nbstat/resource_inspector.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
""" Controlling class for fetching tables with system information, merging them into view and displaying in stream. """
""" Controlling class for fetching tables with system information,
merging them into a view and displaying in a stream.
"""
import os
import re
import json
Expand Down Expand Up @@ -212,7 +214,7 @@ def get_python_pids(self):

def get_process_table(self, formatter=None):
""" Collect information about all Python processes.
Information varies from properties of a process (its path, PID, NGID, status, etc) to system resource usage like
Information varies from process properties (its path, PID, NGID, status, etc) to system resource usage like
CPU utilization or RSS. The table also includes some inferred columns like type and kernel_id.
Some of the fields are intentionally left blank / with meaningless defaults: those are supposed to be filled by
Expand Down Expand Up @@ -489,7 +491,7 @@ def nbstat_check_device_pids(self, device_pids, table, add_to_table=True):

def devicestat_check_device_pids(self, table):
""" Check if some of the `device pids` are not matched to any Python processes.
Add template names to them insted of empty ones.
Add template names to them instead of empty ones.
"""
self.warnings['missing_device_pids'] = set()
for entry in table:
Expand Down
12 changes: 6 additions & 6 deletions nbtools/nbstat/resource_table.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""" ResourceEntry -- a dict-like class to hold all properties (Resources) of an entry.
ResourceTable -- sequence of multiple ResourceEntries with interface of merging, updating, sorting for multiple tables.
Can be formatted into beautiful colored string representation by using `format` method.
Can be formatted into a beautiful colored string representation by using `format` method.
"""

from .resource import Resource
Expand All @@ -18,7 +18,7 @@ class ResourceTable:
versions for working with tables with defined `index`.
For the most part, this class acts as a lightweight version of a`Pandas.DataFrame`: it saves us a huge dependency
and also allows to tweak some of the metods to our needs. As our tables are tiny, efficiency is not a concern.
and also allows to tweak some of the methods to our needs. As our tables are tiny, efficiency is not a concern.
If the `pandas` is already installed, `ResourceTable` can be converted to dataframe by using `to_pd` method.
Also provides method `format` for table visualization as a beautiful colored string representation.
Expand Down Expand Up @@ -313,7 +313,7 @@ def filter_by_index(self, condition, inplace=True):

def filter_on_index(self, condition, inplace=True):
""" Filter subtables and index values, based on `condition`, evaluated on them.
Keep only those which evaluate to True.
Keep only those that evaluate to True.
"""
self = self.maybe_copy(return_self=inplace)

Expand Down Expand Up @@ -359,7 +359,7 @@ def __str__(self):
return repr('\n'.join([str(entry) for entry in self.data]))

def to_format_data(self, resource, terminal, **kwargs):
""" Create a string template and data for a given `resource` column from entire table.
""" Create a string template and data for a given `resource` column from the entire table.
Works by aggregation information in the `resource` column and making string from it.
For more information about formatting refer to `ResourceTable.format` method.
Expand Down Expand Up @@ -394,8 +394,8 @@ def format(self, terminal, formatter, hide_similar=True,
text formatting, and it is enough to format the string from entries.
The header string is produced by (`style` + `name`).
- then we iterate over entries in the table. Each entry is requested to create a `style` and `string` for
current resource: that is done by the `ResourceEntry.to_format_data` method.
- then we iterate over the entries in the table. Each entry is requested to create a `style` and `string`
for the current resource: that is done by the `ResourceEntry.to_format_data` method.
Note that we can't use just the resource and its value from the entry to create the `string`, as some of the
columns require multiple items: for example, device memory requires current and total values.
`style`, returned by the entry, can completely override the style from the Resource, but for the most cases,
Expand Down

0 comments on commit dda700c

Please sign in to comment.