Package: eons
Eons Python FrameworkThe Eons Python Framework provides a user-friendly Python extension to theDevelop Biologyproject. This meanseonshelps you blur the lines between what it means to be, have, and do. Gone are the days of classes meaning "to be", members meaning "to have", and functions meaning "to do". With Eons and Biology, they are all one and the same.Design in short: Self-registering, sequential functors with implicit and automatic inheritance, downloaded just-in-time for use with arbitrary data structures.Kind(totally unrelated to theKind Proof Language; we just wanted a short synonym to "type" that didn't collide with Python's reserved keywords)Eons provides an easy plug-and-play style of development by mElderlanging the myriad Python packages we all love with our own custom syntax. We aim to provide you with something that is familiar when you want it to be, and powerful when you need it to be.The most condensed form of our syntax is as follows:@eons.kind(parent/base,classes)defClassName(member,variables,which="are injected via Fetch"):# Your code goes here.this.isHow="you reference the object / instance"Here's a more complete example:importeons@eons.kind(eons.StandardFunctor)defMyFunctor(external_method=eons.inject('SomeFarAwayFunctor'),constructor=f"""# Until Execution Blocks can be created in Parameter Blocks, formatted, multiline strings are the only way to handle arbitrary logic.this.classVariable = "Whatever you want!"""",):this.result.data.myResult=external_method(this.classVariable)This language style derives from theEons Language of Development for Entropic Reduction(Elderlang). The only real features missing, besides some nicer character choices (e.g. use of{}for Execution Blocks) are Space Autofill, and the ability to define functions, classes, and Functors in Parameter Blocks (i.e.()). So, for now, you're restricted to just lambdas or breaking your larger logic out into a separate Functor.The main differences between the Kind syntax and the Eons Language of Development are:The@eons.kinddecorator is used to declare a Type Block.thisis used instead of./(orselfin Python).epidefis used instead of../.Spatial Separation is big endian, rather than how domains are named (i.e. LSB..TLD).Sequences are built byeons.Flow()s (still under development).Python STILL does not have multiline comments >:(Python has both dictionaries and lists, vs just Containers in Elderlangdefis required to start a Parameter Block &:is required to start an Execution Block, both of which must always happen in that order (and be preceded by a Type Block).Convenient type casting is not fully implemented in Kind.Access control is not yet implemented in Kind.ParentYou can access the parentclass(not a cast of the current object to a parent object) via theparentmember. For example, you can callreturn this.parent.Function(this)to call the parent'sFunction()method. Note that you must still pass the instance (this) explicitly, sincethis.parentreturns a class, not an instance.CallerWhen composing Functors, thethiskeyword is often ambiguous. Between functions of a class,thisalways refers to the class itself. However, when each function is also a class, doesthismean the Functor or the class to which it belongs?To answer this question, Elderlang introduces the keyword./. In Kind, we simply call thisepidef.So, you can useepidef.someMemberto share access across Functors composed by the same class, andthis.someMemberto access the Functor's own members.Access ControlThere is no true access control in Python. So, implementing it via Biology has been slow going. However, for now, you can use something akin to Elderlang'spublic(...)Functor to make defining method injection easier.Instead of saying:@eons.kind(eons.StandardFunctor)defMyFunctor(Method1=eons.inject('Method1'),method2=eons.inject('SomeOtherFunctor'),MeThOd3=eons.inject('METHOD3'),):passyou can say:@eons.kind(eons.StandardFunctor)defMyFunctor(doesNotMatter=eons.public_methods('Method1',method3='SomeOtherFunctor',MeThOd3='METHOD3',),):passUnfortunately, you have to assign the result ofeons.public_methodsto a key word arg. However, the arg name is never used. We recommend usingpublicor something trivial.Eventually, a genericeons.public(...)method should exist such that you can specify variable in addition to methods, but that is not yet implemented.Installationpip install eonsUsageThis library is intended for consumption by other libraries and executables.
To create your own executable, overrideExecutorto add functionality to your program then create children ofDatumandFunctorfor adding your own data structures and operations.For example implementations, check out:apieebbsemiArguments available to all Eons Executors:-vor--verbose(count, i.e-vv= 2) or--verbosity #, where # is some number, or theverbosityenvironment or config value: will show more information and increase the logging level, e.g. print debug messages; seelog-levels, below for more info.--configor-c(string): the path to a json config file from which other values may be retrieved.--no-repoor theno_repoenvironment or config value (bool, i.e. 'True', 'true', etc.): whether or not to enable reaching out to online servers for code (see Dynamic Functionality, below).--log-fileor thelog_fileenvironment or config value (string; supports formatting, e.g. '/var/log/eons/{this.name}.log'): optional value for logging to a file in addition to stderr.--log-time-stardateor thelog_time_stardateenvironment or config value (bool): whether or not to useEons Official Timestardate time in logs (default istrue).--log-indentation(bool): whether or not tab out logs; seeindentation, below.--log-tab-width(int): how many spaces to use for indentation; seeindentation, below.--log-aggregate(bool): whether or not to send logs to a remote aggregation service; seeaggregation, below.--log-aggregate-url(string): the url of the remote aggregation service; seeaggregation, below.FeaturesEons supports 5 major features:Get inputs to functors by drilling down through multiple layers.Allow functors to change behavior with their order of execution.Provide functionality by downloading functors on the fly.Managed composition through External Methods.Resolve errors through dynamic resolution by functors.Inputs Through Configuration File andFetch()Eons provides a simple means of retrieving variables from a wide array of places. When youFetch()a variable, we look through:The system environment (e.g.export some_key="some value")The json configuration file supplied with--config(or specified bythis.default.config.filesperConfigure())Arguments supplied at the command line (e.g. specifying--some-key "some value"makesFetch(some_key)return"some value")Member variables of the Executor (e.g.this.some_key = "some value")The higher the number on the above list, the higher the precedence of the search location. For example, member variables will always be returned before values from the environment.Downstream implementors of the Eons library may optionally extend theFetch()method to look through whatever layers are appropriate for their inputs.You are also allowed to customize the order of each layer by reordering thefetchFrommember (list).NOTE: The supplied configuration file must contain only valid json.Global FetchEons provides an easy way to query the configuration values provided to it: a globalFetch()function.Callingeons.Fetch('desired_config_value')will return the result of invoking the Executor'sFetchmethod. This means any cli args, config values, environment variables, and anything else your Executor is configured tofetchFromwill be searched for yourdesired_config_value. This does not allow you to search a particular Functor's member variables (besides the Executor's). So, you can't execute a chain of Functors and then check the result using the globalFetch().To make this even easier, we aliased the global Fetch asf(). You can just typeeons.f('whatever')and get the value ofwhatever!And, if that's too hard for you, you can use a@recoverablemethod (see Error Resolution, below) and just typewhatever. Eons will do the hard work of catching the NameError and looking up the value. For an example, check out theResolvableByFetchFunctor, under test.Implicit InheritanceThe purpose of Implicit Inheritance is to provide developers with a tool for separating implementation and usage, thus allowing development to occur in smaller, logical pieces instead of monoliths (even modular ones). Using the Implicit Inheritance system, you can build libraries piece by piece and assemble them in different orders to achieve different results. For example, aDoStuffFunctor might callDo(whatever_was_requested)but might rely on a preceding Functor to implement theDo()Method. If bothDoStuffLocallyandDoStuffRemotelyboth defineDo(), we can choose how we want to do stuff entirely by the order of execution (i.e. locally vs remotely, in this case). In other words, by choosing which Functor comes beforeDoStuff, you can effectively choose which members and methods you want to include in your "implicit library" or "implied base class".Functors contain anextmember which enables not just single-function execution but sequences of multiple functions. To maximize the potential these sequences offer, the Eons library allows turning member functions intoMethodsvia the@eons.method()decorator. Methods are, themselves, Functors and can be transferred to other Functors to dynamically populate member functions. We have made it so that if you run some sequence like[FirstFunctor, SecondFunctor], theSecondFunctorautomatically inherits the methods ofFirstFunctorin addition to being able to access member variables from theFirstFunctor. We call this "Implicit Inheritance". Implicit Inheritance is not true inheritance. In the example aboveSecondFunctordoes not (have to) share a type withFirstFunctor(besideseons.Functor). Implicit Inheritance is also determined dynamically at runtime and cannot be (easily) programmed.NOTE: to make a Method available to following Functors, you must setpropagate=True(e.g.@eons.method(propagate=True))Methods do not participate in the main, user-requested sequence; instead, Methods create their own sequence. When a preceding Functor defines the same Method as the Functor currently executing, the current Functor can add the preceding Methods to its own either before or after, as controlled by the configuration of each of the current Functor's Methods. This makes it possible to simply setup or tweak functionality within each Method. Thus, a single function may be assembled from the partial implementations of many different definitions.If that alone wasn't enough,eons.Method()also endows you with the ability to change the code that's written before Python interprets it. You can specifyeons.Method(impl='InterpretMyCustomSyntax')or whatever you would like. Ideally, this will allow us to write Functors using any language. At the very least, we can tweak Python to add things like++, etc.Dynamic Functionality viaGetRegistered()In addition to dynamically Fetching variables, Eons provides a means of dynamically providing instances of classes by name. These classes can be stored on the filesystem or online throughEons Infrastructure Technologies.When provisioning SelfRegistering classes (below), both python package and other SelfRegistering class dependencies will be resolved. This means that, in the course of using this library, your system may be changed in order to provide the requested functionality.When using an Eons Executor, SelfRegistering classes are retrieved withExecutor.GetRegistered(...). If the class you are trying to retrieve is not found in the Registered classes, theErrorResolution,install_from_repowill try to download a package for the class.You may add credentials and even provide your own repo url for searching. If credentials are supplied, private packages will be searched before public ones.
Online repository settings can be set through:--repo-store
--repo-url
--repo-username
--repo-passwordYou may also publish to the online repository throughebbsNOTE: per the above section on the Configuration File, you can setrepo_usernamein the environment to avoid passing credentials on the command line, or worse, you can store them in plain text in the configuration file ;)Managed Composition via@eons.method(impl="External")Composition is a means of building complexity through encapsulation and typically answers the question of "has a ____", where classic inheritance answers "is a ____".
Eons provides a means of making composition easy through the External Method implementation.For example, consider:class MyClass(eons.Functor):
    @method(impl="External")
    def MyExternalFunctor(): passHere, we use a Functor called "MyExternalFunctor" to compose MyClass. The actual code for MyExternalFunctor is not provided here, but is instead retrieved throughGetRegistered(), as described above.Using this technique, we can reuse Functors within other Functors, and none of the code has to be present on the local system at runtime but can be supplied as needed.KindWhen using Kind syntax, useeons.injectinstead of@method(Python prohibits the use of decorators in Parameter Blocks).NOTE: Kind allows you to change the name of the External Method, while the decorator does not.For example:@eons.kind(eons.Functor)defMyClass(WeCanChangeThisNameNow=eons.inject("MyExternalFunctor")):...Requirements & NotesCircular dependencies are not supported. Because of this, any Functors used to compose more complex classes should be stored in sub-folders in the package or repo_store. Sub-folders will be registered before parent directories. SeeSelf Registrationfor more info.NOTE: This is now done for you automatically by the Placement system.When calling an External Method, the members of the Functor are not accessible through the function (e.g.MyClass.MyExternalFunctor.DidFunctionSucceed()is not currently supported). To accomplish such behavior, you must currently access the External Method through themethodsmember. For example,MyClass.methods['MyExternalFunctor'].DidFunctionSucceed().All arguments the External Method accepts are valid to provide to the function. For example, ifMyExternalFunctoracceptsmy_argas an argument, you can callMyClass.MyExternalFunctor(my_arg='whatever').Error Resolution for@recoverableMethodsAny method (i.e. member function) of Executor or Functor may be decorated with@recoverable. If a@recoverablemethod raises an Exception, the Eons error resolution system will engage and attempt to fix the problem.Because there are a lot of ways an error might arise and be resolved, we don't give you the same freedom of execution as we do with genericGetRegistered()calls. While we use GetRegistered under-the-hood, all possible ErrorResolutions have to be specified ahead of time in your Executor'sresolveErrorsWithlist member.If you want to handle errors with your own ErrorResolution, simply callmy_executor.resolveErrorsWith.append('my_fix_everything_functor')(paraphrasing).Creating ErrorResolutions is the same as any other Functor. The only difference is that when you derive from ErrorResolution most of the logic you need has been taken care of for you. You'll just have to implement aResolve(this)method and callthis.ApplyTo(...)in your constructor.NOTE: all ErrorResolution packages should have the 'resolve_' prefix so that they may be readily identified online.Check outinstall_from_repofor an example.Inheritance OverviewInheritance allows you to build functionality without duplicating code and is a primary driver for the core programming tenant of never writing the same line twice.Eons supports several kinds of inheritance. Notably:Classic InheritanceImplicit Inheritance (i.e. Sequence)External Methods (i.e. composition)Inheritance StyleRelationshipCompiletimeRuntimeMethod & Member AccessibilityType SharingClassicis a:heavy_check_mark::x::heavy_check_mark::heavy_check_mark:Implicithow does:x::heavy_check_mark::heavy_check_mark::x:Externalhas a:heavy_check_mark::x::x::x:You are not restricted to a single kind of inheritance. You can, and are encouraged, to use all forms of inheritance in your code!LoggingEons attempts to provide a detailed, robust, and pleasant logging experience. We use theloggingmodule, and shim in additional features through our log formatter.Log LevelsThe log level may be set by theverbosityor-vflags.
