Skip to content

Add docstrings to functions, methods, and class in announce.py and contributors.py #59049

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

Closed
wants to merge 3 commits into from
Closed
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
73 changes: 73 additions & 0 deletions doc/sphinxext/announce.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@


def get_authors(revision_range):
"""
Finds and returns authors within the revision range.

Parameters
-----------
revision_range : str
Revision range to search for authors.

Returns
-------
list[str]
List of authors in the revision range.


"""
pat = "^.*\\t(.*)$"
lst_release, cur_release = (r.strip() for r in revision_range.split(".."))

Expand Down Expand Up @@ -109,6 +124,22 @@ def get_authors(revision_range):


def get_pull_requests(repo, revision_range):
"""
Finds and returns pull requests within the revision range.

Parameters
-----------
repo : github.Repository.Repository
GitHub repository object.
revision_range : str
Revision range to search for pull requests.

Returns
-------
list[github.PullRequest.PullRequest]
List of pull requests in the revision range.
"""

prnums = []

# From regular merges
Expand All @@ -134,6 +165,21 @@ def get_pull_requests(repo, revision_range):


def build_components(revision_range, heading="Contributors"):
"""
Builds components for the release announcement.

Parameters
-----------
revision_range : str
Revision range to search for authors.
heading : str
Heading for the announcement.

Returns
-------
dict[str, str]
Dictionary containing the components for the announcement.
"""
lst_release, cur_release = (r.strip() for r in revision_range.split(".."))
authors = get_authors(revision_range)

Expand All @@ -145,6 +191,21 @@ def build_components(revision_range, heading="Contributors"):


def build_string(revision_range, heading="Contributors"):
"""
Builds a string for the release announcement.

Parameters
-----------
revision_range : str
Revision range to search for authors.
heading : str
Heading for the announcement.

Returns
-------
str
String for the release announcement.
"""
components = build_components(revision_range, heading=heading)
components["uline"] = "=" * len(components["heading"])
components["authors"] = "* " + "\n* ".join(components["authors"])
Expand All @@ -162,6 +223,18 @@ def build_string(revision_range, heading="Contributors"):


def main(revision_range):
"""
Main function for generating author lists for release.

Parameters
-----------
revision_range : str
Revision range to search for authors.

Returns
-------
None
"""
# document authors
text = build_string(revision_range)
print(text)
Expand Down
25 changes: 25 additions & 0 deletions doc/sphinxext/contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,22 @@


class ContributorsDirective(Directive):
"""
Directive to list contributors to a release.
"""

required_arguments = 1
name = "contributors"

def run(self):
"""
Run the directive.

Returns
-------
list[docutils.nodes.Node]
List of nodes to include in the document.
"""
range_ = self.arguments[0]
if range_.endswith("x..HEAD"):
return [nodes.paragraph(), nodes.bullet_list()]
Expand Down Expand Up @@ -53,6 +65,19 @@ def run(self):


def setup(app):
"""
Set up the extension.

Parameters
----------
app : Sphinx
The Sphinx application.

Returns
-------
dict
Metadata for the extension.
"""
app.add_directive("contributors", ContributorsDirective)

return {"version": "0.1", "parallel_read_safe": True, "parallel_write_safe": True}