Package: hypergrowth
ℹ️ What is this?This project is a skeleton framework for building advanced command line utilities. It was developed so that it can grow
with usage. For example, you would typically start off with some lightweight utilities for automating the manual
operations in your environment. As your main project grows, your utilities project will also grow to automate more
operations within your environment. Which is why, a manageable layout is helpful.The interface was kept separated, so that we have flexibility with distribution. In that, a separate client can be
implemented with the same interface and documentation, which may invoke the main project through a lambda function, or
lambda via api-gateway.❔ How does it work?The project is distributed in a typical MVC layout. The View in this case would be the Command Line Interface, while you
use the Model/Controller structure to organize your code based on what they do. The layout explained:💠 Layout🌴 hypergrowth📂framework- This contains implementation to route theinterfaceto thecontroller.💡 example🟡model- Data structures that represents the concepts that you're working with.🗄️repo- Implement Singletons for interacting with external datasets.📜resources- Any declarative configuration files used in the project.⚙️service- Reusable service class that perform the real work, in a parameterized way. Should not store data in these
classes.🎛️controller- Handle the arguments passed in from the command line interface.⚠️error- Define custom Exceptions here.🟢entrypoint.py- The default entrypoint script.🧪tests- Unit tests for the project.👐 example_sharedThis project you will share among all your projects. So that they can all inherit the same Command line interface, even
though, execution may be different. In that, your first project would execute directly, whereas, your distributed
project may execute through a lambda or api-gateway interface🗣️interface- The command line interface that the user would interact with.🟢 EntrypointThe Entrypoint is a module inside the example directoryentrypoint.py. It sets up the main command line interface
object. It then loads interfaces defined inexample.interfaceand consolidates them as sub-commands.🏗️ SetupThe command name can be define here. Currently, it's set todoitas shown in the code segment below:entry_points='''[console_scripts]hg=example.entrypoint:cli'''🗣️ InterfaceThe interface section is meant to define your interface, with associated documentation, without actually executing the
intended process or logic. This will go into a matching Controller The reason for this, is so that the interface can be
used for multiple projects, where you want the execution to be handled differently.example.interface.interface_onedemonstrates how to setup your interface. The interface is implemented
usingclickClick provides a clean way to implement the command line interface, including options, and nested commands.The following is an example for setting up the interface.importclickfromframework.hypergrowthimportConfiguration@click.group()defcli():passConfiguration(controllers="example.controller",interfaces="example.interface",main_command_group=cli)🎛️ ControllerThe controller is the start for your implementation logic. Small commands can be fully implemented in the Controller.
Larger processes with reusable parts should be defined as reusable services.An example controller to handle the above interface, will look like the following:fromframework.hypergrowth.frameworkimportComponentclassOneController(Component):defdo_stuff(self,name,count,context):print(f"doing it{name}{count}")** Notice that the Name of the controllerOneControllermatches the name of the interface groupone. And the method
that handles the command,do_stuffalso matches the command definitiondo_stuffunder the@one.command().In addition to these arguments, an extra required context argument is required. This will contain context information
relating to the execution. For local execution, the function name will be local-cli; however, when deployed as a Lambda
function, it will be that of the function name.
**RequirementsLocal Shell UtilityPython >= 3.8--https://www.python.org/downloads/tox--https://tox.readthedocs.io/en/latest/install.htmlℹ️ UsageLocalactivate your python venvpython3 -m venv path-to-env; source path-to-env/bin/activateinstall the framework with examples:pip3 install hypergrowthTest the example commandhgex one do-stuff jump. This should printdoing it jump 1Follow theexampleandexample_sharedexamples structure in the github project, to implement your own projectOptionally, activate shell forauto-completionℹ️ Additional Notes💻 Autocompletion for Big Sur zsh shellAuto completion for the zsh shell doesn't work right of the bat. The easiest way for me to get this working, was to
installzsh-completionviabrew info zsh-completionsThen adding the following to.zshrciftypebrew&>/dev/null;thenFPATH=$(brew--prefix)/share/zsh-completions:$FPATHautoload-Uzcompinitcompinitfi#HG and hg is based on your configuration in the setup.pyeval"$(_HGEX_COMPLETE=source_zshhgex)"