Skip to content
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

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

Closed
t20100 opened this issue Apr 15, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@t20100
Copy link

t20100 commented Apr 15, 2024

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

  • Run grayskull pypi xypattern

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 <module>
    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

@get_constrained_dep.register
def __get_constrained_dep_dict(dep_spec: dict, dep_name: str):
conda_version = encode_poetry_version(dep_spec.get("version", ""))
return f"{dep_name} {conda_version}".strip()
@get_constrained_dep.register
def __get_constrained_dep_str(dep_spec: str, dep_name: str):
conda_version = encode_poetry_version(dep_spec)
return f"{dep_name} {conda_version}"
def encode_poetry_deps(poetry_deps: dict) -> Tuple[list, list]:
run = []
run_constrained = []
for dep_name, dep_spec in poetry_deps.items():
constrained_dep = get_constrained_dep(dep_spec, dep_name)
try:
assert dep_spec.get("optional", False)
run_constrained.append(constrained_dep)
except (AttributeError, AssertionError):
run.append(constrained_dep)
return run, run_constrained
:

@t20100 t20100 added the bug Something isn't working label Apr 15, 2024
@DhanshreeA
Copy link

We're running into the same issue with ersilia.

@DhanshreeA
Copy link

Looks like this issue is still open here #463

@thewchan
Copy link

@marcelotrevisani
Copy link
Member

It should be fixed by
#592

and it is in the release
https://github.com/conda/grayskull/releases/tag/v2.7.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants