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

Not working with hatchling 1.19+ #12

Closed
yajo opened this issue May 2, 2024 · 24 comments · Fixed by #13 or #16
Closed

Not working with hatchling 1.19+ #12

yajo opened this issue May 2, 2024 · 24 comments · Fixed by #13 or #16

Comments

@yajo
Copy link

yajo commented May 2, 2024

As seen in the release notes:

An error will now be raised if a force-included path does not exist

It seems that error is creating problems with hatch-odoo plugin.

If I add this pyproject.toml file to https://github.com/odoo/design-themes I get an exception when building the wheel:

[build-system]
requires = ['hatchling', 'hatch-odoo']
build-backend = 'hatchling.build'

[project]
name = 'odoo-addons-design-themes'
version = '16.0'
requires-python = '>=3.7'
dynamic = ['dependencies']

[tool.hatch.metadata.hooks.odoo-addons-dependencies]
[tool.hatch.build.hooks.odoo-addons-dirs]

[tool.hatch-odoo]
addons_dirs = ['.']
dependencies = []
odoo_version_override = '16.0'

The error:

Obtaining file:///var/home/yajo/prodevel/buffet-odoo/kitchen/16.0/design-themes
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Installing backend dependencies ... done
  Preparing editable metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Preparing editable metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [52 lines of output]
      Traceback (most recent call last):
        File "/var/home/yajo/prodevel/buffet-odoo/.data/venv/odoo-16.0/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 167, in prepare_metadata_for_build_editable
          hook = backend.prepare_metadata_for_build_editable
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      AttributeError: module 'hatchling.build' has no attribute 'prepare_metadata_for_build_editable'
      
      During handling of the above exception, another exception occurred:
      
      Traceback (most recent call last):
        File "/var/home/yajo/prodevel/buffet-odoo/.data/venv/odoo-16.0/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/var/home/yajo/prodevel/buffet-odoo/.data/venv/odoo-16.0/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/var/home/yajo/prodevel/buffet-odoo/.data/venv/odoo-16.0/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 176, in prepare_metadata_for_build_editable
          whl_basename = build_hook(metadata_directory, config_settings)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-o9cu5aub/overlay/lib/python3.11/site-packages/hatchling/build.py", line 83, in build_editable
          return os.path.basename(next(builder.build(directory=wheel_directory, versions=['editable'])))
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-o9cu5aub/overlay/lib/python3.11/site-packages/hatchling/builders/plugin/interface.py", line 155, in build
          artifact = version_api[version](directory, **build_data)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-o9cu5aub/overlay/lib/python3.11/site-packages/hatchling/builders/wheel.py", line 492, in build_editable
          return self.build_editable_detection(directory, **build_data)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-o9cu5aub/overlay/lib/python3.11/site-packages/hatchling/builders/wheel.py", line 503, in build_editable_detection
          for included_file in self.recurse_selected_project_files():
        File "/tmp/pip-build-env-o9cu5aub/overlay/lib/python3.11/site-packages/hatchling/builders/plugin/interface.py", line 180, in recurse_selected_project_files
          if self.config.only_include:
             ^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-o9cu5aub/overlay/lib/python3.11/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 "/tmp/pip-build-env-o9cu5aub/overlay/lib/python3.11/site-packages/hatchling/builders/wheel.py", line 259, in default_only_include
          return self.default_file_selection_options.only_include
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/python3.11/functools.py", line 1001, in __get__
          val = self.func(instance)
                ^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-o9cu5aub/overlay/lib/python3.11/site-packages/hatchling/builders/wheel.py", line 247, 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 (odoo_addons_design_themes).
      
      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"]
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

@moduon MT-1075

@yajo
Copy link
Author

yajo commented May 2, 2024

The workaround to make it work for now:

-requires = ['hatchling', 'hatch-odoo']
+requires = ['hatchling<1.19', 'hatch-odoo']

@yajo
Copy link
Author

yajo commented May 2, 2024

I also found another workaround (or maybe definitive solution?):

+[tool.hatch.build.targets.wheel]
+packages = ['odoo.addons']

I found out you already knew this @sbidoul from pypa/hatch#1113 (comment). Did you find a fix back then?

@sbidoul
Copy link
Member

sbidoul commented May 2, 2024

I think the issue was with hatchling 1.19 only. Other more recent versions should work.

@sbidoul
Copy link
Member

sbidoul commented May 2, 2024

Don't hesitate to reopen if you see issues with more recent versions of hatchling.

@ofek
Copy link

ofek commented May 5, 2024

Yeah I think that was fixed. There is also the bypass-selection option now.

@yajo
Copy link
Author

yajo commented May 29, 2024

