JGCRI/gcamwrapper

query_library.yml install

pralitp opened this issue · 1 comments

One of the pains about maintaining R and Python packages out of the same repo is how each wants to handle package data which at the moment only consists of query_library.yml

At the moment we cater to R and put it where it wants it: inst/extdata. And for Python we copy it into place in our setup.py. This seems to work although with the plethora of ways a Python package may get installed it is entirely possible it won't in all cases. In which case we should revisit this arrangement.

One such case which fails for python is if you try to load the package while your working directory is the top of the gcamwrapper repo in which case you will see an error such as the following:

>>> import gcamwrapper as gw
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/pralitp/model/temp/gcamwrapper/__init__.py", line 3, in <module>
    from gcamwrapper.main import Gcam, SolutionDebugger
  File "/Users/pralitp/model/temp/gcamwrapper/main.py", line 3, in <module>
    from gcamwrapper.query_library import apply_query_params
  File "/Users/pralitp/model/temp/gcamwrapper/query_library.py", line 19, in <module>
    PACKAGE_QUERIES = yaml.load(pkg_resources.resource_stream(__name__, 'query_library.yml'), Loader=yaml.FullLoader)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pkg_resources/__init__.py", line 1136, in resource_stream
    return get_provider(package_or_requirement).get_resource_stream(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pkg_resources/__init__.py", line 1608, in get_resource_stream
    return open(self._fn(self.module_path, resource_name), 'rb')
FileNotFoundError: [Errno 2] No such file or directory: '/Users/pralitp/model/temp/gcamwrapper/query_library.yml'

A work around is to simply choose any other working directory and python will load the Yaml file from the installed version instead of thinking it should find it from the working directory.