From f8aa6a4a97f11c224f0f29dda808d2ce5cc71383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nichita=20U=C8=9Biu?= Date: Fri, 15 Feb 2019 11:08:44 +0200 Subject: [PATCH] added setup.py so hte script can be used as a cmd utility --- .gitignore | 116 +++++++++++++++++++ README.md | 6 +- gpu_monitor/__init__.py | 1 + gpu_monitor.py => gpu_monitor/gpu_monitor.py | 9 +- setup.py | 35 ++++++ 5 files changed, 161 insertions(+), 6 deletions(-) create mode 100644 .gitignore create mode 100644 gpu_monitor/__init__.py rename gpu_monitor.py => gpu_monitor/gpu_monitor.py (99%) create mode 100644 setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0447b8b --- /dev/null +++ b/.gitignore @@ -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/ diff --git a/README.md b/README.md index eed9146..5404c2a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/gpu_monitor/__init__.py b/gpu_monitor/__init__.py new file mode 100644 index 0000000..d348da5 --- /dev/null +++ b/gpu_monitor/__init__.py @@ -0,0 +1 @@ +from .gpu_monitor import main \ No newline at end of file diff --git a/gpu_monitor.py b/gpu_monitor/gpu_monitor.py similarity index 99% rename from gpu_monitor.py rename to gpu_monitor/gpu_monitor.py index dc875a1..8c00257 100755 --- a/gpu_monitor.py +++ b/gpu_monitor/gpu_monitor.py @@ -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: @@ -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) @@ -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() diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..1f74049 --- /dev/null +++ b/setup.py @@ -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='nikita.utiu@gmail.com', + 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', + ], +)