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 for --import xml.etree.ElementTree #39

Closed
simonw opened this issue Dec 6, 2021 · 2 comments
Closed

Support for --import xml.etree.ElementTree #39

simonw opened this issue Dec 6, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Dec 6, 2021

https://github.com/simonw/neededge-history/blob/main/v1.xml

This should work, but doesn't without a small change:

git-history file neededge.db v1.xml --id url --convert '
tree = xml.etree.ElementTree.fromstring(content)
return [site.attrib for site in tree.iter("site")]
' --import xml.etree.ElementTree

Originally posted by @simonw in #30 (comment)

@simonw simonw added the enhancement New feature or request label Dec 6, 2021
@simonw
Copy link
Owner Author

simonw commented Dec 6, 2021

Here's the fix that worked:

@@ -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)

@simonw
Copy link
Owner Author

simonw commented Dec 6, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant