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

Poetry pyproject.toml wheel dependencies fails to generate #34

Open
mvgijssel opened this issue Mar 16, 2023 · 2 comments
Open

Poetry pyproject.toml wheel dependencies fails to generate #34

mvgijssel opened this issue Mar 16, 2023 · 2 comments

Comments

@mvgijssel
Copy link

Having the following pyproject.toml file

[tool.poetry]
name = "example"
version = "0.1.0"
description = ""
readme = "README.md"
authors = []

[tool.poetry.dependencies]
python = "3.9.10"
torch = [
  {markers = "platform_machine == 'aarch64'", url = "https://download.pytorch.org/whl/torch-1.12.1-cp39-cp39-manylinux2014_aarch64.whl" },
  {markers = "platform_machine == 'x86_64'", url = "https://download.pytorch.org/whl/cpu/torch-1.12.1%2Bcpu-cp39-cp39-linux_x86_64.whl" },
]

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

and the following poetry.lock file

# This file is automatically @generated by Poetry 1.4.0 and should not be changed by hand.

[[package]]
name = "torch"
version = "1.12.1"
description = "Tensors and Dynamic neural networks in Python with strong GPU acceleration"
category = "main"
optional = false
python-versions = ">=3.7.0"
files = [
    {file = "torch-1.12.1-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:6cf6f54b43c0c30335428195589bd00e764a6d27f3b9ba637aaa8c11aaf93073"},
]

[package.dependencies]
typing-extensions = "*"

[package.source]
type = "url"
url = "https://download.pytorch.org/whl/torch-1.12.1-cp39-cp39-manylinux2014_aarch64.whl"

[[package]]
name = "torch"
version = "1.12.1+cpu"
description = "Tensors and Dynamic neural networks in Python with strong GPU acceleration"
category = "main"
optional = false
python-versions = ">=3.7.0"
files = [
    {file = "torch-1.12.1%2Bcpu-cp39-cp39-linux_x86_64.whl", hash = "sha256:870bc47b880fb0488ea5b665bf76fc8df76a55a5cd48917501bf4597e1af6b2e"},
]

[package.dependencies]
typing-extensions = "*"

[package.source]
type = "url"
url = "https://download.pytorch.org/whl/cpu/torch-1.12.1%2Bcpu-cp39-cp39-linux_x86_64.whl"
[[package]]
name = "typing-extensions"
version = "4.5.0"
description = "Backported and Experimental Type Hints for Python 3.7+"
category = "main"
optional = false
python-versions = ">=3.7"
files = [
    {file = "typing_extensions-4.5.0-py3-none-any.whl", hash = "sha256:fb33085c39dd998ac16d1431ebc293a8b3eedd00fd4a32de0ff79002c19511b4"},
    {file = "typing_extensions-4.5.0.tar.gz", hash = "sha256:5cb5f4a79139d699607b3ef622a1dedafa84e115ab0024e0d9c044a9479ca7cb"},
]

[metadata]
lock-version = "2.0"
python-versions = "3.9.10"
content-hash = "b7d2a1b2bf6dddd0bb2fa76dc0a38338509d62e901e7daec4839b316a015fe69"

with the following BUILD.bazel file

load(
    "@jvolkman_rules_pycross//pycross:defs.bzl",
    "pycross_lock_file",
    "pycross_poetry_lock_model",
    "pycross_target_environment",
)

_linux_x86_64 = [
    "@platforms//os:linux",
    "@platforms//cpu:x86_64",
]

pycross_target_environment(
    name = "python_linux_x86_64",
    abis = ["cp39"],
    platforms = [
        "linux_x86_64",
        "manylinux2014_x86_64",
    ] + [
        "manylinux_2_%s_x86_64" % str(i)
        for i in range(17, 25)
    ],
    python_compatible_with = _linux_x86_64,
    version = "3.9.10",
    visibility = ["//visibility:public"],
)

pycross_poetry_lock_model(
    name = "predict_lock_model",
    poetry_lock_file = "poetry.lock",
    poetry_project_file = "pyproject.toml",
)

pycross_lock_file(
    name = "predict_lock",
    out = "predict_lock.bzl",
    lock_model_file = ":predict_lock_model",
    target_environments = [
        ":python_linux_x86_64",
    ],
)

