Skip to content

Commit

Permalink
Merge pull request #19 from sbidoul/build-outside-git
Browse files Browse the repository at this point in the history
Allow building outside git
  • Loading branch information
sbidoul authored Mar 16, 2024
2 parents 9f2e080 + 214fd16 commit f5585d7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions news/18.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow building from outside a git directory. This requires pip>=21.3.
10 changes: 4 additions & 6 deletions src/whool/buildapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@ def _copy_to(addon_dir: Path, dst: Path) -> None:
try:
scm_files = _scm_ls_files(addon_dir)
except NoScmFound:
# TODO DO NOT UNCOMMENT, until pip install and pip wheel build in place.
# TODO In case pip copies, this will crash because of
# TODO missing .git directory. If it would not crash
# TODO the addon name would be wrong because cwd is a temp dir.
# shutil.copytree(addon_dir, dst)
raise
# NOTE This requires pip>=21.3 which builds in-tree. Previous pip versions
# copied to a temporary directory with a different name than the addon, which
# caused the resulting distribution name to be wrong.
shutil.copytree(addon_dir, dst)
else:
dst.mkdir()
for f in scm_files:
Expand Down
21 changes: 21 additions & 0 deletions tests/test_build_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from zipfile import ZipFile

from whool.buildapi import build_wheel
from whool.init import init_addon_dir

from .utils import dir_changer

Expand All @@ -16,3 +17,23 @@ def test_build_wheel(addon1_with_pyproject: Path, tmp_path: Path) -> None:
names = zf.namelist()
assert "odoo/addons/addon1/__manifest__.py" in names
assert "odoo/addons/addon1/pyproject.toml" not in names


def test_build_wheel_without_scm(tmp_path: Path) -> None:
addon_dir = tmp_path / "addon1"
addon_dir.mkdir()
addon_dir.joinpath("__manifest__.py").write_text(
"{'name': 'addon1', 'version': '16.0.1.0.0'}"
)
addon_dir.joinpath("__init__.py").touch()
init_addon_dir(addon_dir)
wheel_path = tmp_path / "wheel"
wheel_path.mkdir()
with dir_changer(addon_dir):
wheel_name = build_wheel(os.fspath(wheel_path))
assert wheel_name == "odoo_addon_addon1-16.0.1.0.0-py3-none-any.whl"
assert (wheel_path / wheel_name).exists()
with ZipFile(wheel_path / wheel_name) as zf:
names = zf.namelist()
assert "odoo/addons/addon1/__manifest__.py" in names
assert "odoo/addons/addon1/pyproject.toml" not in names

0 comments on commit f5585d7

Please sign in to comment.