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 run doesn't work without __init__.py #6525

Closed
AndreuCodina opened this issue Aug 23, 2024 · 2 comments
Closed

uv run doesn't work without __init__.py #6525

AndreuCodina opened this issue Aug 23, 2024 · 2 comments
Assignees
Labels
enhancement New feature or improvement to existing functionality

Comments

@AndreuCodina
Copy link

AndreuCodina commented Aug 23, 2024

The __init__.py file is optional, but if you download the repository https://github.com/astral-sh/uv-fastapi-example (a fresh copy, don't re-use the repository) and remove the app/__init__.py file, when you run:

uv run fastapi dev app/main.py

then you get this error:

Using Python 3.12.1 interpreter at: /Library/Frameworks/Python.framework/Versions/3.12/bin/python3
Creating virtualenv at: .venv
error: Failed to prepare distributions
  Caused by: Failed to fetch wheel: app @ file:///Users/andreu/Git/Andreu/uv-fastapi-example
  Caused by: Build backend failed to build wheel through `build_editable()` with exit status: 1
--- stdout:

--- stderr:
Traceback (most recent call last):
  File "<string>", line 11, in <module>
  File "/Users/.../Library/Caches/uv/builds-v0/.tmpfYT0UH/lib/python3.12/site-packages/hatchling/build.py", line 83, in build_editable
    return os.path.basename(next(builder.build(directory=wheel_directory, versions=['editable'])))
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../Library/Caches/uv/builds-v0/.tmpfYT0UH/lib/python3.12/site-packages/hatchling/builders/plugin/interface.py", line 155, in build
    artifact = version_api[version](directory, **build_data)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../Library/Caches/uv/builds-v0/.tmpfYT0UH/lib/python3.12/site-packages/hatchling/builders/wheel.py", line 494, in build_editable
    return self.build_editable_detection(directory, **build_data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../Library/Caches/uv/builds-v0/.tmpfYT0UH/lib/python3.12/site-packages/hatchling/builders/wheel.py", line 505, in build_editable_detection
    for included_file in self.recurse_selected_project_files():
  File "/Users/.../Library/Caches/uv/builds-v0/.tmpfYT0UH/lib/python3.12/site-packages/hatchling/builders/plugin/interface.py", line 180, in recurse_selected_project_files
    if self.config.only_include:
       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../Library/Caches/uv/builds-v0/.tmpfYT0UH/lib/python3.12/site-packages/hatchling/builders/config.py", line 806, in only_include
    only_include = only_include_config.get('only-include', self.default_only_include()) or self.packages
                                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../Library/Caches/uv/builds-v0/.tmpfYT0UH/lib/python3.12/site-packages/hatchling/builders/wheel.py", line 260, in default_only_include
    return self.default_file_selection_options.only_include
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/functools.py", line 995, in __get__
    val = self.func(instance)
          ^^^^^^^^^^^^^^^^^^^
  File "/Users/.../Library/Caches/uv/builds-v0/.tmpfYT0UH/lib/python3.12/site-packages/hatchling/builders/wheel.py", line 248, in default_file_selection_options
    raise ValueError(message)
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 (app).

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"]

uv version: 0.3.2

@charliermarsh
Copy link
Member

I think describing __init__.py as optional is a bit of a misnomer. Python code sometimes works without an __init__.py due to namespace packages, but that's often "by accident". Regardless, this would be fixed by #6585.

@charliermarsh charliermarsh added the enhancement New feature or improvement to existing functionality label Aug 25, 2024
@charliermarsh charliermarsh self-assigned this Aug 26, 2024
@charliermarsh
Copy link
Member

This should be fixed in v0.4.0. Projects that omit [build-system] will no longer be built and installed by default. You can also set tool.uv.package = false or tool.uv.package = false to control the behavior explicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement to existing functionality
Projects
None yet
Development

No branches or pull requests

2 participants