Ejemplo n.º 1
0
    def _get_roots(self, context: ILoadingContext) -> Iterator[Path]:
        """Return the configured root directories."""
        if self._allow_relative:
            current_location = context.current_location()
            if current_location is not None:
                file_path = Path(current_location)
                parent = file_path.parent
                if parent.is_dir():
                    yield parent

        config = context.get_config(PathHandler.Config)
        if config is not None:
            for root in config.roots:
                yield root
Ejemplo n.º 2
0
    def _convert(self, context: ILoadingContext, value: str) -> Any:
        path = Path(value)

        if not path.is_absolute() and not path.exists():
            location_str = context.current_location()
            if location_str is not None:
                location = Path(location_str)
                parent = location.parent
                path = parent / path

        if self._must_exist and not path.exists():
            context.error(ErrorCode.VALIDATION_ERROR, _("Cannot find path {}."), path)
            return UNDEFINED

        return path
Ejemplo n.º 3
0
 def _load(self, context: ILoadingContext) -> None:
     assert context.current_location() == location
Ejemplo n.º 4
0
 def validate(cls, context: ILoadingContext) -> None:
     """Validate that context as correct current_node_path."""
     nonlocal validate_called
     validate_called = True
     assert context.current_location() == str(file_path)