Regex用于匹配两个子目录中任意一个子目录的任意数量的目录深度



我想忽略所有.git子目录和test子目录。

更大的问题是,我是否可以用一种更可读的方式将其写成非正则表达式。

我想指定compileall 的rx参数

如果正则表达式不适合rx参数,您可以简单地使用名为search的classmethod构造一个满足所需跳过条件的类:

class MyRx(object):
    @classmethod
    def search(cls, p):
        return 'test' in p or '.git' in p

使用

compileall.compile_dir('.', rx=MyRx, ...)

这并没有解决是否可以向rx提供回调方法这一更大的问题,但这似乎对我有效:

compileall.compile_dir('.', maxlevels=20, force=True, 
                       rx=re.compile(r'([/\][.]git|[/\]test)'), quiet=False, 
                       legacy=False, optimize=0)

关于正则表达式运算符的一些文档:

http://metahtml.sourceforge.net/documentation/regex/regex_3.mhtml

最新更新