Indeed, adding this to the pyproject.toml also makes install work again:

+[tool.hatch.build.targets.wheel]
+bypass-selection = true

So, which fix is better? This one or #12 (comment)? Are there any differences between choosing one or the other workaround?

@sbidoul
Copy link
Member

sbidoul commented May 29, 2024

@yajo can't you just avoid hatchling 1.19 ? It works just fine with all other versions.

@sbidoul sbidoul changed the title Not working with hatchling 1.19+ Not working with hatchling 1.19.0 May 29, 2024
@yajo
Copy link
Author

yajo commented May 30, 2024

I have added this patch over the original file, just to make sure I'm using the latest versions:

-requires = ['hatchling', 'hatch-odoo']
+requires = ['hatchling==1.24.2', 'hatch-odoo==1.0']

Then:

> pip install -Ue .
WARNING: Ignoring invalid distribution -doo-addon-base-partner-company-group (/home/yajo/prodevel/buffet-odoo/.data/venv/odoo-16.0/lib/python3.10/site-packages)
WARNING: Ignoring invalid distribution -doo-addon-base-partner-company-group (/home/yajo/prodevel/buffet-odoo/.data/venv/odoo-16.0/lib/python3.10/site-packages)
Obtaining file:///home/yajo/prodevel/buffet-odoo/kitchen/16.0/design-themes
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Installing backend dependencies ... done
  Preparing editable metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Preparing editable metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [42 lines of output]
      Traceback (most recent call last):
        File "/home/yajo/prodevel/buffet-odoo/.data/venv/odoo-16.0/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 167, in prepare_metadata_for_build_editable
          hook = backend.prepare_metadata_for_build_editable
      AttributeError: module 'hatchling.build' has no attribute 'prepare_metadata_for_build_editable'
      
      During handling of the above exception, another exception occurred:
      
      Traceback (most recent call last):
        File "/home/yajo/prodevel/buffet-odoo/.data/venv/odoo-16.0/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/home/yajo/prodevel/buffet-odoo/.data/venv/odoo-16.0/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/home/yajo/prodevel/buffet-odoo/.data/venv/odoo-16.0/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 176, in prepare_metadata_for_build_editable
          whl_basename = build_hook(metadata_directory, config_settings)
        File "/tmp/pip-build-env-0cqra_bf/overlay/lib/python3.10/site-packages/hatchling/build.py", line 83, in build_editable
          return os.path.basename(next(builder.build(directory=wheel_directory, versions=['editable'])))
        File "/tmp/pip-build-env-0cqra_bf/overlay/lib/python3.10/site-packages/hatchling/builders/plugin/interface.py", line 155, in build
          artifact = version_api[version](directory, **build_data)
        File "/tmp/pip-build-env-0cqra_bf/overlay/lib/python3.10/site-packages/hatchling/builders/wheel.py", line 492, in build_editable
          return self.build_editable_detection(directory, **build_data)
        File "/tmp/pip-build-env-0cqra_bf/overlay/lib/python3.10/site-packages/hatchling/builders/wheel.py", line 503, in build_editable_detection
          for included_file in self.recurse_selected_project_files():
        File "/tmp/pip-build-env-0cqra_bf/overlay/lib/python3.10/site-packages/hatchling/builders/plugin/interface.py", line 180, in recurse_selected_project_files
          if self.config.only_include:
        File "/tmp/pip-build-env-0cqra_bf/overlay/lib/python3.10/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 "/tmp/pip-build-env-0cqra_bf/overlay/lib/python3.10/site-packages/hatchling/builders/wheel.py", line 259, in default_only_include
          return self.default_file_selection_options.only_include
        File "/nix/store/h5wq40vfyw8j3afab592x9hpxc2shl3n-python3-3.10.14/lib/python3.10/functools.py", line 981, in __get__
          val = self.func(instance)
        File "/tmp/pip-build-env-0cqra_bf/overlay/lib/python3.10/site-packages/hatchling/builders/wheel.py", line 247, 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 (odoo_addons_design_themes).
      
      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"]
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
WARNING: Ignoring invalid distribution -doo-addon-base-partner-company-group (/home/yajo/prodevel/buffet-odoo/.data/venv/odoo-16.0/lib/python3.10/site-packages)
WARNING: Ignoring invalid distribution -doo-addon-base-partner-company-group (/home/yajo/prodevel/buffet-odoo/.data/venv/odoo-16.0/lib/python3.10/site-packages)
WARNING: Ignoring invalid distribution -doo-addon-base-partner-company-group (/home/yajo/prodevel/buffet-odoo/.data/venv/odoo-16.0/lib/python3.10/site-packages)

