# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
The Guider write templated .py or .md files for explaining how
work a certain Module
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Standards.Interfacers.Deployer"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
import inspect
import os
import sys
#</ImportSpecificModules>
#<DefineFunctions>
ScriptStrAndExtensionStrTuplesList=[
('Latex','.tex'),
('Markdown','.md'),
('Python','.py'),
]
#</DefineFunctions>
#<DefineLocals>
GuidingDocumentMarkdownTextStr='''
<!--
FrozenIsBool False
-->
#<NameStr>
##Doc
----
<ModuleDocStr>
----
<small>
View the <NameStr> notebook on [NbViewer](http://nbviewer.ipython.org/url/shareyoursystem.ouvaton.org/<NameStr>.ipynb)
</small>
'''
GuidingGithubMarkdownTextStr='''
<!--
FrozenIsBool False
-->
##Code
----
<ClassDocStr>
----
```python
<CodeStr>
View the
'''
GuidingOuvatonMarkdownTextStr='''
View the
'''
GuidingClassMarkdownTextStr='''
Special attributes of the
GuidingClassCodeTextStr='''
import ShareYourSystem as SYS
from
SYS._attest(
[
'DefaultAttributeItemTuplesList is '+SYS._str(
'''
GuidingInstanceMarkdownTextStr='''
A default call of an instance gives : '''
GuidingInstanceCodeTextStr='''
from ShareYourSystem.Standards.Classors import Attester
from
SYS._attest(
[
''' GuidingSortStr='_'
@DecorationClass() class GuiderClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'GuidingIndexStr',
'GuidingPageStr',
'GuidingBookStr',
'GuidingScriptStr',
'GuidedIndexStr'
]
def default_init(self,
_GuidingIndexStr="",
_GuidingPageStr="",
_GuidingBookStr="",
_GuidingScriptStr="",
_GuidedIndexStr="",
**_KwargVariablesDict
):
#Call the parent __init__ method
BaseClass.__init__(self,**_KwargVariablesDict)
def do_guide(self):
#Check
if self.PackagingModuleVariable!=None:
#Check
if self.GuidingPageStr!="":
if self.GuidingIndexStr=="":
#Definition
IndexesList=map(
int,
map(
lambda __KeyStr:
__KeyStr.split(
GuidingSortStr
)[0],
self.GuidedDict.values()
)
)
#Definition the last index of Guide
IndexInt=max(IndexesList) if len(IndexesList)>0 else -1
#Define
self.GuidingIndexStr="%02d"%(IndexInt+1)+GuidingSortStr
#debug
'''
self.debug(('self.',self,['PackagedLocalFolderPathStr']))
'''
#Write a new file
self.file(
self.GuidingIndexStr+GuidingSortStr+self.GuidingPageStr+self.GuidingBookStr+(
dict(
ScriptStrAndExtensionStrTuplesList
)
)[self.GuidingScriptStr],
'wt'
)
#Check
if self.FiledHardVariable.mode=='wt':
#Definition
GuidingTextStrKeyStr='Guiding'+self.GuidingPageStr+self.GuidingScriptStr+'TextStr'
#debug
'''
print('self.FiledHardVariable is ',self.FiledHardVariable)
print('')
'''
#Definition
GuidedTextStr=globals()[GuidingTextStrKeyStr]
#debug
'''
print('GuidedTextStr is ',GuidedTextStr)
print('')
'''
#Replace
GuidedTextStr=GuidedTextStr.replace(
'<NameStr>',
self.FolderedNameStr
)
#debug
'''
print('GuidedTextStr is ',GuidedTextStr)
print('')
'''
#Replace
if self.FolderedNameStr=="ShareYourSystem":
GuidedTextStr=GuidedTextStr.replace(
"from <ParentModuleStr> ",""
)
else:
GuidedTextStr=GuidedTextStr.replace(
"<ParentModuleStr>",
self.FolderedParentModuleStr
).replace(
"<GithubPathStr>",
self.PackagedModuleStr.replace('.','/')
).replace(
"<ModuleDocStr>",
sys.modules[
self.PackagedModuleStr
].__doc__.split('</DefineSource>\n'
)[-1].replace(
'\n','\n> '
)
).replace(
"<CodeStr>",
inspect.getsource(
sys.modules[
self.PackagedModuleStr
]
)
)
#debug
'''
print('Guider l.194')
print('self.FiledPathStr is',self.FiledPathStr)
print('')
'''
#Write
self.write(GuidedTextStr,**{'LoadingFormatStr':'txt'})
#Close
self.FiledHardVariable.close()
```
View the Guider sources on Github
In [3]:
#ImportModules
import ShareYourSystem as SYS
from ShareYourSystem.Guiders import Guider
from ShareYourSystem.Standards.Objects import Concluder
#Definition an instance
MyGuider=Guider.GuiderClass(
).package(
Concluder
).guide(
'001','Github','Doc','Markdown',
)
#Definition the AttestedStr
SYS._attest(
[
'MyGuider is '+str(
SYS._str(
MyGuider,
**{
'RepresentingBaseKeyStrsListBool':False
}
)
)
]
)
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
The Scriptbooker defines template of Mardown and Code Scriptbooks for readming a Module.
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Guiders.Guider"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
import os
Guider=BaseModule
#</ImportSpecificModules>
#<DefineClass>
@DecorationClass()
class ScriptbookerClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'ScriptbookingGuideTuplesList',
'ScriptbookedFileKeyStrsList',
'ScriptbookedNewGuideTuplesList',
'ScriptbookedOldGuideTuplesList'
]
def default_init(self,
_ScriptbookingGuideTuplesList=[
('001','Document','Markdown'),
('002','Github','Markdown'),
#('003','Ouvaton','Markdown')
],
_ScriptbookedFileKeyStrsList=None,
_ScriptbookedNewGuideTuplesList=None,
_ScriptbookedOldGuideTuplesList=None,
**_KwargVariablesDict
):
#Call the parent __init__ method
BaseClass.__init__(self,**_KwargVariablesDict)
def do_scriptbook(self):
#debug
'''
self.debug(('self.',self,['FolderedDirKeyStrsList']))
'''
#Definition
self.ScriptbookedFileKeyStrsList=SYS._filter(
lambda __DirKeyStr:
any(
map(
lambda __ExtensionStr:
__DirKeyStr.endswith(
self.GuidingBookStr+__ExtensionStr
),
['.py','.md','.tex']
)),
self.FolderedDirKeyStrsList
)
#Definition
ScriptbookedPageStrsList=map(
lambda __ScriptbookerScriptbookFileKeyStr:
Guider.GuidingSortStr.join(
__ScriptbookerScriptbookFileKeyStr.split(
Guider.GuidingSortStr)[1:]
),
self.ScriptbookedFileKeyStrsList
)
#set
self.ScriptbookedSortDict=dict(
zip(ScriptbookedPageStrsList,self.ScriptbookedFileKeyStrsList)
)
#debug
'''
self.debug(('self.',self,['ScriptbookedSortDict']))
'''
#Check
if len(self.ScriptbookingGuideTuplesList)>0:
#map
ScriptbookedGuideTuplesList=map(
lambda __ScriptbookingGuideTuple:
list(__ScriptbookingGuideTuple)+[
__ScriptbookingGuideTuple[1]+self.GuidingBookStr+dict(
Guider.ScriptStrAndExtensionStrTuplesList
)[
__ScriptbookingGuideTuple[2]
]
],
self.ScriptbookingGuideTuplesList
)
#groupby
[
self.ScriptbookedNewGuideTuplesList,
self.ScriptbookedOldGuideTuplesList
]=SYS.groupby(
lambda __ScriptbookedGuideTuple:
__ScriptbookedGuideTuple[3] not in self.ScriptbookedSortDict,
ScriptbookedGuideTuplesList,
)
#debug
'''
self.debug(('self.',self,[
'ScriptbookedNewGuideTuplesList',
'ScriptbookedOldGuideTuplesList'
]))
'''
#map a guide for the news
map(
lambda __ScriptbookingNewGuideTuple:
self.guide(__ScriptbookingNewGuideTuple[0],
__ScriptbookingNewGuideTuple[1],
self.GuidingBookStr,
__ScriptbookingNewGuideTuple[2]),
self.ScriptbookedNewGuideTuplesList
)
#check if we rewrite for the olds
map(
lambda __ScriptbookingOldGuideTuple:
self.close()
if "#FrozenIsBool True" in self.load(
_FormatStr='txt',
**{
'FilingKeyStr':self.ScriptbookedSortDict[
__ScriptbookingOldGuideTuple[3]
],
'FilingModeStr':'r'
}).LoadedReadVariable
else self.close().guide(
__ScriptbookingOldGuideTuple[0],
__ScriptbookingOldGuideTuple[1],
self.GuidingBookStr,
__ScriptbookingOldGuideTuple[2],
),
self.ScriptbookedOldGuideTuplesList
)
#Return self
#return self
#</DefineClass>
View the Scriptbooker sources on [Github](https://github.com/Ledoux/ShareYourSystem/tree/master/Pythonlogy/ShareYourSystem/Guiders/Scriptbooker)
In [7]:
#ImportModules
import ShareYourSystem as SYS
from ShareYourSystem.Guiders import Scriptbooker
#Definition of a Scriptbooker
MyScriptbooker=Scriptbooker.ScriptbookerClass(
).package(
"ShareYourSystem.Standards.Objects.Object"
).scriptbook(
**{
'GuidingBookStr':'Doc'
}
)
#Definition the AttestedStr
SYS._attest(
[
'MyScriptbooker is '+SYS._str(
MyScriptbooker,
**{
'RepresentingBaseKeyStrsListBool':False,
'RepresentingAlineaIsBool':False
}
)
]
)
#Print
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
The Celler defines template of Mardown and Code Cells for readming a Module.
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Guiders.Scriptbooker"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
import os
import six
import copy
#</ImportSpecificModules>
#<DefineLocals>
CellingInitDict={
'metadata': {
'name': "",
'signature': ""
},
'nbformat': 3,
'nbformat_minor': 0,
'worksheets': []
}
CellingCodeCellDict={
'cell_type':'code',
'collapsed': False,
'input':[],
'language': "python",
'metadata': {'slideshow':{'slide_type':"slide"}},
'prompt_number':0
}
CellingOutputDict={
'output_type': "stream",
'stream': "stdout",
'text': [
]
}
CellingMarkdownCellDict={
'source': "",
'cell_type': 'markdown',
'metadata': {'slideshow':{'slide_type':"slide"}}
}
#</DefineLocals>
#<DefineClass>
@DecorationClass()
class CellerClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'CellingTextStr',
'CellingScriptStr',
'CelledOutputStr',
'CelledNoteDict'
]
def default_init(self,
_CellingTextStr="",
_CellingScriptStr="",
_CelledOutputStr="",
_CelledNoteDict=None,
**_KwargVariablesDict
):
#Call the parent __init__ method
BaseClass.__init__(self,**_KwargVariablesDict)
def do_cell(self):
#Debug
'''
self.debug(
('self.',self,[
'FolderingPathVariable',
#'CellingTextStr'
]
)
)
'''
#Check Code case
if self.CellingScriptStr=='Python':
#folder first
self.folder()
#Definition the self.CelledOutputStr
if self.FolderingPathVariable!=os.getcwd()+'/':
#capture and six method
self.CapturedPrintStrsList=[]
self.capture()
six.exec_(self.CellingTextStr,vars())
self.CapturingStopBool=True
self.CelledOutputStr='\n'.join(self.CapturedPrintStrsList)
else:
#Avoid the output of the corresponding NameStr because it will do a circular effect...
self.CelledOutputStr=""
#Debug
'''
self.debug(('self.',self,['CelledOutputStr']))
'''
#Return
self.CelledNoteDict=dict(
copy.deepcopy(CellingCodeCellDict),
**{
'input':map(
lambda __LineStr:
__LineStr+'\n',
self.CellingTextStr.replace(
"#FrozenIsBool True",""
).replace(
"#FrozenIsBool False",""
).replace(
'\t',
' '
).replace(' \n','\n').split('\n')
),
"outputs":[
dict(
copy.copy(CellingOutputDict),
**
{
"text":map(
lambda __LineStr:
__LineStr+'\n',
self.CelledOutputStr.split('\n')
)
}
)
]
}
)
#Check Markdown case
elif self.CellingScriptStr=='Markdown':
self.CelledNoteDict=dict(
copy.deepcopy(CellingMarkdownCellDict),
**{
'source':self.CellingTextStr
}
)
#</DefineClass>
View the Celler sources on [Github](https://github.com/Ledoux/ShareYourSystem/tree/master/Pythonlogy/ShareYourSystem/Guiders/Celler)
In [11]:
#ImportModules
import ShareYourSystem as SYS
from ShareYourSystem.Guiders import Celler
#Definition an instance
MyCeller=Celler.CellerClass().load(
**{
'FolderingPathVariable':
SYS.ShareYourSystemLocalFolderPathStr+'Pythonlogy/ShareYourSystem/Objects/Rebooter',
'FilingKeyStr':'01_ExampleDoc.py'
}
)
MyCeller.cell(MyCeller.LoadedReadVariable,'Python')
#Definition the AttestedStr
SYS._attest(
[
'MyCeller is '+SYS._str(
MyCeller,
**{
'RepresentingBaseKeyStrsListBool':False,
'RepresentingAlineaIsBool':False
}
)
]
)
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
The Notebooker takes piece of .md,.py,.tex files for putting them in a IPython Notebook
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Guiders.Celler"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
import copy
import os
import sys
from ShareYourSystem.Standards.Interfacers import Filer,Loader
from ShareYourSystem.Guiders import Guider
import importlib
Celler=BaseModule
#</ImportSpecificModules>
#<DefineClass>
@DecorationClass()
class NotebookerClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'NotebookingFileKeyStr',
'NotebookingWriteBool',
'NotebookedTextStrsList',
'NotebookedCodeDict',
'NotebookedPageStrsList',
'NotebookedSubslideStrsList'
]
def default_init(self,
_NotebookingFileKeyStr="",
_NotebookingWriteBool=True,
_NotebookedTextStrsList=None,
_NotebookedCodeDict=None,
_NotebookedPageStrsList=None,
_NotebookedSubslideStrsList=None,
**_KwargVariablesDict
):
#Call the parent __init__ method
BaseClass.__init__(self,**_KwargVariablesDict)
def do_notebook(self):
#debug
'''
self.debug(('self.',self,['NotebookingFileKeyStr']))
'''
#Check
if self.NotebookingFileKeyStr!="":
#debug
'''
self.debug(('self.',self,['ScriptbookedSortDict']))
'''
#map
self.NotebookedTextStrsList=map(
lambda __ScriptbookedFileKeyStr:
self.load(**{
'FilingKeyStr':__ScriptbookedFileKeyStr
}
).LoadedReadVariable,
sorted(self.ScriptbookedSortDict.values())
)
#map
self.NotebookedScriptStrsList=map(
lambda __ScriptbookedFileKeyStr:
SYS.flip(
dict(
Guider.ScriptStrAndExtensionStrTuplesList
)
)[
'.'+__ScriptbookedFileKeyStr.split('.')[-1]
],
sorted(self.ScriptbookedSortDict.values())
)
#debug
'''
self.debug(('self.',self,[
'NotebookedTextStrsList',
'NotebookedScriptStrsList'
]))
'''
#Update
self.LoadingFormatStr='json'
#file first
self.file(
self.NotebookingFileKeyStr,
'w'
)
#Copy
self.NotebookedCodeDict=copy.copy(Celler.CellingInitDict)
#Fill the cells
self.NotebookedCodeDict['worksheets']=[
{
'cells':map(
lambda __NotebookedTextStr,__NotebookedScriptStr,__IndexInt:
dict(
self.cell(
__NotebookedTextStr,
__NotebookedScriptStr
).CelledNoteDict,
**{
'prompt_number':__IndexInt,
}
),
self.NotebookedTextStrsList,
self.NotebookedScriptStrsList,
xrange(len(self.NotebookedTextStrsList))
)
}
]
#map
self.NotebookedPageStrsList=map(
lambda __FileKeyStr:
Guider.GuidingSortStr.join(
__FileKeyStr.split('.')[0].split(
Guider.GuidingSortStr
)[1:]
),
sorted(self.ScriptbookedSortDict.values())
)
#map
self.NotebookedSubslideStrsList=map(
lambda __NotebookedPageStr,__PageIndexInt:
'slide'
if __PageIndexInt==0
else
'subslide'
if self.NotebookedPageStrsList[__PageIndexInt-1]!=__NotebookedPageStr
else '-',
self.NotebookedPageStrsList,
xrange(len(self.NotebookedPageStrsList))
)
#debug
'''
self.debug(
[
('self.',self,['NotebookedSubslideStrsList']),
"self.NotebookedCodeDict['worksheets'][0]['cells'] is "+SYS._str(
self.NotebookedCodeDict['worksheets'][0]['cells'])
]
)
'''
#Specify the page/slide
map(
lambda __CellDict,__NotebookedSubslideStr:
__CellDict['metadata']['slideshow'].__setitem__(
"slide_type",
__NotebookedSubslideStr
)
,
self.NotebookedCodeDict['worksheets'][0]['cells'],
self.NotebookedSubslideStrsList
)
#debug
'''
self.debug(
[
"self.NotebookedCodeDict['worksheets'][0]['cells'] is "+SYS._str(
self.NotebookedCodeDict['worksheets'][0]['cells'])
]
)
'''
#debug
'''
self.debug(
('self.',self,[
'NotebookingWriteBool',
'NotebookedCodeDict',
])
)
'''
#Check
if self.NotebookingWriteBool:
#debug
'''
self.debug(
('self.',self,[
'FolderingPathVariable',
'FilingKeyStr',
'LoadingFormatStr'
])
)
'''
#Write
self.write(self.NotebookedCodeDict)
#Close
self.FiledHardVariable.close()
#Return self
#return self
#</DefineClass>
View the Notebooker sources on Github
In [15]:
#ImportModules
import ShareYourSystem as SYS
from ShareYourSystem.Guiders import Notebooker
#Definition a Notebooker
MyNotebooker=Notebooker.NotebookerClass(
).package(
'ShareYourSystem.Standards.Objects.Concluder'
).scriptbook(
**{
'GuidingBookStr':'Doc'
}
).notebook(
'Presentation.ipynb'
)
#Definition the AttestedStr
SYS._attest(
[
'MyNotebooker is '+SYS._str(
MyNotebooker,
**{
'RepresentingBaseKeyStrsListBool':False,
'RepresentingAlineaIsBool':False
}
)
]
)
#Print
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
The Nbconverter
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Guiders.Notebooker"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
import collections
import copy
import json
import os
import sys
Filer=BaseModule
#</ImportSpecificModules>
#<DefineFunctions>
def getNbconvertedMarkdownCellDictsListWithCodeCellDict(_CellDict):
return [
{
'source': "```python\n"+"".join(
map(
lambda __LineStr:
__LineStr.replace('\t',' '),
_CellDict['input']
)
)+"\n```\n",
'cell_type': 'markdown',
'metadata': {}
}
]+[
{
'source': "```console\n>>>\n"+"".join(
_CellDict['outputs'][0]['text'])+"\n```\n",
'cell_type': 'markdown',
'metadata': {}
}
] if len(_CellDict['outputs'])>0 else []
#</DefineFunctions>
#<DefineLocals>
NbconvertingFilePrefixStr=""
#</DefineLocals>
#<DefineClass>
@DecorationClass()
class NbconverterClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'NbconvertingFileKeyStr'
]
def default_init(self,
_NbconvertingFileKeyStr="",
_NbconvertingFormatStr="Markdown",
**_KwargVariablesDict
):
#Call the parent __init__ method
BaseClass.__init__(self,**_KwargVariablesDict)
def do_nbconvert(self):
#debug
'''
self.debug(('self.',self,['FiledHardVariable']))
'''
#Check
if self.NbconvertingFormatStr=="Markdown":
#debug
'''
self.debug(
'worksheets are before the markdown '+Representer.represent(
self.NbconvertedNotebookDict['worksheets'][0],**{'RepresentingAlineaIsBool':False})
)
'''
#Transform the code cells into Nbconverted cells
NbconvertedWorksheetsList=SYS.flat(
map(
lambda __CellDict:
getNbconvertedMarkdownCellDictsListWithCodeCellDict(
__CellDict
)
if __CellDict['cell_type']=='code'
else __CellDict,
self.NotebookedCodeDict['worksheets'][0]['cells']
)
)
#debug
'''
self.debug(
'NbconvertedWorksheetsList is '+SYS._str(
NbconvertedWorksheetsList,**{'RepresentingAlineaIsBool':False})
)
'''
#set the dict
self.NotebookedCodeDict['worksheets'][0]['cells']=NbconvertedWorksheetsList
#debug
'''
self.debug(('self.',self,['FilingKeyStr']))
'''
#Write
self.file(
self.NbconvertingFileKeyStr.replace('.md','.ipynb'),
'w'
).write(
self.NotebookedCodeDict,**{
'LoadingFormatStr':'json'
}
).FiledHardVariable.close()
#debug
'''
self.debug(('self.',self,[
'FilingKeyStr',
'FilingModeStr',
'FiledPathStr'
]))
'''
#Definition the NbconvertedCommandStr
NbconvertedCommandStr=SYS.IPythonPathStr+" nbconvert --to markdown --output "+self.FiledPathStr.replace('.ipynb','')+" "+self.FiledPathStr
elif self.NbconvertingFormatStr=='Slide':
#Definition the NbconvertedCommandStr
NbconvertedCommandStr=SYS.IPythonPathStr+" nbconvert --to slides --output "+self.FiledPathStr.replace('.ipynb','')+" "+self.FiledPathStr
#debug
'''
self.debug(
'NbconvertedCommandStr is '+NbconvertedCommandStr,
('self.',self,['FiledPathStr'])
)
'''
#debug
'''
self.debug('NbconvertedCommandStr is '+NbconvertedCommandStr)
'''
#Convert
os.popen(NbconvertedCommandStr)
#set the name
if self.NbconvertingFormatStr=='Slide':
#popen
os.popen(
'mv '+self.FiledPathStr.replace(
'.ipynb','.slides.html'
)+' '+self.FiledPathStr.replace(
'.ipynb','.html'
)
)
#change the reveal.js directory
self.load(**{
'FilingKeyStr':self.FiledPathStr.split('/')[-1].replace(
'.ipynb',
'.html'
),
'LoadingFormatStr':'txt'
})
self.LoadedReadVariable=self.LoadedReadVariable.replace(
'reveal.js/','reveal/'
).replace(
"Reveal.initialize({",
#"Reveal.initialize({"
"Reveal.initialize({width: 1000,height: 400,margin: 0.,minScale: 0.5,maxScale: 1.0,"
)
#chunk
DocumentedOldChunkStrsList=SYS.chunk(
['<code class="language-python">','</code>'],
self.LoadedReadVariable,
**{'ChunksInt':"All"}
)
#debug
'''
self.debug(
[
'self.DocumentedOldChunkStrsList is ',
str(DocumentedOldChunkStrsList)
]
)
'''
#map
DocumentedNewChunkStrsList=copy.deepcopy(DocumentedOldChunkStrsList)
map(
lambda __ChunkStr,__ChunkIndexInt:
map(
lambda __RemoveStr:
DocumentedNewChunkStrsList.__setitem__(
__ChunkIndexInt,
DocumentedNewChunkStrsList[__ChunkIndexInt].replace(
__RemoveStr,
''
)
),
map(
lambda __KeyStr:
'<span class="'+__KeyStr+'">',
[
"built_in",
"comment",
"keyword",
"params",
"string",
"number",
"title",
"function",
"decorator",
"class",
#"highlight",
#"kn",
#"c",
#"n",
#"p",
#"o"
]
)+['</span>']
),
DocumentedOldChunkStrsList,
xrange(len(DocumentedOldChunkStrsList))
)
#debug
'''
self.debug(
[
'self.DocumentedNewChunkStrsList is ',
str(DocumentedNewChunkStrsList)
]
)
'''
#replace
map(
lambda __DocumentedOldChunkStr,__DocumentedNewChunkStr:
self.__setattr__(
'LoadedReadVariable',
self.LoadedReadVariable.replace(__DocumentedOldChunkStr,__DocumentedNewChunkStr)
),
DocumentedOldChunkStrsList,
DocumentedNewChunkStrsList
)
#write
self.write(self.LoadedReadVariable).close()
#Return self
#return self
#</DefineClass>
View the Nbconverter sources on Github
In [19]:
#ImportModules
import ShareYourSystem as SYS
from ShareYourSystem.Guiders import Nbconverter
#Definition a Nbconverter
MyNbconverter=Nbconverter.NbconverterClass().package(
'ShareYourSystem.Standards.Objects.Concluder'
).scriptbook(
**{
'GuidingBookStr':'Doc'
}
).notebook(
'Presentation.ipynb'
).nbconvert(
'Readme.md',
'Slide'
)
#Definition the AttestedStr
SYS._attest(
[
'MyNbconverter is '+SYS._str(
MyNbconverter,
**{
'RepresentingBaseKeyStrsListBool':False,
'RepresentingAlineaIsBool':False
}
)
]
)
#Print
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
The Installer collects ModuleStrs to write
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Guiders.Nbconverter"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
import os
import copy
from ShareYourSystem.Standards.Interfacers import Loader,Writer
#</ImportSpecificModules>
#<DefineLocals>
InstallingSysFolderPathStr=SYS.PythonlogyLocalFolderPathStr
InstallingLibraryFolderPathStr=InstallingSysFolderPathStr+'/docs/LibraryReference/'
#</DefineLocals>
#<DefineClass>
@DecorationClass(**{
'ClassingSwitchMethodStrsList':['install']
})
class InstallerClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'InstallingModuleStrsList',
'InstallingAllBool'
]
def default_init(self,
_InstallingModuleStrsList=None,
_InstallingAllBool=False,
**_KwargVariablesDict
):
#Call the parent __init__ method
BaseClass.__init__(self,**_KwargVariablesDict)
def do_install(self):
#Definition
self.load(
**{
'FolderingPathVariable':InstallingSysFolderPathStr,
'FilingKeyStr':'setup.py'
}
)
#chunk to set the InstalledModuleStrsList
InstalledPackageStr=SYS.chunk(
['packages=[','],'],self.LoadedReadVariable
)[0]
InstalledTextStrsList=InstalledPackageStr.split('\n')
InstalledTextStrListsList=SYS._filter(
lambda __InstalledChunkList:
len(__InstalledChunkList)>0,
map(
lambda __InstalledTextStr:
SYS.chunk(
["'ShareYourSystem","',"],
__InstalledTextStr
),
InstalledTextStrsList
)
)
self.InstallingModuleStrsList=map(
lambda __InstalledTextStrList:
('ShareYourSystem'+__InstalledTextStrList[0])
if __InstalledTextStrList[0]!="'"
else 'ShareYourSystem',
InstalledTextStrListsList
)
#debug
'''
self.debug(('self.',self,['InstallingModuleStrsList']))
'''
#map
self.InstalledModulePathStrsList=map(
lambda __InstallingModuleStr:
__InstallingModuleStr.replace('.','/'),
self.InstallingModuleStrsList
)
#debug
'''
self.debug(('self.',self,['InstalledModulePathStrsList']))
'''
#set with all the NameStrs
self.InstalledNameStrsList=map(
lambda __InstalledModulePathStr:
__InstalledModulePathStr.split('/')[-1],
self.InstalledModulePathStrsList
)
#Return self
#return self
#</DefineClass>
View the Installer sources on Github
In [23]:
#ImportModules
import ShareYourSystem as SYS
from ShareYourSystem.Guiders import Installer
#Definition a Installer instance
MyInstaller=Installer.InstallerClass().install(_AllBool=True)
#Definition the AttestedStr
SYS._attest(
[
'MyInstaller is '+SYS._str(
MyInstaller,
**{
'RepresentingBaseKeyStrsListBool':False
}
)
]
)
#Print
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
The Documenter
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Guiders.Documenter"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
import collections
import os
import copy
import sys
from ShareYourSystem.Standards.Classors import Doer
from ShareYourSystem.Guiders import Celler
Readmer=BaseModule
#</ImportSpecificModules>
#<DefineLocals>
DocumentingOntologyLocalFolderPathStr=SYS.ShareYourSystemLocalFolderPathStr+'Ouvaton/'
DocumentingNbviewerLocalFolderPathStr=SYS.ShareYourSystemLocalFolderPathStr+'Ouvaton/'
DocumentingDocumentLocalFolderPathStr=SYS.ShareYourSystemLocalFolderPathStr+'docs/LibraryReference/'
DocumentingOntologyOuvatonFolderPathStr='/httpdocs/slides/'
DocumentingNbviewerOuvatonFolderPathStr='/httpdocs/ipython/'
#</DefineLocals>
#<DefineFunctions>
def getDocumentedReadmeInstanceVariableWithFolderPathStr(
_InstanceVariable,_FolderPathStr
):
#file first
return _InstanceVariable.notebook(
**{
'FolderingPathVariable':_FolderPathStr,
'GuidingBookStr':"Doc",
'NotebookingFileKeyStr':"Presentation.ipynb"
}
).nbconvert("Readme.md")
#</DefineFunctions>
#<DefineClass>
@DecorationClass()
class DocumenterClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'DocumentingConceptFolderPathStr',
'DocumentingSubReadmeIsBool',
'DocumentingConceptReadmeIsBool',
'DocumentingConceptDocumentIsBool',
'DocumentingConceptSlideIsBool',
'DocumentingSiteDocumentIsBool',
'DocumentedConceptModule',
'DocumentedConceptModuleStr',
'DocumentedConceptModuleFolderPathStr',
'DocumentedSubNameStrsList',
'DocumentedSubModulesList',
'DocumentedSubModuleStrsList',
'DocumentedSubModuleLocalFolderPathStrsList',
#'DocumentedPresentationsDictsList',
#'DocumentedConceptNotebookDict'
]
def default_init(self,
_DocumentingConceptFolderPathStr="",
_DocumentingSubReadmeIsBool=True,
_DocumentingConceptReadmeIsBool=True,
_DocumentingConceptDocumentIsBool=True,
_DocumentingConceptSlideIsBool=True,
_DocumentingSiteDocumentIsBool=True,
_DocumentedConceptModule=None,
_DocumentedConceptModuleStr="",
_DocumentedConceptModuleFolderPathStr="",
_DocumentedSubNameStrsList=None,
_DocumentedSubModulesList=None,
_DocumentedSubModuleStrsList=None,
_DocumentedSubModuleLocalFolderPathStrsList=None,
_DocumentedPresentationsDictsList=None,
_DocumentedConceptNotebookDict=None,
**_KwargVariablesDict
):
#Call the parent __init__ method
BaseClass.__init__(self,**_KwargVariablesDict)
def do_inform(self):
#debug
'''
self.debug(('self.',self,['DocumentingSubReadmeIsBool','DocumentingConceptDocumentIsBool']))
'''
#install first
self.install()
#Check
if self.DocumentingConceptFolderPathStr=="":
self.DocumentingConceptFolderPathStr='ShareYourSystem'.join(
os.getcwd().split('ShareYourSystem')[:-1]
)+'ShareYourSystem/'
#debug
'''
self.debug(('self.',self,['DocumentingConceptFolderPathStr']))
'''
#debug
self.folder(self.DocumentingConceptFolderPathStr)
self.DocumentedConceptModuleStr=self.FolderedModuleStr
#debug
'''
self.debug(('self.',self,[
'FolderedModuleStr',
'FolderedDirKeyStrsList'
]))
'''
#filter
self.DocumentedSubNameStrsList=SYS._filter(
lambda __FolderedDirKeyStr:
os.path.isdir(
self.FolderingPathVariable+__FolderedDirKeyStr
) and __FolderedDirKeyStr in Doer.DoerStrToDoStrOrderedDict.keys(),
self.FolderedDirKeyStrsList
)
#debug
'''
self.debug(('self.',self,['DocumentedSubNameStrsList','InstalledNameStrsList']))
'''
#sort
self.DocumentedSubNameStrsList=SYS._filter(
lambda __InstalledNameStr:
__InstalledNameStr in self.DocumentedSubNameStrsList,
self.InstalledNameStrsList
)
#map
self.DocumentedSubModuleStrsList=map(
lambda __DocumentedSubNameStr:
self.DocumentedConceptModuleStr+'.'+__DocumentedSubNameStr,
self.DocumentedSubNameStrsList
)
#Check
self.DocumentedConceptNameStr=self.FolderingPathVariable.split(
'/'
)[-1] if self.FolderingPathVariable[-1]!='/' else self.FolderingPathVariable.split('/'
)[-2]
#debug
'''
self.debug(('self.',self,[
'DocumentedSubNameStrsList',
'DocumentedSubModuleStrsList',
'DocumentedConceptNameStr'
]))
'''
#check
if self.DocumentedConceptNameStr in SYS.PluralStrToSingularStrOrderedDict.keys():
#package
self.DocumentedConceptModule=self.package(
self.FolderedModuleStr
).PackagedModuleVariable
#join
self.DocumentedConceptModuleFolderPathStr='/'.join(
self.DocumentedConceptModule.__file__.split(
'/'
)[:-1]
)+'/'
#debug
'''
self.debug(('self.',self,['DocumentedConceptModule']))
'''
#filter
self.DocumentedSubModulesList=SYS._filter(
lambda __AttributeValueVariable:
type(__AttributeValueVariable).__name__=='module',
self.DocumentedConceptModule.__dict__.values()
)
#debug
'''
self.debug((
'self.',self,[
'DocumentedSubModulesList'
]
))
'''
#Check
if self.DocumentingSubReadmeIsBool:
#debug
'''
self.debug(
[
'we build sub modules readmes here',
('self.',self,['DocumentedSubModuleStrsList'])
]
)
'''
#map
map(
lambda __DocumentedSubModuleStr:
self.package(
__DocumentedSubModuleStr
).scriptbook(
_GuideTuplesList=[
('001','Document','Markdown'),
],
**{
'GuidingBookStr':"Doc",
}
).notebook(
"PreReadme.ipynb"
).nbconvert(
"Readme.md"
),
self.DocumentedSubModuleStrsList
)
#Check
if self.DocumentingConceptSlideIsBool:
#debug
'''
self.debug(
[
'we slide here',
('self.',self,['DocumentedSubModuleStrsList'])
]
)
'''
#map
map(
lambda __DocumentedSubModuleStr:
self.package(
__DocumentedSubModuleStr
).scriptbook(
_GuideTuplesList=[
('001','Document','Markdown'),
('002','Github','Markdown'),
],
**{
'GuidingBookStr':"Doc",
}
).notebook(
"Presentation.ipynb",
**{'WritingLoadBool':False}
).nbconvert(
"Presentation.html",
'Slide'
),
self.DocumentedSubModuleStrsList
)
#mv for Nbviewer ipython notebooks
map(
lambda __DocumentedSubModuleStr:
os.popen(
'cp '+sys.modules[
__DocumentedSubModuleStr
].LocalFolderPathStr+'Presentation.ipynb '+DocumentingNbviewerLocalFolderPathStr+__DocumentedSubModuleStr.split(
'.'
)[-1]+'.ipynb'
),
self.DocumentedSubModuleStrsList
)
#mv for Ouvaton slide in html
map(
lambda __DocumentedSubModuleStr:
os.popen(
'cp '+sys.modules[
__DocumentedSubModuleStr
].LocalFolderPathStr+'Presentation.html '+DocumentingOntologyLocalFolderPathStr+__DocumentedSubModuleStr.split(
'.'
)[-1]+'.html'
),
self.DocumentedSubModuleStrsList
)
#mv for Ouvaton slide in php
map(
lambda __DocumentedSubModuleStr:
os.popen(
'cp '+sys.modules[
__DocumentedSubModuleStr
].LocalFolderPathStr+'Presentation.html '+DocumentingOntologyLocalFolderPathStr+__DocumentedSubModuleStr.split(
'.'
)[-1]+'.php'
),
self.DocumentedSubModuleStrsList
)
#map
self.DocumentedSubModuleLocalFolderPathStrsList=map(
lambda __DocumentedSubModuleStr:
SYS.PythonlogyLocalFolderPathStr+__DocumentedSubModuleStr.replace(
'.','/'
),
self.DocumentedSubModuleStrsList
)
#map
self.DocumentedPresentationsDictsList=map(
lambda __DocumentedSubModuleFolderPathStr:
self.load(
**{
'FolderingPathVariable':__DocumentedSubModuleFolderPathStr,
'FilingKeyStr':'Presentation.ipynb',
'LoadingFormatStr':'json'
}
).close(
).LoadedReadVariable,
self.DocumentedSubModuleLocalFolderPathStrsList
)
#debug
'''
self.debug(
'self.DocumentedPresentationsDictsList is '+SYS._str(self.DocumentedPresentationsDictsList)
)
'''
#copy
self.DocumentedConceptNotebookDict=copy.copy(Celler.CellingInitDict)
#flat
DocumentedFlatPresentationsDictsList=SYS.flat(
map(
lambda __DocumentedPresentationsDict:
copy.deepcopy(
__DocumentedPresentationsDict['worksheets'][0]['cells']
),
self.DocumentedPresentationsDictsList
)
)
#Flat all the presentations
self.DocumentedConceptNotebookDict['worksheets']=[
{
'cells':map(
lambda __DocumentedFlatPresentationsDict,__IndexInt:
dict(__DocumentedFlatPresentationsDict,**{
'prompt_number':__IndexInt}),
DocumentedFlatPresentationsDictsList,
xrange(len(DocumentedFlatPresentationsDictsList))
)
}
]
#debug
'''
self.debug(('self.',self,['DocumentedConceptNotebookDict']))
'''
#Write
self.write(
self.DocumentedConceptNotebookDict,
**{
'FolderingPathVariable':self.DocumentingConceptFolderPathStr,
'FilingKeyStr':'Concept'+self.GuidingBookStr+'.ipynb',
'LoadingFormatStr':'json'
}
).close()
#nbconvert
self.NotebookedCodeDict=self.DocumentedConceptNotebookDict
self.nbconvert(
_FormatStr='Slide',
**{
'FolderingPathVariable':self.DocumentingConceptFolderPathStr,
'NotebookingFileKeyStr':'Concept'+self.GuidingBookStr+'.ipynb'
}
)
#set
self.DocumentedSlideLocalFilePathStr=DocumentingOntologyLocalFolderPathStr+self.DocumentedConceptModule.__name__.split('.')[-1]+'.html'
#cp
os.popen('cp '+self.FiledPathStr+' '+self.DocumentedSlideLocalFilePathStr+self.DocumentedConceptModule.__name__.split('.')[-1]+'.ipynb')
#mv with .html extension
os.popen(
'cp '+self.FiledPathStr.replace(
'.ipynb',
'.html'
)+' '+self.DocumentedSlideLocalFilePathStr
)
#mv with .php extension
os.popen(
'mv '+self.FiledPathStr.replace(
'.ipynb',
'.html'
)+' '+self.DocumentedSlideLocalFilePathStr.replace('.html','.php')
)
#deploy
try:
self.deploy(
_ClientFilePathStrToServerFilePathStrOrderedDict=collections.OrderedDict(
[
(
self.DocumentedSlideLocalFilePathStr,
DocumentingOntologyOuvatonFolderPathStr+self.DocumentedConceptModule.__name__.split('.'
)[-1]+'.php'
)
]
)
)
except:
print('There is NO Internet !')
#Check
if self.DocumentingConceptReadmeIsBool:
#debug
'''
self.debug('we build the concept readme here')
'''
#import submodules
'''
map(
lambda __DocumentedSubModuleStr:
importlib.import_modules(__DocumentedSubModuleStr),
self.DocumentedSubModuleStrsList
)
'''
#readme
self.package(
self.DocumentedConceptModuleStr
).scriptbook(
_GuideTuplesList=[
('001','Document','Markdown'),
('002','Ouvaton','Markdown'),
('1','Github','Markdown'),
],
**{'GuidingBookStr':"Doc"}
)
#notebook
self.scriptbook(
_GuideTuplesList=[]
).notebook(
"PreReadme.ipynb"
).nbconvert(
"Readme.md",
'Markdown',
)
#Check
if self.DocumentingConceptDocumentIsBool:
#debug
'''
self.debug(
[
'we document here',
('self.',self,['DocumentedConceptModuleFolderPathStr'])
]
)
'''
'''
#document
self.document(
**{'PackagingModuleVariable':self.DocumentedConceptModuleStr}
)
'''
#package
self.package(self.DocumentedConceptModuleStr)
#mv with .php extension
os.popen(
'cp '+self.PackagedLocalFolderPathStr+'Readme.md '+DocumentingDocumentLocalFolderPathStr+self.DocumentedConceptModuleStr.split('.')[-1]+'.md'
)
#Return self
#return self
if self.DocumentingSiteDocumentIsBool:
#open
os.popen(
'mkdocs build --clean'
)
#deploy
try:
self.deploy(
_ClientFilePathStrToServerFilePathStrOrderedDict=collections.OrderedDict(
[
(
self.DocumentedSlideLocalFilePathStr,
DocumentingOntologyOuvatonFolderPathStr+self.DocumentedConceptModule.__name__.split('.'
)[-1]+'.php'
)
]
)
)
except:
print('There is NO Internet !')
#</DefineClass>
View the Documenter sources on Github
In [27]:
#ImportModules
import ShareYourSystem as SYS
from ShareYourSystem.Guiders import Documenter
#Definition an Documenter instance
MyDocumenter=Documenter.DocumenterClass()
#Definition the AttestedStr
SYS._attest(
[
'MyDocumenter is '+SYS._str(
MyDocumenter,
**{
'RepresentingBaseKeyStrsListBool':False,
'RepresentingAlineaIsBool':False
}
)
]
)
# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
The Documenter export in the mkdoc the readme of a Module
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Guiders.Installer"
DecorationModuleStr="ShareYourSystem.Standards.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
import os
import copy
from ShareYourSystem.Standards.Interfacers import Loader,Writer
#</ImportSpecificModules>
#<DefineLocals>
DocumentingSysFolderPathStr=SYS.ShareYourSystemLocalFolderPathStr
DocumentingLibraryFolderPathStr=DocumentingSysFolderPathStr+'/docs/LibraryReference/'
#</DefineLocals>
#<DefineClass>
@DecorationClass()
class DocumenterClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'DocumentedModulePathStr',
'DocumentedMkdocsList',
'DocumentedModulePathStr'
]
def default_init(self,
_DocumentingNewIsBool=False,
_DocumentingMkdocWriteIsBool=False,
_DocumentedMkdocsList=None,
_DocumentedMkdocsDict=None,
**_KwargVariablesDict
):
#Call the parent __init__ method
BaseClass.__init__(self,**_KwargVariablesDict)
def do_document(self):
#first package
self.package()
#map
self.DocumentedModulePathStr=self.PackagedModuleStr.replace('.','/')
self.DocumentedNameStr=self.DocumentedModulePathStr.split('/')[-1]
#debug
'''
self.debug(('self.',self,[
'DocumentedModulePathStr',
'DocumentedNameStr'
]))
'''
#Load the readmes and write them into the docs Library reference folder
self.load(
**{
'FolderingPathVariable':SYS.PythonlogyLocalFolderPathStr+'/'+self.DocumentedModulePathStr,
'FilingKeyStr':'Readme.md',
'LoadingFormatStr':'txt'
}
).write(
**{
'FolderingPathVariable':DocumentingLibraryFolderPathStr,
'FilingKeyStr':self.DocumentedNameStr+'.md',
'WritingLoadBool':True
}
)
#Definition in the future yaml config mkdocs
self.DocumentedMkdocsList=[
'docs'.join(
DocumentingLibraryFolderPathStr.split('docs/')[1:]
)+self.DocumentedNameStr+'.md',
'Library Reference',
self.DocumentedNameStr
]
#debug
'''
self.debug(('self.',self,[
'DocumentedMkdocsList'
]))
'''
#Definition
self.load(
**{
'FolderingPathVariable':SYS.PythonlogyLocalFolderPathStr+self.__class__.__module__.replace(
'.','/')
if self.DocumentingNewIsBool
else DocumentingSysFolderPathStr,
'FilingKeyStr':'mkdocs.yml',
'LoadingFormatStr':'yaml'
}
)
#Add to the pages
self.LoadedReadVariable['pages'].append(self.DocumentedMkdocsList)
#Copy
self.DocumentedMkdocsDict=copy.copy(
self.LoadedReadVariable
)
#debug
'''
self.debug(('self.',self,[
'DocumentedMkdocsDict'
]))
'''
if self.DocumentingMkdocWriteIsBool:
#Close and write now in the top root folder
self.write(
self.DocumentedMkdocsDict,
**{
'FolderingPathVariable':DocumentingSysFolderPathStr,
}
).FiledHardVariable.close()
#Return self
#return self
#</DefineClass>
View the Documenter sources on Github
In [31]:
#ImportModules
import ShareYourSystem as SYS
from ShareYourSystem.Guiders import Documenter
#Definition a Documenter instance
MyDocumenter=Documenter.DocumenterClass().document(
True,
**{
'PackagingModuleVariable':'ShareYourSystem.Standards.Objects'
}
)
#Definition the AttestedStr
SYS._attest(
[
'MyDocumenter is '+SYS._str(
MyDocumenter,
**{
'RepresentingBaseKeyStrsListBool':False
}
)
]
)
#Print