AMONCode / Analysis

Repository for the AMON software
2 stars 0 forks source link

Add a config module to help with config parser object discovery #7

Closed chadhanna closed 4 years ago

chadhanna commented 7 years ago

Closely integrated with setuptools is the pkg_resources module which helps with data discovery in a distribution. We should use it to retrieve our ini file config parser. I would like to add a module called "config.py" into amonpy/tools. Here are the contents

import pkg_resources
from ConfigParser import ConfigParser as CP
AMON_CONFIG = CP();
with open(pkg_resources.resource_filename("amonpy", "amon_replace.ini")) as f:
        AMON_CONFIG.readfp(f)

Then any code can access the config parser already initialized by simply doing:

from amonpy.tools.config import AMON_CONFIG

You then have access to the ConfigParser, e.g.,

>>> AMON_CONFIG.sections()
['database', 'dirs', 'machine', 'mailing_list']
>>> 
AMONCode commented 4 years ago

This was completely implemented into amonpy.