radon
radon copied to clipboard
Radon crashes on unrelated config option in pyproject.toml
When I have a string format in an unrelated section in pyproject.toml, radon crashes with the following message:
Traceback (most recent call last):
File "/Users/mkj/.local/bin/radon", line 8, in <module>
sys.exit(main())
^^^^^^
File "/Users/mkj/.local/pipx/venvs/radon/lib/python3.11/site-packages/radon/__init__.py", line 10, in main
from radon.cli import program, log_error
File "/Users/mkj/.local/pipx/venvs/radon/lib/python3.11/site-packages/radon/cli/__init__.py", line 90, in <module>
_cfg = FileConfig()
^^^^^^^^^^^^
File "/Users/mkj/.local/pipx/venvs/radon/lib/python3.11/site-packages/radon/cli/__init__.py", line 45, in __init__
self.file_cfg = self.file_config()
^^^^^^^^^^^^^^^^^^
File "/Users/mkj/.local/pipx/venvs/radon/lib/python3.11/site-packages/radon/cli/__init__.py", line 85, in file_config
config.read_dict(FileConfig.toml_config())
File "/opt/homebrew/Cellar/[email protected]/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/configparser.py", line 770, in read_dict
self.set(section, key, value)
File "/opt/homebrew/Cellar/[email protected]/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/configparser.py", line 1220, in set
super().set(section, option, value)
File "/opt/homebrew/Cellar/[email protected]/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/configparser.py", line 910, in set
value = self._interpolation.before_set(self, section, option,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/configparser.py", line 403, in before_set
raise ValueError("invalid interpolation syntax in %r at "
ValueError: invalid interpolation syntax in '%(lineno)d' at position 0
My minimal example config:
[tool.some_tool]
some_option = "%(lineno)d"
I have encountered this when upgrading to radon 6.0.1 while using a custom log_format option in a pytest configuration section.
Happens to me with a Pytorch dependency. 'torch': {'url': 'https://download.pytorch.org/whl/cu117/torch-1.13.1%2Bcu117-cp310-cp310-linux_x86_64.whl'},
Very interesting issue @jannismain, thanks for raising! I have opened a PR to resolve the issue (#252), would be great if you could take a look - and maintainers such as @rubik - to review the changes and provide any feedback.
In essence, the issue is a result of radon using a config parser that uses the '%' sign for inserting or substituting values from other keys and that radon passes the entire configuration file to the parser - as opposed to the radon section only.
If you are not not dependent on radon versions later than 6.0.0 (including pyproject.toml support for radon configuration), rolling back to 5.1.0 should resolve the issue for you until the PR is merged.
@kieran-ryan the solution you provided in #252 solved the issue I described above for my minimal example. Scoping the config parser to only the radon section is an elegant solution 👍🏻