Ticket #12037 (closed enhancement: fixed)

Opened 19 months ago

Last modified 19 months ago

`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

trac_12037.patch Download (821 bytes) - added by ddrake 19 months ago.

Change History

comment:1 follow-up: ↓ 2 Changed 19 months ago by jhpalmieri

I've been annoyed about this too. Something like this should do it:

  • sage/misc/sagedoc.py

    diff --git a/sage/misc/sagedoc.py b/sage/misc/sagedoc.py
    a b You can build this with 'sage -docbuild  
    695695    # done with preparation; ready to start search 
    696696    for dirpath, dirs, files in os.walk(os.path.join(base_path, module)): 
    697697        for f in files: 
     698            # if f matches some pattern because it's a temporary file, skip it: 
     699            if f.startswith('.#'): 
     700                continue 
    698701            if re.search("\.(" + "|".join(exts) + ")$", f): 
    699702                filename = os.path.join(dirpath, f) 
    700703                if re.search(path_re, filename): 

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 ".#..."?

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).

Changed 19 months ago by ddrake

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!

comment:9 Changed 19 months ago by jdemeyer

  • Status changed from positive_review to closed
  • Resolution set to fixed
  • Merged in set to sage-4.8.alpha2
Note: See TracTickets for help on using tickets.