Skip to content

Commit

Permalink
Merge pull request #248 from tangkong/enh_cli_report
Browse files Browse the repository at this point in the history
ENH: add report output option to atef check cli
  • Loading branch information
tangkong authored Aug 5, 2024
2 parents 11b15c0 + 132314e commit f5d1e2e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
30 changes: 28 additions & 2 deletions atef/bin/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from ..config import (AnyConfiguration, AnyPreparedConfiguration,
ConfigurationFile, FailedConfiguration,
PreparedComparison, PreparedFile, PreparedGroup)
from ..report import PassiveAtefReport
from ..result import Result
from ..util import ophyd_cleanup

Expand Down Expand Up @@ -130,6 +131,11 @@ def build_arg_parser(argparser=None):
help="Acquire data for comparisons in parallel",
)

argparser.add_argument(
"-r", "--report-path",
help="Path to the report save path, if provided"
)

return argparser


Expand Down Expand Up @@ -400,7 +406,7 @@ async def check_and_log(
parallel: bool = True,
cache: Optional[DataCache] = None,
filename: Optional[str] = None,
):
) -> PreparedFile:
"""
Check a configuration and log the results.
Expand All @@ -420,6 +426,11 @@ async def check_and_log(
Pre-fill cache in parallel when possible.
cache : DataCache
The data cache instance.
Returns
-------
PreparedFile
The completed checkout file, with results recorded
"""
name_filter = list(name_filter or [])

Expand Down Expand Up @@ -452,6 +463,17 @@ async def check_and_log(
else:
console.print(tree)

return prepared_file


def save_report(prep_file: PreparedFile, report_path: str):
# Normalize report path
from pathlib import Path
save_path = Path(report_path).resolve()

doc = PassiveAtefReport(str(save_path), config=prep_file)
doc.create_report()


async def main(
filename: str,
Expand All @@ -465,6 +487,7 @@ async def main(
show_config_description: bool = False,
show_tags: bool = False,
show_passed_tests: bool = False,
report_path: Optional[str] = None,
):

verbosity = VerbositySetting.from_kwargs(
Expand All @@ -481,7 +504,7 @@ async def main(
cache = DataCache(signals=signal_cache or get_signal_cache())
try:
with console.status("[bold green] Performing checks..."):
await check_and_log(
prep_file = await check_and_log(
config_file,
console=console,
name_filter=name_filter,
Expand All @@ -490,6 +513,9 @@ async def main(
filename=filename,
verbosity=verbosity,
)
if report_path is not None:
with console.status("[bold green] Saving report..."):
save_report(prep_file, report_path)
finally:
if cleanup:
ophyd_cleanup()
2 changes: 1 addition & 1 deletion conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ requirements:
- databroker <2.0.0a0
- happi
- ipython
- numpy
- numpy <2.0.0
- ophyd
- pcdsutils >=0.14.1
- pydm
Expand Down
22 changes: 22 additions & 0 deletions docs/source/upcoming_release_notes/248-enh_cli_report.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
248 enh_cli_report
##################

API Breaks
----------
- N/A

Features
--------
- Adds report output option to `atef check` cli tool

Bugfixes
--------
- N/A

Maintenance
-----------
- N/A

Contributors
------------
- tangkong
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ bluesky-widgets
databroker<2.0.0a0
happi
ipython
numpy
# numpy >2 incompatible with xraylib and others
numpy<2.0.0
ophyd
pcdsutils>=0.14.1
pydm
Expand Down

0 comments on commit f5d1e2e

Please sign in to comment.