-
Notifications
You must be signed in to change notification settings - Fork 22
Enable Direct Python File Imports #78
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
Conversation
patham9
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thank you very much!
Only minor suggestion:
Please add the Python script to the ./examples folder then it is more self-contained, calling it python_import_file.py or so.
c34162c to
d6620a9
Compare
Thank you for your comment. Now I have added it. |
patham9
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two issues popped up:
load_metta_file(Path, _, '&self')should not be there. In main branch it isload_metta_file(Path, _, Space), else it can only import to&selfafter merging this PR.- The two ! cases in python_import.metta should be turned into
!(test (py-call ...) expectedOutput)each, else the test system sees the metta file as failing as it did not generate a test success output.
After these two are resolved I will be happy to merge it in!
UPDATE: since it is a weekend I decided to add these two adjustments myself to speed it up a bit.
Formatting consistency with rest of the project, and changed the load_metta_file back to Space. Signed-off-by: Patrick Hammer <[email protected]>
formatting consistency Signed-off-by: Patrick Hammer <[email protected]>
Added to test output. Signed-off-by: Patrick Hammer <[email protected]>
Signed-off-by: Patrick Hammer <[email protected]>
Overview
This PR is intended to enhance the
import!predicate insrc/metta.plto support direct importing of Python (.py) files. This allows PeTTa to load and utilize Python modules without needing separate setup steps or complex path management.Changes
src/metta.pl:import!to detect.pyextensions.sys.path, and import the module usingexamples/python_import_example.metta:Usage
You can now import Python scripts directly using their relative or absolute path:
Updated
import!Predicate insrc/metta.plFileto stringSFileand get working directoryBase.SFilehas.pyextension, resolve absolute pathPath, extract directoryDirand module nameModuleName, addDirtosys.path, and import the module..mettatoSFileand load as MeTTa file.