Skip to content

Commit 97f891f

Browse files
Revert "Change when we do source file verification (#344)"
This reverts commit 31fd7d5.
1 parent 31fd7d5 commit 97f891f

File tree

1 file changed

+15
-42
lines changed

1 file changed

+15
-42
lines changed

pypandoc/__init__.py

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -138,61 +138,34 @@ def convert_file(source_file:Union[list, str, Path, Generator], to:str, format:U
138138
:raises OSError: if pandoc is not found; make sure it has been installed and is available at
139139
path.
140140
"""
141-
# check if we have a working directory
142-
# if we don't, we use the current working directory
143-
if cworkdir is None:
144-
cworkdir = os.getcwd()
145-
146141
# TODO: remove 'encoding' parameter and warning
147142
if encoding != "utf-8":
148143
logger.warning("The 'encoding' parameter will be removed in version 1.13. Just remove the parameter, because currently the method does not use it.")
149144

145+
# This if block effectively adds support for pathlib.Path objects
146+
# and generators produced by pathlib.Path().glob().
147+
if not isinstance(source_file, str):
148+
try:
149+
source_file = list(map(str, source_file))
150+
except TypeError:
151+
source_file = str(source_file)
152+
153+
if not _identify_path(source_file):
154+
raise RuntimeError("source_file is not a valid path")
150155
if _is_network_path(source_file): # if the source_file is an url
151156
format = _identify_format_from_path(source_file, format)
152157
return _convert_input(source_file, format, 'path', to, extra_args=extra_args,
153158
outputfile=outputfile, filters=filters,
154159
verify_format=verify_format, sandbox=sandbox,
155160
cworkdir=cworkdir)
156161

157-
# convert the source file to a path object internally
158-
if isinstance(source_file, str):
159-
source_file = Path(source_file)
160-
elif isinstance(source_file, list):
161-
source_file = [Path(x) for x in source_file]
162-
elif isinstance(source_file, Generator):
163-
source_file = [Path(x) for x in source_file]
164-
165-
166-
# we are basically interested to figure out if its an absolute path or not
167-
# if it's not, we want to prefix the working directory
168-
# if it's a list, we want to prefix the working directory to each item if it's not an absolute path
169-
# if it is, just use the absolute path
170-
if isinstance(source_file, list):
171-
source_file = [x if x.is_absolute() else Path(cworkdir, x) for x in source_file]
172-
elif isinstance(source_file, Generator):
173-
source_file = (x if x.is_absolute() else Path(cworkdir, x) for x in source_file)
174-
# check ifjust a single path was given
175-
elif isinstance(source_file, Path):
176-
source_file = source_file if source_file.is_absolute() else Path(cworkdir, source_file)
177-
178-
179162
discovered_source_files = []
180-
# if we have a list of files, we need to glob them
181-
# if we have a single file, we need to glob it
182-
# remember that we already converted the source_file to a path object
183-
# so for glob.glob use both the dir and file name
184-
if isinstance(source_file, list):
185-
for single_source in source_file:
186-
discovered_source_files.extend(glob.glob(str(single_source)))
187-
if discovered_source_files == []:
188-
discovered_source_files = source_file
189-
else:
190-
discovered_source_files.extend(glob.glob(str(source_file)))
191-
if discovered_source_files == []:
192-
discovered_source_files = [source_file]
163+
if isinstance(source_file, str):
164+
discovered_source_files += glob.glob(source_file)
165+
if isinstance(source_file, list): # a list of possibly file or file patterns. Expand all with glob
166+
for filepath in source_file:
167+
discovered_source_files.extend(glob.glob(filepath))
193168

194-
if not _identify_path(discovered_source_files):
195-
raise RuntimeError("source_file is not a valid path")
196169
format = _identify_format_from_path(discovered_source_files[0], format)
197170
if len(discovered_source_files) == 1:
198171
discovered_source_files = discovered_source_files[0]

0 commit comments

Comments
 (0)