BstLabs / py-dynacli

DynaCLI is a cloud-friendly Python library for converting pure Python functions into Linux Shell commands.
https://bstlabs.github.io/py-dynacli/
MIT License
98 stars 5 forks source link

[BUG] Insufficient diagnostics and protection against rogue cli package #101

Closed asterkin closed 2 years ago

asterkin commented 2 years ago

Describe the bug When caios-21-12 switched to the most recent Open Source version of dynacli one of commands started failing. Tracking down what's wrong is not easy.

To Reproduce Steps to reproduce the behavior: caios ide -h

Expected behavior A clear and concise description of what you expected to happen. Should print a normal help or a clear error message

Screenshots If applicable, add screenshots to help explain your problem. image

Extra info:

asterkin commented 2 years ago

It assumes that every module has a file attribute which appears to be wrong. What this _Environ module is is yet to be found.

asterkin commented 2 years ago

_Environ is a class inside os.py: https://github.com/python/cpython/blob/3.10/Lib/os.py. os is included in the module init.py

asterkin commented 2 years ago

Yes, importing python os in package init leads to this problem. The diagnostics about wrong init structure is still insufficient:

image

ShahriyarR commented 2 years ago

Reproduced as:

Adding from os import environ in the __init__.py of the package introduced new bug:

Traceback (most recent call last):
+   File "/home/ssm-user/OSS/py-dynacli/test/integrated/testclinested", line 23, in <module>
+     main(
+   File "/home/ssm-user/.local/lib/python3.9/site-packages/dynacli/dynacli.py", line 772, in main
+     current_state = current_state(iter_, context)
+   File "/home/ssm-user/.local/lib/python3.9/site-packages/dynacli/dynacli.py", line 726, in _waiting_for_nested_feature_or_command
+     context.build_feature_help()
+   File "/home/ssm-user/.local/lib/python3.9/site-packages/dynacli/dynacli.py", line 494, in build_feature_help
+     self._set_known_names()
+   File "/home/ssm-user/.local/lib/python3.9/site-packages/dynacli/dynacli.py", line 452, in _set_known_names
+     _is_callable(module) or _is_module_shortcut(name, self._current_package)
+   File "/home/ssm-user/.local/lib/python3.9/site-packages/dynacli/dynacli.py", line 121, in _is_module_shortcut
+     and not _is_package(package.__dict__[name])
+   File "/home/ssm-user/.local/lib/python3.9/site-packages/dynacli/dynacli.py", line 115, in _is_package
+     return module.__file__ and module.__file__.endswith("__init__.py")
+ AttributeError: '_Environ' object has no attribute '__file__'