and running

bazel build //predict:predict_lock

results in the following error

INFO: Invocation ID: efb054fe-51cd-4e9f-a8ff-a1a6a3681f81
INFO: Analyzed target //predict:predict_lock (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /workspaces/data-platform/predict/BUILD.bazel:34:26: Action predict/predict_lock_model.json failed: (Exit 1): poetry_translator failed: error executing command (from target //predict:predict_lock_model) bazel-out/aarch64-opt-exec-2B5CBBC6/bin/external/jvolkman_rules_pycross/pycross/private/tools/poetry_translator --poetry-project-file predict/pyproject.toml --poetry-lock-file predict/poetry.lock ... (remaining 2 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
Traceback (most recent call last):
  File "/home/devcontainer/bazel/output_base/sandbox/processwrapper-sandbox/9/execroot/data_platform/bazel-out/aarch64-opt-exec-2B5CBBC6/bin/external/jvolkman_rules_pycross/pycross/private/tools/poetry_translator.runfiles/jvolkman_rules_pycross/pycross/private/tools/poetry_translator.py", line 298, in <module>
    app.run(main, flags_parser=parse_flags)
  File "/home/devcontainer/bazel/output_base/sandbox/processwrapper-sandbox/9/execroot/data_platform/bazel-out/aarch64-opt-exec-2B5CBBC6/bin/external/jvolkman_rules_pycross/pycross/private/tools/poetry_translator.runfiles/rules_pycross_pypi_deps_absl_py/site-packages/absl/app.py", line 308, in run
    _run_main(main, args)
  File "/home/devcontainer/bazel/output_base/sandbox/processwrapper-sandbox/9/execroot/data_platform/bazel-out/aarch64-opt-exec-2B5CBBC6/bin/external/jvolkman_rules_pycross/pycross/private/tools/poetry_translator.runfiles/rules_pycross_pypi_deps_absl_py/site-packages/absl/app.py", line 254, in _run_main
    sys.exit(main(argv))
  File "/home/devcontainer/bazel/output_base/sandbox/processwrapper-sandbox/9/execroot/data_platform/bazel-out/aarch64-opt-exec-2B5CBBC6/bin/external/jvolkman_rules_pycross/pycross/private/tools/poetry_translator.runfiles/jvolkman_rules_pycross/pycross/private/tools/poetry_translator.py", line 258, in main
    lock_set = translate(args.poetry_project_file, args.poetry_lock_file)
  File "/home/devcontainer/bazel/output_base/sandbox/processwrapper-sandbox/9/execroot/data_platform/bazel-out/aarch64-opt-exec-2B5CBBC6/bin/external/jvolkman_rules_pycross/pycross/private/tools/poetry_translator.runfiles/jvolkman_rules_pycross/pycross/private/tools/poetry_translator.py", line 133, in translate
    pinned_package_specs[pin] = parse_constraint(pin_info["version"])
TypeError: list indices must be integers or slices, not str
Target //predict:predict_lock failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.288s, Critical Path: 0.16s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully

Reading the error message and reading the code it looks like the poetry_translator.py doesn't like two things:

  1. Currently it's being passed a list instead of a string / dict
  2. If it's passed a dict it requires the dict to contain the version key
@jvolkman
Copy link
Owner

Thanks. I haven't tried to reproduce the issue, but just looking at the error and what you've provided I'm guessing that I don't handle this syntax:

torch = [
  {markers = "platform_machine == 'aarch64'", url = "https://download.pytorch.org/whl/torch-1.12.1-cp39-cp39-manylinux2014_aarch64.whl" },
  {markers = "platform_machine == 'x86_64'", url = "https://download.pytorch.org/whl/cpu/torch-1.12.1%2Bcpu-cp39-cp39-linux_x86_64.whl" },
]

The translation step assumes the simpler format, e.g. torch = "=1.2.1". I'll have to take a closer look to see if this more complex form can be supported.

@wingsofovnia
Copy link
Contributor

wingsofovnia commented May 27, 2024

I am having the same issue with a dependency defined as:

tensorflow = [
    {version = "2.16.1", platform="linux", extras=["and-cuda"]},
    {version = "2.16.1", platform="darwin"},
]

which is to my knowledge the only way to define tensorflow dependency expected to work in both environments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants