Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Radon crashes on unrelated config option in pyproject.toml #244

Open
jannismain opened this issue Apr 4, 2023 · 3 comments · May be fixed by #252
Open

Radon crashes on unrelated config option in pyproject.toml #244

jannismain opened this issue Apr 4, 2023 · 3 comments · May be fixed by #252

Comments

@jannismain
Copy link

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.

@radandreicristian
Copy link

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'},

@kieran-ryan
Copy link

kieran-ryan commented Sep 2, 2023

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.

@jannismain
Copy link
Author

@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 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants