From fcd7ca6480ebf6f612b1ae3f5aeeb89a08d7748b Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Sat, 5 Feb 2022 12:27:32 +0000 Subject: [PATCH] fbmessenger: only import from .export in legacy mode --- my/fbmessenger/__init__.py | 23 +++++++++++------------ tests/test_import_warnings.sh | 0 2 files changed, 11 insertions(+), 12 deletions(-) mode change 100644 => 100755 tests/test_import_warnings.sh diff --git a/my/fbmessenger/__init__.py b/my/fbmessenger/__init__.py index 14bc326..910d7a6 100644 --- a/my/fbmessenger/__init__.py +++ b/my/fbmessenger/__init__.py @@ -10,18 +10,11 @@ https://github.com/karlicoss/HPI/issues/102 """ # TODO ^^ later, replace the above with from my.fbmessenger.all, when we add more data sources -# For now, including this here, since importing the module -# causes .export to be imported, which requires fbmessengerexport -REQUIRES = [ - 'git+https://github.com/karlicoss/fbmessengerexport', -] - import re import inspect -mname = 'fbmessenger' # todo infer from __name__? - +mname = __name__.split('.')[-1] # allow stuff like 'import my.module.submodule' and such imported_as_parent = False @@ -45,12 +38,18 @@ for f in inspect.stack(): # todo 'export' is hardcoded, not sure how to infer allowed objects anutomatically.. importing_submodule = True -warn = not (imported_as_parent or importing_submodule) +legacy = not (imported_as_parent or importing_submodule) -if warn: +if legacy: from my.core import warnings as W # TODO: add link to instructions to migrate W.high("DEPRECATED! Instead of my.fbmessengerexport, import from my.fbmessengerexport.export") + # only import in legacy mode + # otherswise might have unfortunate side effects (e.g. missing imports) + from .export import * - -from .export import * +# kinda annoying to keep it, but it's so legacy 'hpi module install my.fbmessenger' work +# needs to be on the top level (since it's extracted via ast module), but hopefully it doesn't hurt here +REQUIRES = [ + 'git+https://github.com/karlicoss/fbmessengerexport', +] diff --git a/tests/test_import_warnings.sh b/tests/test_import_warnings.sh old mode 100644 new mode 100755