Merged
Conversation
* centralize on one get_run() * use dotenv for Tiled API key
Contributor
There was a problem hiding this comment.
Pull request overview
This PR moves Tiled access toward a from_uri-based approach and starts threading a Tiled API key through Prefect flows/tasks to enable running workflows outside NSLS-II profile-based infrastructure.
Changes:
- Added
get_run()(Tiledfrom_uri) and updated workflows/exporters to fetch runs via this helper and accept anapi_keyparameter. - Removed Tiled profile mounts/env from the Prefect Docker deployment configuration.
- Updated end-of-run workflow to pass
api_keythrough to downstream exporters/logging.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
data_validation.py |
Adds from_uri-based get_run() and updates validation flow to use it. |
xrf_hdf5_exporter.py |
Switches run loading to get_run() and adds api_key plumb-through. |
xanes_exporter.py |
Switches run loading to get_run() and adds api_key parameters across exporters. |
logscan.py |
Starts switching to get_run() and adds api_key parameters (but still has profile/Secret globals). |
end_of_run_workflow.py |
Uses get_run() and passes api_key to downstream flows. |
prefect.yaml |
Removes Tiled profile env/volume from the deployment container configuration. |
Comments suppressed due to low confidence (3)
logscan.py:86
logscan()acceptsapi_keybut doesn't pass it intologscan_detailed(), so the nested call will run withapi_key=Noneand may fail to authenticate against Tiled. Thread theapi_keyargument through (logscan_detailed(ref, api_key=api_key)).
def logscan(ref, api_key=None):
logger = get_run_logger()
logger.info("Start writing logfile...")
logscan_detailed(ref)
logger.info("Finish writing logfile.")
logscan.py:11
- This module still initializes
Secret.load(...)andfrom_profile(...)at import time (and definestiled_client_raw) even though the actual code path now usesget_run(...)instead. With the Prefect deployment no longer mounting/setting Tiled profiles, this import-timefrom_profile('nsls2', ...)is likely to fail before the flow runs. Remove these globals (and theSecret/from_profileimports) or migrate them tofrom_uriand only construct clients inside functions when needed.
from prefect.blocks.system import Secret
from tiled.client import from_profile
from data_validation import get_run
api_key = Secret.load("tiled-srx-api-key", _sync=True).get()
tiled_client = from_profile("nsls2", api_key=api_key)["srx"]
tiled_client_raw = tiled_client["raw"]
xanes_exporter.py:340
xanes_exporter()acceptsapi_keyand uses it to determinescan_type, but it does not passapi_keyintoxas_step_exporter()/xas_fly_exporter(). As a result those tasks will run withapi_key=Noneand may fail when they callget_run(...). Passapi_keythrough to the selected exporter task.
def xanes_exporter(ref, api_key=None):
logger = get_run_logger()
logger.info("Start writing file with xanes_exporter...")
# Get scan type
scan_type = (
get_run(ref, api_key=api_key).start.get("scan", {}).get("type", "unknown")
)
# Redirect to correction function - or pass
if scan_type == "XAS_STEP":
logger.info("Starting xanes step-scan exporter.")
xas_step_exporter(ref)
logger.info("Finished writing file with xanes step-scan exporter.")
elif scan_type == "XAS_FLY":
logger.info("Starting xanes fly-scan exporter.")
xas_fly_exporter(ref)
logger.info("Finished writing file with xanes fly-scan exporter.")
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* unused code to get Tiled client - replace by using get_run() from data_validation()
* output more info for xas_fly_exporter as it seems to have a better structure
AbbyGi
reviewed
Mar 30, 2026
AbbyGi
reviewed
Mar 31, 2026
Contributor
AbbyGi
left a comment
There was a problem hiding this comment.
Two things, otherwise looks good
Co-authored-by: Abby Giles <35899293+AbbyGi@users.noreply.github.com>
Co-authored-by: Abby Giles <35899293+AbbyGi@users.noreply.github.com>
AbbyGi
approved these changes
Mar 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Update toward the template repo: