Skip to content
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

Support --import xml.etree.ElementTree in sqlite-utils convert #351

Closed
simonw opened this issue Dec 7, 2021 · 1 comment
Closed

Support --import xml.etree.ElementTree in sqlite-utils convert #351

simonw opened this issue Dec 7, 2021 · 1 comment
Labels
cli-tool enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Dec 7, 2021

It's not possible to use a module that requires a nested import, such as xml.etree.ElementTree, at the moment. I found and fixed this bug in git-history, I should replicate that fix (and accompanying documentation) here: simonw/git-history#39

@simonw simonw added enhancement New feature or request cli-tool labels Dec 7, 2021
@simonw
Copy link
Owner Author

simonw commented Dec 7, 2021

The fix there was:

@@ -463,7 +473,7 @@ def compile_convert(convert, imports):
     locals = {}
     globals = {"json": json}
     for import_ in imports:
-        globals[import_] = __import__(import_)
+        globals[import_.split(".")[0]] = __import__(import_)
     exec(code_o, globals, locals)

With this example (needs to be modified here):

git-history file items.xml --convert '
tree = xml.etree.ElementTree.fromstring(content)
return [el.attrib for el in tree.iter("item")]
' --import xml.etree.ElementTree

@simonw simonw closed this as completed in 7a43af2 Dec 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli-tool enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant