prefix-dev / pixi

Package management made easy
https://pixi.sh
BSD 3-Clause "New" or "Revised" License
2.91k stars 161 forks source link

pyproject.toml fails with cowpy #1903

Closed benmoss closed 1 week ago

benmoss commented 3 weeks ago

Checks

Reproducible example

Looks like the same as #1815 but I'm not init-ing in a subdirectory or anything.

pixi init --format pyproject
pixi add cowpy

Issue description

$ pixi add cowpy
  × error updating pypi prefix
  ├─▶ Failed to prepare distributions
  ├─▶ Failed to fetch wheel: pixi-env @ file:///private/tmp/pixi-env
  ╰─▶ 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/bmoss40/Library/Caches/rattler/cache/uv-cache/builds-v0/.tmpZp4nIe/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/bmoss40/Library/Caches/rattler/cache/uv-cache/builds-v0/.tmpZp4nIe/lib/python3.12/site-packages/hatchling/builders/plugin/
      interface.py", line 155, in build
          artifact = version_api[version](directory, **build_data)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/Users/bmoss40/Library/Caches/rattler/cache/uv-cache/builds-v0/.tmpZp4nIe/lib/python3.12/site-packages/hatchling/builders/wheel.py", line
      494, in build_editable
          return self.build_editable_detection(directory, **build_data)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/Users/bmoss40/Library/Caches/rattler/cache/uv-cache/builds-v0/.tmpZp4nIe/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/bmoss40/Library/Caches/rattler/cache/uv-cache/builds-v0/.tmpZp4nIe/lib/python3.12/site-packages/hatchling/builders/plugin/
      interface.py", line 180, in recurse_selected_project_files
          if self.config.only_include:
             ^^^^^^^^^^^^^^^^^^^^^^^^
        File "/Users/bmoss40/Library/Caches/rattler/cache/uv-cache/builds-v0/.tmpZp4nIe/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/bmoss40/Library/Caches/rattler/cache/uv-cache/builds-v0/.tmpZp4nIe/lib/python3.12/site-packages/hatchling/builders/wheel.py", line
      260, in default_only_include
          return self.default_file_selection_options.only_include
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/private/tmp/pixi-env/.pixi/envs/default/lib/python3.12/functools.py", line 993, in __get__
          val = self.func(instance)
                ^^^^^^^^^^^^^^^^^^^
        File "/Users/bmoss40/Library/Caches/rattler/cache/uv-cache/builds-v0/.tmpZp4nIe/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 (pixi_env).

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

Expected behavior

The package should be installed

benmoss commented 3 weeks ago
mkdir pixi_env
touch pixi_env/__init__.py

seems to fix this, but this is a bit of a rough piece of default behavior. Maybe pixi should init this folder structure?

baszalmstra commented 3 weeks ago

I agree, it would be nice if we add that file immediately too.

olivier-lacroix commented 3 weeks ago

Not a bad idea indeed. Note however that there are two typical layouts, which means that pixi would force that choice on users. Should pixi generate a flat, or src layout ? See https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/#src-layout-vs-flat-layout for instance

benmoss commented 2 weeks ago

@olivier-lacroix I think if we just agree on one users can always opt to switch manually, it's not like a permanent decision

tdejager commented 2 weeks ago

When reading the link from @olivier-lacroix, I think defaulting to a src layout makes sense because:

  1. A source layout requires an editable install, which we already add by default.
  2. "The src layout helps prevent accidental usage of the in-development copy of the code". This sounds good to me :)

And finally:

The src layout helps enforce that an editable installation is only able to import files that were meant to be importable. This is especially relevant when the editable installation is implemented using a path configuration file that adds the directory to the import path.

Seeing as we default to hatch as a buildsystem now, and that uses .pth, this point might be relevant as well.

Opinions?

Hofer-Julian commented 2 weeks ago

To be honest, I never found this nice list of advantages of the src layout. Sounds to me as well like we should opt for the src layout

olivier-lacroix commented 2 weeks ago

Sounds good to me!