izar / pytm

A Pythonic framework for threat modeling
Other
861 stars 161 forks source link

Enhancement request: move pyDAL to local import #234

Closed colesmj closed 4 months ago

colesmj commented 4 months ago

pyDAL is used for only 1 purpose within 1 function - pytm.py:1175 SQLDump() For readability and to reduce pre-installation requirements for likely most users, consider making the import of pyDAL currently on pytm.py:24 be local to SQLDump(). This is allowed by Python and means if no one uses SQLDump() pyDAL is never loaded; otherwise it is a requirement and always loaded even if never used.

izar commented 4 months ago

hm, but wouldn't that cause a fail if someone started slow and didn't use the sql functionality, but then did so? we would be banking on the idea that they know how to deal with an import error in Python.

raphaelahrens commented 4 months ago

You can catch the failed import error and print guidance on how to proceed to stdout.

try:
    import pyDAL
except ImportError:
   print("please do ....")
izar commented 4 months ago

... and I just learned a new one. This day already paid off, thanks! In that case, PR away!

raphaelahrens commented 4 months ago

I think this can be closed now.