在系统路径中将.ipynb文件作为模块导入。
nostalgiaforever的Python项目详细描述
pip install nostalgiaforever
笔记本是一种假设
If a notebook is a hypothesis then it can be tested.
现代科学家正在向笔记本是通用货币的时代过渡。考虑一下测试和文档是可重用开源软件的关键方面这些最佳实践是为了支持开发该软件的社区而发展起来的。一代又一代的开放源代码建立了习惯用法和风格指南,使软件协作能够在全球范围内进行。现在,可重用软件的使用正与现代科学融合在一起,这两个学科在解决日益复杂的多目标问题上有着相似的全球雄心。
因此,笔记本电脑已经不再是个人洞察力的媒介,而成为社区创新的资产。对于那些将程序性“思维单元”作为计算性叙述进行评估的科学家来说,它们代表了额外的个人物品。在某种程度上,笔记本代表了一种现代的假设形式,科学家们必须很快地与他人分享不幸的是,新的作者缺乏在科学界共享笔记本作为假设的惯例本文介绍了从识字编程到创建可读、可重用和可复制的笔记本电脑的策略这些笔记本编写实践促进了文档和单元测试的改进。
See deathbeds present @ JupyterCon
fromnostalgiaforeverimportimporting,testing,reuse
关键技术
要点
- 笔记本电脑可用于测试和软件
- 编写可测试计算论文的最佳实践
订单
在谈话之前
重新启动机器
启动观察程序
source activate p6 && cd ahypothesis/nostalgiaforever && watchmedo tricks tricks.yml
嘿,艺术书呆子!打开颜色
切断释放装置。
建立文档。
fromnbconvert.exporters.markdownimportMarkdownExporterfromnbconvert.preprocessorsimportPreprocessorclassReplaceLinks(Preprocessor):defpreprocess_cell(self,cell,resources=None,index=0):ifcell['cell_type']=='markdown':ifisinstance(cell['source'],list):cell['source']=''.join(cell['source'])cell['source']=cell['source'].replace('.ipynb','')returncell,resources
frompathlibimportPathif__name__=='__main__':fromIPythonimportget_ipython!jupyternbconvert--tomarkdownreadme.ipynbforpathinPath('.').rglob('*.ipynb'):ifall(notpart.startswith('.')forpartinpath.parts):to=('docs'/path)print(path)to.parent.mkdir(exist_ok=True)MarkdownExporter(preprocessors=[ReplaceLinks()]).from_filename(path)[0]to.with_suffix('.md').write_text(("---\n"*2iflen(path.parts)>1else"")+MarkdownExporter(preprocess=[ReplaceLinks()]).from_filename(path)[0])
[NbConvertApp] Converting notebook readme.ipynb to markdown
[NbConvertApp] Writing 5882 bytes to readme.md
readme.ipynb
nostalgiaforever/importing.ipynb
nostalgiaforever/plugin.ipynb
nostalgiaforever/reuse.ipynb
nostalgiaforever/testing.ipynb
nostalgiaforever/util.ipynb
test/test_nostalgia.ipynb
带watchdog
的观察程序source activate p6 && cd ahypothesis/nostalgiaforever/ && watchmedo tricks tricks.yml
运行单元测试
if__name__=='__main__':try:__import__('unittest').main('test',argv='--verbose'.split())exceptSystemExit:...
.
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
# Summary [clear all output then "Run All" -- or it didn't happen]
摘要[清除所有输出,然后“全部运行”--否则不会发生]
if __name__ == '__main__':
!source activate p6 && ipython --profile pidgin -m nostalgiaforever.importing
!source activate p6 && ipython --profile pidgin -m nostalgiaforever.testing
!source activate p6 && ipython --profile pidgin -m nostalgiaforever.reuse