Skip to content

Commit b4f5759

Browse files
committed
Allow image to be "none"
- Make sure the image name is None by default - Do not include an "image" tag in the API request if we don't need it. - Fix up some flake8 errors
1 parent 9723487 commit b4f5759

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

servicex/servicex.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ServiceXDataset(ServiceXABC):
3838
def __init__(self,
3939
dataset: str,
4040
backend_type: Optional[str] = None,
41-
image: str = 'sslhep/servicex_func_adl_xaod_transformer:v1.0.0-rc.2', # NOQA
41+
image: str = None,
4242
max_workers: int = 20,
4343
servicex_adaptor: ServiceXAdaptor = None,
4444
minio_adaptor: Union[MinioAdaptor, MinioAdaptorFactory] = None,
@@ -60,7 +60,9 @@ def __init__(self,
6060
will default to xaod, unless you have any endpoint listed
6161
in your servicex file. It will default to best match there,
6262
in that case.
63-
image Name of transformer image to use to transform the data
63+
image Name of transformer image to use to transform the data. If
64+
left as default, `None`, then the default image for the
65+
ServiceX backend will be used.
6466
max_workers Maximum number of transformers to run simultaneously on
6567
ServiceX.
6668
servicex_adaptor Object to control communication with the servicex instance
@@ -83,8 +85,8 @@ def __init__(self,
8385
and `awkward`, including default settings for expected
8486
datatypes from the backend.
8587
ignore_cache Always ignore the cache on any query for this dataset. This
86-
is only meaningful if no cache adaptor is provided. Defaults
87-
to false - the cache is used if possible.
88+
is only meaningful if no cache adaptor is provided.
89+
Defaults to false - the cache is used if possible.
8890
8991
Notes:
9092
@@ -95,6 +97,8 @@ def __init__(self,
9597
takes `(total_files, transformed, downloaded, skipped)` as an argument. The
9698
`total_files` parameter may be `None` until the system knows how many files need to
9799
be processed (and some files can even be completed before that is known).
100+
- The full description of calling parameters is recorded in the local cache, including
101+
things like `image` name and tag.
98102
'''
99103
ServiceXABC.__init__(self, dataset, image, max_workers,
100104
status_callback_factory,
@@ -414,16 +418,20 @@ def _build_json_query(self, selection_query: str, data_type: str) -> Dict[str, s
414418
Notes:
415419
- Internal routine.
416420
'''
421+
# Items that must always be present
417422
json_query: Dict[str, str] = {
418423
"did": self._dataset,
419424
"selection": selection_query,
420-
"image": self._image,
421425
"result-destination": "object-store",
422426
"result-format": 'parquet' if data_type == 'parquet' else "root-file",
423427
"chunk-size": '1000',
424428
"workers": str(self._max_workers)
425429
}
426430

431+
# Optional items
432+
if self._image is not None:
433+
json_query['image'] = self._image
434+
427435
logging.getLogger(__name__).debug(f'JSON to be sent to servicex: {str(json_query)}')
428436

429437
return json_query

servicex/servicex_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def get_servicex_adaptor_config(self, backend_type: Optional[str] = None) -> \
9191
9292
Returns:
9393
Tuple[str, str]: The tuple of info to create a `ServiceXAdaptor`: end point,
94-
token.
94+
token (optionally).
9595
'''
9696
# Find a list of all endpoints.
9797
# It is an error if this is not specified somewhere.

servicex/servicexabc.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ServiceXABC(ABC):
2727

2828
def __init__(self,
2929
dataset: str,
30-
image: str = 'sslhep/servicex_func_adl_xaod_transformer:v0.4',
30+
image: Optional[str] = None,
3131
max_workers: int = 20,
3232
status_callback_factory: Optional[StatusUpdateFactory] = _run_default_wrapper,
3333
):
@@ -37,7 +37,8 @@ def __init__(self,
3737
Arguments
3838
3939
dataset Name of a dataset from which queries will be selected.
40-
image Name of transformer image to use to transform the data
40+
image Name of transformer image to use to transform the data. If
41+
None the default implementation is used.
4142
cache_adaptor Runs the caching for data and queries that are sent up and
4243
down.
4344
max_workers Maximum number of transformers to run simultaneously on

tests/test_servicex.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ def test_default_ctor_cache_no(mocker):
7979

8080
config = mocker.MagicMock(spec=ServiceXConfigAdaptor)
8181
config.settings = Configuration('servicex', 'servicex')
82-
config.get_servicex_adaptor_config.return_value = ('http://no-way.dude', 'j@1232j322432j22token.com')
82+
config.get_servicex_adaptor_config.return_value = ('http://no-way.dude',
83+
'j@1232j322432j22token.com')
8384

8485
cache = mocker.MagicMock(spec=Cache)
8586
cache_create_call = mocker.patch('servicex.servicex.Cache', return_value=cache)
@@ -98,6 +99,7 @@ def test_ignore_cache_on_ds(mocker):
9899
config.get_servicex_adaptor_config.return_value = ('http://no-way.dude', '1232j322432j22token')
99100

100101
got_called = False
102+
101103
@contextmanager
102104
def do_context():
103105
nonlocal got_called
@@ -432,6 +434,25 @@ async def test_image_spec(mocker, good_awkward_file_data):
432434
assert called['image'] == 'fork-it-over:latest'
433435

434436

437+
@pytest.mark.asyncio
438+
async def test_no_image_spec(mocker, good_awkward_file_data):
439+
mock_cache = build_cache_mock(mocker)
440+
mock_logger = mocker.MagicMock(spec=log_adaptor)
441+
mock_servicex_adaptor = MockServiceXAdaptor(mocker, "123-456")
442+
mock_minio_adaptor = MockMinioAdaptor(mocker, files=['one_minio_entry'])
443+
444+
ds = fe.ServiceXDataset('localds://mc16_tev:13',
445+
servicex_adaptor=mock_servicex_adaptor, # type: ignore
446+
minio_adaptor=mock_minio_adaptor, # type: ignore
447+
cache_adaptor=mock_cache,
448+
local_log=mock_logger,
449+
data_convert_adaptor=good_awkward_file_data)
450+
await ds.get_data_rootfiles_async('(valid qastle string)')
451+
452+
called = mock_servicex_adaptor.query_json
453+
assert 'image' not in called
454+
455+
435456
@pytest.mark.asyncio
436457
async def test_max_workers_spec(mocker, good_awkward_file_data):
437458
mock_cache = build_cache_mock(mocker)

0 commit comments

Comments
 (0)