Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ With Pip:

$ pip install radon

With Pip and `pyproject.toml` support on Python <3.11:

.. code-block:: sh

$ pip install radon[toml]

Or download the source and run the setup file:

.. code-block:: sh
Expand Down
1 change: 1 addition & 0 deletions docs/commandline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ For example, all of the radon commands have a ``--exclude`` and ``--ignore`` arg
Radon will look for the following files to determine default arguments:

* ``radon.cfg``
* ``pyproject.toml`` (with optional toml install before python 3.11)
* ``setup.cfg``
* ``~/.radon.cfg``

Expand Down
22 changes: 22 additions & 0 deletions radon/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
from contextlib import contextmanager

from mando import Program
try:
# Python 3.11+
import tomllib
except ImportError:
try:
# Support for python <3.11
import tomli as tomllib
except ImportError:
pass

import radon.complexity as cc_mod
from radon.cli.colors import BRIGHT, RED, RESET
Expand Down Expand Up @@ -49,13 +58,26 @@ def get_value(self, key, type, default):
CONFIG_SECTION_NAME, key, fallback=default
)

@staticmethod
def toml_config():
try:
with open("pyproject.toml", "rb") as pyproject_file:
pyproject = tomllib.load(pyproject_file)
config_dict = pyproject["tool"]
except tomllib.TOMLDecodeError as exc:
raise exc
except Exception:
config_dict = {}
return config_dict

@staticmethod
def file_config():
'''Return any file configuration discovered'''
config = configparser.ConfigParser()
for path in (os.getenv('RADONCFG', None), 'radon.cfg'):
if path is not None and os.path.exists(path):
config.read_file(open(path))
config.read_dict(FileConfig.toml_config())
config.read(['setup.cfg', os.path.expanduser('~/.radon.cfg')])
return config

Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
'colorama==0.4.1;python_version<="3.4"',
'colorama>=0.4.1;python_version>"3.4"',
],
extras_require={
'toml': ["tomli>=2.0.1"]
},
entry_points={
'console_scripts': ['radon = radon:main'],
'setuptools.installation': [
Expand Down