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

Deprecate or remove use __file__ #196

Open
jayvdb opened this issue Apr 11, 2020 · 5 comments
Open

Deprecate or remove use __file__ #196

jayvdb opened this issue Apr 11, 2020 · 5 comments

Comments

@jayvdb
Copy link

jayvdb commented Apr 11, 2020

For reading .tld_set, __file__ should be replaced with pkgutil.get_data, which is used for .tld_set_snapshot.

The dataset file may have been placed into the package data via another means, and the attribute __file__ may not be present at all, as it is an optional attribute of the Python module loading system. tldextract fails badly atm when it is missing. An example of when it is missing is PyOxidizer, and Nuitka also has similar problems.

When it is missing, or when the package directory is not writable, the cache should be stored in a different location without a warning.

Currently I see the following for every invocation which imports tldextract, because it is installed as a system package used by system apps:

WARNING unable to cache TLDs in file /usr/lib/python3.8/site-packages/tldextract/.tld_set: [Errno 13] Permission denied: '/usr/lib/python3.8/site-packages/tldextract/.tld_set'

@john-kurkowski
Copy link
Owner

Makes sense. I don't suppose it's as easy as this? Plus changing types from filename strings to read-in-file strings.

-CACHE_FILE_DEFAULT = os.path.join(os.path.dirname(__file__), '.tld_set')
+CACHE_FILE_DEFAULT = pkgutil.get_data(__name__, '.tld_set')

@john-kurkowski
Copy link
Owner

When it is missing, or when the package directory is not writable, the cache should be stored in a different location without a warning.

Is there a standard, usually writable location for this? Or a library to determine it?

@jayvdb
Copy link
Author

jayvdb commented Aug 5, 2020

The xdg standard defines cache directories.

appdirs package is typical solution.

@john-kurkowski
Copy link
Owner

That is what I've been looking for. Maybe that's the most robust solution to #9, #149, and this ticket.

@merwok
Copy link

merwok commented Nov 9, 2021

FYI, platformdirs is a replacement for appdirs that’s actively maintained and more performant.

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

No branches or pull requests

3 participants