From dd2c7f0ed79571fe4245d22a9b1d20bdb6cb8260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jord=C3=A0=20Polo?= Date: Wed, 8 Jan 2025 12:50:09 -0800 Subject: [PATCH] Format imports with isort MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jordà Polo --- docs/conf.py | 2 +- grafana/scripts/filter-dashboard | 3 +-- omnistat/annotate.py | 2 +- omnistat/collector_events.py | 10 ++++++---- omnistat/collector_rms.py | 2 +- omnistat/collector_smi.py | 3 ++- omnistat/collector_smi_process.py | 11 +++++++++-- omnistat/collector_smi_v2.py | 6 ++++-- omnistat/monitor.py | 4 ++-- omnistat/node_monitoring.py | 3 +-- omnistat/omni_util.py | 6 +++--- omnistat/query.py | 32 ++++++++++++++++++++----------- omnistat/rms_env.py | 2 +- omnistat/standalone.py | 10 +++++----- omnistat/utils.py | 1 - pyproject.toml | 3 +++ test/test_integration.py | 4 +--- test/test_job_system.py | 5 ++--- test/test_job_user_pull.py | 6 ++---- test/test_job_user_push.py | 6 ++---- 20 files changed, 68 insertions(+), 53 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index b6c6c48e..d4d15546 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -13,8 +13,8 @@ # documentation root, use os.path.abspath to make it absolute, like shown here. # import os -import sys import subprocess as sp +import sys sys.path.insert(0, os.path.abspath("..")) diff --git a/grafana/scripts/filter-dashboard b/grafana/scripts/filter-dashboard index 17ca80bd..84d2bd69 100755 --- a/grafana/scripts/filter-dashboard +++ b/grafana/scripts/filter-dashboard @@ -39,11 +39,10 @@ # 3. Rewrite dashboard UID and update all URLs accordingly. import argparse +import json import re import sys -import json - def panel_contains_pattern(panel, pattern): for target in panel.get("targets", []): diff --git a/omnistat/annotate.py b/omnistat/annotate.py index ccec9359..2de1d4d0 100755 --- a/omnistat/annotate.py +++ b/omnistat/annotate.py @@ -35,9 +35,9 @@ """ import argparse -import time import json import os +import time class omnistat_annotate: diff --git a/omnistat/collector_events.py b/omnistat/collector_events.py index 145f1818..68e4cd20 100644 --- a/omnistat/collector_events.py +++ b/omnistat/collector_events.py @@ -22,15 +22,17 @@ # SOFTWARE. # ------------------------------------------------------------------------------- -from amdsmi import * -from amdsmi import amdsmi_interface import _thread -import time import logging import os import sys +import time + +from amdsmi import * +from amdsmi import amdsmi_interface +from prometheus_client import CollectorRegistry, Gauge, generate_latest + from omnistat.collector_base import Collector -from prometheus_client import Gauge, generate_latest, CollectorRegistry class ROCMEvents(Collector): diff --git a/omnistat/collector_rms.py b/omnistat/collector_rms.py index 05fd81c8..f6b19a5c 100644 --- a/omnistat/collector_rms.py +++ b/omnistat/collector_rms.py @@ -30,11 +30,11 @@ user-provided annotation timestamps. """ -import sys import json import logging import os import platform +import sys from prometheus_client import Gauge diff --git a/omnistat/collector_smi.py b/omnistat/collector_smi.py index 8a6a3d7a..cd887d0d 100644 --- a/omnistat/collector_smi.py +++ b/omnistat/collector_smi.py @@ -46,7 +46,8 @@ import os import sys from enum import IntEnum -from prometheus_client import Gauge, generate_latest, CollectorRegistry + +from prometheus_client import CollectorRegistry, Gauge, generate_latest from omnistat.collector_base import Collector from omnistat.utils import gpu_index_mapping_based_on_guids diff --git a/omnistat/collector_smi_process.py b/omnistat/collector_smi_process.py index 828bb2c4..82d77b74 100644 --- a/omnistat/collector_smi_process.py +++ b/omnistat/collector_smi_process.py @@ -37,10 +37,17 @@ """ import logging -from omnistat.collector_base import Collector + +from amdsmi import ( + amdsmi_get_gpu_process_info, + amdsmi_get_gpu_process_list, + amdsmi_get_processor_handles, + amdsmi_init, +) from prometheus_client import Gauge + +from omnistat.collector_base import Collector from omnistat.utils import GPU_MAPPING_ORDER -from amdsmi import amdsmi_init, amdsmi_get_processor_handles, amdsmi_get_gpu_process_list, amdsmi_get_gpu_process_info def get_gpu_processes(device): diff --git a/omnistat/collector_smi_v2.py b/omnistat/collector_smi_v2.py index de7592ad..12687aa0 100644 --- a/omnistat/collector_smi_v2.py +++ b/omnistat/collector_smi_v2.py @@ -42,12 +42,14 @@ """ import logging -import packaging.version import statistics import sys + import amdsmi as smi -from omnistat.collector_base import Collector +import packaging.version from prometheus_client import Gauge + +from omnistat.collector_base import Collector from omnistat.utils import convert_bdf_to_gpuid, gpu_index_mapping_based_on_bdfs diff --git a/omnistat/monitor.py b/omnistat/monitor.py index 9179289e..9e7f65d5 100644 --- a/omnistat/monitor.py +++ b/omnistat/monitor.py @@ -35,9 +35,9 @@ import platform import re import sys - from pathlib import Path -from prometheus_client import generate_latest, CollectorRegistry + +from prometheus_client import CollectorRegistry, generate_latest from omnistat import utils diff --git a/omnistat/node_monitoring.py b/omnistat/node_monitoring.py index abe4e1ff..a5de2f8b 100755 --- a/omnistat/node_monitoring.py +++ b/omnistat/node_monitoring.py @@ -40,8 +40,7 @@ import sys import gunicorn.app.base - -from flask import Flask, request, abort, jsonify +from flask import Flask, abort, jsonify, request from omnistat import utils from omnistat.monitor import Monitor diff --git a/omnistat/omni_util.py b/omnistat/omni_util.py index 0ab1dbeb..e9f71f65 100755 --- a/omnistat/omni_util.py +++ b/omnistat/omni_util.py @@ -24,8 +24,8 @@ # ------------------------------------------------------------------------------- import argparse -import importlib.resources import getpass +import importlib.resources import logging import os import platform @@ -35,10 +35,10 @@ import sys import tempfile import time -import yaml - from pathlib import Path +import yaml + # Use libssh instead of the default libssh2 to avoid issues with certain keys # and newer versions of SSH. from pssh.clients.ssh.parallel import ParallelSSHClient diff --git a/omnistat/query.py b/omnistat/query.py index b1476e54..9b906365 100755 --- a/omnistat/query.py +++ b/omnistat/query.py @@ -23,27 +23,37 @@ # SOFTWARE. # ------------------------------------------------------------------------------- -from prometheus_api_client import PrometheusConnect, MetricSnapshotDataFrame -from prometheus_api_client.utils import parse_datetime -from datetime import datetime, timedelta import argparse import logging -import numpy as np import os +import shutil import subprocess import sys import timeit -import matplotlib.pylab as plt -import matplotlib.dates as mdates -import shutil +from datetime import datetime, timedelta from pathlib import Path + +import matplotlib.dates as mdates +import matplotlib.pylab as plt +import numpy as np +from prometheus_api_client import MetricSnapshotDataFrame, PrometheusConnect +from prometheus_api_client.utils import parse_datetime from reportlab.lib import colors -from reportlab.pdfgen import canvas -from reportlab.lib.pagesizes import letter, landscape -from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image, Table, TableStyle, PageBreak, HRFlowable -from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle from reportlab.lib.enums import TA_JUSTIFY +from reportlab.lib.pagesizes import landscape, letter +from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet from reportlab.lib.units import inch +from reportlab.pdfgen import canvas +from reportlab.platypus import ( + HRFlowable, + Image, + PageBreak, + Paragraph, + SimpleDocTemplate, + Spacer, + Table, + TableStyle, +) from omnistat import utils diff --git a/omnistat/rms_env.py b/omnistat/rms_env.py index fb8b7cad..016c91a3 100755 --- a/omnistat/rms_env.py +++ b/omnistat/rms_env.py @@ -30,12 +30,12 @@ # Default path for output_file: /tmp/omni_rmsjobinfo # ------------------------------------------------------------------------------- +import argparse import fcntl import json import os import subprocess import sys -import argparse def main(): diff --git a/omnistat/standalone.py b/omnistat/standalone.py index 46aa5fb8..be23a012 100755 --- a/omnistat/standalone.py +++ b/omnistat/standalone.py @@ -34,15 +34,16 @@ import logging import os import platform -import requests -import sys import signal +import sys import threading import time import warnings from datetime import datetime, timezone -from flask import Flask, request, jsonify, abort -from prometheus_client import Gauge, REGISTRY + +import requests +from flask import Flask, abort, jsonify, request +from prometheus_client import REGISTRY, Gauge # Ensure current directory is part of Python's path; allows direct execution # from the top directory of the project when package is not installed. @@ -52,7 +53,6 @@ from omnistat import utils from omnistat.monitor import Monitor - app = Flask(__name__) terminateFlagEvent = threading.Event() dataDeliveredEvent = threading.Event() diff --git a/omnistat/utils.py b/omnistat/utils.py index 27f17672..a6f09be7 100644 --- a/omnistat/utils.py +++ b/omnistat/utils.py @@ -30,7 +30,6 @@ import shutil import subprocess import sys - from importlib.metadata import version from pathlib import Path diff --git a/pyproject.toml b/pyproject.toml index 29d2d2c7..49127bb5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,3 +42,6 @@ filterwarnings = [ [tool.black] line-length = 120 include = '\.py$' + +[tool.isort] +profile = "black" diff --git a/test/test_integration.py b/test/test_integration.py index 135a6a83..1f113a8b 100644 --- a/test/test_integration.py +++ b/test/test_integration.py @@ -1,10 +1,8 @@ +import config import pytest import requests - from prometheus_api_client import PrometheusConnect -import config - class TestIntegration: def test_request(self): diff --git a/test/test_job_system.py b/test/test_job_system.py index 948c2f4e..276d667f 100644 --- a/test/test_job_system.py +++ b/test/test_job_system.py @@ -1,10 +1,9 @@ import os -import pytest import time -from prometheus_api_client import PrometheusConnect - import config +import pytest +from prometheus_api_client import PrometheusConnect class TestJobSystem: diff --git a/test/test_job_user_pull.py b/test/test_job_user_pull.py index 74cfb4d6..55d0533f 100644 --- a/test/test_job_user_pull.py +++ b/test/test_job_user_pull.py @@ -16,16 +16,14 @@ # server, allowing further validation of the trace. import os -import pytest import re import subprocess import time - from string import Template -from prometheus_api_client import PrometheusConnect - import config +import pytest +from prometheus_api_client import PrometheusConnect slurm_job_template = """\ #!/bin/bash diff --git a/test/test_job_user_push.py b/test/test_job_user_push.py index 1752d11d..34661c5d 100644 --- a/test/test_job_user_push.py +++ b/test/test_job_user_push.py @@ -16,16 +16,14 @@ # server, allowing further validation of the trace. import os -import pytest import re import subprocess import time - from string import Template -from prometheus_api_client import PrometheusConnect - import config +import pytest +from prometheus_api_client import PrometheusConnect slurm_job_template = """\ #!/bin/bash