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

allow "uv run" to work without a project #8666

Open
mmerickel opened this issue Oct 29, 2024 · 20 comments
Open

allow "uv run" to work without a project #8666

mmerickel opened this issue Oct 29, 2024 · 20 comments
Assignees
Labels
needs-decision Undecided if this should be done question Asking for clarification or support

Comments

@mmerickel
Copy link

It'd be nice if this flow worked simply to avoid needing to activate a virtualenv - regardless of whether I'm using a full uv project or not.

$ uv venv
$ uv pip install -e .
$ uv run python

However as of 0.4.28 I get the following error:

$ uv run python
error: No `project` table found in: `/Users/michael/work/oss/webob/pyproject.toml`

Obviously in this case I'm not asking uv to do anything except use the correct path as if I was activating the virtualenv - equivalent to .venv/bin/activate; python.

@zanieb
Copy link
Member

zanieb commented Oct 29, 2024

uv run --no-project should work there

@zanieb zanieb added the question Asking for clarification or support label Oct 29, 2024
@mmerickel
Copy link
Author

Yeah thanks for pointing that out and I confirmed it works. Having to add an extra arg there on every command is a deal breaker right - uv run is the primary command I’m using all the time during dev. I’d instead activate the env or use .venv/bin/python … (my current flow). I guess this issue becomes a feature request to drop the flag and make it the default fallback behavior when no project can be found.

@zanieb
Copy link
Member

zanieb commented Oct 29, 2024

What are you using the pyproject.toml for? Just want to understand the use-case more.

@mmerickel
Copy link
Author

Things like build-system, black config, isort config, and tool.ruff config.

@zanieb
Copy link
Member

zanieb commented Oct 29, 2024

What build system are you using without a [project] table 👀

@mmerickel
Copy link
Author

setuptools doesn’t require it - it can pull all the data from setup.py and setup.cfg like it has for decades. :-) I guess I should switch it up to use project but it’s not required by the build backend PEP.

@mmerickel
Copy link
Author

mmerickel commented Oct 29, 2024

To be clear I know it’s required to use uv sync and uv lock + lock files but that’s not my short term goal.

@zanieb zanieb added the needs-decision Undecided if this should be done label Oct 29, 2024
@samypr100
Copy link
Collaborator

Having to add an extra arg there on every command is a deal breaker right - uv run is the primary command I’m using all the time during dev

Maybe as an alternative workaround, setup an shell alias for uv run to be uv run --no-project?

@mmerickel
Copy link
Author

mmerickel commented Nov 1, 2024

Yeah I can work around it, but this ticket is here incase y'all want a cleaner story for the larger community for "older" projects.

In pyramid we have for years recommended for people to do the following as a simple starter sequence:

python3 -m venv env
env/bin/pip install -e .
env/bin/pshell site.ini

And I thought it'd be cool to at least have a "drop in replacement" story for uv where we'd recommend the following:

uv venv
uv pip install -e .
uv run pshell site.ini

As of today we need to add --no-project to every uv run command and that's no fun. :-) Personally I think the error that is raised about "no project table" is not worth requiring an explicit flag to get past compared to the logical fallback to just run the command in the virtualenv even if there's no project.

Also mainly for my sanity and to clarify for anyone else I went back to just check and this issue occurs whether or not you have a pyproject.toml. It's just complaining about the missing [project] section therein.

@zanieb
Copy link
Member

zanieb commented Nov 1, 2024

Fwiw I think this should probably work but doesn't

❯ cat pyproject.toml
[tool.uv]
managed = false

❯ uv run python
error: No `project` table found in: `/Users/zb/workspace/uv/example/pyproject.toml`

@mattp-
Copy link

mattp- commented Nov 5, 2024

👍 on this, I use uv primarily as a manager to venv's per project, but im not necessarily making changes to the projects im dropping into that would allow me to modify pyproject.toml. Being able to set an env var that silences no-project, but still works when a project dir i go to actually DOES have project settings, would be ideal.

@matterhorn103
Copy link

If a directory contains nothing but a script, with no pyproject.toml or .venv in sight, uv run script.py works.

If there's a .venv but no pyproject.toml, it also works.

Is that the intended behaviour? If so it seems strange to require a [project] table when pyproject.toml is present, but not otherwise.

@zanieb
Copy link
Member

zanieb commented Nov 7, 2024

The presence of a pyproject.toml is what we use to determine if you're working... in a project :) I think it does make some sense, though I can understand why you would want it to work differently. I'll be exploring some approaches to resolve this.

@zanieb zanieb self-assigned this Nov 7, 2024
@trim21
Copy link

trim21 commented Nov 21, 2024

What build system are you using without a [project] table 👀

I have a example for this, a python backend web server doesn't need any build-system.

When deploying I just need to copy everything to docker and install deps from requirements.txt, no [project] involved.

Maybe we can add a option or env to make --no-project enabled by default.

For example, UV_RUN_NO_PROJECT=1 uv run ... ( even uv doesn't load dotenv for itself direnv can still work in this case ) or tool.uv.no-project = true in config file

@trim21
Copy link

trim21 commented Nov 28, 2024

I just find that we have a option tool.uv.package, maybe we can use this option when tool.uv.package = false?

Setting `tool.uv.package = false` will force a project package _not_ to be built and installed into
the project environment. uv will ignore a declared build system when interacting with the project.

@Avasam
Copy link

Avasam commented Dec 26, 2024

For real world examples, I've been hitting this in typeshed. Not sure if I wanna try adding a dummy project config.

@stefanv
Copy link

stefanv commented Jan 17, 2025

In trying to use uv to prepare environments for a web application (no compilation or package involved), I noticed that uv run gives:

error: No `project` table found in: `<somepath>/pyproject.toml`

OK, so we add the project section to pyproject.toml. Now we get:

$ uv run make
  × Failed to build `skyportal @ file:///<path-to-project>`
  ├─▶ The build backend returned an error
  ╰─▶ Call to `setuptools.build_meta:__legacy__.build_wheel` failed (exit status: 1)

      [stderr]
      error: Multiple top-level packages discovered in a flat-layout: ...

OK, so it seems I have to run uv run --no-project. Which, presumably should have been the case originally when the project section was missing. Having a way to configure this behavior, without a manual flag on each invocation, would be very helpful.

(EDIT: To pre-empt the question of "why do you have a pyproject.toml" in the first place: it's where we configure project linting.)

@T-256
Copy link
Contributor

T-256 commented Jan 23, 2025

Also related to #10204 and #10208

@helderco
Copy link

helderco commented Jan 31, 2025

Here's an example I ran into today: https://github.com/swe-bench/SWE-bench

It has a pyproject.toml but with only the following:

[build-system]
requires = ['setuptools>=42']
build-backend = 'setuptools.build_meta'

Notice the above doesn't include a [project] section, but you can install it with pip install -e .. There's a setup.py where the dependencies are declared.

My team member is having issues with his environment, so I wish I could tell him to just slap uv run in front:

❯ uv run -m swebench.harness.run_evaluation \
    --predictions_path gold \
    --max_workers 1 \
    --instance_ids sympy__sympy-20590 \
    --run_id validate-gold
error: No `project` table found in: `/.../SWE-bench/pyproject.toml`

Don't want to instruct on changing that open source project's pyproject.toml to accomodate, and wish I wouldn't have to recommend going through the uv pip route.

@charliermarsh
Copy link
Member

👍 We do currently plan to support this -- hopefully soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-decision Undecided if this should be done question Asking for clarification or support
Projects
None yet
Development

No branches or pull requests