conda / grayskull

Grayskull :skull: - Recipe generator for Conda
https://conda.github.io/grayskull/
Apache License 2.0
320 stars 69 forks source link

[BUG] Failed to parse `tool.poetry.dependencies` with multiple constraints dependencies #535

Open t20100 opened 7 months ago

t20100 commented 7 months ago

Describe the bug

grayskull fails to parse poetry's multiple constraints dependencies syntax when run on the xypattern package with a grayskull.strategy.py_toml.InvalidPoetryDependency exception (see below).

This is the xypatterns's pyproject.toml [tool.poetry.dependencies] section.

To Reproduce

Expected behavior

Have grayskull supporting poetry's multiple constraints dependencies syntax.

Outputs

Raised exception ``` Checking for pyproject.toml pyproject.toml found in /tmp/grayskull-xypattern-r04377da/xypattern-1.1.2/pyproject.toml Traceback (most recent call last): File "py312/bin/grayskull", line 10, in sys.exit(main()) ^^^^^^ File "py312/lib/python3.12/site-packages/grayskull/main.py", line 277, in main generate_recipes_from_list(args.pypi_packages, args) File "py312/lib/python3.12/site-packages/grayskull/main.py", line 300, in generate_recipes_from_list recipe, config = create_python_recipe( ^^^^^^^^^^^^^^^^^^^^^ File "py312/lib/python3.12/site-packages/grayskull/main.py", line 335, in create_python_recipe GrayskullFactory.create_recipe( File "py312/lib/python3.12/site-packages/grayskull/base/factory.py", line 46, in create_recipe GrayskullFactory.REGISTERED_STRATEGY[repo_type.lower()].fetch_data( File "py312/lib/python3.12/site-packages/grayskull/strategy/pypi.py", line 62, in fetch_data update_recipe(recipe, config, sections or ALL_SECTIONS) File "lib/python3.12/site-packages/grayskull/strategy/pypi.py", line 499, in update_recipe metadata = get_metadata(recipe, config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "py312/lib/python3.12/site-packages/grayskull/strategy/pypi.py", line 350, in get_metadata sdist_metadata, pypi_metadata = get_origin_wise_metadata(config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "py312/lib/python3.12/site-packages/grayskull/strategy/pypi.py", line 235, in get_origin_wise_metadata sdist_metadata = get_sdist_metadata( ^^^^^^^^^^^^^^^^^^^ File "py312/lib/python3.12/site-packages/grayskull/strategy/py_base.py", line 772, in get_sdist_metadata pyproject_metadata = get_all_toml_info(pyproject_toml) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "py312/lib/python3.12/site-packages/grayskull/strategy/py_toml.py", line 294, in get_all_toml_info add_poetry_metadata(metadata, toml_metadata) File "py312/lib/python3.12/site-packages/grayskull/strategy/py_toml.py", line 200, in add_poetry_metadata req_run, req_run_constrained = encode_poetry_deps(poetry_deps) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "py312/lib/python3.12/site-packages/grayskull/strategy/py_toml.py", line 185, in encode_poetry_deps constrained_dep = get_constrained_dep(dep_spec, dep_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "py312/lib/python3.12/functools.py", line 909, in wrapper return dispatch(args[0].__class__)(*args, **kw) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "py312/lib/python3.12/site-packages/grayskull/strategy/py_toml.py", line 158, in get_constrained_dep raise InvalidPoetryDependency( grayskull.strategy.py_toml.InvalidPoetryDependency: Expected Poetry dependency specification to be of type str or dict, received list ```

Environment:

grayskull --version: 2.5.3

Additional context

As a quick workaround, I added

@get_constrained_dep.register
def __get_constrained_dep_list(dep_spec: list, dep_name: str):
    conda_version = encode_poetry_version(dep_spec[0].get("version", ""))
    return f"{dep_name} {conda_version}".strip()

to https://github.com/conda/grayskull/blob/a34b757801e0963aec0977187c3e8ebe2abd1aee/grayskull/strategy/py_toml.py#L164-L186 :

DhanshreeA commented 6 months ago

We're running into the same issue with ersilia.

DhanshreeA commented 6 months ago

Looks like this issue is still open here https://github.com/conda/grayskull/issues/463