Skip to content

Commit

Permalink
Fixed issue with jumbled printing of results (#995)
Browse files Browse the repository at this point in the history
Co-authored-by: Jayasimha Raghavan <[email protected]>
  • Loading branch information
jayasimha-raghavan-unskript and Jayasimha Raghavan authored Feb 20, 2024
1 parent 1e81014 commit cbe2a3a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-and-release-docker-lite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ jobs:
git checkout ${{ inputs.awesome_branch }}
cd ..
make syncrunbooks
sed -i "s/BUILD_NUMBER = .*/BUILD_NUMBER = \"${{ inputs.build_number }}\"/g" awesome/unskript-ctl/unskript_ctl_version.py
cp -Rf awesome/unskript-ctl/* $HOME/devops/dockers/jupyterlab/oss_docker_lite/
cp -Rf awesome/bin/* $HOME/devops/dockers/jupyterlab/oss_docker_lite/
cd $HOME/devops/dockers/jupyterlab/oss_docker_lite/
Expand Down
2 changes: 2 additions & 0 deletions unskript-ctl/unskript_ctl_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@


from unskript_utils import *
from unskript_ctl_version import *
from unskript_ctl_factory import NotificationFactory

# This class implements Notification function for Slack
Expand Down Expand Up @@ -378,6 +379,7 @@ def create_email_header(self, title: str = None):
<center>
<h1> {email_title} </h1>
<h3> <strong>Tested On <br> {datetime.now().strftime("%a %b %d %I:%M:%S %p %Y %Z")} </strong></h3>
<h4> <strong>Version : {BUILD_NUMBER} </strong></h4><br>
</center>
'''
return message
Expand Down
28 changes: 16 additions & 12 deletions unskript-ctl/unskript_ctl_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ def __init__(self, **kwargs):
self._common = CommonAction()
self.uglobals = UnskriptGlobals()
self.uglobals['global'] = self.info_globals
self.jit_mapping = {}

if self.info_globals:
for k,v in self.info_globals.items():
Expand Down Expand Up @@ -700,23 +701,24 @@ def run(self, **kwargs):

# Internal routine to run through all python JIT script and return the output
def _execute_script(script, idx):
check_name = self.check_entry_functions[idx]
connector_name = self.connector_types[idx]
result_key = f"{connector_name}/{check_name}"
script = script.strip()
# Lets get the result_key from the jit_mapping. Why? because
# action_entry_function list will fail in case of matrix argument
result_key = self.jit_mapping.get(script)

if not self.uglobals['info_action_results'].get(result_key):
self.uglobals['info_action_results'][result_key] = []
self.uglobals['info_action_results'][result_key] = ''

try:
result = subprocess.run(['python', script], capture_output=True, check=True, text=True)
self.logger.debug(result.stdout)
if len(self.uglobals["info_action_results"].get(result_key)) != 0:
self.uglobals['info_action_results'][result_key].append(result.stdout)
else:
self.uglobals['info_action_results'][result_key] = result.stdout

except subprocess.CalledProcessError as e:
sys.logger.error(f"Error executing {script}: {str(e)}")
raise ValueError(e)
finally:
return result.stdout

self.uglobals['info_action_results'][result_key] += '\n' + result.stdout
return result.stdout

script_files = [f for f in os.listdir(self.temp_jit_dir) if f.endswith('.py')]
with concurrent.futures.ThreadPoolExecutor() as executor, tqdm(total=len(script_files), desc="Running") as pbar:
Expand Down Expand Up @@ -747,6 +749,10 @@ def _create_jit_script(self, action_list: list = None):
first_cell_content = self.get_first_cell_content()
for index, action in enumerate(action_list):
jit_file = os.path.join(self.temp_jit_dir, self.temp_jit_base_name + str(index) + '.py')
# Lets create a mapping of which action_entry_function maps to which script file
_name = action.get('metadata', {}).get('action_entry_function', '')
_connector = action.get('metadata', {}).get('action_type', '').replace('LEGO_TYPE_', '').lower()
self.jit_mapping[jit_file] = _connector + '/' + _name
with open(jit_file, 'w') as f:
f.write(first_cell_content)
f.write('\n\n')
Expand Down Expand Up @@ -812,5 +818,3 @@ def create_checks_for_matrix_argument(self, list_of_actions: list):
action_list = self._common.create_checks_for_matrix_argument(actions=list_of_actions,
matrix=self.matrix)
return action_list


0 comments on commit cbe2a3a

Please sign in to comment.