Move PrefixedCommandRunner -> Prefix

This commit is contained in:
Anthony Sottile 2018-01-11 21:41:48 -08:00
parent c751f629a6
commit 7d87da8acd
23 changed files with 270 additions and 372 deletions

20
pre_commit/prefix.py Normal file
View file

@ -0,0 +1,20 @@
from __future__ import unicode_literals
import os.path
class Prefix(object):
def __init__(self, prefix_dir):
self.prefix_dir = prefix_dir.rstrip(os.sep) + os.sep
def path(self, *parts):
path = os.path.join(self.prefix_dir, *parts)
return os.path.normpath(path)
def exists(self, *parts):
return os.path.exists(self.path(*parts))
def star(self, end):
return tuple(
path for path in os.listdir(self.prefix_dir) if path.endswith(end)
)