Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop or relax dependency on pkg_resources? #356

Open
anthrotype opened this issue Oct 16, 2019 · 4 comments · May be fixed by #553
Open

drop or relax dependency on pkg_resources? #356

anthrotype opened this issue Oct 16, 2019 · 4 comments · May be fixed by #553

Comments

@anthrotype
Copy link

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 pytest-dev/pluggy#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:
indygreg/PyOxidizer#134

@anthrotype
Copy link
Author

anthrotype commented Oct 16, 2019

(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 anthrotype changed the title replace pkg_resources with importlib_metadata? drop or relax dependency on pkg_resources? Oct 16, 2019
@lurch
Copy link
Contributor

lurch commented Oct 17, 2019

I know nothing about any of this, but would #13 (i.e. standalone commands) also affect it? 🤷‍♂️

@anthrotype
Copy link
Author

@lurch no, that's completely unrelated issue.

@willmcgugan
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants