Skip to content

Commit

Permalink
refactor: move out recursive file paths loop
Browse files Browse the repository at this point in the history
  • Loading branch information
TyShkan committed Mar 24, 2023
1 parent fe28566 commit 4761772
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions tap_csv/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ def get_records(self, context: Optional[dict]) -> Iterable[dict]:

yield dict(zip(self.header, row))

def _get_recursive_file_paths(self, file_path: str) -> list:
file_paths = []

for dirpath, _, filenames in os.walk(file_path):
for filename in filenames:
file_path = os.path.join(dirpath, filename)
if self.is_valid_filename(file_path):
file_paths.append(file_path)

return file_paths

def get_file_paths(self) -> list:
"""Return a list of file paths to read.
Expand All @@ -67,11 +78,7 @@ def get_file_paths(self) -> list:
file_paths = []
if os.path.isdir(file_path):
clean_file_path = os.path.normpath(file_path) + os.sep
for dirpath, _, filenames in os.walk(clean_file_path):
for filename in filenames:
file_path = os.path.join(dirpath, filename)
if self.is_valid_filename(file_path):
file_paths.append(file_path)
file_paths = self._get_recursive_file_paths(clean_file_path)
else:
if self.is_valid_filename(file_path):
file_paths.append(file_path)
Expand Down

0 comments on commit 4761772

Please sign in to comment.