my.reddit: refactor into module that supports pushshift/gdpr (#179)

* initial pushshift/rexport merge implementation, using id for merging
* smarter module deprecation warning using regex
* add `RedditBase` from promnesia
* `import_source` helper for gracefully handing mixin data sources
This commit is contained in:
Sean Breckenridge 2021-10-31 13:39:04 -07:00 committed by GitHub
parent b54ec0d7f1
commit 8422c6e420
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 374 additions and 58 deletions

41
my/reddit/__init__.py Normal file
View file

@ -0,0 +1,41 @@
"""
This is here temporarily, for backwards compatability purposes
It should be removed in the future, and you should replace any imports
like:
from my.reddit import ...
to:
from my.reddit.all import ...
since that allows for easier overriding using namespace packages
https://github.com/karlicoss/HPI/issues/102
"""
# For now, including this here, since importing the module
# causes .rexport to be imported, which requires rexport
REQUIRES = [
'git+https://github.com/karlicoss/rexport',
]
import re
import traceback
# some hacky traceback to inspect the current stack
# to see if the user is using the old style of importing
warn = False
for f in traceback.extract_stack():
line = f.line or '' # just in case it's None, who knows..
# cover the most common ways of previously interacting with the module
if 'import my.reddit ' in (line + ' '):
warn = True
elif 'from my import reddit' in line:
warn = True
elif re.match(r"from my\.reddit\simport\s(comments|saved|submissions|upvoted)", line):
warn = True
# TODO: add link to instructions to migrate
if warn:
from my.core import warnings as W
W.high("DEPRECATED! Instead of my.reddit, import from my.reddit.all instead.")
from .rexport import *