klen / pylama

Code audit tool for python.
MIT License
1.05k stars 99 forks source link

Read configuration from pyproject.toml #171

Open thejcannon opened 4 years ago

thejcannon commented 4 years ago

Configuring your tool in pyproject.toml is all the new rage. Several tools have already added support, and other tools are talking about it.

Feel free to steal ideas from those projects/discussions (such as only considering it as a valid config if the toml package is installed, which is what isort does).

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/88055292-read-configuration-from-pyproject-toml?utm_campaign=plugin&utm_content=tracker%2F394650&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F394650&utm_medium=issues&utm_source=github).
Jaakkonen commented 3 years ago

The link to https://github.com/carlosperate/awesome-pyproject is invalid, you're missing a 't' in the end. This feature would be really good to have and overall leading python ecosystem to a state where one could just have one file configuring dependencies, executables, linter line lengths and tests. Currently there's direct support from PyLint and wrapper support for Flake8 via Flake9 and FlakeHell. I think this feature without any more wrapper layers would enable better adoption for new projects whose developers have a idea that they want to try the pyproject.toml and make their compromises in libraries which don't support it.

nico-unity commented 2 years ago

Any progress on providing support for pyproject.toml configuration similarly to pytest. Example here ? :)

gmolveau commented 2 years ago

Hi, any updates on this ? :) Thank's !

KevinMGranger commented 2 years ago

It looks like this was added in 8.4.0. Woo hoo!

alorence commented 1 year ago

Did somebody succeed to configure pylama with pyproject.toml file ? I get the following error with 8.4.1, which is 4 months old now. The issue seems to be a pure ProgrammingError (I didn't check in sources)

$ pylama -o pyproject.toml .                                                                                                                                           130 ↵
Traceback (most recent call last):
  File "/home/alorence/.local/bin/pylama", line 8, in <module>
    sys.exit(shell())
  File "/home/alorence/.local/pipx/venvs/pylama/lib/python3.10/site-packages/pylama/main.py", line 100, in shell
    options = parse_options(args)
  File "/home/alorence/.local/pipx/venvs/pylama/lib/python3.10/site-packages/pylama/config.py", line 203, in parse_options
    cfg = get_config(options.options, rootdir=rootdir)
  File "/home/alorence/.local/pipx/venvs/pylama/lib/python3.10/site-packages/pylama/config.py", line 272, in get_config
    return get_config_toml(cfg_path)
  File "/home/alorence/.local/pipx/venvs/pylama/lib/python3.10/site-packages/pylama/config.py", line 290, in get_config_toml
    config = config_toml.Namespace()
NameError: name 'config_toml' is not defined. Did you mean: 'get_config_toml'?

My pyproject.toml:

[tool.pylama]
max_line_length = 120
skip = "*/.pytest_cache/*, */.tox/*, */mypy_cache/*, ./dist, ./docs"

[tool.pylama.linter.mccabe]
max-complexity = 10
vinibiavatti1 commented 1 year ago

@alorence same issue here

It happens because there is some validation at config.py file that tries to import the config_toml module. For some reason, in our environments, the module could not be imported.

config.py

try:
    from pylama import config_toml
    CONFIG_FILES = ["pylama.ini", "pyproject.toml", "setup.cfg", "tox.ini", "pytest.ini"]
except ImportError:
    CONFIG_FILES = ["pylama.ini", "setup.cfg", "tox.ini", "pytest.ini"]
vinibiavatti1 commented 1 year ago

I noticed that the library "toml" is optional, and should be added by perfoming the following command:

pip install pylama[toml]