netromdk / vermin

Concurrently detect the minimum Python versions needed to run code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adding vermin to pyproject.toml?

Eutropios opened this issue · comments

It'd be nice to have the ability to add vermin to pyproject.toml as an alternative to a separate .cfg/.ini file. Having vermin exist within a separate cfg or ini file should still be an option for those who would like it, though.

Thanks for the suggestion. I will take it into consideration. Vermin must be vanilla Python so no external dependencies can be utilized. Thus this would require a custom TOML parser to be written for pyproject.toml files and a new Vermin config parser on top.

commented

Python 3.11 includes tomllib. Perhaps the feature itself could be for python3.11+ only and use the parser from the stdlib?

Yes, that is a possibility but it is against the general nature of the library. I will consider it, though.

Thank you for the consideration!

Unfortunately, the built-in tomllib is not very good.

Let's look at an example where strings are not quoted (even though they should be!), which I've seen to be most usages online:

>>> tomllib.loads("""
... [vermin]
... format = default
... """)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "python3.11/tomllib/_parser.py", line 102, in loads
    pos = key_value_rule(src, pos, out, header, parse_float)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "python3.11/tomllib/_parser.py", line 326, in key_value_rule
    pos, key, value = parse_key_value_pair(src, pos, parse_float)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "python3.11/tomllib/_parser.py", line 369, in parse_key_value_pair
    pos, value = parse_value(src, pos, parse_float)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "python3.11/tomllib/_parser.py", line 649, in parse_value
    raise suffixed_err(src, pos, "Invalid value")
tomllib.TOMLDecodeError: Invalid value (at line 3, column 10)

Whereas the following parses just fine:

>>> tomllib.loads("""
... [vermin]
... format = "default"
... """)
{'vermin': {'format': 'default'}}

This means that parsing the majority of projects' "pyproject.toml" would most likely fail, and some other TOML parser would be needed anyway.

Python 3.11 includes tomllib. Perhaps the feature itself could be for python3.11+ only and use the parser from the stdlib?

It can be difficult for a user to tell which Python version is currently being used as a runtime for a CLI tool.
Even if they always knew with certainty, it’s still just another moving part from the user’s point of view as they still would have to memorize the “Python 3.11 rule.”

If they didn’t, the config from pyproject.toml would sometimes be loaded and sometimes it wouldn’t.
So users could never really trust whether or not the config is active.

Exactly, @claui. Thanks.

I'm going to close this issue for now.