-
-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to dynamically import packages? #335
Comments
You could do like: if optional_package_available:
import optional_package
...
if optional_package_available:
parser.add_function_args(optional_package.some_function, ...)
Not really sure what you mean by this. |
Yes, but if I try to run a command with arguments, it won't recognize them and exit, and the only way to show a message about installing additional packages, as I understand, is to catch |
I guess what you need is an if optional_package_available:
from optional_package import some_function
...
if optional_package_available:
parser.add_function_arguments(some_function, "group")
else:
parser.add_argument("--group", action=ActionNotAvaliable("please install optional_package")) The CLI would exit with the given message if any option
|
I'm designing a package that have main functionality and optional functionality that requires extra packages to be installed. I want to build a CLI for the package.
jsonargparse
dissuades use ofparse_known_args()
, so I cannot import packages only when needed.For example, I want to add optional function arguments. I cannot use
parser.add_function_args
because it would need me to import the function. I must add arguments manually, but I can't always do this, because some arguments may depend on classes in my optional functionality. How to manage this case? Thank youThe text was updated successfully, but these errors were encountered: