pyfilesystem2 icon indicating copy to clipboard operation
pyfilesystem2 copied to clipboard

drop or relax dependency on pkg_resources?

Open anthrotype opened this issue 4 years ago • 4 comments

setuptools' pkg_resources is considered sort of deprecated nowadays, and it's being replaced by importlib.resources (added to python3.7 stdlib) and importlib.metadata (included in python3.8). Both of the latter have backports on PyPI for previous pythons: https://pypi.org/project/importlib_resources/ https://pypi.org/project/importlib-metadata/

As far as I understand, fs needs pkg_resources for two reasons:

  1. for implementing namespace packages
  2. for dynamically loading plugins as entry-points

For the first, the Python Packaging Authority's packaging guide recommends to use pkgutil-style namespace packages which allegedly work on both py2 and py3 (I have never used them though): https://packaging.python.org/guides/packaging-namespace-packages/#pkgutil-style-namespace-packages

For the second point, I think importlib.metadata should support this. Other big projects like pytest have recently switched to using that (see https://github.com/pytest-dev/pluggy/pull/199).

My immediate issue is that I cannot package my app (https://github.com/googlefonts/fontmake) with PyObsidizer because the latter does not support pkg_resources: https://github.com/indygreg/PyOxidizer/issues/134?#issuecomment-542652539

anthrotype avatar Oct 16 '19 11:10 anthrotype

(by the way, also importlib.metadata is incompatible with pyoxidizer because the latter strips all metadata...)

I was looking at fs.opener.registry module, and it appears that it's only calling pkg_resources.iter_entry_points when load_extern option of Registry class is True (and the default registry has it True).

I was thinking, maybe we could set the default registry's load_extern=False if attempting to import pkg_resources fails, and thus we make pkg_resources (setuptools) itself an optional requirement?

Of couse, making pkg_resources optional would also mean replacing its namespace-package machinery with the equivalent method that uses pkgutil. I have not considered what the implications of the latter are, since I'm not familiar with namespace packages inner workings.

@willmcgugan would you be willing to let go of pkg_resources hard install requirement and make it optional or soft-required? So, if one wants to load plugin filesystems, one needs setuptools installed. Otherwise if only using core filesystem modules, then no setuptools would be needed.

anthrotype avatar Oct 16 '19 12:10 anthrotype

I know nothing about any of this, but would #13 (i.e. standalone commands) also affect it? :man_shrugging:

lurch avatar Oct 17 '19 10:10 lurch

@lurch no, that's completely unrelated issue.

anthrotype avatar Oct 17 '19 11:10 anthrotype

Sounds like a good idea. If we can maintain the current feature set with recommended libraries, then I'm for it.

I'm traveling at the moment. I'll look in to it in more detail when I'm back.

willmcgugan avatar Oct 18 '19 01:10 willmcgugan