jaumeamoresds / nbmodular Goto Github PK
View Code? Open in Web Editor NEWConvert notebooks to modular code
Home Page: https://jaumeamoresds.github.io/nbmodular/
License: MIT License
Convert notebooks to modular code
Home Page: https://jaumeamoresds.github.io/nbmodular/
License: MIT License
example:
%%function --test
def test_my_function ():
pass
This avoids hack
if True:
(...)
used in update_cell_code
Currently, this creates another code cell at the end of the list, keeping the previous ones. If --merge is not added, the previous ones are just set to not valid. Let's see this with an example:
%%function
def add1 (x):
y = x + 1
return y
%%function --merge
def add1 (x, x2):
y2 = x2 + 1
return y, y2
%%function
def add1 (x, x2):
y = x + 1
y2 = x2 + 1
print (f'{x} + 1 = {y}')
print (f'{x2} + 1 = {y2}')
return y, y2
The result is a list with three code cells: the first two with valid=False, and the last one with valid=True
Imagine the third cell replaced the first cell, i.e., the code in the third definition is written in the first cell. We could add a flag --replace-cell
that makes it replace. But we need to add also an index of what cell to replace.
We could also add two magic lines:
%list_cells function_name
listing the code cells existing for a particular function_name
, along with the function indexes, to know which one needs to be replaced.%delete funcion_cell function_name idx
deleting the function cell in position idx
of the list of function cells self.code_cells[function_name]
.We just initialize it before the function, use it, and it will automatically be added to function arguments
With visitor we might not even need to initialize before, provided we don't run the function
myfunc
(don't remember what this is about)I think these are already covered:
ast_examples.ipynb
in nbs/dev_tutorials
folderAdd magic debug_function
which doesn't run function but instead debugs it. It could use the variables in memory or passed as arguments:
%%debug_function --input-values a=1 b=2
def add_and_print(a, b):
c = a + b
print (c)
set_pipe (function_name, pipeline_name)
if pipeline_name != 'None' and pipeline_name not in self.pipelines:
self.pipelines.append (pipeline_name)
for pipeline in self.pipelines:
self.create_pipeline (pipeline)
def create_pipeline (pipeline=None):
if pipeline is None:
pipeline = self.file_name_without_extension
function_list = self.get_function_list (pipeline=pipeline)
get_function_list (self, ..., pipeline=None):
if pipeline is not None:
function_list = (... and f.pipeline==pipeline)
del
), with the disadvantage that we won't be able to inspect it later on.%%function --input-values a=1 b=2
def add_and_print (a, b=10):
c = a + b
print (c)
x, y, x, y = analyze ()
keyword arguments
avoid calling previous code when merging! This can be very inefficient and wrong if code has side-effects.
magic line %set allows to set any param.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.