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

uv does not recognize dependencies declared in script #6700

Closed
bongomachine opened this issue Aug 27, 2024 · 9 comments · Fixed by #6706
Closed

uv does not recognize dependencies declared in script #6700

bongomachine opened this issue Aug 27, 2024 · 9 comments · Fixed by #6706
Assignees
Labels
bug Something isn't working

Comments

@bongomachine
Copy link

Howdy and thanks for a great piece of software! I'm not sure if this is a bug or if I'm simply doing things wrong. Anyway..

When I run the following piece of python:

# /// script
# requires-python = ">=3.12"
# dependencies = [
#     "cyclonedds ==0.11.0",
# ]

# [tool.uv]
# index-strategy = "unsafe-best-match"

# [tool.uv.sources]
# cyclonedds = { git = "https://github.com/eclipse-cyclonedds/cyclonedds-python.git", rev = "080dfd4b26e4c4dc2529694ef9cf9589750360c1" }

# ///


import cyclonedds as dds

print("Hello, World!")

With command: CYCLONEDDS_HOME=~/.local uv -v run test.py

I get the following error:

DEBUG uv 0.3.4
DEBUG No project found; searching for Python interpreter
DEBUG Searching for Python interpreter in managed installations or system path
DEBUG Searching for managed installations at `~/.local/share/uv/python`
DEBUG Found `cpython-3.12.3-linux-x86_64-gnu` at `/usr/bin/python3` (search path)
DEBUG Using Python 3.12.3 interpreter at: /usr/bin/python3
DEBUG Running `python test.py`
Traceback (most recent call last):
  File "~/tmp/test.py", line 15, in <module>
    import cyclonedds as dds
ModuleNotFoundError: No module named 'cyclonedds'

However, if I run the following: uv venv && CYCLONEDDS_HOME=~/.local uv pip install git+https://github.com/eclipse-cyclonedds/cyclonedds-pytho n@080dfd4b26e4c4dc2529694ef9cf9589750360c1 && uv run test.py, everything works.

As stated earlier, this might be the intended behavior, but I'm not sure.

  • The current uv platform.
    Linux (x86_64) Ubuntu 24.04

  • The current uv version (uv --version).
    uv 0.3.4

@charliermarsh
Copy link
Member

I agree that this should work, at least from the above description.

@zanieb
Copy link
Member

zanieb commented Aug 27, 2024

I presume the problem here is that we're not respecting [tool.uv.sources]? Or are we not installing cyclonedds at all? Kind of looks like the latter...

@charliermarsh
Copy link
Member

charliermarsh commented Aug 27, 2024

The problem is the break in the script -- try this:

# /// script
# requires-python = ">=3.12"
# dependencies = [
#     "cyclonedds ==0.11.0",
# ]
#
# [tool.uv]
# index-strategy = "unsafe-best-match"
#
# [tool.uv.sources]
# cyclonedds = { git = "https://github.com/eclipse-cyclonedds/cyclonedds-python.git", rev = "080dfd4b26e4c4dc2529694ef9cf9589750360c1" }
#
# ///


import cyclonedds as dds

print("Hello, World!")

@charliermarsh
Copy link
Member

I need to review the spec to see what the correct behavior is.

@zanieb
Copy link
Member

zanieb commented Aug 27, 2024

Ah gotcha... I wonder if we can / should warn here? We could document it, at least.

@charliermarsh
Copy link
Member

Okay, it is correct to reject that per the spec:

Every line between these two lines (# /// TYPE and # ///) MUST be a comment starting with #. If there are characters after the # then the first character MUST be a space.

But I think we should warn if we see # /// script but don't identify a script?

@bongomachine
Copy link
Author

The problem is the break in the script -- try this:

# /// script
# requires-python = ">=3.12"
# dependencies = [
#     "cyclonedds ==0.11.0",
# ]
#
# [tool.uv]
# index-strategy = "unsafe-best-match"
#
# [tool.uv.sources]
# cyclonedds = { git = "https://github.com/eclipse-cyclonedds/cyclonedds-python.git", rev = "080dfd4b26e4c4dc2529694ef9cf9589750360c1" }
#
# ///


import cyclonedds as dds

print("Hello, World!")

That worked! Thanks!

FYI: The break was introduced when I first ran the following command: CYCLONEDDS_HOME=~/.local uv add --script test.py git+https://github.com/eclipse-cyclonedds/cyclonedds-python.git --rev 080dfd4b26e4c4dc2529694ef9cf9589750360c1. (And then I added index-strategy and explicit version while debugging).

@charliermarsh
Copy link
Member

Ohh nice, now that is a bug!

@charliermarsh charliermarsh self-assigned this Aug 27, 2024
@charliermarsh charliermarsh added the bug Something isn't working label Aug 27, 2024
charliermarsh added a commit that referenced this issue Aug 27, 2024
Should this be user-facing by default? It seems annoying because then
it's unavoidable if you (for whatever reason) have an intentionally
unclosed tag.

Motivated by #6700.
charliermarsh added a commit that referenced this issue Aug 27, 2024
## Summary

We were writing empty lines between the dependencies and the
`tool.uv.sources` table, which led to the `/// script` tag being
unclosed and thus not recognized.

Closes #6700.
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

Successfully merging a pull request may close this issue.

4 participants
@charliermarsh @zanieb @bongomachine and others