python-3.xos.pathpkg-resources

Is there a way to define resource directories (not just filenames) for extraction with pkg_resources in Python?


I am going over the pkg_resources documentation (https://setuptools.readthedocs.io/en/latest/pkg_resources.html) and trying to implement an object similar to resource_filename, but I just want the resource directory that the file exists in. Do I define this as a default somewhere else, like in setup.py or something?

Also, if such a path object exists, is there any benefit to using it as opposed to just an os.path object?

How can this package contain methods like resource_isdir and resource_listdir when there is no way to actually make the resource a dir?


Solution

  • pkg_resources.resource_filename accepts directories as an argument -- however, you have to specify the package as the parent directory within your package.