我想忽略所有.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