Children and other modules of Eons may employ their own logging levels. However, Eons provides the following levels by default:
0.CRITICAL: only get notified if absolutely necessary.WARNING: get notified about potential problems.INFO: see what's generally going on.DEBUG+ urllib3 WARNING: see what's really going on.Empty: reserved for modules.DEBUG: see everything.Log FeaturesIndentationTo make logs easier to read, each Functor can be optionally tabbed out as it might be in source code, allowing you to readily see the scope where a log occurs. Each indentation begins with a|character and is followed by a number of spaces equal to the tab width minus one. For example, using a tab width of 2, a log line at the top level would be| ..., while a log at the second level would be| | ....This feature is enabled by default. To disable it you can setlog_indentationtoFalse.To configure the size of the indentation, you can setlog_tab_widthto the number of spaces you want to use. For example a tab width of 1 would be just|, while a tab width of 4 would be|.AggregationFor security information and event management (SIEM), Eons supports sending logs to a remote endpoint.This will only be done if a valid repo username and password are provided. If you provide a username and password, but don't want to send your logs to a remote server, you can setlog_aggregatetoFalse.You may also set thelog_aggregate_urlto wherever you'd like to send your logs. By default, this is set tohttps://eons.sh/log.PerformanceAt Eons LLC, we always prefer functionality over performance. This is the same as the whole "don't prematurely optimize" argument. With that said, optimizing is always good and we try to do it as much as possible.Please let us know if you are hitting any bottlenecks in this or any of our other libraries!DesignFunctors. Functors...FunctorsFunctors are classes (objects) that have an invokable()operator. This allows you to treat them like functions.
Eons uses functors (implemented as the Functor class) to provide input, analysis, and output functionalities, which are made simple through classic and implicit inheritance.Imagine you write 2 functions that take inputsaandb. You can choose to duplicate these inputs, as is the classic means of writing functions:firstFunction(a, b)andsecondFunction(a, b). However, with Functors, you can makebaseFunctor{inputs=[a,b]}and then simplyfirstFunctor(baseFunctor)andsecondFunctor(baseFunctor), thus creating 2 Functors with identical inputs. The result offirstFunctor(a, b) == firstFunction(a, b)and likewise for the seconds; only, by using Functors we've saved ourselves from duplicating code.InputsFor extensibility, all Functors take both an*argsand**kwargsargument when called. This allows you to provide arbitrary key word arguments (e.g. key="value") to your objects.Each functor supports:requiredKWArgs- the arguments which the functor cannot be called without.staticKWArgs- also required arguments but which are onlyFetch()ed once.optionalKWArgs- arguments which have a default and do not have to be supplied.Non-key-word arguments can be specified by appending valid key-word arguments to theargMappingmember (list). You cannot directly set the implicit args (how would we know what to call them?).All values provided in these members will be populated by calls toFetch(), as described above. This means that if the user calling your Functor does not provide, say their password, it can be automatically looked up in the environment variables.For other supported features, check outFunctor.pySelf RegistrationNormally, one has toimportthe files they create into their "main" file in order to use them. That does not apply when using Eons. Instead, you simply have to derive from an appropriate base class and then callSelfRegistering.RegisterAllClassesInDirectory(...)(which is usually done for you based on therepo.storeandthis.default.repo.directorymembers), providing the directory of the file as the only argument. This will essentiallyimportall files in that directory and make them instantiable viaSelfRegistering("ClassName").Dynamic error resolutions enables this self registration system to work with inheritance as well. This means that, within downloaded functor, you canfrom some_module_to_download import my_desired_classto download another.NOTE:SelfRegistering.RegisterAllClassesInDirectory(...)is depth-first, meaning any sub-folders in the given folder will be loaded before the parent directory. This helps to organize inheritance dependencies, but can be disabled withrecurse=False.ExampleIn someMyDatum.pyin aMyDatadirectory, you might have:import logging
from Eons import Datum
class MyDatum(Datum): #Datum is a useful child of SelfRegistering
    def __init__(this, name="only relevant during direct instantiation"):
        logging.info(f"init MyDatum")
        super().__init__()From our main.py, we can then call:import sys, os
