8000 bpo-23216: IDLE: Add docstrings to search modules by csabella · Pull Request #12141 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-23216: IDLE: Add docstrings to search modules #12141

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

Merged
merged 6 commits into from
Mar 16, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Enhance docstrings for grep.py
  • Loading branch information
csabella committed Mar 5, 2019
commit 8e3fe18f12f35b962f5652ed8b1c6645acf1f32d
46 changes: 36 additions & 10 deletions Lib/idlelib/grep.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@
from idlelib import searchengine

# Importing OutputWindow here fails due to import loop
# EditorWindow -> GrepDialop -> OutputWindow -> EditorWindow
# EditorWindow -> GrepDialog -> OutputWindow -> EditorWindow


def grep(text, io=None, flist=None):
"""Create or find singleton GrepDialog instance.
"""Open the Find in Files dialog.

Module-level function to access the singleton GrepDialog
instance and open the dialog. If text is selected, it is
used as the search phrase; otherwise, the previous entry
is used.

Args:
text: Text widget that contains the selected text for
default search phrase.
io: iomenu.IOBinding instance with default path to search.
flist: filelist.FileList instance for OutputWindow parent.
"""

root = text._root()
engine = searchengine.get(root)
if not hasattr(engine, "_grepdialog"):
Expand All @@ -50,17 +54,29 @@ def __init__(self, root, engine, flist):
searchengine instance to prepare the search.

Attributes:
globvar: Value of Text Entry widget for path to search.
recvar: Boolean value of Checkbutton widget
for traversing through subdirectories.
flist: filelist.Filelist instance for OutputWindow parent.
globvar: String value of Entry widget for path to search.
globent: Entry widget for globvar. Created in
create_entries().
recvar: Boolean value of Checkbutton widget for
traversing through subdirectories.
"""
SearchDialogBase.__init__(self, root, engine)
super().__init__(root, engine)
self.flist = flist
self.globvar = StringVar(root)
self.recvar = BooleanVar(root)

def open(self, text, searchphrase, io=None):
"Make dialog visible on top of others and ready to use."
"""Make dialog visible on top of others and ready to use.

Extend the SearchDialogBase open() to set the initial value
for globvar.

Args:
text: Multicall object containing the text information.
searchphrase: String phrase to search.
io: iomenu.IOBinding instance containing file path.
"""
SearchDialogBase.open(self, text, searchphrase)
if io:
path = io.filename or ""
Expand All @@ -85,9 +101,9 @@ def create_other_buttons(self):
btn.pack(side="top", fill="both")

def create_command_buttons(self):
"Create base command buttons and add button for search."
"Create base command buttons and add button for Search Files."
SearchDialogBase.create_command_buttons(self)
self.make_button("Search Files", self.default_command, 1)
self.make_button("Search Files", self.default_command, isdef=True)

def default_command(self, event=None):
"""Grep for search pattern in file path. The default command is bound
Expand Down Expand Up @@ -119,6 +135,10 @@ def grep_it(self, prog, path):
search each line for the matching pattern. If the pattern is
found, write the file and line information to stdout (which
is an OutputWindow).

Args:
prog: The compiled, cooked search pattern.
path: String containing the search path.
"""
dir, base = os.path.split(path)
list = self.findfiles(dir, base, self.recvar.get())
Expand Down Expand Up @@ -149,7 +169,13 @@ def grep_it(self, prog, path):
def findfiles(self, dir, base, rec):
"""Return list of files in the dir that match the base pattern.

Use the current directory if dir has no value.
If rec is True, recursively iterate through subdirectories.

Args:
dir: Directory path to search.
base: File search pattern.
rec: Boolean for recursive search through subdirectories.
"""
try:
names = os.listdir(dir or os.curdir)
Expand Down
0