aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/modules/fs.py
diff options
context:
space:
mode:
authorMichael Hirsch, Ph.D <scivision@users.noreply.github.com>2019-11-08 03:11:45 -0500
committerMichael Hirsch, Ph.D <scivision@users.noreply.github.com>2019-11-17 00:17:00 -0500
commit3bbd06557686424d04859973fde21f69a85b47e6 (patch)
tree8f9c80622ddc8caaa283d51b5e515a965c2a75c7 /mesonbuild/modules/fs.py
parentc6f93b6bf67500c963cdaa33b0500ea1a15232b0 (diff)
downloadmeson-3bbd06557686424d04859973fde21f69a85b47e6.zip
meson-3bbd06557686424d04859973fde21f69a85b47e6.tar.gz
meson-3bbd06557686424d04859973fde21f69a85b47e6.tar.bz2
fs: use pathlib.Path, add type hint check
Diffstat (limited to 'mesonbuild/modules/fs.py')
-rw-r--r--mesonbuild/modules/fs.py31
1 files changed, 17 insertions, 14 deletions
diff --git a/mesonbuild/modules/fs.py b/mesonbuild/modules/fs.py
index 61ad917..f4b8080 100644
--- a/mesonbuild/modules/fs.py
+++ b/mesonbuild/modules/fs.py
@@ -12,13 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import os
+import typing
+from pathlib import Path
from . import ExtensionModule
from . import ModuleReturnValue
from ..mesonlib import MesonException
from ..interpreterbase import stringArgs, noKwargs
+if typing.TYPE_CHECKING:
+ from ..interpreter import ModuleState
class FSModule(ExtensionModule):
@@ -28,32 +31,32 @@ class FSModule(ExtensionModule):
@stringArgs
@noKwargs
- def exists(self, state, args, kwargs):
+ def exists(self, state: 'ModuleState', args: typing.Sequence[str], kwargs: dict) -> ModuleReturnValue:
if len(args) != 1:
MesonException('method takes exactly one argument.')
- test_file = os.path.join(state.source_root, state.subdir, args[0])
- return ModuleReturnValue(os.path.exists(test_file), [])
+ test_file = Path(state.source_root) / state.subdir / args[0]
+ return ModuleReturnValue(test_file.exists(), [])
- def _check(self, check_fun, state, args):
+ def _check(self, check: str, state: 'ModuleState', args: typing.Sequence[str]) -> ModuleReturnValue:
if len(args) != 1:
MesonException('method takes exactly one argument.')
- test_file = os.path.join(state.source_root, state.subdir, args[0])
- return ModuleReturnValue(check_fun(test_file), [])
+ test_file = Path(state.source_root) / state.subdir / args[0]
+ return ModuleReturnValue(getattr(test_file, check)(), [])
@stringArgs
@noKwargs
- def is_symlink(self, state, args, kwargs):
- return self._check(os.path.islink, state, args)
+ def is_symlink(self, state: 'ModuleState', args: typing.Sequence[str], kwargs: dict) -> ModuleReturnValue:
+ return self._check('is_symlink', state, args)
@stringArgs
@noKwargs
- def is_file(self, state, args, kwargs):
- return self._check(os.path.isfile, state, args)
+ def is_file(self, state: 'ModuleState', args: typing.Sequence[str], kwargs: dict) -> ModuleReturnValue:
+ return self._check('is_file', state, args)
@stringArgs
@noKwargs
- def is_dir(self, state, args, kwargs):
- return self._check(os.path.isdir, state, args)
+ def is_dir(self, state: 'ModuleState', args: typing.Sequence[str], kwargs: dict) -> ModuleReturnValue:
+ return self._check('is_dir', state, args)
-def initialize(*args, **kwargs):
+def initialize(*args, **kwargs) -> FSModule:
return FSModule(*args, **kwargs)