patman: Fix up argument/return docs in patchstream

Add missing documentation and type information. Fix up some missing docs
on exceptions also.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2020-10-29 21:46:22 -06:00
parent e3a816b9f4
commit 1cb1c0fc8d

View file

@ -90,9 +90,10 @@ class PatchStream:
are scanning a 'git log'. are scanning a 'git log'.
Args: Args:
line: Source line containing tag (useful for debug/error messages) line (str): Source line containing tag (useful for debug/error
name: Tag name (part after 'Series-') messages)
value: Tag value (part after 'Series-xxx: ') name (str): Tag name (part after 'Series-')
value (str): Tag value (part after 'Series-xxx: ')
""" """
if name == 'notes': if name == 'notes':
self.in_section = name self.in_section = name
@ -106,7 +107,7 @@ class PatchStream:
When a Commit-xxx tag is detected, we come here to record it. When a Commit-xxx tag is detected, we come here to record it.
Args: Args:
name: Tag name (part after 'Commit-') name (str): Tag name (part after 'Commit-')
""" """
if name == 'notes': if name == 'notes':
self.in_section = 'commit-' + name self.in_section = 'commit-' + name
@ -116,8 +117,9 @@ class PatchStream:
"""Add a response tag to the current commit """Add a response tag to the current commit
Args: Args:
key: rtag type (e.g. 'Reviewed-by') rtag_type (str): rtag type (e.g. 'Reviewed-by')
who: Person who gave that rtag, e.g. 'Fred Bloggs <fred@bloggs.org>' who (str): Person who gave that rtag, e.g.
'Fred Bloggs <fred@bloggs.org>'
""" """
self.commit.AddRtag(rtag_type, who) self.commit.AddRtag(rtag_type, who)
@ -139,11 +141,14 @@ class PatchStream:
"""Parse a version from a *-changes tag """Parse a version from a *-changes tag
Args: Args:
value: Tag value (part after 'xxx-changes: ' value (str): Tag value (part after 'xxx-changes: '
line: Source line containing tag line (str): Source line containing tag
Returns: Returns:
The version as an integer int: The version as an integer
Raises:
ValueError: the value cannot be converted
""" """
try: try:
return int(value) return int(value)
@ -184,10 +189,14 @@ class PatchStream:
don't want, and add things we think are required. don't want, and add things we think are required.
Args: Args:
line: text line to process line (str): text line to process
Returns: Returns:
list of output lines, or [] if nothing should be output list: list of output lines, or [] if nothing should be output
Raises:
ValueError: a fatal error occurred while parsing, e.g. an END
without a starting tag, or two commits with two change IDs
""" """
# Initially we have no output. Prepare the input line string # Initially we have no output. Prepare the input line string
out = [] out = []
@ -428,7 +437,7 @@ class PatchStream:
and the prefix. and the prefix.
Args: Args:
outfd: Output stream file object outfd (io.IOBase): Output stream file object
""" """
if not self.commit.change_id: if not self.commit.change_id:
return return
@ -468,8 +477,8 @@ class PatchStream:
This is used to process patch files one at a time. This is used to process patch files one at a time.
Args: Args:
infd: Input stream file object infd (io.IOBase): Input stream file object
outfd: Output stream file object outfd (io.IOBase): Output stream file object
""" """
# Extract the filename from each diff, for nice warnings # Extract the filename from each diff, for nice warnings
fname = None fname = None
@ -510,14 +519,15 @@ def get_metadata_for_list(commit_range, git_dir=None, count=None,
are interested in. are interested in.
Args: Args:
commit_range: Range of commits to count (e.g. 'HEAD..base') commit_range (str): Range of commits to count (e.g. 'HEAD..base')
git_dir: Path to git repositiory (None to use default) git_dir (str): Path to git repositiory (None to use default)
count: Number of commits to list, or None for no limit count (int): Number of commits to list, or None for no limit
series: Series object to add information into. By default a new series series (Series): Object to add information into. By default a new series
is started. is started.
allow_overwrite: Allow tags to overwrite an existing tag allow_overwrite (bool): Allow tags to overwrite an existing tag
Returns: Returns:
A Series object containing information about the commits. Series: Object containing information about the commits.
""" """
if not series: if not series:
series = Series() series = Series()
@ -538,9 +548,12 @@ def get_metadata(branch, start, count):
are interested in. are interested in.
Args: Args:
branch: Branch to use (None for current branch) branch (str): Branch to use (None for current branch)
start: Commit to start from: 0=branch HEAD, 1=next one, etc. start (int): Commit to start from: 0=branch HEAD, 1=next one, etc.
count: Number of commits to list count (int): Number of commits to list
Returns:
Series: Object containing information about the commits.
""" """
return get_metadata_for_list( return get_metadata_for_list(
'%s~%d' % (branch if branch else 'HEAD', start), None, count) '%s~%d' % (branch if branch else 'HEAD', start), None, count)
@ -550,6 +563,9 @@ def get_metadata_for_test(text):
Args: Args:
text: text:
Returns:
Series: Object containing information about the commits.
""" """
series = Series() series = Series()
pst = PatchStream(series, is_log=True) pst = PatchStream(series, is_log=True)
@ -567,11 +583,13 @@ def fix_patch(backup_dir, fname, series, cmt):
A backup file is put into backup_dir (if not None). A backup file is put into backup_dir (if not None).
Args: Args:
fname: Filename to patch file to process backup_dir (str): Path to directory to use to backup the file
series: Series information about this patch set fname (str): Filename to patch file to process
cmt: Commit object for this patch file series (Series): Series information about this patch set
cmt (Commit): Commit object for this patch file
Return: Return:
A list of errors, or [] if all ok. list: A list of errors, each str, or [] if all ok.
""" """
handle, tmpname = tempfile.mkstemp() handle, tmpname = tempfile.mkstemp()
outfd = os.fdopen(handle, 'w', encoding='utf-8') outfd = os.fdopen(handle, 'w', encoding='utf-8')
@ -594,8 +612,8 @@ def fix_patches(series, fnames):
The patch files are processed in place, and overwritten. The patch files are processed in place, and overwritten.
Args: Args:
series: The series object series (Series): The Series object
fnames: List of patch files to process fnames (:type: list of str): List of patch files to process
""" """
# Current workflow creates patches, so we shouldn't need a backup # Current workflow creates patches, so we shouldn't need a backup
backup_dir = None #tempfile.mkdtemp('clean-patch') backup_dir = None #tempfile.mkdtemp('clean-patch')
@ -617,9 +635,9 @@ def insert_cover_letter(fname, series, count):
"""Inserts a cover letter with the required info into patch 0 """Inserts a cover letter with the required info into patch 0
Args: Args:
fname: Input / output filename of the cover letter file fname (str): Input / output filename of the cover letter file
series: Series object series (Series): Series object
count: Number of patches in the series count (int): Number of patches in the series
""" """
fil = open(fname, 'r') fil = open(fname, 'r')
lines = fil.readlines() lines = fil.readlines()