Ticket #12037 (closed enhancement: fixed)
`search_src` and friends shouldn't look in hidden files
| Reported by: | ddrake | Owned by: | jason |
|---|---|---|---|
| Priority: | major | Milestone: | sage-4.8 |
| Component: | misc | Keywords: | |
| Cc: | Work issues: | ||
| Report Upstream: | N/A | Reviewers: | John Palmieri |
| Authors: | Dan Drake | Merged in: | sage-4.8.alpha2 |
| Dependencies: | Stopgaps: |
Description
I'm currently editing a file in the Sage library, and emacs created a hidden file .#plot.py that, until I save plot.py, is a broken symlink. When I do search_def, I get:
IOError: [Errno 2] No such file or directory: '/scratch/sage-4.7.2/devel/sage/sage/plot/.#plot.py'
I think search_src and friends should just ignore hidden files, since no genuine source file in the Sage library is hidden!
Attachments
Change History
comment:2 in reply to: ↑ 1 Changed 19 months ago by ddrake
Replying to jhpalmieri:
Are there any patterns to ignore besides ".#..."?
I would ignore all hidden files. Do we only look through .py and .pyx files? Because emacs also makes a #plot.py# file which we should ignore. I know vim makes .foo.swp files, and I don't know anything about any other editor.
comment:3 Changed 19 months ago by kini
I notice that ls -B (from GNU coreutils anyway) ignores files that end with "~". Not that ls has anything to do with search_src() in particular, but maybe we should consider ignoring those too since such a universal tool considers them ignore-worthy.
comment:4 Changed 19 months ago by jhpalmieri
As it is, the search functions only look at files ending in .html (for search_doc) or ['.py', '.pyx', '.pxd'] (for search_src and search_def). So we don't need to worry about suffixes, just prefixes.
comment:5 Changed 19 months ago by kini
Ah, good point. Never mind then. This also means that looking for ^#(.*)#$ is unnecessary (emacs seems to produce these too, at least on my machine).
comment:6 Changed 19 months ago by ddrake
- Status changed from new to needs_review
- Authors set to Dan Drake
A one-line patch! Please review.
(John, I modified your example. Add yourself to the author field if you like.)
I tested this by creating a dangling symlink; I suppose I can make a doctest to test that, but that doesn't seem all that necessary. Should I do so anyway?
comment:7 follow-up: ↓ 8 Changed 19 months ago by jhpalmieri
- Status changed from needs_review to positive_review
- Reviewers set to John Palmieri
How could you doctest this?
comment:8 in reply to: ↑ 7 Changed 19 months ago by ddrake
Replying to jhpalmieri:
How could you doctest this?
I'm not sure...create a hidden file with an unlikely string in it, do search_src for that string? Check it returns nothing?
OTOH, I feel pretty confident about the code "not f.startswith('.')". So it seems reasonable to leave this one as it is.
Thanks for the review!


I've been annoyed about this too. Something like this should do it:
sage/misc/sagedoc.py
But maybe a regular expression match for temporary files would be better, perhaps combined with the line "if re.search(...)". Are there any patterns to ignore besides ".#..."?