Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jul 24, 2023
1 parent 0ee684d commit a6b10df
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,4 @@ export const populateNotebook = async (notebookContent: JupyterCellProps[], note
}
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const plugin: JupyterFrontEndPlugin<void> = {
initVDKConfigCell(notebookTracker);
});

const fileBrowser = factory.defaultBrowser;
const fileBrowser = factory.defaultBrowser;

updateVDKMenu(commands, docManager, fileBrowser, notebookTracker);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,4 @@ export async function getServerDirRequest(): Promise<string> {
);
return '';
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Copyright 2021-2023 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0

import glob
import os
import shutil
import glob


def validate_dir(dir_path):
Expand Down Expand Up @@ -33,7 +36,7 @@ def get_archive_name(self) -> str:
return os.path.join(parent_dir, f"{dir_name}_archive")

def archive_folder(self):
shutil.make_archive(self.get_archive_name(), 'zip', self._dir_path)
shutil.make_archive(self.get_archive_name(), "zip", self._dir_path)


class ConvertJobDirectoryProcessor:
Expand All @@ -56,20 +59,20 @@ def __init__(self, dir_path):
self._code_structure = []

def process_files(self):
all_files = sorted(glob.glob(os.path.join(self._dir_path, '*')))
all_files = sorted(glob.glob(os.path.join(self._dir_path, "*")))
self._archiver.archive_folder()

for file in all_files:
if file.endswith('.sql'):
with open(file, 'r') as f:
if file.endswith(".sql"):
with open(file) as f:
content = f.read()
self._code_structure.append(f'job_input.execute_query("""{content}""")')
os.remove(file)
elif file.endswith('.py'):
with open(file, 'r') as f:
elif file.endswith(".py"):
with open(file) as f:
content = f.read()

if 'def run(job_input: IJobInput)' in content:
if "def run(job_input: IJobInput)" in content:
self._code_structure.append(content)
os.remove(file)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,4 @@ def add_handler(handler, endpoint):
add_handler(CreateDeploymentHandler, "deploy")
add_handler(GetNotebookInfoHandler, "notebook")
add_handler(GetVdkCellIndicesHandler, "vdkCellIndices")
add_handler(GetServerPathHandler, "serverPath")
add_handler(GetServerPathHandler, "serverPath")
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Copyright 2021-2023 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0

import os
import unittest
import tempfile
import shutil
import tempfile
import unittest

from vdk_jupyterlab_extension.transform_job import TransformJobDirectoryProcessor


Expand All @@ -18,13 +22,13 @@ def hello():
print("Hello, World!")
"""

with open(os.path.join(self.temp_dir, 'test.sql'), 'w') as f:
with open(os.path.join(self.temp_dir, "test.sql"), "w") as f:
f.write(self.sql_content)
with open(os.path.join(self.temp_dir, 'test_run.py'), 'w') as f:
with open(os.path.join(self.temp_dir, "test_run.py"), "w") as f:
f.write(self.py_content_run)
with open(os.path.join(self.temp_dir, 'test_without_run.py'), 'w') as f:
with open(os.path.join(self.temp_dir, "test_without_run.py"), "w") as f:
f.write(self.py_content_without_run)
with open(os.path.join(self.temp_dir, 'config.ini'), 'w') as f:
with open(os.path.join(self.temp_dir, "config.ini"), "w") as f:
pass

self.processor = TransformJobDirectoryProcessor(self.temp_dir)
Expand All @@ -39,10 +43,12 @@ def test_process_files(self):
self.py_content_run,
]
self.assertEqual(self.processor.get_code_structure(), expected_code_structure)
self.assertFalse(os.path.exists(os.path.join(self.temp_dir, 'test.sql')))
self.assertFalse(os.path.exists(os.path.join(self.temp_dir, 'test_run.py')))
self.assertTrue(os.path.exists(os.path.join(self.temp_dir, 'test_without_run.py')))
self.assertTrue(os.path.exists(os.path.join(self.temp_dir, 'config.ini')))
self.assertFalse(os.path.exists(os.path.join(self.temp_dir, "test.sql")))
self.assertFalse(os.path.exists(os.path.join(self.temp_dir, "test_run.py")))
self.assertTrue(
os.path.exists(os.path.join(self.temp_dir, "test_without_run.py"))
)
self.assertTrue(os.path.exists(os.path.join(self.temp_dir, "config.ini")))

def test_get_code_structure(self):
self.processor.process_files()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from vdk_jupyterlab_extension.convert_job import ConvertJobDirectoryProcessor
from vdk_jupyterlab_extension.convert_job import DirectoryArchiver


class RestApiUrlConfiguration:
@staticmethod
def get_rest_api_url():
Expand Down Expand Up @@ -242,4 +243,4 @@ def convert_job(job_dir: str):
"removed_files": processor.get_removed_files(),
}
processor.cleanup()
return message
return message

0 comments on commit a6b10df

Please sign in to comment.