-
-
Notifications
You must be signed in to change notification settings - Fork 81
Description
Describe the bug
grayskull fails on nannyml=0.12.1 for a dependency that uses caret ^ and a non semver standard version ^0.8.post1.
pyfiglet = "^0.8.post1"
grayskull crashes when trying to coerce it to semver while computing the floor for the lower bound during the rendering of ^0.8.post1 to >=0.8.post1,<0.9.0.
grayskull/grayskull/strategy/parse_poetry_version.py
Lines 217 to 224 in 77ed4b3
| if poetry_clause.startswith("^"): | |
| # handle ^ operator | |
| target = poetry_clause[1:] | |
| floor = coerce_to_semver(target) | |
| ceiling = get_caret_ceiling(target) | |
| conda_clauses.append(">=" + floor) | |
| conda_clauses.append("<" + ceiling) | |
| continue |
Precisely here:
| floor = coerce_to_semver(target) |
This happens because 0.8.post1 is PEP 440 standard and not semver.
From the documentation of Poetry about the tilda operator, it is not clear whether the version used in a caret/tilde operator should or could be following the semver standard, but in a more general paragraph:
Poetry requires PEP 440-compliant versions for all projects.
While Poetry does not enforce any release convention, it used to encourage the use of semantic versioning within the scope of PEP 440 and supports version constraints that are especially suitable for semver.
It's the other way around: one could use a subset of semver that is in line with PEP 440 but a version must be coerced to PEP 440.
According to PEP 440 0.8.post1 (0.8.0.post1) is a valid post-release (stable) version, more recent than 0.8.0.
It should be accepted and rendered with >=0.8.0.post1,<0.9.0.
To Reproduce
Steps to reproduce the behavior:
- Run
grayskull pypi "nannyml=0.12.1" - See error
Expected behavior
Can create a recipe from pyproject.toml. The version ^0.8.post1 is rendered to >=0.8.post1,<0.9.0, or ^0.8.post1 to >=0.8.0.post1,<0.9.0 (or ^0.8.post1 to >=0.8.0.post1,<0.9.0).
Outputs
Traceback
Checking for pyproject.toml
pyproject.toml found in /var/folders/jy/vvgmwwxx4sn5zpfmg9qmsqyc0000gp/T/grayskull-nannyml-cy3nbcry/nannyml-0.12.1/pyproject.toml
Traceback (most recent call last):
File "/Users/lorepirri/miniconda3/envs/sow_refinement/bin/grayskull", line 10, in <module>
sys.exit(main())
File "/Users/lorepirri/miniconda3/envs/sow_refinement/lib/python3.10/site-packages/grayskull/main.py", line 312, in main
generate_recipes_from_list(args.pypi_packages, args)
File "/Users/lorepirri/miniconda3/envs/sow_refinement/lib/python3.10/site-packages/grayskull/main.py", line 363, in generate_recipes_from_list
recipe, config = create_python_recipe(
File "/Users/lorepirri/miniconda3/envs/sow_refinement/lib/python3.10/site-packages/grayskull/main.py", line 399, in create_python_recipe
GrayskullFactory.create_recipe(
File "/Users/lorepirri/miniconda3/envs/sow_refinement/lib/python3.10/site-packages/grayskull/base/factory.py", line 48, in create_recipe
GrayskullFactory.REGISTERED_STRATEGY[repo_type.lower()].fetch_data(
File "/Users/lorepirri/miniconda3/envs/sow_refinement/lib/python3.10/site-packages/grayskull/strategy/pypi.py", line 64, in fetch_data
update_recipe(recipe, config, sections or ALL_SECTIONS)
File "/Users/lorepirri/miniconda3/envs/sow_refinement/lib/python3.10/site-packages/grayskull/strategy/pypi.py", line 507, in update_recipe
metadata = get_metadata(recipe, config)
File "/Users/lorepirri/miniconda3/envs/sow_refinement/lib/python3.10/site-packages/grayskull/strategy/pypi.py", line 352, in get_metadata
sdist_metadata, pypi_metadata = get_origin_wise_metadata(config)
File "/Users/lorepirri/miniconda3/envs/sow_refinement/lib/python3.10/site-packages/grayskull/strategy/pypi.py", line 238, in get_origin_wise_metadata
sdist_metadata = get_sdist_metadata(
File "/Users/lorepirri/miniconda3/envs/sow_refinement/lib/python3.10/site-packages/grayskull/strategy/py_base.py", line 783, in get_sdist_metadata
pyproject_metadata = get_all_toml_info(pyproject_toml)
File "/Users/lorepirri/miniconda3/envs/sow_refinement/lib/python3.10/site-packages/grayskull/strategy/py_toml.py", line 260, in get_all_toml_info
add_poetry_metadata(metadata, toml_metadata)
File "/Users/lorepirri/miniconda3/envs/sow_refinement/lib/python3.10/site-packages/grayskull/strategy/py_toml.py", line 67, in add_poetry_metadata
req_run, req_run_constrained = encode_poetry_deps(poetry_deps)
File "/Users/lorepirri/miniconda3/envs/sow_refinement/lib/python3.10/site-packages/grayskull/strategy/py_toml.py", line 52, in encode_poetry_deps
for constrained_dep in get_constrained_dep(dep_spec, dep_name):
File "/Users/lorepirri/miniconda3/envs/sow_refinement/lib/python3.10/site-packages/grayskull/strategy/py_toml.py", line 36, in __get_constrained_dep_str
conda_version = encode_poetry_version(dep_spec)
File "/Users/lorepirri/miniconda3/envs/sow_refinement/lib/python3.10/site-packages/grayskull/strategy/parse_poetry_version.py", line 206, in encode_poetry_version
floor = coerce_to_semver(target)
File "/Users/lorepirri/miniconda3/envs/sow_refinement/lib/python3.10/site-packages/grayskull/strategy/parse_poetry_version.py", line 64, in coerce_to_semver
parsed_version = parse_version(version)
File "/Users/lorepirri/miniconda3/envs/sow_refinement/lib/python3.10/site-packages/grayskull/strategy/parse_poetry_version.py", line 40, in parse_version
raise InvalidVersion(f"Could not parse version {version}.")
grayskull.strategy.parse_poetry_version.InvalidVersion: Could not parse version 0.8.post1.
Environment:
grayskull --version:2.7.3