Skip to content

Commit

Permalink
Merge pull request #16 from acsone/add-editable-failing-test
Browse files Browse the repository at this point in the history
Fix editable installs where there are only addons at the root of the project
  • Loading branch information
sbidoul authored Jun 5, 2024
2 parents 796810d + 15a3cd8 commit d1cf06a
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/hatch_odoo/build_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,8 @@ def initialize(self, version: str, build_data: dict[str, Any]) -> None:
force_include_editable[pth_file.name] = (
f"{project_name}_editable_odoo_addons.pth"
)
# work around for https://github.com/acsone/hatch-odoo/issues/12
force_include = build_data["force_include"]
force_include[pth_file.name] = (
f"{project_name}_editable_odoo_addons.pth"
)
6 changes: 6 additions & 0 deletions tests/data/project6/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# project6

A basic project with only Odoo addons in the root directory.

This layout is recommended when packaging existing addons repositories with addons at
the root and nothing else.
Empty file.
4 changes: 4 additions & 0 deletions tests/data/project6/addon_uninstallable/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "uninstallable",
"installable": False,
}
Empty file.
7 changes: 7 additions & 0 deletions tests/data/project6/addona/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "a",
"depends": ["mis-builder"],
"external_dependencies": {
"python": ["wrapt"],
},
}
Empty file.
4 changes: 4 additions & 0 deletions tests/data/project6/addonb/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "b",
"depends": ["addona"],
}
18 changes: 18 additions & 0 deletions tests/data/project6/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[build-system]
requires = ["hatchling", "hatch-odoo"]
build-backend = "hatchling.build"

[project]
name = "project6"
version = "1.0"
readme = "README.md"
dynamic = ["dependencies"]

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

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

[tool.hatch-odoo]
odoo_version_override = "15.0"
dependencies = ["click-odoo-contrib"]
addons_dirs = ["."]
18 changes: 15 additions & 3 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,23 @@


@pytest.mark.parametrize(
"project", ["project1", "project2", "project3", "project4", "project5"]
"project, addons_only",
[
("project1", False),
("project2", False),
("project3", False),
("project4", False),
("project5", False),
("project6", True),
],
)
@pytest.mark.parametrize("build_via_sdist", [True, False])
def test_build(
project: str, build_via_sdist: bool, data_path: Path, tmp_path: Path
project: str,
addons_only: bool,
build_via_sdist: bool,
data_path: Path,
tmp_path: Path,
) -> None:
build_cmd = [
sys.executable,
Expand All @@ -39,4 +51,4 @@ def test_build(
for addon_name in ("addona", "addonb", "addon_uninstallable"):
assert f"odoo/addons/{addon_name}/__init__.py" in files
assert f"odoo/addons/{addon_name}/__manifest__.py" in files
assert f"{project}/__init__.py" in files
assert addons_only or f"{project}/__init__.py" in files
4 changes: 4 additions & 0 deletions tests/test_editable.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
("project3", [""]),
("project4", ["src", "addons_group1", "addons_group2"]),
("project5", ["", "build/__editable_odoo_addons__"]),
("project6", ["build/__editable_odoo_addons__"]),
],
)
def test_odoo_addons_dependencies(
Expand Down Expand Up @@ -58,3 +59,6 @@ def test_odoo_addons_dependencies(
if (addons_dir / addon_name).is_dir():
editable_addon_names.append(addon_name)
assert sorted(editable_addon_names) == expected_editable_addon_names
# Check that the project odoo packages have not been copied to the target.
assert not tmp_path.joinpath("odoo").exists()
assert not tmp_path.joinpath(project_name).exists()
3 changes: 2 additions & 1 deletion tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@


@pytest.mark.parametrize(
"project_name", ["project1", "project2", "project3", "project4", "project5"]
"project_name",
["project1", "project2", "project3", "project4", "project5", "project6"],
)
def test_odoo_addons_dependencies(
project_name: str, data_path: Path, tmp_path: Path
Expand Down

0 comments on commit d1cf06a

Please sign in to comment.