在Jupyter Notebook上运行任何标准的Python代码质量工具
项目描述
在Jupyter Notebooks上运行ruff, isort, pyupgrade, mypy, pylint, flake8, black, blacken-docs等工具
- ✅ 优雅地处理IPython魔法
- ✅ 尊重您的配置文件
- ✅ 保留“安静模式”中的分号
- ✅ 检查代码和Markdown单元格
目录
🎉 安装
在你的虚拟环境中运行(注意:$
不是命令的一部分)
$ python -m pip install -U nbqa
同时安装所有支持的代码检查器和格式化工具
$ python -m pip install -U "nbqa[toolchain]"
🚀 示例
命令行
使用black重新格式化你的笔记本
$ nbqa black my_notebook.ipynb
reformatted my_notebook.ipynb
All done! ✨ 🍰 ✨
1 files reformatted.
使用isort整理你的导入语句
$ nbqa isort my_notebook.ipynb --float-to-top
Fixing my_notebook.ipynb
使用pyupgrade升级你的语法
$ nbqa pyupgrade my_notebook.ipynb --py37-plus
Rewriting my_notebook.ipynb
使用blacken-docs格式化你的Markdown单元格
$ nbqa blacken-docs my_notebook.ipynb --nbqa-md --nbqa-diff
Cell 2
------
--- my_notebook.ipynb
+++ my_notebook.ipynb
@@ -1,2 +1 @@
-First level heading
-===
+# First level heading
To apply these changes, remove the `--nbqa-diff` flag
格式化通过Jupytext保存的.md
文件(需要已安装jupytext
)
$ nbqa black my_notebook.md
reformatted my_notebook.md
All done! ✨ 🍰 ✨
1 files reformatted.
查看涉及doctest、flake8、mypy、pylint、autopep8、pydocstyle、yapf和ruff的命令行示例
预提交
以下是如何设置一些pre-commit钩子的示例:将以下内容放入你的.pre-commit-config.yaml
文件中(查看作为pre-commit钩子的用法)
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.9.0
hooks:
- id: nbqa-black
additional_dependencies: [jupytext] # optional, only if you're using Jupytext
- id: nbqa-pyupgrade
args: ["--py37-plus"]
- id: nbqa-isort
args: ["--float-to-top"]
如果你需要选择这些代码检查器和格式化工具的特定版本,请将它们添加到additional_dependencies
中。
🥳 使用者
点击这里查看(非详尽)的仓库列表
- https://github.com/ComPWA/ampform
- https://github.com/ComPWA/tensorwaves
- https://github.com/DataS-DHSC/os-maps-example
- https://github.com/Eazhi/World-Happiness-Analysis
- https://github.com/GoogleCloudPlatform/ai-platform-samples
- https://github.com/MRCIEU/epigraphdb
- https://github.com/OpenMined/PyDP
- https://github.com/PlasmaPy/PlasmaPy
- https://github.com/ProjectPythia/pythia-foundations
- https://github.com/SeldonIO/alibi
- https://github.com/TeoZosa/deep-learning-v2-pytorch
- https://github.com/WM-SEMERU/mlproj_template
- https://github.com/alan-turing-institute/sktime
- https://github.com/amor71/LiuAlgoTrader
- https://github.com/bbernst/base_envs
- https://github.com/cheginit/HyRiver-examples
- https://github.com/cheginit/pygeohydro
- https://github.com/cheginit/pynhd
- https://github.com/covid-19-impact-lab/sid-germany
- https://github.com/covid-19-impact-lab/sid
- https://github.com/dapperfu/Python-Simulink
- https://github.com/deepcharles/ruptures
- https://github.com/dhassault/cyclegan_pytorch
- https://github.com/gboeing/osmnx
- https://github.com/glotzerlab/freud-examples
- https://github.com/glotzerlab/hoomd-examples
- https://github.com/glotzerlab/signac-docs
- https://github.com/glotzerlab/signac-examples
- https://github.com/grapl-security/grapl
- https://github.com/hainegroup/oceanspy
- https://github.com/henryiii/python-compiled-minicourse
- https://github.com/intake/intake-esm
- https://github.com/jameslamb/lightgbm-dask-testing
- https://github.com/jdb78/pytorch-forecasting
- https://github.com/jhrcook/advent-of-code_2020
- https://github.com/julian-west/asset_price_correlations
- https://github.com/kratsg/drstorage
- https://github.com/madebr/pyOpt
- https://github.com/matthewfeickert/heputils
- https://github.com/matyama/deep-rl-hands-on
- https://github.com/mayou36/raredecay
- https://github.com/neomatrix369/nlp_profiler
- https://github.com/openforcefield/openff-system
- https://github.com/pandas-profiling/pandas-profiling
- https://github.com/paw-lu/dotfiles
- https://github.com/pawamoy/wps-light
- https://github.com/phinate/clarinet
- https://github.com/pik-primap/climate_categories
- https://github.com/pik-primap/primap2
- https://github.com/pik-primap/unfccc_di_api
- https://github.com/pymc-devs/pymc-examples
- https://github.com/pymc-devs/resources
- https://github.com/saturncloud/examples
- https://github.com/scikit-hep/boost-histogram
- https://github.com/scikit-hep/iminuit
- https://github.com/scikit-hep/mplhep
- https://github.com/scikit-hep/pyhf
- https://github.com/scikit-hep/pylhe
- https://github.com/v-goncharenko/data-science-template
- https://github.com/wemake-services/wemake-python-styleguide
- https://github.com/zfit/phasespace
- https://github.com/zfit/zfit
- https://github.com/zfit/zfit-physics
- https://github.com/zfit/zfit-tutorials
如果你的项目缺失,请告诉我们,或发起一个pull request!
💬 留言
迈克尔·肯尼迪 & 布莱恩·奥肯,《Python Bytes播客》的主播
这真是太酷了。我认为它将大量的代码格式化、代码分析和清理带到了笔记本中,而这在我看来一直是非常欠缺的
尼基塔·索博列夫,wemake.services的CTO
太神奇了!
亚历克斯·安多拉,数据科学家、ArviZ & PyMC开发者、“学习贝叶斯统计”播客主播
在
nbqa
上做得很好 @MarcoGorelli!在CI中将会非常实用。
马修·菲克尔特,伊利诺伊大学博士后,研究LHC物理学
将nbqa添加到您的pre-commit hooks中,与@codewithanthony的pre-commit CI服务一起使用真是太棒了!每个使用Jupyter笔记本的人都应该这样做。
吉里什·帕苏帕蒂,软件工程师,现在是核心贡献者
非常感谢您为创建如此有用的工具所做的努力。
西蒙·布鲁格曼,数据科学家 & pandas-profiling开发者
nbQA帮助我们使笔记本与代码的其他部分保持相同的标准。如果你对代码标准认真负责,你应该在笔记本和Python脚本之间保持一致性。这是生态系统中的一项伟大补充,谢谢!
布拉德利·迪斯,物理学与科学计算博士研究生
nbqa是一个干净、易于使用且有效的笔记本代码风格工具。在项目文档中渲染笔记本时,格式化和可读性产生了巨大的差异!
詹姆斯·兰姆,@saturn_cloud工程师、LightGBM维护者
今天我了解到
nbqa
,这是一个在@ProjectJupyter笔记本中的Python代码上运行linters(如flake8
)的命令行工具。感谢@jayyqi让我知道了它。到目前为止,我非常喜欢它。
拉斯·耶肯,@Our World In Data技术负责人
非常有用!我只希望它被集成到Jupyterlab中。
文森特·D·沃默达尔,@calmcode.io维护者
不错。nbQA看起来是预防Untitled12.ipynb现象的好方法。我喜欢!
马尼·萨卡尔,Kaggle 3x专家,贡献者
nbQA是一个鼓舞人心的项目,该项目背后的团队知识渊博,并能跳出框外想出创意和解决方案。
👥 贡献
我将向任何提交有用pull request的人提供写权限——有关如何做到这一点的详细信息,请参阅贡献指南。
感谢这些可爱的人们(emoji键)
本项目遵循all-contributors规范。欢迎任何形式的贡献!
项目详情
下载文件
下载适合您平台的应用程序文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源代码分发
构建分发
nbqa-1.9.0.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 48c0acd83675bd6d086efba3885e1137d9475c0da328c74f46b9acbc664fe36f |
|
MD5 | 29dc4a960c4937be2e1deadcf13fe631 |
|
BLAKE2b-256 | 535811a261eaf1326f39ac7deadc462ded37af29c279a657a54225c5afba4f0b |
nbqa-1.9.0-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 89da6b55ce0b47b5e8be45c5b94404e1d861e45df36959dd34a5d15cf45141ea |
|
MD5 | 33d2096b80c4ad46cac86e9baf7a4863 |
|
BLAKE2b-256 | 61b22f9bca9d17466258caec88c8eb15069924c0d1db66633869a1ef83861943 |