Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Llama Index
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
run-llama
Llama Index
Commits
c24b9650
Unverified
Commit
c24b9650
authored
1 year ago
by
Sai Ramana Reddy
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix path implementation for non-local FS (#12141)
parent
ae382b7f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
llama-index-core/llama_index/core/readers/file/base.py
+11
-8
11 additions, 8 deletions
llama-index-core/llama_index/core/readers/file/base.py
with
11 additions
and
8 deletions
llama-index-core/llama_index/core/readers/file/base.py
+
11
−
8
View file @
c24b9650
...
@@ -8,7 +8,7 @@ import warnings
...
@@ -8,7 +8,7 @@ import warnings
from
datetime
import
datetime
from
datetime
import
datetime
from
functools
import
reduce
from
functools
import
reduce
from
itertools
import
repeat
from
itertools
import
repeat
from
pathlib
import
Path
from
pathlib
import
Path
,
PurePosixPath
import
fsspec
import
fsspec
from
fsspec.implementations.local
import
LocalFileSystem
from
fsspec.implementations.local
import
LocalFileSystem
from
typing
import
Any
,
Callable
,
Dict
,
Generator
,
List
,
Optional
,
Type
from
typing
import
Any
,
Callable
,
Dict
,
Generator
,
List
,
Optional
,
Type
...
@@ -196,18 +196,19 @@ class SimpleDirectoryReader(BaseReader):
...
@@ -196,18 +196,19 @@ class SimpleDirectoryReader(BaseReader):
self
.
exclude_hidden
=
exclude_hidden
self
.
exclude_hidden
=
exclude_hidden
self
.
required_exts
=
required_exts
self
.
required_exts
=
required_exts
self
.
num_files_limit
=
num_files_limit
self
.
num_files_limit
=
num_files_limit
_Path
=
Path
if
is_default_fs
(
self
.
fs
)
else
PurePosixPath
if
input_files
:
if
input_files
:
self
.
input_files
=
[]
self
.
input_files
=
[]
for
path
in
input_files
:
for
path
in
input_files
:
if
not
self
.
fs
.
isfile
(
path
):
if
not
self
.
fs
.
isfile
(
path
):
raise
ValueError
(
f
"
File
{
path
}
does not exist.
"
)
raise
ValueError
(
f
"
File
{
path
}
does not exist.
"
)
input_file
=
Path
(
path
)
input_file
=
_
Path
(
path
)
self
.
input_files
.
append
(
input_file
)
self
.
input_files
.
append
(
input_file
)
elif
input_dir
:
elif
input_dir
:
if
not
self
.
fs
.
isdir
(
input_dir
):
if
not
self
.
fs
.
isdir
(
input_dir
):
raise
ValueError
(
f
"
Directory
{
input_dir
}
does not exist.
"
)
raise
ValueError
(
f
"
Directory
{
input_dir
}
does not exist.
"
)
self
.
input_dir
=
Path
(
input_dir
)
self
.
input_dir
=
_
Path
(
input_dir
)
self
.
exclude
=
exclude
self
.
exclude
=
exclude
self
.
input_files
=
self
.
_add_files
(
self
.
input_dir
)
self
.
input_files
=
self
.
_add_files
(
self
.
input_dir
)
...
@@ -229,20 +230,22 @@ class SimpleDirectoryReader(BaseReader):
...
@@ -229,20 +230,22 @@ class SimpleDirectoryReader(BaseReader):
all_files
=
set
()
all_files
=
set
()
rejected_files
=
set
()
rejected_files
=
set
()
rejected_dirs
=
set
()
rejected_dirs
=
set
()
# Default to POSIX paths for non-default file systems (e.g. S3)
_Path
=
Path
if
is_default_fs
(
self
.
fs
)
else
PurePosixPath
if
self
.
exclude
is
not
None
:
if
self
.
exclude
is
not
None
:
for
excluded_pattern
in
self
.
exclude
:
for
excluded_pattern
in
self
.
exclude
:
if
self
.
recursive
:
if
self
.
recursive
:
# Recursive glob
# Recursive glob
excluded_glob
=
Path
(
input_dir
)
/
Path
(
"
**
"
)
/
excluded_pattern
excluded_glob
=
_
Path
(
input_dir
)
/
_
Path
(
"
**
"
)
/
excluded_pattern
else
:
else
:
# Non-recursive glob
# Non-recursive glob
excluded_glob
=
Path
(
input_dir
)
/
excluded_pattern
excluded_glob
=
_
Path
(
input_dir
)
/
excluded_pattern
for
file
in
self
.
fs
.
glob
(
str
(
excluded_glob
)):
for
file
in
self
.
fs
.
glob
(
str
(
excluded_glob
)):
if
self
.
fs
.
isdir
(
file
):
if
self
.
fs
.
isdir
(
file
):
rejected_dirs
.
add
(
Path
(
file
))
rejected_dirs
.
add
(
_
Path
(
file
))
else
:
else
:
rejected_files
.
add
(
Path
(
file
))
rejected_files
.
add
(
_
Path
(
file
))
file_refs
:
List
[
str
]
=
[]
file_refs
:
List
[
str
]
=
[]
if
self
.
recursive
:
if
self
.
recursive
:
...
@@ -253,7 +256,7 @@ class SimpleDirectoryReader(BaseReader):
...
@@ -253,7 +256,7 @@ class SimpleDirectoryReader(BaseReader):
for
ref
in
file_refs
:
for
ref
in
file_refs
:
# Manually check if file is hidden or directory instead of
# Manually check if file is hidden or directory instead of
# in glob for backwards compatibility.
# in glob for backwards compatibility.
ref
=
Path
(
ref
)
ref
=
_
Path
(
ref
)
is_dir
=
self
.
fs
.
isdir
(
ref
)
is_dir
=
self
.
fs
.
isdir
(
ref
)
skip_because_hidden
=
self
.
exclude_hidden
and
self
.
is_hidden
(
ref
)
skip_because_hidden
=
self
.
exclude_hidden
and
self
.
is_hidden
(
ref
)
skip_because_bad_ext
=
(
skip_because_bad_ext
=
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment