Skip to content
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

'jsonvalidator' is not defined #38

Closed
kennyworkman opened this issue Jan 30, 2021 · 6 comments
Closed

'jsonvalidator' is not defined #38

kennyworkman opened this issue Jan 30, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@kennyworkman
Copy link

As you can see from path and stack trace - python3.9 and issue arises when invoking add_argument.

  File "/Users/kenny/semantic/semantic-convs/scae/args.py", line 56, in add_pcae_args
    pcae_args.add_argument(
  File "/Users/kenny/.virtualenvs/semantic-convs/lib/python3.9/site-packages/jsonargparse/core.py", line 86, in add_argument
    kwargs['action'] = ActionJsonSchema(annotation=kwargs.pop('type'), enable_path=enable_path)
  File "/Users/kenny/.virtualenvs/semantic-convs/lib/python3.9/site-packages/jsonargparse/jsonschema.py", line 94, in __init__
    jsonvalidator.check_schema(schema)
NameError: name 'jsonvalidator' is not defined
@mauvilsa
Copy link
Member

@kennyworkman you have not supplied any code to reproduce or the version of jsonargparse you are using, which you should when creating issues. I don't know what exactly you are doing, but have a look at https://jsonargparse.readthedocs.io/en/stable/#installation. There are several optional features, and you must install specifying extras requires depanding on what you want. For what you want it seems you are missing jsonschema.

@kennyworkman
Copy link
Author

Thank you - let me know what else I should provide to be helpful.

I have some questions after digging a bit through source.

  1. On lines 83-85, we have calls to add_argument with any type in the supported_types list leading to the creation of an ActionJsonSchema like so:
            if type_in(kwargs['type'], supported_types) or \
                    (inspect.isclass(kwargs['type']) and not _issubclass(kwargs['type'], (str, int, float, Enum, Path))):
                kwargs['action'] = ActionJsonSchema(annotation=kwargs.pop('type'), enable_path=enable_path)

This ActionJsonSchema relies on the jsonschema package not as a "feature", but anytime one wants to use a bool type within the add_argument function.

Is this an intentional design choice? I think this should be made more clear in the documentation if so.

@kennyworkman
Copy link
Author

ie. in jsonschema.py effort is made to check for "json schema support":

if jsonschema_support:
    jsonschema, jsonvalidator = import_jsonschema('jsonschema.py')

However, you reference the conditionally instantiated jsonvalidator regardless of jsonschema_support in the ActionJsonSchema class. Would you consider this a bug?

@mauvilsa
Copy link
Member

If you see the boolean arguments section in the documentation it does say that jsonschema is required. The issue is that jsonargparse grew a lot in features and in the length of the documentation. So it is not easy to know how to improve these kind of details in the documentation. Though it is true that the stack trace you got is not helpful. Actually this is handled better in other files, which give a better error message. I will change it so that it is like in jsonnet.py#L74.

@mauvilsa mauvilsa added the enhancement New feature or request label Jan 31, 2021
mauvilsa added a commit that referenced this issue Feb 1, 2021
…al features #38.

- Better exception message when using ActionJsonSchema and jsonschema not installed #38.
- default_config_files is now a property of parser objects.
- Prepare for release v3.4.0.
@mauvilsa
Copy link
Member

mauvilsa commented Feb 1, 2021

I have changed the code so that the exception error message is more clear and also added a table in the installation section of the readme to make it easier to understand which features require which extras requires. Please have a look.

@kennyworkman
Copy link
Author

Thank you, able to reproduce with more informative error. Learned a lot picking through the repo - thanks for your work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants