Skip to content

Commit 3ddcfb2

Browse files
shriram192Prajwal  Kiran KumarBenGalewsky
authored
Changes made for Multiple Codegen (#8)
* Update __init__.py * read variable from environ * Update post_operation.py * app config file removal in codegen - xAOD * Update post_operation.py * os environ changes * directly read from env var * Final changes for multiple codegen * Remove unused imports * added back config transformer image * deleted .DS_Store * revert to current_app.config at post_operation and DS Store gitignore * Update post_operation.py * Pick up science image from app config * Code generators return language and science command --------- Co-authored-by: Prajwal Kiran Kumar <[email protected]> Co-authored-by: Ben Galewsky <[email protected]>
1 parent b395605 commit 3ddcfb2

File tree

5 files changed

+29
-9
lines changed

5 files changed

+29
-9
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,7 @@ dmypy.json
128128
# Pyre type checker
129129
.pyre/
130130

131-
.idea/
131+
.idea/
132+
133+
#DS Store Mac OS
134+
.DS_Store

servicex_codegen/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ def create_app(test_config=None, provided_translator=None):
5858
if test_config:
5959
app.config.from_mapping(test_config)
6060
else:
61-
if 'APP_CONFIG_FILE' in os.environ:
62-
app.config.from_envvar('APP_CONFIG_FILE')
6361
if 'CODEGEN_CONFIG_FILE' in os.environ:
6462
app.config.from_envvar('CODEGEN_CONFIG_FILE')
6563

64+
app.config['TRANSFORMER_SCIENCE_IMAGE'] = os.environ.get('TRANSFORMER_SCIENCE_IMAGE')
65+
6666
with app.app_context():
6767
translator = provided_translator
6868

servicex_codegen/post_operation.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,17 @@
2626
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2727
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
#
29-
29+
import json
3030
#
3131
# Redistribution and use in source and binary forms, with or without
3232
# modification, are permitted provided that the following conditions are met:
3333
#
3434
import os
35+
3536
import zipfile
3637
from tempfile import TemporaryDirectory
3738

38-
from flask import Response, current_app, request
39+
from flask import Response, request, current_app
3940
from flask_restful import Resource
4041
from requests_toolbelt import MultipartEncoder
4142

@@ -84,6 +85,10 @@ def stream_generated_code(self, generated_code_result: GeneratedFileResult) -> b
8485

8586
def post(self):
8687
try:
88+
with open("transformer_capabilities.json") as capabilities_file:
89+
capabilities = json.load(capabilities_file)
90+
print("capable", capabilities['language'], capabilities['command'])
91+
8792
with TemporaryDirectory() as tempdir:
8893
body = request.get_json()
8994
generated_code_result = self.code_generator.generate_code(
@@ -92,12 +97,14 @@ def post(self):
9297
zip_data = self.stream_generated_code(generated_code_result)
9398
# code gen transformer returns the default transformer image mentioned in
9499
# the config file
95-
transformer_image = current_app.config.get("TRANSFORMER_SCIENCE_IMAGE")
100+
transformer_image = current_app.config['TRANSFORMER_SCIENCE_IMAGE']
96101

97102
# MultipartEncoder library takes multiple types of data fields and merge
98103
# them into a multipart mime data type
99104
m = MultipartEncoder(
100105
fields={'transformer_image': transformer_image,
106+
'language': capabilities['language'],
107+
'command': capabilities['command'],
101108
'zip_data': zip_data}
102109
)
103110

tests/test_post_operation.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ def test_post_good_query_with_params(self, mocker):
6666
)
6767

6868
config = {
69-
'TARGET_BACKEND': 'uproot'
69+
'TARGET_BACKEND': 'uproot',
70+
'TRANSFORMER_SCIENCE_IMAGE': "foo/bar:latest"
7071
}
7172
app = create_app(config, provided_translator=mock_ast_translator)
7273
client = app.test_client()
@@ -85,7 +86,7 @@ def test_post_good_query_with_params(self, mocker):
8586
decoder_parts = decoder.MultipartDecoder(response.data, content_type)
8687

8788
transformer_image = str(decoder_parts.parts[0].content, 'utf-8')
88-
zip_file = decoder_parts.parts[1].content
89+
zip_file = decoder_parts.parts[3].content
8990

9091
print("Transformer Image: ", transformer_image)
9192
print("Zip File: ", zip_file)
@@ -130,7 +131,7 @@ def test_post_good_query_without_params(self, mocker):
130131
decoder_parts = decoder.MultipartDecoder(response.data, content_type)
131132

132133
transformer_image = str(decoder_parts.parts[0].content, 'utf-8')
133-
zip_file = decoder_parts.parts[1].content
134+
zip_file = decoder_parts.parts[3].content
134135

135136
print("Transformer Image: ", transformer_image)
136137
print("Zip File: ", zip_file)

transformer_capabilities.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "FuncADL based uproot transformer",
3+
"description": "Extracts data from flat ntuple style root files.",
4+
"limitations": "Would be good to note what isn't implemented",
5+
"file-formats": ["parquet"],
6+
"stats-parser": "UprootStats",
7+
"language": "python",
8+
"command": "/generated/transform_single_file.py"
9+
}

0 commit comments

Comments
 (0)