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 can't run when use pytest log fornat: $()d #251

Open
yukihiko-shinoda opened this issue Sep 1, 2023 · 1 comment · May be fixed by #252
Open

Radon can't run when use pytest log fornat: $()d #251

yukihiko-shinoda opened this issue Sep 1, 2023 · 1 comment · May be fixed by #252

Comments

@yukihiko-shinoda
Copy link

yukihiko-shinoda commented Sep 1, 2023

Radon reports ValueError: invalid interpolation syntax when use pytest log format with $()d. But pytest official documentation uses $()d:

_pytest.logging — pytest documentation

DEFAULT_LOG_FORMAT = "%(levelname)-8s %(name)s:%(filename)s:%(lineno)d %(message)s"

How to reproduce

pyproject.toml:

[tool.pytest.ini_options]
log_format = "%(asctime)s %(process)d %(levelname)s %(name)s:%(filename)s:%(lineno)d %(message)s"
$ radon
Traceback (most recent call last):
  File "/workspace/.venv/bin/radon", line 8, in <module>
    sys.exit(main())
  File "/workspace/.venv/lib/python3.9/site-packages/radon/__init__.py", line 10, in main
    from radon.cli import program, log_error
  File "/workspace/.venv/lib/python3.9/site-packages/radon/cli/__init__.py", line 90, in <module>
    _cfg = FileConfig()
  File "/workspace/.venv/lib/python3.9/site-packages/radon/cli/__init__.py", line 45, in __init__
    self.file_cfg = self.file_config()
  File "/workspace/.venv/lib/python3.9/site-packages/radon/cli/__init__.py", line 85, in file_config
    config.read_dict(FileConfig.toml_config())
  File "/usr/local/lib/python3.9/configparser.py", line 754, in read_dict
    self.set(section, key, value)
  File "/usr/local/lib/python3.9/configparser.py", line 1204, in set
    super().set(section, option, value)
  File "/usr/local/lib/python3.9/configparser.py", line 894, in set
    value = self._interpolation.before_set(self, section, option,
  File "/usr/local/lib/python3.9/configparser.py", line 402, in before_set
    raise ValueError("invalid interpolation syntax in %r at "
ValueError: invalid interpolation syntax in "{'log_format': '%(asctime)s %(process)d %(levelname)s %(name)s:%(filename)s:%(lineno)d %(message)s'}" at position 17

To avoid this issue, it requires to replace log_format in pyproject.toml as following:

- log_format = "%(asctime)s %(process)d %(levelname)s %(name)s:%(filename)s:%(lineno)d %(message)s"
+ log_format = "%(asctime)s %(process)s %(levelname)s %(name)s:%(filename)s:%(lineno)s %(message)s"

radon version: 6.0.1

$ radon --version
6.0.1

When rollback to radon 5.1.0, it can be avoided.

Tested python version: 3.9.16

$ python --version
Python 3.9.16

OS info:

$ cat /etc/os-release 
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"
@kieran-ryan
Copy link

kieran-ryan commented Sep 2, 2023

Thanks for raising this detailed issue @yukihiko-shinoda. This appears to be a Duplicate of #244.

I have opened a PR to resolve the issue (#252); it would be great if you could take a look 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.

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.

2 participants