Grokzen / pykwalify

Python YAML/JSON schema validation library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add ability to use package resources as data source

eirnym opened this issue · comments

Currently pykwalify library doesn't provide an easy way to override where resources are located and all named resources must be reachable by open function. This disallows a user to open them with custom names or using package resources including API provided by Python 3.7 and backported to earlier versions.

To provide this posibility I suggest:

  • add ability to supply dict containing some required data such as custom types, external resources, etc
  • replace all open() calls by an overridable function as a parameter or by a custom class method

What API resources provided in python 3.7 are you talking about? I do not know what you mean by that.

How would adding the ability to point a specific open() help? Most times the normal open method is good enough, the issue is more with the arguments to the open function like encoding for example. If i still have to handle the arguments into the method from inside pykwalify, the overriden open function would provide little value. If you can elaborate in more detail on this, please do.

One bad thing about the additional dict into the class, is that it will be very hard to map it to cli arguments or similar. You either have to configure pykwalify through some settings file for that to even be a viable solution for most users. Some of this functionality is already in place with custom data into the class for some features, and some stuff is already present for config file.

The CLI interface could be the same, I'm talking only about programmable interface as in most cases developers would use your library as a library, not as a tool. One of major usage of it as I see is to check incoming data from a network against defined API schemas.

Python 3.7 added brand new rewrited importlib.resources package allowing a developer to access any resource inside packages. There's many advantages over existing implementation. All information you can read here

I will not implement this feature. I will leave it up to the user of this lib to sort out the fetching and loading of data into the Core class. The Core class now can take so many different types of objects and data when building itself that it should be easy enough to make your own usage of resources when using this in lib mode.