保存时自动将Jupyter笔记本导出为各种文件格式(.py、.html等)。

nbautoexport的Python项目详细描述


nbautoexport公司

Docs StatusPyPIconda-forgetestscodecov

Making it easier to code review Jupyter notebooks, one script at a time.

nbautoexport使用Jupyter时,保存时自动将Jupyter笔记本导出为各种文件格式(.py、.html等)。一个很好的用例是自动生成笔记本的脚本版本,以方便代码评审注释。在

安装

首先,您需要安装nbautoexport。这应该安装在运行Jupyter Notebook或Jupyter Lab所在的环境中。nbautoexport可从PyPI经由pip或从{a7}经由conda获得。在

pip install nbautoexport
^{pr2}$

{juter>自动运行时,{juter>或pyjuter}自动运行:

nbautoexport install

如果已经有一个Jupyter服务器正在运行,则需要重新启动它才能生效。在

简单用法

假设您有一个项目,并将您的笔记本放在notebooks/子目录中。在

要将该目录配置为自动导出,请运行以下命令:

nbautoexport configure notebooks

这将创建一个配置文件notebooks/.nbautoexport。在

如果您已经将nbautoexport设置为与Jupyter一起工作(使用install命令,如前一节所述),那么每当您在Jupyter中保存笔记本时,都会运行一个钩子来检查在与笔记本相同的目录中是否存在.nbautoexport配置文件。如果是这样,它将使用该文件中指定的设置来导出您的笔记本。默认情况下,它将生成以笔记本命名的笔记本的脚本版本(扩展名为.py),并保存在notebooks/script目录中。在

如果一切正常,您的笔记本目录应以如下示例所示的文件结尾:

notebooks
├──0.1-ejm-data-exploration.ipynb
├──0.2-ejm-feature-creation.ipynb
└── script
    └── 0.1-ejm-data-exploration.py
    └── 0.2-ejm-feature-creation.py

配置导出选项

默认的.nbautoexport配置文件如下所示:

{"export_formats":["script"],"organize_by":"extension"}

保存后,这将导致笔记本被导出到保存到notebooks/script目录中的脚本。在

notebooks
├──0.1-ejm-data-exploration.ipynb
├──0.2-ejm-feature-creation.ipynb
└── script
    └── 0.1-ejm-data-exploration.py
    └── 0.2-ejm-feature-creation.py

组织导出文件的另一种方法是为每个笔记本创建一个目录。这对于在tab完成时匹配笔记本和子目录非常方便,然后在完成部分之后使用*进行全局匹配。在

nbautoexport configure notebooks --organize-by notebook
notebooks
├── 0.1-ejm-data-exploration
│   └── 0.1-ejm-data-exploration.py
├── 0.2-ejm-feature-creation
│   └── 0.2-ejm-feature-creation.py
├──0.1-ejm-data-exploration.ipynb
└──0.2-ejm-feature-creation.ipynb

如果您不喜欢所选的设置,您可以通过以下方式进行更改:1)使用新参数和--overwrite标志重新运行nbautoexport命令,或者2)手动编辑.nbautoexport文件。在

您还可以指定任意多个导出格式。我们支持^{}提供的大多数导出格式,例如htmlmd和{}。要指定格式,请对要包含的每个格式使用--export-format。在

高级示例

nbautoexport configure sprint_one_notebooks -f script -f html --organize-by extension

保存后,这将在sprint_one_notebooks文件夹中创建.py和{}版本的Jupyter笔记本,并产生以下组织:

notebooks
├──0.1-ejm-data-exploration.ipynb
├──0.2-ejm-feature-creation.ipynb
├── script
│   └── 0.1-ejm-data-exploration.py
│   └── 0.1-ejm-features-creation.py
└── html
    └── 0.1-ejm-data-exploration.html
    └── 0.1-ejm-features-creation.html

更多功能

nbautoexportCLI有两个附加命令:

  • export用于临时导出笔记本或笔记本目录
  • clean(实验性)将删除目录中不是由当前.nbautoexport配置生成的文件

使用--help标志查看文档。在

命令行帮助

nbautoexport --help
Usage: nbautoexport [OPTIONS] COMMAND [ARGS]...

  Automatically export Jupyter notebooks to various file formats (.py,
  .html, and more) upon save. One great use case is to automatically have
  script versions of your notebooks to facilitate code review commenting.

  To set up, first use the 'install' command to register nbautoexport with
  Jupyter. If you already have a Jupyter server running, you will need to
  restart it.

  Next, you will need to use the 'configure' command to create a
  .nbautoexport configuration file in the same directory as the notebooks
  you want to have export automatically.

  Once nbautoexport is installed with the first step, exporting will run
  automatically when saving a notebook in Jupyter for any notebook where
  there is a .nbautoexport configuration file in the same directory.

Options:
  --version             Show nbautoexport version.
  --install-completion  Install completion for the current shell.
  --show-completion     Show completion for the current shell, to copy it or
                        customize the installation.

  --help                Show this message and exit.

Commands:
  clean      (EXPERIMENTAL) Remove subfolders/files not matching...
  configure  Create a .nbautoexport configuration file in a directory.
  export     Manually export notebook or directory of notebooks.
  install    Register nbautoexport post-save hook with Jupyter.

这个存储库最初是使用Cookiecutter^{}创建的。在

历史

0.2.1(2020年9月18日)

  • nbconvert发布了Verion6,它破坏了一些功能。固定到nbconvert<6,直到我们可以寻址#57。在

0.2.0(2020-09-04)

  • 添加选项以指定全局样式模式,以在使用clean时从删除中排除文件。详见documentation。(#46#54

0.1.1(2020-08-06)

  • 修复了从源代码发行版安装时丢失的requirements.txt错误。(#50#52

0.1.0(2020-08-05)

  • PyPI的第一个版本。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何使用从PreparedStatement返回的RowId。getGeneratedKeys()?   selenium chrome驱动程序中下一个网站url的java空白页   java如何将参数化匿名类转换为lambda?   java JUnit在AfterClass上获取测试结果   java将动态XML/JSON内容与静态标记化负载进行比较,并检索标记值   java共享一个需要数据持久性的项目[数据库]   java在调用方法时获取意外的参数类型。getParameterTypes()   java如何用jdbc在swing中用另一个字段替换外键?   需要java Jersey Tomcat CDI依赖项解释   java如何生成UML图   java如何编写Jersey rest服务可以通过给定的spring代码访问   SpringMaven存储库管理器Nexus与Java依赖项的Artifactory   java将包从另一个项目导入eclipse中的当前项目   加密Java使用密码加密文件