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

Avoid use of __file__ #2196

jayvdb opened this issue Nov 9, 2019 · 0 comments · Fixed by #2198

Avoid use of __file__ #2196

jayvdb opened this issue Nov 9, 2019 · 0 comments · Fixed by #2198


Copy link

@jayvdb jayvdb commented Nov 9, 2019

It appears the use of __file__ here is mostly unnecessary, or could be replaced with importlib.resources/pkgutil. See indygreg/PyOxidizer#69 for more info about why, but the tl;dr version is __file__ is an optional attribute and should not be relied upon.

> GIT_PAGER=cat git grep -E '(__file__|ROOT|STDLIB)' hypothesis-python/src/hypothesis
hypothesis-python/src/hypothesis/ = os.path.dirname(__file__)
hypothesis-python/src/hypothesis/ = os.path.dirname(os.__file__)
hypothesis-python/src/hypothesis/internal/    root = os.path.dirname(package.__file__)
hypothesis-python/src/hypothesis/    os.path.join(os.path.dirname(__file__), "vendor", "tlds-alpha-by-domain.txt")

At the moment, import hypothesis fails on any Python runtime that doesnt attach __file__ to hypothesis or doesnt attach __file__ to os.

As show there, ROOT and STDLIB are unused within the main runtime code.
If they are needed elsewhere, the definitions should be moved closer to the need, so that at least the top level import hypothesis works.

Loading of tlds-alpha-by-domain.txt should ideally be done using importlib.resources and backport ``importlib_resources, however pkgutil` could be used to avoid the need for the backport. Using `pkgutil` would mean hypothesis doesn't work under PyOxidizer 0.4, however I expect that will be fixed soon.

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

Successfully merging a pull request may close this issue.

2 participants