Search code examples
pythonack

ignore *.egg-info directories with ack-grep


I've noticed that ack-grep doesn't ignore the <module>.egg-info directory that python creates alongside the source code. I was hoping I could add

--ignore-dir=*.egg-info
or
--ignore-file=ext:egg-info

as a catchall without having to add each project's .egg-info directory manually to ~/.ackrc.

Is there a way to do this without having to manually add all of them?


Solution

  • You can use the same filtering system to specify --ignore-dir as you can when specifying types. Use ack --dump to see the default settings, and they should give you an idea of how to do this. (As well as seeing the "Specifying your own types" in the manual at ack --man)

    So you can do this:

    ack --ignore-dir=match:[.]egginfo$ whatever
    

    Note that when you're using match, it's a Perl regular expression, not a glob. What this is saying is "Ignore any directory that matches .egginfo at the end of the name". The . is a metacharacter that is put in a character class ([.]) to remove its special meaning. You could also have used \., but then that runs into confusion with the shell, too.

    So you can drop that --ignore-dir=match:[.]egginfo$ in your ~/.ackrc and not worry about it any more.

    ...

    For those of us who aren't familiar with the Python ecosystem, can you say more about what the <module>.egg-info directories are, and where and how they get created? Is it basically a build directory? I'm the author of ack, and it sounds like something that might be good for ack to ignore by default.