简而言之,它的目标是更容易地管理许多不同的项目。
其中一个有用的方法是自动检测我正在工作的项目类型,正确设置一些命令。在
目前我正在使用一个classmethod“match”函数和一个遍历各种“match”的detect函数。
我肯定有更好的设计,但是找不到。在
有什么想法吗?在class ProjectType(object):
build_cmd = ""
@classmethod
def match(cls, _):
return True
class PythonProject(ProjectType):
build_cmd = "python setup.py develop --user"
@classmethod
def match(cls, base):
return path.isfile(path.join(base, 'setup.py'))
class AutoconfProject(ProjectType):
#TODO: there should be also a way to configure it
build_cmd = "./configure && make -j3"
@classmethod
def match(cls, base):
markers = ('configure.in', 'configure.ac', 'makefile.am')
return any(path.isfile(path.join(base, x)) for x in markers)
class MakefileOnly(ProjectType):
build_cmd = "make"
@classmethod
def match(cls, base):
# if we can count on the order the first check is not useful
return (not AutoconfProject.match(base)) and \
(path.isfile(path.join(base, 'Makefile')))
def detect_project_type(path):
prj_types = (PythonProject, AutoconfProject, MakefileOnly, ProjectType)
for p in prj_types:
if p.match(path):
return p()