MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / clean_description

Function clean_description

src/packagedcode/pypi.py:1905–1928  ·  view source on GitHub ↗

Return a cleaned description text, removing extra leading whitespaces if needed. Some metadata formats padd each description line with 8 spaces. Some do not. We check first and cleanup if needed.

(description)

Source from the content-addressed store, hash-verified

1903
1904
1905def clean_description(description):
1906 """
1907 Return a cleaned description text, removing extra leading whitespaces if
1908 needed. Some metadata formats padd each description line with 8 spaces. Some
1909 do not. We check first and cleanup if needed.
1910 """
1911 # TODO: verify what is the impact of Description-Content-Type: if any
1912 description = description or ''
1913 description = description.strip()
1914 lines = description.splitlines(False)
1915
1916 space_padding = ' ' * 8
1917
1918 # we need cleaning if any of the first two lines starts with 8 spaces
1919 need_cleaning = any(l.startswith(space_padding) for l in lines[:2])
1920 if not need_cleaning:
1921 return description
1922
1923 cleaned_lines = [
1924 line[8:] if line.startswith(space_padding) else line
1925 for line in lines
1926 ]
1927
1928 return '\n'.join(cleaned_lines)
1929
1930
1931def get_legacy_description(location):

Callers 1

get_descriptionFunction · 0.85

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected