Open akmiller01 opened 5 years ago
I think you are right that this is due to filepaths. Specifically, I think it’s because resources are all loaded via relative filepaths:
I think best practice in packages is to use absolute filepaths everywhere. I guess that’s the problem here.
Oddly enough it works just fine on my Ubuntu partition and doesn't try and access /resources/
at my system root. Just a Windows specific bug for the moment.
Yes, same. I think using relative paths in this way is dodgy, because it’s not always obvious what it is relative to. That’s why package developers usually do something like:
basepath = os.path.dirname(os.path.abspath(__file__))
…and then prepend that to all relative paths.
Aside: contrary to what the usage section in the README says, this library is not currently under active development.
See this announcement on IATI discuss: https://discuss.iatistandard.org/t/state-of-pyiati/1360/7
Found a fix, in case this project is ever rebooted.
On line 99 here, https://github.com/IATI/pyIATI/blob/269a2c1cb73479875a534ae3dfcb6ef9c03e1766/iati/resources.py#L99
folder_path[len(resource_filesystem_path('')):]
comes out as "\\resources\\standard\\2-03\\codelists"
on Windows, while it comes out as "/resources/standard/2-03/codelists"
on Unix based operating systems.
For some reason, the default Python package resource manager pkg_resources
interprets that as relative to the package for Unix, but absolute to the C: drive for Windows. Can be fixed by importing os
, splitting the path, and re-joining it before searching for the resources.
import os
files = pkg_resources.resource_listdir(PACKAGE, os.path.join(*folder_path[len(resource_filesystem_path('')):].split(os.sep)))
I've added a PR to fix this in #329.
I've also separately added python 3.7 builds to Travis in #330 - ideally you would have a seperate Travis builds running in both Unix and Windows to confirm cross-platform support, but I haven't looked into if/how that is possible.
ideally you would have a seperate Travis builds running in both Unix and Windows to confirm cross-platform support, but I haven't looked into if/how that is possible.
It’s not currently. Travis says:
The language 'python' is currently unsupported on the Windows Build Environment.
Here's my full error trace.
Should be reproducible with just the code in the README:
Seems to be an issue with absolute filepaths?