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

CLI apps based on click-app won't work with "uv run" if name doesn't contain hyphens #97

Open
wolfmanstout opened this issue Nov 25, 2024 · 0 comments

Comments

@wolfmanstout
Copy link

wolfmanstout commented Nov 25, 2024

This isn't a bug per se, but it may be surprising and worth addressing soon to avoid inconsistency down the line.

Looking at:
https://github.com/simonw/til/blob/main/python/uv-cli-apps.md

If you follow this with "demo" instead of "demo-app" (or any other name without hyphens), then uv run demo will produce this error:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\james\projects\demo\demo\__main__.py", line 1, in <module>
    from .cli import cli
ImportError: attempted relative import with no known parent package

... assuming it is run at the top-level of the repo. The problem is that there's a demo subdirectory and uv resolves the ambiguity by attempting to run that subdirectory as a module from the parent directory, instead of running the demo executable. The preferred directory structure for uv (based on uv init --app --package) is to nest the demo package under an src directory. That fixes the issue.

If it's helpful, check out my fork of click-app which both fixes this issue and uses uv throughout the repo (e.g. for GitHub actions, based on uv's own docs), adhering more closely to uv init conventions in pyproject.toml (e.g. hatchling as a build backend).

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

1 participant