From 0051e93b5aaea69d2ba7ea343b030d2ab7e6988c Mon Sep 17 00:00:00 2001 From: Tasha Upchurch Date: Tue, 28 Nov 2023 20:06:01 -0500 Subject: [PATCH] update_js.py: This file introduces a Python script for managing JavaScript extension files within a specific directory structure. It includes an import statement for the os module. Imports essential variables ETK_PATH and GDE_PATH from the custom_nodes.EternalKernelLiteGraphNodes.local_shared module. Defines a function called check_for_js_extension(), which: Verifies the existence of JavaScript extension files. Compares modification timestamps to determine which file is newer. Copies files between directories if they are outdated. Provides user feedback during the copying process. Calls the check_for_js_extension() function at the end of the script to perform the checks and copying. --- tests/test_pytorch_nodes.py | 43 +++++++++++++++++++++++++++++++++++++ update_js.py | 30 ++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 tests/test_pytorch_nodes.py create mode 100644 update_js.py diff --git a/tests/test_pytorch_nodes.py b/tests/test_pytorch_nodes.py new file mode 100644 index 0000000..19dcb18 --- /dev/null +++ b/tests/test_pytorch_nodes.py @@ -0,0 +1,43 @@ +import unittest +from torch import nn + +from ..pytorch_nodes import PyTorchDatasetDownloader, AddLinearLayerNode, SequentialModelProvider, PyTorchInferenceNode +class TestPyTorchNodes(unittest.TestCase): + def test_dataset_downloader(self): + downloader = PyTorchDatasetDownloader() + dataset_name = "mnist" + download_path = "./data/tmp" + result = downloader.download_dataset(dataset_name, download_path) + self.assertIsNotNone(result) + + def test_linear_layer_node(self): + # Prepare a toy model for testing + toy_model = nn.Sequential( + nn.Linear(10, 20), + nn.ReLU(), + nn.Linear(20, 2) + ) + + linear_adder = AddLinearLayerNode() + in_features = 2 + out_features = 5 + result_model, = linear_adder.add_linear_layer(toy_model, in_features, out_features) + # Perform assertions to verify the modification to the model + + def test_sequential_model_provider(self): + provider = SequentialModelProvider() + input_channels = 3 + output_classes = 10 + result_model, = provider.provide_default_model(input_channels, output_classes) + # Perform assertions to verify the default architecture of the created model + + def test_inference_node(self): + toy_data = torch.rand(1, 3, 224, 224) # Toy data for inference + toy_model = torchvision.models.resnet18(pretrained=False) # Toy model for inference + inference_node = PyTorchInferenceNode() + result, = inference_node.inference(toy_model, toy_data) + # Perform assertions to validate the inference operation + + +if __name__ == "__main__": + unittest.main() diff --git a/update_js.py b/update_js.py new file mode 100644 index 0000000..45f8766 --- /dev/null +++ b/update_js.py @@ -0,0 +1,30 @@ +import os +from custom_nodes.EternalKernelLiteGraphNodes.local_shared import ETK_PATH, GDE_PATH +def check_for_js_extension(): + # here we check to see that the js extension is installed at {GDE_PATH}/web/extensions/etk/ui_modifications.js + # if it is not, we will copy it there from the ETK_PATH + # check if the file exists + + import shutil + for fn in ["ui_modifications.js", "ui_helpers.js"]: + check_full_path = os.path.normpath(os.path.join(ETK_PATH, f"{GDE_PATH}/web/extensions/etk/{fn}")) + etk_dir_file_mtime = os.path.getmtime(check_full_path) + web_dir_file_mtime = os.path.getmtime(os.path.join(ETK_PATH, fn)) + + # determine direction of copy + if etk_dir_file_mtime > web_dir_file_mtime: + # copy from etk to web + copy_from = check_full_path + copy_to = os.path.join(ETK_PATH, fn) + else: + # copy from web to etk + copy_from = os.path.join(ETK_PATH, fn) + copy_to = check_full_path + + # copy the file, give the user feedback, overwrite if necessary + print(f"copying {copy_from} to {copy_to}, because the file is out of date") + shutil.copyfile(copy_from, copy_to) + print(f"copied {copy_from} to {copy_to}") + + +check_for_js_extension() \ No newline at end of file