Git Product home page Git Product logo

hatch-odoo's Introduction

hatch-odoo

PyPI - Version PyPI - Python Version


A hatch(ling) plugin to work with projects containing Odoo addons. This tool will help you package a project containing Odoo addons so it can be installed with pip:

  • automatically generates dependencies based on Odoo addons manifests,
  • package addons into the odoo/addons namespace independently of the source project layout,
  • install the addons in editable mode without fiddling with --addons-path,

πŸ’‘ This project is best used when working with end-customer projects. To package individual reusable addons, consider the whool project.

Table of Contents

Quick start

Assuming you have a project containing your awesome Odoo addons at the root of your project repository, you can set it up by creating a pyproject.toml file like so.

# Use the hatchling build backend, with the hatch-odoo plugin.
[build-system]
requires = ["hatchling", "hatch-odoo"]
build-backend = "hatchling.build"

[project]
name = "MyAwesomeProject"
version = "1.0"
readme = "README.md"
requires-python = ">=3.8"
# Dependencies are dynamic because they will be generated from Odoo addons manifests.
dynamic = ["dependencies"]

# Enable the hatch-odoo metadata hook to generate dependencies from addons manifests.
[tool.hatch.metadata.hooks.odoo-addons-dependencies]
# Enable the hatch-odoo build hook to package the Odoo addons into odoo/addons.
[tool.hatch.build.hooks.odoo-addons-dirs]

[tool.hatch-odoo]
# If our addons have non standard version numbers, let's help hatch-odoo discover the Odoo version.
odoo_version_override = "15.0"
# Let's add additional dependencies that are not declared in addons manifests.
dependencies = ["click-odoo-contrib"]
# Our addons are in the project root directory.
addons_dirs = ["."]

You can then install it in editable mode, together with its dependencies in a virtual environment with a procedure like this:

# python3 -m venv .venv
# source .venv/bin/activate
# pip install --upgrade pip setuptools wheel
# pip install -r https://raw.githubusercontent.com/odoo/odoo/15.0/requirements.txt
# pip install -e git+https://github.com/odoo/[email protected]
# pip install -e .
# odoo

All dependencies (such as OCA addons and external dependencies) declared in your project addons manifests will be downloaded and installed from PyPI automatically.

There is no need to configure the Odoo addons path: since addons are installed in odoo/addons, the regular Python import machinery works out of the box

You can then pin dependencies for reproducibility with pip freeze or other tools. pip-deepfreeze is known to work well with git URLs, but other tools such as pip-tools, may work as well.

Alternative project layouts

Depending on your taste and requirements, there are several alternative ways to organize your source code. The test projects in tests/data each have a README that describe the layout and corresponding tradeoffs, with the corresponding pyproject.toml.

License

hatch-odoo is distributed under the terms of the MIT license.

hatch-odoo's People

Contributors

pre-commit-ci[bot] avatar sbidoul avatar vincent-hatakeyama avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

hatch-odoo's Issues

Not working with hatchling 1.19+

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

Fix coverage

Coverage does not work with subprocesses that the test suite uses.

Hatch-odoo doesn't support Odoo 16

On Odoo master, the first alpha version for the 16 series is 16.1. When installing odoo from master, it complains about the odoo version that should be odoo<16.1dev,>=16.0a but is 16.1a1

Installing addons using hatch breaks Odoo installation

Not sure is this because of #12 because I have applied some patches from there however the issue still persists.

Steps to reproduce

Build image

Install Odoo from source in venv using git

Build is completed successfully with no issues.

Run container

Run container using docker-compose.yml

Expected behaviour

  • Postgres is up and running
  • Odoo is up and running

Current behaviour

  • Postgres is up and running
  • Odoo fails with error:
db-1   | 2024-06-04 20:53:01.438 UTC [59] LOG:  database system was shut down at 2024-06-04 20:53:01 UTC
db-1   | 2024-06-04 20:53:01.440 UTC [1] LOG:  database system is ready to accept connections
web-1  | Traceback (most recent call last):
web-1  |   File "/opt/odoo-venv/bin/odoo", line 8, in <module>
web-1  |     odoo.cli.main()
web-1  | AttributeError: module 'odoo' has no attribute 'cli'
web-1 exited with code 1

Notes

Same image runs fine if extra addons are not installed:

Steps to reproduce

  • Remove the part that installs third party addons using hatch-odoo
  • Rebuild the image
  • Run container

Result

  • Postgres is runnig
  • Odoo is running, all functions are working fine

Here are all the files used for build.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.