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

Port iter_matching_entrypoints to importlib.metadata #513

Closed
flying-sheep opened this issue Jan 19, 2021 · 9 comments · Fixed by #514
Closed

Port iter_matching_entrypoints to importlib.metadata #513

flying-sheep opened this issue Jan 19, 2021 · 9 comments · Fixed by #514

Comments

@flying-sheep
Copy link
Contributor

When calling _version_from_entrypointsiter_matching_entrypoints, we should use importlib.metadata instead of pkg_resources, as pkg_resources isn’t the standard way to do this, and is also buggy in this context (see pypa/setuptools#2531)

The changes required would be pretty minimal:

requirements:

importlib_metadata; python_version < "3.8"

code:

try:
    from importlib.metadata import entry_points
except ImportError:
    from importlib_metadata import entry_points
@RonnyPfannschmidt
Copy link
Contributor

i consider this low prio as the issue can't affect setuptools_scm in the intended usage scsenario as of now

additionally this poses a issue as i don't really want to add the extra dependency for old pythons

so i may decide to just leave it be until the pythons that don't have importlib_metadata no longer need to be supported

@flying-sheep
Copy link
Contributor Author

flying-sheep commented Jan 20, 2021

Can you please elaborate on why that isn’t the intended usage scenario? Your readme says:

In order to use setuptools_scm from code that is one directory deeper than the project's root, you can use:

from setuptools_scm import get_version
version = get_version(root='..', relative_to=__file__)

We do exactly that, and the setuptools maintainers explicitly ask you to no longer use pkg_resources.

If you want to keep it, in order to avoid hard-to-debug breakage, please create a new WorkingSet and use that instead of the global one.

additionally this poses a issue as i don't really want to add the extra dependency for old pythons

why is that?

@RonnyPfannschmidt
Copy link
Contributor

In the use case for setuptools_scm a stale workingset is typically not a issue, in particular with more modern tools around,
However additional dependencies make packaging more painful

That Being said, if a pr is submitted to use importlib on pythons that support it, im happy to merge and release

@jaraco
Copy link
Member

jaraco commented Jan 20, 2021

Thanks Ronny. I support this initiative. Even though pkg_resources isn't deprecated, I am working toward deprecation and discouraging its use. I'll be happy to shepherd these changes as well. Thanks flying-sheep for the effort.

@flying-sheep
Copy link
Contributor Author

That Being said, if a pr is submitted to use importlib on pythons that support it, I’m happy to merge and release

Entirely possible!

Are you actually importing anything from setuptools apart from pkg_resources.iter_entry_points? This might actually reduce the amount of runtime dependencies.

@flying-sheep
Copy link
Contributor Author

pkg_resources is now officially deprecated:

Use of pkg_resources is discouraged in favor of importlib.resources, importlib.metadata, and their backports (resources, metadata). Please consider using those libraries instead of pkg_resources.

@RonnyPfannschmidt what’s the plan?

@RonnyPfannschmidt
Copy link
Contributor

given that setup_requires usage is now deprecated, lets add it for the next feature release

@flying-sheep
Copy link
Contributor Author

Okay! Since #526 is merged, this should be very simple. I updated #514

@flying-sheep
Copy link
Contributor Author

flying-sheep commented Oct 8, 2021

I just noticed how much this step improved import times, so this was a good move!

$ PYTHONPROFILEIMPORTTIME=1 python -c 'import setuptools_scm' 2>! importprofile.log
$ tuna importprofile.log

before:

before

after:

after

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

Successfully merging a pull request may close this issue.

3 participants