-
Notifications
You must be signed in to change notification settings - Fork 56
Add --force-filetype option to force a filetype for an instance file #557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,11 +65,16 @@ def __init__( | |
} | ||
|
||
def get( | ||
self, path: pathlib.Path | str, default_filetype: str | ||
self, | ||
path: pathlib.Path | str, | ||
default_filetype: str, | ||
force_filetype: str | None, | ||
mschoettle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
) -> t.Callable[[t.IO[bytes]], t.Any]: | ||
filetype = path_to_type(path, default_type=default_filetype) | ||
|
||
if filetype in self._by_tag: | ||
filetype = force_filetype or filetype | ||
|
||
|
||
return self._by_tag[filetype] | ||
|
||
if filetype in MISSING_SUPPORT_MESSAGES: | ||
|
@@ -83,16 +88,25 @@ def get( | |
) | ||
|
||
def parse_data_with_path( | ||
self, data: t.IO[bytes] | bytes, path: pathlib.Path | str, default_filetype: str | ||
self, | ||
data: t.IO[bytes] | bytes, | ||
path: pathlib.Path | str, | ||
default_filetype: str, | ||
force_filetype: str | None, | ||
mschoettle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
) -> t.Any: | ||
loadfunc = self.get(path, default_filetype) | ||
loadfunc = self.get(path, default_filetype, force_filetype) | ||
try: | ||
if isinstance(data, bytes): | ||
data = io.BytesIO(data) | ||
return loadfunc(data) | ||
except LOADING_FAILURE_ERROR_TYPES as e: | ||
raise FailedFileLoadError(f"Failed to parse {path}") from e | ||
|
||
def parse_file(self, path: pathlib.Path | str, default_filetype: str) -> t.Any: | ||
def parse_file( | ||
self, | ||
path: pathlib.Path | str, | ||
default_filetype: str, | ||
force_filetype: str | None, | ||
mschoettle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
) -> t.Any: | ||
with open(path, "rb") as fp: | ||
return self.parse_data_with_path(fp, path, default_filetype) | ||
return self.parse_data_with_path(fp, path, default_filetype, force_filetype) |
Uh oh!
There was an error while loading. Please reload this page.