(self, state: 'ModuleState', args: T.Tuple['FileOrString'], kwargs: 'ReadKwArgs')
return data
Read a file from the source tree and return its value as a decoded
        string.

        If the encoding is not specified, the file is assumed to be utf-8
        encoded. Paths must be relative by default (to prevent accidents) and
        are forbidden to be read from the build directory (to prevent build
        loops)
Read a file from the source tree and return its value as a decoded
        string.
Read a file from the source tree and return its value as a decoded string .
def read(self, state: 'ModuleState', args: T.Tuple['FileOrString'], kwargs: 'ReadKwArgs') -> str:
        """Read a file from the source tree and return its value as a decoded
        string.

        If the encoding is not specified, the file is assumed to be utf-8
        encoded. Paths must be relative by default (to prevent accidents) and
        are forbidden to be read from the build directory (to prevent build
        loops)
        """
        path = args[0]
        encoding = kwargs['encoding']
        src_dir = self.interpreter.environment.source_dir
        sub_dir = self.interpreter.subdir
        build_dir = self.interpreter.environment.get_build_dir()

        if isinstance(path, File):
            if path.is_built:
                raise MesonException(
                    'fs.read_file does not accept built files() objects')
            path = os.path.join(src_dir, path.relative_name())
        else:
            if sub_dir:
                src_dir = os.path.join(src_dir, sub_dir)
            path = os.path.join(src_dir, path)

        path = os.path.abspath(path)
        if path_is_in_root(Path(path), Path(build_dir), resolve=True):
            raise MesonException('path must not be in the build tree')
        try:
            with open(path, encoding=encoding) as f:
                data = f.read()
        except UnicodeDecodeError:
            raise MesonException(f'decoding failed for {path}')
        # Reconfigure when this file changes as it can contain data used by any
        # part of the build configuration (e.g. `project(..., version:
        # fs.read_file('VERSION')` or `configure_file(...)`
        self.interpreter.add_build_def_file(path)
        return data
def read ( self , state : 'ModuleState' , args : T . Tuple [ 'FileOrString' ] , kwargs : 'ReadKwArgs' ) -> str : path = args [ 0 ] encoding = kwargs [ 'encoding' ] src_dir = self . interpreter . environment . source_dir sub_dir = self . interpreter . subdir build_dir = self . interpreter . environment . get_build_dir ( ) if isinstance ( path , File ) : if path . is_built : raise MesonException ( 'fs.read_file does not accept built files() objects' ) path = os . path . join ( src_dir , path . relative_name ( ) ) else : if sub_dir : src_dir = os . path . join ( src_dir , sub_dir ) path = os . path . join ( src_dir , path ) path = os . path . abspath ( path ) if path_is_in_root ( Path ( path ) , Path ( build_dir ) , resolve = True ) : raise MesonException ( 'path must not be in the build tree' ) try : with open ( path , encoding = encoding ) as f : data = f . read ( ) except UnicodeDecodeError : raise MesonException ( f'decoding failed for {path}' ) # Reconfigure when this file changes as it can contain data used by any # part of the build configuration (e.g. `project(..., version: # fs.read_file('VERSION')` or `configure_file(...)` self . interpreter . add_build_def_file ( path ) return data