from Eons import SelfRegistering
SelfRegistering.RegisterAllClassesInDirectory(os.path.join(os.path.dirname(os.path.abspath(__file__)), "MyData"))Here, we useos.pathto make the file path relevant to the project folder and not the current working directory.
Then, from main, etc. we can call:myDatum = SelfRegistering("MyDatum")and we will get aMyDatumobject, fully instantiated.ExtensionWhen extending a program that derives from eons, defer to that program's means of extension. However, the following utilities may greatly aid in standardizing downstream code.Your Very Own FunctorsWhen creating your own Functors, derive fromeons.StandardFunctor(unless you know what you're doing). The StandardFunctor just makes your life easier. For example, when extendingStandardFunctor, the following utilities become available to you:#RETURNS: an opened file object for writing.#Creates the path if it does not exist.defCreateFile(this,file,mode="w+"):...#Copy a file or folder from source to destination.#This really shouldn't be so hard...defCopy(this,source,destination):...#Delete a file or folderdefDelete(this,target):...#Run whatever.#DANGEROUS!!!!!#RETURN: Return value and, optionally, the output as a list of lines.#per https://stackoverflow.com/questions/803265/getting-realtime-output-using-subprocessdefRunCommand(this,command,saveout=False,raiseExceptions=True):...These methods take care of logging, some error resolution, and other things that the traditional python solutions fail to address.
The source for these methods is available inStandardFunctor.py.In your Functor, you should set the____KWArgsmembers in__init__(this, name)and define theFunction(this)andDidFunctionSucceed(this)methods. That's pretty much it. For more advanced configuration, seeFunctor.py.