Skip to content

Commit

Permalink
feat(parser): blueprint description is now optional
Browse files Browse the repository at this point in the history
  • Loading branch information
fyhertz committed Sep 20, 2022
1 parent 18cb47c commit d4921f5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/ops2deb/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def format_description(description: str) -> str:

def format_blueprint(blueprint: Dict[str, Any]) -> Dict[str, Any]:
blueprint = json.loads(Blueprint.construct(**blueprint).json(exclude_defaults=True))
blueprint["description"] = format_description(blueprint["description"])
if "description" in blueprint.keys():
blueprint["description"] = format_description(blueprint["description"])
keys_to_remove: List[str] = []
for key, value in blueprint.items():
if isinstance(value, list) and not blueprint.get(key):
Expand Down
2 changes: 1 addition & 1 deletion src/ops2deb/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Blueprint(Base):
revision: int = Field(1, description="Package revision")
arch: Architecture = Field("amd64", description="Package architecture")
summary: str = Field(..., description="Package short description, one line only")
description: str = Field(..., description="Package description")
description: str = Field("", description="Package description")
build_depends: List[str] = Field(
default_factory=list, description="Package build dependencies"
)
Expand Down
2 changes: 1 addition & 1 deletion src/ops2deb/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{%- if package.recommends %}{{ '\n' }}Recommends: {{ package.recommends|sort|join(', ') }}{% endif %}
{%- if package.conflicts %}{{ '\n' }}Conflicts: {{ package.conflicts|sort|join(', ') }}{% endif %}
Description: {{ package.summary }}
{% for line in package.description.split('\n') %} {{ line or '.' }}{{ '\n' if not loop.last else '' }}{% endfor %}
{% if package.description %}{% for line in package.description.split('\n') %} {{ line or '.' }}{{ '\n' if not loop.last else '' }}{% endfor %}{% endif %}
"""

Expand Down
27 changes: 26 additions & 1 deletion tests/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,34 @@
"""


blueprint_4 = Blueprint(
name="great-app",
version="1.0.0",
summary="My great app",
)


control_4 = """Source: great-app
Priority: optional
Maintainer: ops2deb <[email protected]>
Build-Depends: debhelper
Standards-Version: 3.9.6
Package: great-app
Architecture: amd64
Description: My great app
"""


@pytest.mark.parametrize(
"blueprint, control",
[(blueprint_1, control_1), (blueprint_2, control_2), (blueprint_3, control_3)],
[
(blueprint_1, control_1),
(blueprint_2, control_2),
(blueprint_3, control_3),
(blueprint_4, control_4),
],
)
def test_generate_should_produce_identical_control_file_snapshot(
tmp_path, blueprint, control
Expand Down
1 change: 0 additions & 1 deletion tests/test_ops2deb.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
revision: 2
arch: all
summary: Great package
description: A detailed description of the great package.
fetch:
url: http://testserver/{{version}}/great-app.tar.gz
sha256: f1be6dd36b503641d633765655e81cdae1ff8f7f73a2582b7468adceb5e212a9
Expand Down

0 comments on commit d4921f5

Please sign in to comment.