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

Handle markdown and plain text readme too and include content type in metadata #79

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/manifestoo_core/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@ def _set(key: str, value: Union[None, str, List[str]]) -> None:
_set("Author", _no_nl(manifest.author))
_set("Author-email", _author_email(manifest.author))
_set("Classifier", _make_classifiers(odoo_series, manifest))
long_description = _long_description(addon)
long_description, long_description_content_type = _long_description(addon)
if long_description:
meta.set_payload(long_description)
if long_description_content_type:
_set("Description-Content-Type", long_description_content_type)

return meta

Expand Down Expand Up @@ -368,11 +370,20 @@ def _no_nl(s: Optional[str]) -> Optional[str]:
return " ".join(s.split())


def _long_description(addon: Addon) -> Optional[str]:
def _long_description(addon: Addon) -> Tuple[Optional[str], Optional[str]]:
"""
:return: a tuple with long description and its content type
"""
readme_path = addon.path / "README.rst"
if readme_path.is_file():
return readme_path.read_text(encoding="utf-8")
return addon.manifest.description
return readme_path.read_text(encoding="utf-8"), "text/x-rst"
readme_path = addon.path / "README.md"
if readme_path.is_file():
return readme_path.read_text(encoding="utf-8"), "text/markdown"
readme_path = addon.path / "README.txt"
if readme_path.is_file():
return readme_path.read_text(encoding="utf-8"), "text/plain"
return addon.manifest.description, "text/x-rst"


def _make_classifiers(odoo_series: OdooSeries, manifest: Manifest) -> List[str]:
Expand Down
25 changes: 20 additions & 5 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def _m( # noqa: PLR0913 too many arguments
summary: Optional[str] = None,
description: Optional[str] = None,
readme_rst: Optional[str] = None,
readme_md: Optional[str] = None,
depends: Optional[List[str]] = None,
external_dependencies: Optional[Dict[str, List[str]]] = None,
website: Optional[str] = None,
Expand Down Expand Up @@ -82,6 +83,9 @@ def _m( # noqa: PLR0913 too many arguments
if readme_rst:
readme_path = addon_dir / "README.rst"
readme_path.write_text(readme_rst)
if readme_md:
readme_path = addon_dir / "README.md"
readme_path.write_text(readme_md)
return msg_to_json(
metadata_from_addon_dir(
addon_dir,
Expand Down Expand Up @@ -111,6 +115,7 @@ def test_basic(tmp_path: Path) -> None:
"Framework :: Odoo :: 14.0",
],
"metadata_version": "2.1",
"description_content_type": "text/x-rst",
}


Expand Down Expand Up @@ -333,18 +338,28 @@ def test_description_from_readme(
tmp_path: Path,
readme_rst: str = "A readme\n\nwith two lines",
) -> None:
assert _m(tmp_path, readme_rst=readme_rst)["description"] == readme_rst
m = _m(tmp_path, readme_rst=readme_rst)
assert m["description"] == readme_rst
assert m["description_content_type"] == "text/x-rst"


def test_description_from_readme_md(
tmp_path: Path,
readme_md: str = "A readme\n\nwith two lines",
) -> None:
m = _m(tmp_path, readme_md=readme_md)
assert m["description"] == readme_md
assert m["description_content_type"] == "text/markdown"


def test_description_from_description_and_readme(
tmp_path: Path,
description: str = "A description",
readme_rst: str = "A readme\n\nwith two lines",
) -> None:
assert (
_m(tmp_path, description=description, readme_rst=readme_rst)["description"]
== readme_rst
)
m = _m(tmp_path, description=description, readme_rst=readme_rst)
assert m["description"] == readme_rst
assert m["description_content_type"] == "text/x-rst"


def test_author(tmp_path: Path) -> None:
Expand Down
Loading