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

Make callable from Python #2

Open
alexander-bauer opened this issue Nov 26, 2019 · 3 comments
Open

Make callable from Python #2

alexander-bauer opened this issue Nov 26, 2019 · 3 comments

Comments

@alexander-bauer
Copy link

Hello!

I am looking into calling EasyUCS from a Python module. Ideally, this would look like the existing easyucs.py script decomposed into a handful of functions that validate their arguments like the current argparse ones are validated.

This is a reasonably tall order, of course, and demands some pretty major restructuring. I think the pieces are these:

  1. Make EasyUCS into a package that can be installed with distutils/pip, so that it can be imported sanely.
  2. Adjust the easyucs.py and easyucs_gui.py tooling and documentation to be invoked as Python modules, so that both the new distutils/pip install and the existing "invoke from the current working directory" methods work as expected
    • (This would look like python -m easyucs.easyucs <cmdline_arguments> or python -m easyucs.easyucs_gui <cmdline_arguments>. Perhaps easyucs and easyucs_gui scripts could be installed to make those invocations easier.)
  3. Move the program logic and input validation in easyucs.py into one or a few high-level functions elsewhere in the package that easyucs.py can then import, and call after parsing its arguments like today.

I will submit a pull request soon that addresses most of points 1 and 2, but would appreciate your (@vesposito) input.

@vesposito
Copy link
Owner

Hello!
I actually already thought about making EasyUCS a pip package, but my goal was just to simplify the installation process... so your idea is much larger than this.

The easyucs.py script is already calling a bunch of functions (like import_config, push_config, etc.), though it does also have some logic itself to handle complex cases like doing both a reset and a setup in a single command.
If you simply need to use EasyUCS for pushing a config or fetching an inventory/config, you could probably avoid re-writing the easyucs.py file, and simply call the appropriate methods directly.

I'd like to avoid changing too much the way EasyUCS is executed today - since most people are using it as a simple tool without needing to include it in a larger Python project. However I think being able to use EasyUCS as a Python module could be very useful as it could open some interesting possibilities.
What I'd like to achieve is being able to install it using pip, and then call easyucs <cmdline_arguments> directly from any working directory (improvement from current state), while at the same time having the capability to use the easyucs package installed from pip as a module.

@alexander-bauer
Copy link
Author

It's great to hear back from you so quickly!

I see where you're coming from with not changing the invocation methods. If you think it's an acceptable to change to invoke as easyucs (or easyucs_gui) rather than easyucs.py, I think it would be straightforward to write each as a one-liner shell script to invoke like python -m easyucs.easyucs, though making it use the right interpreter might be tricky. If we could, then it would be simple to include them as "scripts" in the package to be installed somewhere in the PATH by Pip.

I think it would be possible to include the easyucs.py as a "script" itself, and have it be renamed to just easyucs, but I noticed that easyucs_gui.py imports it. That's why I went with the module approach in my branch.

@alexander-bauer
Copy link
Author

As for being an installable Pip module, I've made some great progress. I'm going to open a in-dev PR shortly, so you can comment directly.

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

No branches or pull requests

2 participants