scikit-hep / pyhf

pure-Python HistFactory implementation with tensors and autodiff
https://pyhf.readthedocs.io/
Apache License 2.0
285 stars 84 forks source link

Have pyhf CLI detect if files are compressed or not #1090

Open matthewfeickert opened 4 years ago

matthewfeickert commented 4 years ago

Description

This suggestion comes from @jpivarski in an IRIS-HEP Slack thread:

@kratsg: It's pretty easy for pyhf to just pipe through, e.g. gunzip foo.zip --extract bkgonly.json | pyhf inspect

@jpivarski: You could also make it easier on pyhf users by recognizing the zipped data by magic headers: gzip (b"\x1f\x8b"), zip (b"PK"), JSON (re.compile(br"^\s*{")), then use Python's gzip or zipfile internally. Then you could just pipe it in without worrying about whether it's compressed: you'd take on compressed JSON as a recognized input format.

kratsg commented 4 years ago

best to use something like https://github.com/ahupp/python-magic