fs: deduplicate functions

pull/6150/head
Michael Hirsch, Ph.D 5 years ago
parent 3bbd065576
commit 9fc76b0323
No known key found for this signature in database
GPG Key ID: 6D23CDADAB0294F9
  1. 13
      mesonbuild/modules/fs.py

@ -29,20 +29,17 @@ class FSModule(ExtensionModule):
super().__init__(interpreter)
self.snippets.add('generate_dub_file')
@stringArgs
@noKwargs
def exists(self, state: 'ModuleState', args: typing.Sequence[str], kwargs: dict) -> ModuleReturnValue:
if len(args) != 1:
MesonException('method takes exactly one argument.')
test_file = Path(state.source_root) / state.subdir / args[0]
return ModuleReturnValue(test_file.exists(), [])
def _check(self, check: str, state: 'ModuleState', args: typing.Sequence[str]) -> ModuleReturnValue:
if len(args) != 1:
MesonException('method takes exactly one argument.')
test_file = Path(state.source_root) / state.subdir / args[0]
return ModuleReturnValue(getattr(test_file, check)(), [])
@stringArgs
@noKwargs
def exists(self, state: 'ModuleState', args: typing.Sequence[str], kwargs: dict) -> ModuleReturnValue:
return self._check('exists', state, args)
@stringArgs
@noKwargs
def is_symlink(self, state: 'ModuleState', args: typing.Sequence[str], kwargs: dict) -> ModuleReturnValue:

Loading…
Cancel
Save