-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Support for pyproject.toml #21
Comments
How does one declare supported Python versions in a pyproject.toml? (Trick question! pyproject.toml allows one to use any build backend, and that build backend can declare classifiers/python_requires any way it wants! I'll definitely want to support the more popular ones at least. E.g. the declarative version of setuptools where classifiers and requires_python are spelled out in a setup.cfg (#8). Ideally people will send me PRs.) On a side note, I've recently wanted to use check-python-versions on a Vim plugin that had a |
Any news on this ? This affects cookiecutter templates as well! |
No news yet. |
for poetry users, the pyproject.toml file contains [tool.poetry]
name = "..."
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Intended Audience :: Developers',
'Natural Language :: English',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
] ps Regards. |
So turns out there's a spec (PEP 621) that should be suitable for all project backends. The canonical spec location is https://packaging.python.org/en/latest/specifications/declaring-project-metadata/#declaring-project-metadata.
The PEP also links to flit/setuptools/poetry documentation. E.g. flit supports old-style metadata ( |
Having noticed some issues with the merged PR I'm now fixing them:
|
could you create the tests on a branch? I can try to fix it when I have some time.
could you create the tests on a branch? I can try to fix it when I have some time.
I didn't add it because new-style was introduced since flit 3.2 (two years ago), and actually there is flit 3.8 . if anyone still uses the old-style, an issue will be opened. |
I am a complete idiot ant the previous statement is incorrect. |
The first half of this statement is true, the second is false. While both |
I've created a test marked with check-python-versions/tests/sources/test_pyproject.py Lines 207 to 216 in 012cce2
I'd appreciate some assistance for making it pass. I fear that we either need to implement a parser for the Poetry dependency specification format, or find a library we can import and reuse. The new code should live in parsers/poetry_version_spec.py (unless there's a better known name for this format? I think NPM uses it too). It should roughly mirror the API that parsers/requires_python.py exposes. If I have that, I can finish hooking it up inside sources/pyproject.py myself. |
Hmm, the PEP-440 format is a strict subset of the Poetry format, isn't it? So as long as nobody uses caret or tilde requirements, the existing code should continue to work. Maybe it doesn't make sense to maintain two separate parsers when 90% of the code is going to be duplicated. Let me think about this a bit. |
Or maybe not. I don't see |
it's not correct, on line 214 it should be caret version Seems does not exist any library that parses poetry-like dependencies. Start a branch with some tests added to verify poetry version constraints, I'll try to work there. |
I made some awful implementation that interprets tilde and caret, returning the same string expected as described on poetry's version constraint: def last_zero_idx(lst: list) -> int:
idx = 0
for _i in range(0, len(lst)):
if lst[_i] == '0':
idx = _i
return idx
def all_zero_list(lst: list) -> bool:
ret = True
for l in lst:
if l and l != '0':
ret = False
return ret
if __name__ == '__main__':
import re
_r = re.compile(r'([~^])(\d)(.(\d)){0,1}(.(\d)){0,1}')
_str = ['d', '^0', '^0.0', '^0.0.0', '^0.2.3', '^0.0.3', '^1', '^1.2', '^1.2.3', '~1', '~1.2', '~1.2.3']
for _s in _str:
_v = re.findall(_r, _s)
if _v:
_symbol = _v[0][0]
_groups = _v[0]
_filtered = list(map(lambda x: '0' if not x else x, _groups))
print("------------\n" + _s)
if _symbol == '^':
_min_ver = '>=' + '.'.join(_filtered[1::2])
_numbers = _groups[1::2]
try:
_numbers.index('0')
except ValueError as ve:
# 0 not in string
_mapped = list(map(lambda x: '0' if not x else x, _numbers))
_first_zero = 1
_mapped = _mapped[0:1] + ['0' for x in _mapped[1:]]
_mapped[_first_zero - 1] = str(int(_mapped[_first_zero - 1]) + 1)
else:
_l = len(list(filter(lambda x: x, _numbers)))
_zero_list = all_zero_list(_numbers)
_last_zero_idx = last_zero_idx(_numbers)
_mapped = list(map(lambda x: '0' if not x else x, _numbers))
if _zero_list:
_mapped[_last_zero_idx] = '1'
else:
_mapped[_last_zero_idx + 1] = str(int(_mapped[_last_zero_idx + 1]) + 1)
for _i in range(_last_zero_idx + 2, len(_mapped)):
_mapped[_i] = '0'
_max_ver = '<' + '.'.join(_mapped)
print(f"{_min_ver} {_max_ver}")
if _symbol == '~':
_min_ver = '>=' + '.'.join(_filtered[1::2])
_numbers = _groups[1::2]
_mapped = list(map(lambda x: '0' if not x else x, _numbers))
try:
_numbers.index('0')
except ValueError as ve:
# 0 not in string
try:
_first_zero = _mapped.index('0')
except ValueError:
_first_zero = len(_mapped) -1
_mapped[_first_zero - 1] = str(int(_mapped[_first_zero - 1]) + 1)
_mapped[_first_zero] = '0'
_max_ver = '<' + '.'.join(_mapped)
print(f"{_min_ver} {_max_ver}") I don't know if this can be integrated (probably the _min_ver or _max_ver can be parsed with Version) or how can be used, but here it is 😉 |
The test uses |
One thing I'm not sure about Poetry version specs is if plain versions are allowed, e.g. [tool.poetry.dependencies]
python = "3.7.10"
# or
python = "3.7"
# or
python = "3" and if so, will they be treated the same as specifying |
I got nerd-sniped into implementing this. Please test and report bugs! I myself tested it on https://github.com/jedie/python-creole, and there are some things I'm not entirely happy with, e.g.
drops the comment from the classifier list and drops the |
P.S.: This is just the information, that currently
check-python-versions
does not support projects which only use a pyproject.toml and no setup.py, which maybe a future trend.At the current time, personally, I do not need this support and I still think using the common
setup.py
approach is superior.The text was updated successfully, but these errors were encountered: