#82 Improvements for Summary/Description generation
Merged 4 years ago by zbyszek. Opened 4 years ago by ignatenkobrain.
fedora-rust/ ignatenkobrain/rust2rpm summary  into  master

file modified
+34 -1
@@ -3,6 +3,7 @@ 

  import collections

  import copy

  import json

+ import re

  import subprocess

  

  import semantic_version as semver
@@ -116,11 +117,43 @@ 

          self.license = None

          self.license_file = None

          self.readme = None

-         self.description = None

+         self._description = None

+         self._summary = None

          self.targets = set()

          self.dependencies = {}

          self.dev_dependencies = set()

  

+     @property

+     def description(self):

+         return self._description

+ 

+     @property

+     def summary(self):

+         return self._summary

+ 

+     @description.setter

+     def description(self, description):

+         # https://salsa.debian.org/rust-team/debcargo/blob/master/src/crates.rs

+         # get_summary_description()

+         if description is None:

+             self._description = self._summary = None

+             return

+         description = description.replace('\n\n', '\r').replace('\n', ' ').replace('\r', '\n').strip()

+         description = re.sub(r'^(?:a|an|the)\s+', '', description, flags=re.I)

+         description = f'{description[0].upper()}{description[1:]}'

+         if description[-1] != '.':

+             description = f'{description}.'

+ 

+         p1 = description.find('.')

+         p2 = description.find('\n')

+         if p2 != -1:

+             p = min(p1, p2)

+         else:

+             p = p1

+ 

+         self._description = description

+         self._summary = description[:p]

+ 

      @classmethod

      def from_json(cls, metadata):

          md = metadata

file modified
+6 -6
@@ -16,8 +16,7 @@ 

  {% if md.description is none %}

  Summary:        # FIXME

  {% else %}

- {% set description_lines = md.description.split("\n") %}

- Summary:        {{ description_lines|join(" ")|trim }}

+ Summary:        {{ md.summary }}

  {% endif %}

  {% if rust_group is defined %}

  Group:          {{ rust_group }}
@@ -65,12 +64,13 @@ 

  {% endfor %}

  {% endif %}

  

- %global _description \

+ %global _description %{expand:

  {% if md.description is none %}

  %{summary}.

- {% else %}

- {{ md.description|wordwrap(wrapstring="\\\n")|trim }}

- {% endif %}

+ {%- else %}

+ {{ md.description|wordwrap }}

+ {%- endif %}

+ }

  

  %description %{_description}

  

no initial comment

rebased onto 216de8e

4 years ago

Pull-Request has been merged by zbyszek

4 years ago

LGTM. Both projects have MIT license to there's no issue with copying code.

There's str.capitalize() that could be used in one of the lines, but this doesn't matter much.

@zbyszek, unfortunately that one is changing whole string:

In [1]: 'barani KKT'.capitalize()                                                                                                                                                   
Out[1]: 'Barani kkt'