-
Notifications
You must be signed in to change notification settings - Fork 137
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
Allow passing BytesIO objects to xls2xform_convert #698
Conversation
I just added two updates:
|
Hi @spwoodcock, thanks for time preparing this PR. I know we don't have a contributing guidelines in this project repo, so apologies for that, though the ODK docs guidelines has the gist of it. Ideally before opening a PR, a feature request or bug report should be raised on the ODK forum first, or at least in a GitHub issue. That way, the pyxform team can work with contributors to understand the problem or use case, consider design issues or how an implementation might fit into the project functionality without causing regressions, and decide whether it's a change that can reasonably be supported in future with the project's limited resources. The forum has the benefit of higher exposure, so you can potentially get feedback from other users as well. Currently it's unclear as to why, when, or what types of users would need to pass in a BytesIO object to Please help us out by opening an ODK forum thread or GitHub issue to address and discuss the above. Thanks! |
Hi @lindsay-stevens, thanks for the detailed feedback! I agree, it would be a good idea creating a forum post, my apologies. While the documentation is fantastic for users creating XLSForms, there doesn't seem to be much in terms of developer documentation (correct me if I am wrong). There is currently support for passing memory objects in from pyxform.xls2json import parse_file_to_json
from pyxform.builder import create_survey_element_from_dict
xlsform_data = ... # code to get xlsform bytes
json_data = parse_file_to_json(path="/dummy/path/with/file/ext.xls", file_object=xlsform_data)
xform = create_survey_element_from_dict(json_data)
xform_xml = xform.to_xml() If so, could I contribute an example like this to the docs? Funnily enough our use case is exactly the same as pyxform-http, where we have a web API that users can upload XLSForms to. Originally the devs implemented by writing the XLSForm to a temp file, converting and writing the XForm to a temp file, then inserting the XForm bytes into a database, then deleting the temp files. I will open a forum post with all of this info 😄 |
This gets at some questions @lindsay-stevens and I have asked ourselves over the past few years about what Your 4-liner looks ok to me but it would also need to reimplement some logic to support pretty printing, different validators, etc? And I do think the question of what the interface should be for a client that wants to convert an in-memory XLSForm into an in-memory XForm would make for a good forum discussion topic if you're up for moving the discussion there so it gets more visibility. |
Closing in favour of #712 |
Included
xls2xform_convert
, with output of the converted XForm as a BytesIO object also.xls2json
andxls2json_backends
, but it was not included in higher levelxls2xform_convert
.xlsform_path
when `xlsform_object=BytesIO(...). However, this is required to not break existing functionality.xlsform_path=/tmp/form.xls
orxlsform_path=/tmp/form.xlsx
allows us to determine the type of form input (XLS, XLSX, or CSV formats).We do need to know the file type of the BytesIO object though, so this works
Why is this the best possible solution? Were any other approaches considered?
What are the regression risks?
Does this change require updates to documentation? If so, please file an issue here and include the link below.
Before submitting this PR, please make sure you have:
tests
python -m unittest
and verified all tests passruff format pyxform tests
andruff check pyxform tests
to lint code (I ran this and it updated all the files in the repo - I ran it only on the files I edited instead)