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

ensure pyang can be used embedded in another program #325

Open
mbj4668 opened this issue Jul 6, 2017 · 4 comments
Open

ensure pyang can be used embedded in another program #325

mbj4668 opened this issue Jul 6, 2017 · 4 comments
Assignees

Comments

@mbj4668
Copy link
Owner

mbj4668 commented Jul 6, 2017

The idea from the start was that all pyang functionality should be available to some other python program that just imports pyang. Unfortunately, over time too much logic is done in the executable script bin/pyang. This should be cleaned up.

@mbj4668 mbj4668 self-assigned this Jul 6, 2017
@remingtonc
Copy link
Contributor

Are there any examples of using pyang as a library? Or is this currently not possible?

@llhotka
Copy link
Collaborator

llhotka commented Jul 28, 2017

If you want a documented Python library, Yangson is another option. Its aims and functionality are somewhat different though so it depends on what you need to do with it.

@tarkatronic
Copy link

@mbj4668 Is there any movement on this? Anything which could be done to assist? This would help greatly with the testing for pyangbind, so I would love to see it happen!

@mbj4668
Copy link
Owner Author

mbj4668 commented May 3, 2018

I haven't had time to work on this. If you want to help, that'd be great!

We should move from optparse to argparse, and move as much logic as possible from bin/pyang into the library. If you have a need for this ticket to be fixed, you probably know what needs to be done ;-)

Here's some notes I wrote earlier:

An application will have to do something like:

pyang.init_plugins(plugindirs)
[<optionally create an optparse object> 

pyang.add_options(optparse)]
repos = pyang.FileRepository(path, no_path_recurse)
ctx = pyang.Context(repos)

Currently, each plugin adds its own options to the optparse object, but if it called from within an application there won't be an optparse object. This might be ok, but then the plugins rely on the optparse.Value object to check what to do. Maybe it is ok if the application creates such an object itself, sets the option values it needs to set, and then continue?

Or we could provide a pyang method that would create a suitable optparse.Value instance, with the default values pyang expects, for the application to retrieve and modify as desired.

This would be backwards incompatible, and all plugins would have to be adjusted.

Also, time to introduce a plugin API version, so that we can give a proper error message if an old plugin is being used with a newer version of pyang.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants