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

Improve errors / diagnostics when package is missing __init__.py #8212

Closed
drmason13 opened this issue Oct 15, 2024 · 2 comments
Closed

Improve errors / diagnostics when package is missing __init__.py #8212

drmason13 opened this issue Oct 15, 2024 · 2 comments
Labels
question Asking for clarification or support

Comments

@drmason13
Copy link

uv 0.4.18
Running uv build --package my-project in a project (within a workspace, though I suspect a more minimal repro is possible) where the workspace member package is laid out in a typical style:

pyproject.toml
src/
    my_project/
        < distinct lack of __init__.py >

I've seen this error a few times:

The most likely cause of this is that there is no directory that matches the name of your project (my_project)

but it can be a confusing and frustrating error when there is a directory with that name.

The actual problem is that python doesn't recognise the directory as a module/package due to the lack of __init__.py.

Forgetting/losing your __init__.py is a silly error to make but I think it's common enough that it is worth mentioning in uv's error that your directory also needs an __init__.py. You've done the hard part in naming the directory that is problematic.

I might suggest the following:

The most likely cause of this is that there is no directory that matches the name of your project (my_project) or that directory does not contain an __init__.py file.

Before
ValueError: Unable to determine which files to ship inside the wheel using the following heuristics: https://hatch.pypa.io/latest/plugins/builder/wheel/#default-file-selection

The most likely cause of this is that there is no directory that matches the name of your project (my_project).

At least one file selection option must be defined in the `tool.hatch.build.targets.wheel` table, see: https://hatch.pypa.io/latest/config/build/

As an example, if you intend to ship a directory named `foo` that resides within a `src` directory located at the root of your project, you can define the following:

[tool.hatch.build.targets.wheel]
packages = ["src/foo"]
After
ValueError: Unable to determine which files to ship inside the wheel using the following heuristics: https://hatch.pypa.io/latest/plugins/builder/wheel/#default-file-selection

The most likely cause of this is that there is no directory that matches the name of your project (my_project) or that directory does not contain an __init__.py file.

At least one file selection option must be defined in the `tool.hatch.build.targets.wheel` table, see: https://hatch.pypa.io/latest/config/build/

As an example, if you intend to ship a directory named `foo` that resides within a `src` directory located at the root of your project, you can define the following:

[tool.hatch.build.targets.wheel]
packages = ["src/foo"]

Bonus points if uv actually checks and works out what is missing: __init__.py or the directory

@charliermarsh
Copy link
Member

Unfortunately those errors come from the build backend, which we don't control. (In your case, it's coming from hatchling.) I think this is something we can improve once we've shipped our own build backend (see #3957), but I'm hesitant to add our own error handling heuristics around this stuff since different build backends may treat these cases differently, they may rely on build backend-specific configuration, etc.

@charliermarsh charliermarsh added the question Asking for clarification or support label Oct 16, 2024
@drmason13
Copy link
Author

Ah I see, thanks for the clarification. I can go ask the same question at the hatchling repo.

Absolutely fine to close this, I agree it's not your issue. Thank you for your excellent work with uv, it's been a joy to use!

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

No branches or pull requests

2 participants