Skip to content

Commit

Permalink
added setup.py so hte script can be used as a cmd utility
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitautiu committed Feb 15, 2019
1 parent e307ace commit f8aa6a4
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 6 deletions.
116 changes: 116 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ This uses Linux's `finger` command.
> ./gpu_monitor.py -fU myserver.com
Server myserver.com:
GPU 0 (GeForce RTX 2080 Ti, 0%, 23/10986 MiB): Used by gdm (Gnome Display Manager, 23 MiB)
GPU 1 (GeForce RTX 2080 Ti, 33 %, 4933/10989 MiB): Used by joe (Joe Average, 4933 MiB)
GPU 3 (GeForce RTX 2080 Ti, 0%, 0/10989 MiB): Free
GPU 0 (GeForce RTX 2080 Ti, 0%, 23/10986 MiB): Used by gdm (Gnome Display Manager, 23 MiB)
GPU 1 (GeForce RTX 2080 Ti, 33%, 4933/10989 MiB): Used by joe (Joe Average, 4933 MiB)
GPU 3 (GeForce RTX 2080 Ti, 0%, 0/10989 MiB): Free
```

## Setup for Convenience
Expand Down
1 change: 1 addition & 0 deletions gpu_monitor/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .gpu_monitor import main
9 changes: 6 additions & 3 deletions gpu_monitor.py → gpu_monitor/gpu_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ def print_gpu_infos(server, gpu_infos, run_ps, run_get_real_names,
filter_by_user=None,
translate_to_real_names=False,
show_utilization=False):

# get pids of processes using the gpu and get their corresponding users
pids = [pid for gpu_info in gpu_infos for pid in gpu_info['pids']]
if len(pids) > 0:
Expand Down Expand Up @@ -291,7 +290,7 @@ def print_gpu_infos(server, gpu_infos, run_ps, run_get_real_names,
info(format_aligned(gpu_text_data))


def main(argv):
def run_cmd(argv):
args = parser.parse_args(argv)
logging.basicConfig(format='%(message)s',
level=logging.DEBUG if args.verbose else logging.INFO)
Expand Down Expand Up @@ -358,5 +357,9 @@ def main(argv):
print_free_gpus(server, gpu_infos)


def main():
run_cmd(sys.argv[1:])


if __name__ == '__main__':
main(sys.argv[1:])
main()
35 changes: 35 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
from setuptools import setup


# Utility function to read the README file.
# Used for the long_description. It's nice, because now 1) we have a top level
# README file and 2) it's easier to type in the README file than to put a raw
# string in below ...
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()


setup(
name='gpu-monitor',
version='0.1.0',
author='Nichita Utiu',
author_email='[email protected]',
description='Simple script to monitor gpu usage remotely or locally',
license='GPLv3',
keywords='script utility gpu monitor',
url='https://github.com/nikitautiu/gpu-monitor/',

packages=['gpu_monitor'],
entry_points={
'console_scripts': [
'gpu-monitor = gpu_monitor:main',
],
},

long_description=read('README.md'),
classifiers=[
'Topic :: Utilities',
'License :: OSI Approved :: GPL License',
],
)

0 comments on commit f8aa6a4

Please sign in to comment.