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

Nuitka doesn't support pkg_resources.get_distribution #146

Closed
kayhayen opened this issue Sep 22, 2018 · 6 comments
Closed

Nuitka doesn't support pkg_resources.get_distribution #146

kayhayen opened this issue Sep 22, 2018 · 6 comments
Assignees
Labels

Comments

@kayhayen
Copy link
Member

Sometimes code will check installed package versions with require or use the version information of installed packages for outputs. For standalone packages that does not work:

__version__ = pkg_resources.get_distribution('requests').version

However, by teaching pkg_resources about our meta path based importer, we could convince it
to provide the information even when egg data, etc. has been lost.

The source of the information is easy to get:

env = pkg_resources.Environment()
env.scan()
print(env._distmap)

This produces a dictionary with the information to use to produce Distribution objects at run time.

This apparently mostly does the job, but is bare of robustness:

def get_importer(path_item):
    return sys.meta_path[0]

def my_finder(a,b,c):
    yield pkg_resources.Distribution(project_name = "requests", version = "5")

pkg_resources.register_finder(type(sys.meta_path[0]), my_finder)
pkg_resources.get_importer = get_importer

__version__ = pkg_resources.get_distribution('requests').version

This code could become a post-load for pkg_resources to monkey patch it for finding resources hidden in the meta path based loader. Our meta path based loader should not be assumed to be only one (it is not for Python3 anyway), but directly accessed.

Also maybe it could read the distribution data from disk, to avoid caching issues, and it's nicer
to read that way probably too.

@kayhayen kayhayen self-assigned this Sep 22, 2018
@kayhayen kayhayen added bug delayed This is waiting for something else to be done first. help wanted Please help with this, we think you can labels Sep 22, 2018
@kayhayen kayhayen removed the delayed This is waiting for something else to be done first. label Jan 5, 2019
@kayhayen
Copy link
Member Author

kayhayen commented Jan 5, 2019

With 0.6.1 release, I want to work on this for the next release.

@kiranmantri
Copy link

Hi @kayhayen,
Do you know what is the status of this issue?

Thanks

@oz123
Copy link
Contributor

oz123 commented May 17, 2020

I have had similar issues in the past with pyinstaller. When running a program packages with pyinstaller one can detect if the environment is frozen with run time information. Maybe a similar approach can be implemented in nuitka?
Can you expand on how to detect during run time whether an application is inside a binary packaged by nuitka?

@kayhayen
Copy link
Member Author

There is a plugin in Nuitka that detects these kinds of version stuff, and resolves them now at compile time to the correct value, avoiding any runtime code, which makes this a solved issue.

@kayhayen kayhayen removed the help wanted Please help with this, we think you can label Nov 27, 2021
@oz123
Copy link
Contributor

oz123 commented Nov 27, 2021

@kayhayen maybe you can link to the plugin?

@kayhayen
Copy link
Member Author

It's automatically enabled.

@Nuitka Nuitka locked and limited conversation to collaborators Oct 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants