Example #1
0
 def add_field_from(path: Path):
     data.add_field(
         name='files',
         value=exitstack.enter_context(
             open(complete_path(path) if complete else path, 'rb')),
         filename=path.name,
     )
Example #2
0
    def add(self, path: Path):
        """add a field to Form

        :param path: filepath
        """
        self.add_field(
            name='files',
            value=self._stack.enter_context(
                open(
                    complete_path(path, extra_search_paths=[self._cur_dir])
                    if self._complete else path,
                    'rb',
                )),
            filename=path.name,
        )
Example #3
0
    def add_modules(*paths):
        """
        Import modules from paths.

        :param paths: Paths of the modules.
        """
        from jina.jaml.helper import complete_path

        paths = [complete_path(m) for m in paths]

        for p in paths:
            if not os.path.exists(p):
                raise FileNotFoundError(
                    f'cannot import module from {p}, file not exist')

            _path_import(p)
Example #4
0
    def filepaths(self) -> List[Path]:
        """Get file/directories to be uploaded to remote workspace

        :return: filepaths to be uploaded to remote
        """
        paths = set()
        if not self.args.upload_files:
            self._logger.warning(f'no files passed to upload to remote')
        else:
            for path in self.args.upload_files:
                try:
                    fullpath = Path(complete_path(path))
                    paths.add(fullpath)
                except FileNotFoundError:
                    self._logger.error(f'invalid path {path} passed')

        return list(paths)
Example #5
0
def test_complete_path_not_found():
    with pytest.raises(FileNotFoundError):
        assert complete_path('unknown.yaml')
Example #6
0
def test_complete_path_success():
    assert complete_path('test_helper.py')
    assert complete_path('helper.py')
    assert complete_path('bash')
Example #7
0
 def valid_path(path):
     try:
         complete_path(path)
         return True
     except FileNotFoundError:
         return False