Reorganized the files (moved experimetal and tests), refactored imports in code, improved execution paths (python -m and script entrypoint)

This commit is contained in:
HackTestes
2025-07-04 11:59:15 -03:00
parent 94236e356a
commit 713994fa15
7 changed files with 24 additions and 7 deletions

View File

@@ -46,5 +46,6 @@ classifiers = [
[project.urls]
Repository = "https://github.com/HackTestes/NVML-GPU-Control"
# caiohack-nvml or chnvml for short
[project.scripts]
nvml-gpu-control = "caioh_nvml_gpu_control.nvml_gpu_control:main"
chnvml = "caioh_nvml_gpu_control.__main__:script_call"

View File

@@ -1,3 +1,17 @@
import caioh_nvml_gpu_control.nvml_gpu_control as nvml_gpu_control
import sys
import os
nvml_gpu_control.main()
# If we run the script from main (like python -m or directly from script), the other scripts might not find the imports
# So we add the dir where __main__ resides as an import path
# This also helps to keep the rest of the code clean
sys.path.append(os.path.dirname( os.path.realpath(__file__) ))
import nvml_gpu_control
# Call from python -m
if __name__ == '__main__':
nvml_gpu_control.main()
# Call from script entrypoint
def script_call():
nvml_gpu_control.main()

View File

@@ -1,9 +1,10 @@
from pynvml import *
import sys
import caioh_nvml_gpu_control.helper_functions as main_funcs
import caioh_nvml_gpu_control.parse_args as parse_args
import helper_functions as main_funcs
import parse_args
import time
def main():
# Getting a configuration obj

View File

@@ -1,4 +1,4 @@
import caioh_nvml_gpu_control.helper_functions as helper_functions
import helper_functions
class InvalidAction(Exception):
pass

0
test/__init__.py Normal file
View File

View File

@@ -2,8 +2,9 @@ import unittest
from unittest.mock import Mock
import sys
import ctypes
sys.path.append('./src/caioh_nvml_gpu_control/') # Necessary so the tested files can all find each other from the projects root
import parse_args
import caioh_nvml_gpu_control.helper_functions as main_funcs
import helper_functions as main_funcs
# Test command: python.exe .\tests.py -b