pepkit / pipestat

Pipeline results reporting package
https://pep.databio.org/pipestat/
BSD 2-Clause "Simplified" License
4 stars 2 forks source link

Allow parameterizing via env vars #164

Closed nsheff closed 1 week ago

nsheff commented 5 months ago

Here I have an example of some code that allows a database-backed Python object to be parameterized either via constructor, or via ENV vars:

https://github.com/refgenie/seqcolapi/blob/fa889f818e1858573cb261077fd737af905178af/seqcolapi/scconf.py#L79-L94

I have found this convenient, because to use it I just do something like:

source settings.env
python

Then

db = RDBDict()

which is quite nice, and also cloud-friendly. I have found myself wanting to do this with pipestat. Would it be possible to make the constructor work like this so it can be configured via ENV vars?

I know it's a little different since there's a pipestat config file, and there's nothing like that here.

I wonder if priority_get could help;

https://github.com/databio/yacman/blob/5db6323a6469347abfa16a590fc8b48d21b7b16f/yacman/yacman_future.py#L358-L389

donaldcampbelljr commented 3 months ago

Is this actually already possible? Looks as though we are using priority_get to potentially use any environment variables: https://github.com/pepkit/pipestat/blob/e7d42370aaf01267956fedb426ba16d6d73b3be0/pipestat/pipestat.py#L187-L210

donaldcampbelljr commented 3 months ago

I did confirm that this works fine. The only snag I ran into was sourcing my .env file. I found a package that assisted with this in Python. https://github.com/theskumar/python-dotenv

Example of Code, assuming main.py and .env are parallel:

from pipestat import PipestatManager
from dotenv import load_dotenv

load_dotenv()
psm1=PipestatManager()
psm1.report(values={"number_of_things":3})