You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
currently we're using pkg_resources to load resource files like the default.conf. Since Python 3.7, there is the importlib.resources module in the standard library, which provides a more convenient and efficient way to access resources.
Only problem is that we're currently compatible with Python 3.6; should we make >=3.7 a requirement or leave this for now? The benefit is not huge, but support for Python 3.6 will end this year anyway.
We can probably replace the current implementation with
fromimportlib.abcimportTraversablefromimportlib.resourcesimportfilesdefget_resource_string(path: str) ->str:
""" Load a package resource (i.e. a file from within this package) :param path: the path, starting at the root of the current module (e.g. 'res/default.conf'). must be a string, not a Path object! :return: the contents of the resource file as string """returnget_resource_path(path).read_text()
defget_resource_bytes(path: str) ->bytes:
""" Load a package resource (i.e. a file from within this package) :param path: the path, starting at the root of the current module (e.g. 'res/image.png'). must be a string, not a Path object! :return: the contents of the resource file as bytes """returnget_resource_path(path).read_bytes()
defget_resource_path(path: Union[str, Traversable]) ->Traversable:
"""Get a reference to a package internal path object"""module_name=__name__.split('.')[0]
returnfiles(module_name).joinpath(path)
The text was updated successfully, but these errors were encountered:
I just noticed that importlib.resources.files is only available in Python >=3.9 and the functions available since 3.7, well they suck. So I think we can keep pkg_resources until Python 3.9 becomes the min version for at-python-template...
currently we're using
pkg_resources
to load resource files like thedefault.conf
. Since Python 3.7, there is theimportlib.resources
module in the standard library, which provides a more convenient and efficient way to access resources.Only problem is that we're currently compatible with Python 3.6; should we make >=3.7 a requirement or leave this for now? The benefit is not huge, but support for Python 3.6 will end this year anyway.
We can probably replace the current implementation with
The text was updated successfully, but these errors were encountered: