From 0e56bdddc23ca5ec416adba80721a10e2f9c950e Mon Sep 17 00:00:00 2001 From: Kieran Ryan Date: Mon, 23 Dec 2024 18:11:34 +0000 Subject: [PATCH] feat: 'notebook' extra requirement with nbformat Simplifies `pip install radon nbformat` to `pip install radon[notebook]`. Protects against changing underlying dependency in future. --- README.rst | 8 +++++--- docs/commandline.rst | 6 ++++-- poetry.lock | 5 ++++- pyproject.toml | 8 ++++++++ setup.py | 5 ++++- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 0bcbdee..3b32ae5 100644 --- a/README.rst +++ b/README.rst @@ -51,7 +51,7 @@ With Pip: $ pip install radon If you want to configure Radon from `pyproject.toml` and you run Python <3.11, -you'll need the extra `toml` dependency: +you will need to install the extra `toml` dependency: .. code-block:: sh @@ -159,9 +159,11 @@ Usage with Jupyter Notebooks Radon can be used with ``.ipynb`` files to inspect code metrics for Python cells. Any ``%`` macros will be ignored in the metrics. -.. note:: +You will need to install the extra `notebook` dependency: - Jupyter Notebook support requires the optional ``nbformat`` package. To install, run ``pip install nbformat``. +.. code-block:: sh + + $ pip install radon[notebook] To enable scanning of Jupyter notebooks, add the ``--include-ipynb`` flag. diff --git a/docs/commandline.rst b/docs/commandline.rst index 44776ed..7115035 100644 --- a/docs/commandline.rst +++ b/docs/commandline.rst @@ -42,9 +42,11 @@ Usage with Jupyter Notebooks Radon can be used with ``.ipynb`` files to inspect code metrics for Python cells. Any ``%`` macros will be ignored in the metrics. -.. note:: +You will need to install the extra `notebook` dependency: + +.. code-block:: sh - Jupyter Notebook support requires the optional ``nbformat`` package. To install, run ``pip install nbformat``. + $ pip install radon[notebook] To enable scanning of Jupyter notebooks, add the ``--include-ipynb`` flag with any of the commands. diff --git a/poetry.lock b/poetry.lock index 9bcbfd6..255a981 100644 --- a/poetry.lock +++ b/poetry.lock @@ -806,7 +806,10 @@ files = [ docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more-itertools", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)"] +[extras] +notebook = ["nbformat"] + [metadata] lock-version = "2.0" python-versions = ">=3.7,<4.0" -content-hash = "5b4be22bd8f95aca6d5e73cbea202308c983455943f5bc9127346d778a046cc0" +content-hash = "4eb5cd71ada4e743bf51e23bba01d55143dfd3c8727c03dc7ee8f46c63215324" diff --git a/pyproject.toml b/pyproject.toml index 104d57f..a09fe34 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,6 +14,11 @@ colorama = [ {version = "==0.4.1", markers = "python_version == \"3.4\""} ] +# A list of all of the optional dependencies, which are included in the +# below `extras`. They can be opted into by apps. +# https://python-poetry.org/docs/pyproject/#extras +nbformat = { version = "*", optional = true } + [tool.poetry.group.dev.dependencies] coverage = "*" coveralls = "*" @@ -23,6 +28,9 @@ argparse = "*" nbformat = "*" tox = "^4.4.7" +[tool.poetry.extras] +notebook = ["nbformat"] + [tool.poetry.scripts] radon = "radon:main" diff --git a/setup.py b/setup.py index 72258c6..aadf654 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,7 @@ import os + from setuptools import setup, find_packages + import radon @@ -27,7 +29,8 @@ 'colorama>=0.4.1;python_version>"3.4"', ], extras_require={ - 'toml': ["tomli>=2.0.1"] + 'toml': ["tomli>=2.0.1"], + 'notebook': ['nbformat'], }, entry_points={ 'console_scripts': ['radon = radon:main'],