It looks great to me, although I would make two improvements.
1- Use a metaclass to automatically collect all ProjectTypes, rather than manually listing them, which will avoid skipping any type of project by mistake or in the wrong order, for example.
class ProjectTypeManger(type): klasses = [] def __new__(meta, classname, bases, classDict): klass = type.__new__(meta, classname, bases, classDict) meta.klasses.append(klass) return klass @classmethod def detect_project_type(meta, path): for p in meta.klasses: if p.match(path): return p() class ProjectType(object): __metaclass__ = ProjectTypeManger build_cmd = "" @classmethod def match(cls, _): return None
The 2- match method should return the object itself, not true / false. Thus, the class can configure the object anyway, it wants + you can call the base class mapping method, for example. MakefileOnly can be inferred from AutoconfProject so that it first checks the base class for any matches, but is not sure if such inheritance makes sense
class MakefileOnly(AutoconfProject): build_cmd = "make" @classmethod def match(cls, base): ret = super(MakefileOnly, cls).match(base) if ret is not None: return ret if path.isfile(path.join(base, 'Makefile')): return cls() return None
source share