[notice] A new release of pip is available: 23.0.1 -> 24.0
[notice] To update, run: pip install --upgrade pip

So the problem happens with hatchling 1.19 and later versions AFAICS.

@ofek
Copy link

ofek commented May 30, 2024

Perhaps open up a new issue on this repository with your full project config file.

@yajo
Copy link
Author

yajo commented May 30, 2024

Nothing has changed... it's the same as #12 (comment) 🤷🏼‍♂️

yajo added a commit to moduon/hatch-odoo that referenced this issue May 31, 2024
@yajo
Copy link
Author

yajo commented May 31, 2024

I think the simplest way to fix this is #15

@sbidoul
Copy link
Member

sbidoul commented May 31, 2024

Ok, so I'm reopening. Thanks for the reproducer, @yajo. This combination of addons_dir = ['.'] and editable install is not something I use often, but it should work.

# git clone https://github.com/odoo/design-themes
# cat <<EOF > pyproject.toml
[build-system]
requires = ['hatchling', 'hatch-odoo']
build-backend = 'hatchling.build'

[project]
name = 'odoo-addons-design-themes'
version = '16.0'
requires-python = '>=3.7'
dynamic = ['dependencies']

[tool.hatch.metadata.hooks.odoo-addons-dependencies]
[tool.hatch.build.hooks.odoo-addons-dirs]
[tool.hatch-odoo]
addons_dirs = ['.']
dependencies = []
odoo_version_override = '16.0'
EOF
# pip install -e .

@sbidoul sbidoul reopened this May 31, 2024
@sbidoul sbidoul changed the title Not working with hatchling 1.19.0 Not working with hatchling 1.19+ May 31, 2024
@sbidoul
Copy link
Member

sbidoul commented May 31, 2024

And I can confirm the reproducer above does work with hatchling<1.19.

@ofek
Copy link

ofek commented May 31, 2024

Issue with plugin or Hatchling? I thought everything was fixed (as your tests and current usage show).

@sbidoul
Copy link
Member

sbidoul commented May 31, 2024

@ofek thanks for chiming in. I had not tested the specific case in #12 (comment) yet, but I verified just now that it started breaking with hatchling 1.19. I also note the problem is in editable mode only, for which the workaround proposed in #15 does not feel natural. Can't tell more at the moment.

@sbidoul
Copy link
Member

sbidoul commented May 31, 2024

But at the moment, my bet is on an issue with hatchling ;)

@ofek
Copy link

ofek commented May 31, 2024

Can you please tell me about how that case that was untested is different?

@sbidoul
Copy link
Member

sbidoul commented May 31, 2024

That particular usage mode creates a directory named build/__editable_odoo_addons__/odoo/addons that contains symlinks, and adds a .pth in the editable wheel pointing to it, but nothing else (it's the "link farm" mode of PEP 660). Maybe the error is triggered because no files from the project are added to the wheel.

Would there be a way for the plugin to tell hatchling that this is the expected outcome?

@sbidoul
Copy link
Member

sbidoul commented May 31, 2024

Hm, not quite. The mode that works also adds a .pth but nothing else. Forget about that, I'll fire my debugger and try to understand better.

@sbidoul
Copy link
Member

sbidoul commented Jun 1, 2024

@ofek I have done some digging, and think its a hatchling issue.

Indeed in the case that fails, the plugin creates and adds a .pth file in build_data["force_include_editable"], and there is literally nothing else to add in the editable wheel. That is the difference with the cases that do work where I always have a little something added to the wheel with standard hatchling mechanisms.

For non editable wheels pypa/hatch#1120 fixed pypa/hatch#1113 (comment) by considering force_include (IIUC). Maybe something similar should be done for force_include_editable ?

Alternatively would there be a way to let the plugin expand dev-mode-dirs at build time ?

I have added a failing test reproducing this issue in #16

@sbidoul
Copy link
Member

sbidoul commented Jun 1, 2024

I can work around it by adding my .pth file in force_include in addition to force_include_editable, which I did in #16 too.

@ofek
Copy link

ofek commented Jun 3, 2024

Thank you for debugging, that helps a lot! When @potiuk finishes pypa/hatch#1511 then I will take the time to fix the issue here and make a release which will contain both. Right now I'm deep into the workspaces implementation and want to focus on finishing.

@potiuk
Copy link

potiuk commented Jun 3, 2024

Yeah. I am on it. I am at conference (running a data-engineering track there :) ) this next 3 days so I am not sure if I manage to finish it quickly but I absolutely intend to do it :)

@ofek
Copy link

ofek commented Jun 3, 2024

Take your time, I really don't want to context-switch away from workspaces 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment