unfurl
unfurl copied to clipboard
refactor code to separate API logic from core.py logic
Description
TLDR: I (and surely others) cannot use unfurl as a python library but refactoring code.py would fix that.
The current core.py contains both the logic needed to do something like:
from unfurl.core import Unfurl
unfurl = Unfurl(remote_lookups=False)
unfurl.add_to_queue(data_type='url', key=None, value=url)
unfurl.parse_queue()
print(unfurl.generate_json())
as well as the logic needed to run the flask API.
That would normally not pose an issue except doing a fresh installation of the library does not seem to work for python 3.10 on linux (possibly other OSes and versions) since the API code uses flask-restx and the current version of that is using a try/catch import strategy (the reason is described in this SO question):
try:
from flask.helpers import _endpoint_from_view_func
except ImportError:
from flask.scaffold import _endpoint_from_view_func
the code inside try does not work on the setup I describe so the execution defaults to the catch block.
So, in order to run this library I would have to manually install Flask-Scaffold, but the problem is that doing so leads to a conflict dependency:
The conflict is caused by:
dfir-unfurl 20230901 depends on flask>=2.2.0
flask-scaffold 0.5.1 depends on Flask==0.10.1
The result is I cannot do from unfurl.core import Unfurl and thus cannot use the library :cry:
A solution I've tried that works is separating the flask logic into a new file that's not core.py so that doing the import does not lead us down the flask nightmare, that should be feasible since core.py does not need the flask logic, and only the flask logic needs core.py :eyes:
Would it make sense for you to separate these?