Package: py-build
py-buildA package that includes a class for building applications using pythonUsageThe builder uses decorators to designate build steps:importpy_build# Create the builder objectbuilder=py_build.Builder()# Add steps to the builder@builder.build_step()defstep1():return"Output from step 1"@builder.build_step()defstep2():return"Output from step 2"Call each step to run the build:step1()step2()Capturing build step resultsThe output from build steps (or other processes from inside a build step) can be captured using theBuilder().capture_resultsdecorator method.This method accepts a list ofCallable's that will be called in the order given with the return value from function decorated.The following code will print the results from each build step on screen:importpy_builddefoutput_fnc(output:str):print(output)# Create the builder objectbuilder=py_build.Builder()# Add steps to the builder@builder.build_step()@builder.capture_results(output_fnc)defstep1():return"Output from step 1"@builder.build_step()@builder.capture_results(output_fnc)defstep2():return"Output from step 2"step1()step2()# Prints:# Output from step 1# Output from step 2Progress ReportingThe progress of the build can be captured as well using theBuilder().capture_progressdecorator method. This method accepts a list ofCallable's that accept afloatbetween0and1The following code will print the progress of the build in percentile:importpy_builddefprogress_fnc(progress:float):print(round(progress*100))# Create the builder objectbuilder=py_build.Builder()# Add steps to the builder@builder.build_step()@builder.capture_progress(progress_fnc)defstep1():return"Output from step 1"@builder.build_step()@builder.capture_progress(progress_fnc)defstep2():return"Output from step 2"step1()step2()# Prints:# 50# 100Composed DecoratorsThe builder can also combine decorators into a single decorator. This can be useful for preventing repeat code like in the examples above. It can also be used to differentiate main steps from substeps and the like.The following code will print the results and progress from each step:importpy_builddefprogress_fnc(progress:float):print(round(progress*100))defoutput_fnc(output:str):print(output)# Create the builder objectbuilder=py_build.Builder()main_step=builder.composed(@builder.build_step(),@builder.capture_progress(progress_fnc),@builder.capture_results(output_fnc))# Add steps to the builder@main_stepdefstep1():return"Output from step 1"@main_stepdefstep2():return"Output from step 2"step1()step2()# Prints:# Output from step 1# 50# Output from step 2# 100TheBuilder().build()methodWe can also make the builder run steps sequentially with a single method call.This example does the same thing as the previous example, but uses theBuilder().build()method to execute all the build steps:importpy_builddefprogress_fnc(progress:float):print(round(progress*100))defoutput_fnc(output:str):print(output)# Create the builder objectbuilder=py_build.Builder()main_step=builder.composed(@builder.build_step(),@builder.capture_progress(progress_fnc),@builder.capture_results(output_fnc))# Add steps to the builder@main_stepdefstep1():return"Output from step 1"@main_stepdefstep2():return"Output from step 2"builder.build()# Prints:# Output from step 1# 50# Output from step 2# 100There are a few caveats to note about the above example:TheBuilder().build_step()must be the first decorator for a function for the example to work correctlyBuild steps that require arguments should be defined as keyword arguments at definitionBuilderinstances are callable, so callingBuilder()()is the same as callingBuilder().build().Sub stepsTheBuilder().build()method can also handle steps that have a sub step. These can be designed as such:importpy_builddefprogress_fnc(progress:float):print(round(progress*100))defoutput_fnc(output:str):print(output)# Create the builder objectbuilder=py_build.Builder()main_step=builder.composed(@builder.build_step(),@builder.capture_progress(progress_fnc),@builder.capture_results(output_fnc))@main_stepdefget_hello():"""Get the salulation"""return"Hello"@main_stepdefsub_step():new_builder=py_build.Builder()substep=new_builder.composed(new_builder.build_step(),new_builder.capture_progress(progress_fnc),# We will use the same progress reporting method as in main stepsnew_builder.capture_results(output_fnc),# We will use the same result reporting method as in main steps)@substepdefsub_step_1():"""Get the sub step"""return"Sub step 1"@substepdefsub_step_2():"""Get the sub step"""return"Sub step 2"# Returning a builder object indicates that the step has its own stepsreturnnew_builder@main_stepdefget_name(name='Cory'):"""Get the name"""returnnamebuilder.build()# Prints:# Hello# 33# Sub step 1# 50# Sub step 2# 67# Cory# 100Release NotesThere are several changes that may break compatibility between version 0.1.0 and 0.2.0 as outlined below:Builder().composed()has been renamed toBuilder().composed_step()and its functionality has changed