{"metadata":{"language_info":{"name":"python","version":"3.7.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import sys, subprocess\nsubprocess.check_call([sys.executable, '-m', 'pip', 'install', '--upgrade','epyk'])","metadata":{"trusted":true},"execution_count":1,"outputs":[{"execution_count":1,"output_type":"execute_result","data":{"text/plain":"0"},"metadata":{}}]},{"cell_type":"markdown","source":"# Pyk Reports\nA Pyk report is a report that allows you to specify objects to export for another reports to use.\nThis is especially useful to prevent you to duplicate code that is fairly reusable.\nWith this method you can reuse components that you're particularly proud of or even things you want to share for other people to leverage on !\n## 2-Steps Process \nTo take advantage of this feature you simply need to declare within your reports the objects you would like to be reusable.\nThis is very similar to the Node.js export/require mechanisms.\n\n### Exports\n\nFirst - Within a report you've created you can define functions/epyk components you would like to share.\nFor instance we've create a pyk_report.py script that looks like this:","metadata":{}},{"cell_type":"code","source":"from epyk.core.Page import Report\nrptObj = Report()\n\nbutton = rptObj.ui.buttons.button('This is button')\nimp = rptObj.ui.buttons.important('This is an important button')\n\nrptObj.outs.jupyter()","metadata":{"trusted":true},"execution_count":2,"outputs":[{"execution_count":2,"output_type":"execute_result","data":{"text/plain":"","text/html":"\n\n\n\n\n\n\n\n"},"metadata":{}}]},{"cell_type":"markdown","source":"For now this script left like this wouldn't be able to share anything with another report. To remedy that you just need to add those lines:\n```\nfrom epyk.core.py import Pyk\nPyk.exports({'button': button, 'imp': imp})\n```\n\nHere we simple tell Epyk that we wish to ```exports``` our button and imp components using a dictionary. The key of the dictionaries are simply the aliases we wish to give our object. These aliases will be used to then retreive the object on the consumer side.","metadata":{}},{"cell_type":"code","source":"from epyk.core.Page import Report\nfrom epyk.core.py import Pyk\nrptObj = Report()\n\n\nbutton = rptObj.ui.buttons.button('This is button')\nimp = rptObj.ui.buttons.important('This is an important button')\n\nPyk.exports({'button': button, 'imp': imp})\nrptObj.outs.jupyter()","metadata":{"trusted":true},"execution_count":3,"outputs":[{"execution_count":3,"output_type":"execute_result","data":{"text/plain":"","text/html":"\n\n\n\n\n\n\n\n"},"metadata":{}}]},{"cell_type":"markdown","source":"Here we have created our output for jupyter AND we specified that some of our components were going to be reused elsewhere. We could have very well skipped the ```rptObj.outs.jupyter()```. But we wanted to show that both method were not exclusive.","metadata":{}},{"cell_type":"markdown","source":"Now both ```button``` and ```imp``` would be available to be called from another report\n### Imports\n\nNow to be able to use objects coming from a Pyk, we will see what needs to be done on the consumer side.\n\nFirst we need to specify where we're going to need to pick up object. This is done through the ```requires``` method:\n\n```\nfrom epyk.core.Page import Report\npyk_rpt = Pyk.requires(r'pyk_report.py')\n```\nor\n```pyk_rpt = Pyk.requires('pyk_report') #if pyk report is on Pypi```\n\nThe ```requires``` method will work for two cases:\n- given an absolute path to a python script\n- given a package name, if the package is already installed for the interpreter it will work automatically, if not you will either need to install it prealably or specify the ```autoinstall``` argument to ```True```\n\nFinally to add the imported object to your report you will need to call the ```register``` function at the moment you want to add your component within the report.\n\n```rpt_obj.register(pyk_rpt.button)```\n\nThis accept accept a single components as well as a list of those\n","metadata":{}},{"cell_type":"code","source":"import os\nfrom epyk.core.py import Pyk\nfrom epyk.core.Page import Report\n\npyk_rpt = Pyk.requires(os.path.abspath('pyk_report.py'))\n\n\nrptObj = Report()\n\nrptObj.ui.text(\"Here we have a text followed by a normal button\")\n\nrptObj.register(pyk_rpt.button)\n\nrptObj.ui.text(\"Then we have an important button\")\n\nrptObj.register(pyk_rpt.imp)\n\nrptObj.outs.jupyter()\n","metadata":{"trusted":true},"execution_count":4,"outputs":[{"execution_count":4,"output_type":"execute_result","data":{"text/plain":"","text/html":"\n\n\n\n\n
Here we have a text followed by a normal button
\n\n
Then we have an important button
\n\n\n"},"metadata":{}}]},{"cell_type":"markdown","source":"You now have a mixture of object defined from your own report and object imported from another one !!","metadata":{}}]}